Exemplo n.º 1
0
  public void testTopLevelReadUnGrouped() {
    epService.getEPAdministrator().getConfiguration().addEventType(AggBean.class);
    epService.getEPAdministrator().createEPL("create objectarray schema MyEvent(c0 int)");
    epService
        .getEPAdministrator()
        .createEPL(
            "create table windowAndTotal ("
                + "thewindow window(*) @type(MyEvent), thetotal sum(int))");
    epService
        .getEPAdministrator()
        .createEPL(
            "into table windowAndTotal "
                + "select window(*) as thewindow, sum(c0) as thetotal from MyEvent.win:length(2)");

    EPStatement stmt =
        epService
            .getEPAdministrator()
            .createEPL("select windowAndTotal as val0 from SupportBean_S0");
    stmt.addListener(listener);

    Object[] e1 = new Object[] {10};
    epService.getEPRuntime().sendEvent(e1, "MyEvent");

    String[] fieldsInner = "thewindow,thetotal".split(",");
    epService.getEPRuntime().sendEvent(new SupportBean_S0(0));
    EPAssertionUtil.assertPropsMap(
        (Map) listener.assertOneGetNewAndReset().get("val0"), fieldsInner, new Object[][] {e1}, 10);

    Object[] e2 = new Object[] {20};
    epService.getEPRuntime().sendEvent(e2, "MyEvent");

    epService.getEPRuntime().sendEvent(new SupportBean_S0(1));
    EPAssertionUtil.assertPropsMap(
        (Map) listener.assertOneGetNewAndReset().get("val0"),
        fieldsInner,
        new Object[][] {e1, e2},
        30);

    Object[] e3 = new Object[] {30};
    epService.getEPRuntime().sendEvent(e3, "MyEvent");

    epService.getEPRuntime().sendEvent(new SupportBean_S0(2));
    EPAssertionUtil.assertPropsMap(
        (Map) listener.assertOneGetNewAndReset().get("val0"),
        fieldsInner,
        new Object[][] {e2, e3},
        50);

    // test typable output
    stmt.destroy();
    EPStatement stmtConvert =
        epService
            .getEPAdministrator()
            .createEPL("insert into AggBean select windowAndTotal as val0 from SupportBean_S0");
    stmtConvert.addListener(listener);

    epService.getEPRuntime().sendEvent(new SupportBean_S0(2));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(),
        "val0.thewindow,val0.thetotal".split(","),
        new Object[] {new Object[][] {e2, e3}, 50});
  }
Exemplo n.º 2
0
  private void runAssertionTopLevelReadGrouped2Keys(boolean soda) {
    SupportModelHelper.createByCompileOrParse(
        epService, soda, "create objectarray schema MyEvent as (c0 int, c1 string, c2 int)");
    SupportModelHelper.createByCompileOrParse(
        epService,
        soda,
        "create table windowAndTotal ("
            + "keyi int primary key, keys string primary key, thewindow window(*) @type('MyEvent'), thetotal sum(int))");
    SupportModelHelper.createByCompileOrParse(
        epService,
        soda,
        "into table windowAndTotal "
            + "select window(*) as thewindow, sum(c2) as thetotal from MyEvent.win:length(2) group by c0, c1");

    EPStatement stmtSelect =
        SupportModelHelper.createByCompileOrParse(
            epService, soda, "select windowAndTotal[id,p00] as val0 from SupportBean_S0");
    stmtSelect.addListener(listener);
    assertTopLevelTypeInfo(stmtSelect);

    Object[] e1 = new Object[] {10, "G1", 100};
    epService.getEPRuntime().sendEvent(e1, "MyEvent");

    String[] fieldsInner = "thewindow,thetotal".split(",");
    epService.getEPRuntime().sendEvent(new SupportBean_S0(10, "G1"));
    EPAssertionUtil.assertPropsMap(
        (Map) listener.assertOneGetNewAndReset().get("val0"),
        fieldsInner,
        new Object[][] {e1},
        100);

    Object[] e2 = new Object[] {20, "G2", 200};
    epService.getEPRuntime().sendEvent(e2, "MyEvent");

    epService.getEPRuntime().sendEvent(new SupportBean_S0(20, "G2"));
    EPAssertionUtil.assertPropsMap(
        (Map) listener.assertOneGetNewAndReset().get("val0"),
        fieldsInner,
        new Object[][] {e2},
        200);

    Object[] e3 = new Object[] {20, "G2", 300};
    epService.getEPRuntime().sendEvent(e3, "MyEvent");

    epService.getEPRuntime().sendEvent(new SupportBean_S0(10, "G1"));
    EPAssertionUtil.assertPropsMap(
        (Map) listener.assertOneGetNewAndReset().get("val0"), fieldsInner, null, null);
    epService.getEPRuntime().sendEvent(new SupportBean_S0(20, "G2"));
    EPAssertionUtil.assertPropsMap(
        (Map) listener.assertOneGetNewAndReset().get("val0"),
        fieldsInner,
        new Object[][] {e2, e3},
        500);

    // test typable output
    stmtSelect.destroy();
    EPStatement stmtConvert =
        epService
            .getEPAdministrator()
            .createEPL(
                "insert into AggBean select windowAndTotal[20, 'G2'] as val0 from SupportBean_S0");
    stmtConvert.addListener(listener);

    epService.getEPRuntime().sendEvent(new SupportBean_S0(0));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(),
        "val0.thewindow,val0.thetotal".split(","),
        new Object[] {new Object[][] {e2, e3}, 500});

    epService.getEPAdministrator().destroyAllStatements();
  }