Ejemplo n.º 1
0
  private void runAssertion(long timestamp) {
    String[] fields = "engineURI,statementName".split(",");

    assertEquals(4, listener.getNewDataList().size());
    EventBean[] received = listener.getNewDataListFlattened();

    EPAssertionUtil.assertProps(received[0], fields, new Object[] {"MyURI", "cpuStmtOne"});
    EPAssertionUtil.assertProps(received[1], fields, new Object[] {"MyURI", "cpuStmtTwo"});
    EPAssertionUtil.assertProps(received[2], fields, new Object[] {"MyURI", "wallStmtThree"});
    EPAssertionUtil.assertProps(received[3], fields, new Object[] {"MyURI", "wallStmtFour"});

    long cpuOne = (Long) received[0].get("cpuTime");
    long cpuTwo = (Long) received[1].get("cpuTime");
    long wallOne = (Long) received[2].get("wallTime");
    long wallTwo = (Long) received[3].get("wallTime");

    assertTrue("cpuOne=" + cpuOne, cpuOne > cpuGoalOneNano);
    assertTrue("cpuTwo=" + cpuTwo, cpuTwo > cpuGoalTwoNano);
    assertTrue("wallOne=" + wallOne, (wallOne + 50) > wallGoalOneMsec);
    assertTrue("wallTwo=" + wallTwo, (wallTwo + 50) > wallGoalTwoMsec);

    for (int i = 0; i < 4; i++) {
      assertEquals(1L, received[i].get("numOutputIStream"));
      assertEquals(0L, received[i].get("numOutputRStream"));
      assertEquals(timestamp, received[i].get("timestamp"));
    }

    listener.reset();
  }
Ejemplo n.º 2
0
  public void testNamedWindowAndViewShare() throws Exception {
    epService = EPServiceProviderManager.getDefaultProvider(getConfig(-1, 1000, false));
    epService.initialize();

    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(0));
    epService
        .getEPAdministrator()
        .createEPL(
            "@Name('0') create schema StatementMetric as " + StatementMetric.class.getName());
    epService
        .getEPAdministrator()
        .createEPL(
            "@Name('A') create window MyWindow.std:lastevent() as select * from SupportBean");
    epService
        .getEPAdministrator()
        .createEPL("@Name('B1') insert into MyWindow select * from SupportBean");
    epService
        .getEPAdministrator()
        .createEPL("@Name('B2') insert into MyWindow select * from SupportBean");
    epService.getEPAdministrator().createEPL("@Name('C') select sum(intPrimitive) from MyWindow");
    epService
        .getEPAdministrator()
        .createEPL("@Name('D') select sum(w1.intPrimitive) from MyWindow w1, MyWindow w2");

    String appModuleTwo =
        "@Name('W') create window SupportBeanWindow.win:keepall() as SupportBean;"
            + ""
            + "@Name('M') on SupportBean oe\n"
            + "  merge SupportBeanWindow pw\n"
            + "  where pw.theString = oe.theString\n"
            + "  when not matched \n"
            + "    then insert select *\n"
            + "  when matched and oe.intPrimitive=1\n"
            + "    then delete\n"
            + "  when matched\n"
            + "    then update set pw.intPrimitive = oe.intPrimitive";
    epService.getEPAdministrator().getDeploymentAdmin().parseDeploy(appModuleTwo, null, null, null);

    EPStatement stmt =
        epService.getEPAdministrator().createEPL("@Name('X') select * from StatementMetric");
    stmt.addListener(listener);
    String fields[] = "statementName,numInput".split(",");

    epService.getEPRuntime().sendEvent(new SupportBean("E1", 1));
    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(1000));
    EventBean[] received =
        ArrayHandlingUtil.reorder("statementName", listener.getNewDataListFlattened());
    for (EventBean theEvent : received) {
      System.out.println(theEvent.get("statementName") + " = " + theEvent.get("numInput"));
    }
    EPAssertionUtil.assertPropsPerRow(
        received,
        fields,
        new Object[][] {
          {"A", 2L}, {"B1", 1L}, {"B2", 1L}, {"C", 2L}, {"D", 2L}, {"M", 1L}, {"W", 1L}
        });

    /* Comment-in for printout.
    for (int i = 0; i < received.length; i++) {
        EventBean event = received[i];
        System.out.println(event.get("statementName") + " " + event.get("wallTime") + " " + event.get("numInput"));
    }
    */
  }
Ejemplo n.º 3
0
  public void testEnabledDisableStatement() {
    String[] fields = new String[] {"statementName"};
    EPStatement[] statements = new EPStatement[5];
    Configuration config = getConfig(-1, 10000, true);

    ConfigurationMetricsReporting.StmtGroupMetrics configOne =
        new ConfigurationMetricsReporting.StmtGroupMetrics();
    configOne.setInterval(-1);
    configOne.addIncludeLike("%@METRIC%");
    config.getEngineDefaults().getMetricsReporting().addStmtGroup("metrics", configOne);

    epService = EPServiceProviderManager.getProvider("MyURI", config);
    epService.initialize();

    sendTimer(1000);

    statements[0] =
        epService
            .getEPAdministrator()
            .createEPL("select * from " + StatementMetric.class.getName(), "MyStatement@METRIC");
    statements[0].addListener(listenerStmtMetric);

    statements[1] =
        epService
            .getEPAdministrator()
            .createEPL(
                "select * from SupportBean(intPrimitive=1).win:keepall() where 2=2", "stmtone");
    sendEvent("E1", 1, cpuGoalOneNano);
    statements[2] =
        epService
            .getEPAdministrator()
            .createEPL(
                "select * from SupportBean(intPrimitive>0).std:lastevent() where 1=1", "stmttwo");
    sendEvent("E2", 1, cpuGoalOneNano);

    sendTimer(11000);
    EPAssertionUtil.assertPropsPerRow(
        listenerStmtMetric.getNewDataListFlattened(),
        fields,
        new Object[][] {{"stmtone"}, {"stmttwo"}});
    listenerStmtMetric.reset();

    sendEvent("E1", 1, cpuGoalOneNano);
    sendTimer(21000);
    EPAssertionUtil.assertPropsPerRow(
        listenerStmtMetric.getNewDataListFlattened(),
        fields,
        new Object[][] {{"stmtone"}, {"stmttwo"}});
    listenerStmtMetric.reset();

    epService.getEPAdministrator().getConfiguration().setMetricsReportingStmtDisabled("stmtone");

    sendEvent("E1", 1, cpuGoalOneNano);
    sendTimer(31000);
    EPAssertionUtil.assertPropsPerRow(
        listenerStmtMetric.getNewDataListFlattened(), fields, new Object[][] {{"stmttwo"}});
    listenerStmtMetric.reset();

    epService.getEPAdministrator().getConfiguration().setMetricsReportingStmtEnabled("stmtone");
    epService.getEPAdministrator().getConfiguration().setMetricsReportingStmtDisabled("stmttwo");

    sendEvent("E1", 1, cpuGoalOneNano);
    sendTimer(41000);
    EPAssertionUtil.assertPropsPerRow(
        listenerStmtMetric.getNewDataListFlattened(), fields, new Object[][] {{"stmtone"}});
    listenerStmtMetric.reset();
  }