public void testSkipToNextRow() {
    Configuration config = SupportConfigFactory.getConfiguration();
    config.addEventType("MyEvent", SupportRecogBean.class);
    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(config);
    epService.initialize();

    String[] fields = "a_string,b_string".split(",");
    String text =
        "select * from MyEvent.win:keepall() "
            + "match_recognize ("
            + "  measures A.theString as a_string, B.theString as b_string "
            + "  all matches "
            + "  after match skip to next row "
            + "  pattern (A B) "
            + "  define B as B.value > A.value"
            + ") "
            + "order by a_string, b_string";

    EPStatement stmt = epService.getEPAdministrator().createEPL(text);
    SupportUpdateListener listener = new SupportUpdateListener();
    stmt.addListener(listener);

    epService.getEPRuntime().sendEvent(new SupportRecogBean("E1", 5));
    epService.getEPRuntime().sendEvent(new SupportRecogBean("E2", 3));
    assertFalse(listener.isInvoked());
    assertFalse(stmt.iterator().hasNext());

    epService.getEPRuntime().sendEvent(new SupportRecogBean("E3", 6));
    EPAssertionUtil.assertPropsPerRow(
        listener.getAndResetLastNewData(), fields, new Object[][] {{"E2", "E3"}});
    EPAssertionUtil.assertPropsPerRow(stmt.iterator(), fields, new Object[][] {{"E2", "E3"}});

    epService.getEPRuntime().sendEvent(new SupportRecogBean("E4", 4));
    assertFalse(listener.isInvoked());
    EPAssertionUtil.assertPropsPerRow(stmt.iterator(), fields, new Object[][] {{"E2", "E3"}});

    epService.getEPRuntime().sendEvent(new SupportRecogBean("E5", 6));
    EPAssertionUtil.assertPropsPerRow(
        listener.getAndResetLastNewData(), fields, new Object[][] {{"E4", "E5"}});
    EPAssertionUtil.assertPropsPerRow(
        stmt.iterator(), fields, new Object[][] {{"E2", "E3"}, {"E4", "E5"}});

    epService.getEPRuntime().sendEvent(new SupportRecogBean("E6", 10));
    EPAssertionUtil.assertPropsPerRow(
        listener.getAndResetLastNewData(), fields, new Object[][] {{"E5", "E6"}});
    EPAssertionUtil.assertPropsPerRow(
        stmt.iterator(), fields, new Object[][] {{"E2", "E3"}, {"E4", "E5"}, {"E5", "E6"}});

    epService.getEPRuntime().sendEvent(new SupportRecogBean("E7", 9));
    epService.getEPRuntime().sendEvent(new SupportRecogBean("E8", 4));
    assertFalse(listener.isInvoked());
    EPAssertionUtil.assertPropsPerRow(
        stmt.iterator(), fields, new Object[][] {{"E2", "E3"}, {"E4", "E5"}, {"E5", "E6"}});

    stmt.stop();
  }
Ejemplo n.º 2
0
  public void testInsertIntoPlusPattern() {
    String stmtOneTxt =
        "insert into InZone "
            + "select 111 as statementId, mac, locationReportId "
            + "from "
            + SupportRFIDEvent.class.getName()
            + " "
            + "where mac in ('1','2','3') "
            + "and zoneID = '10'";
    EPStatement stmtOne = epService.getEPAdministrator().createEPL(stmtOneTxt);
    SupportUpdateListener listenerOne = new SupportUpdateListener();
    stmtOne.addListener(listenerOne);

    String stmtTwoTxt =
        "insert into OutOfZone "
            + "select 111 as statementId, mac, locationReportId "
            + "from "
            + SupportRFIDEvent.class.getName()
            + " "
            + "where mac in ('1','2','3') "
            + "and zoneID != '10'";
    EPStatement stmtTwo = epService.getEPAdministrator().createEPL(stmtTwoTxt);
    SupportUpdateListener listenerTwo = new SupportUpdateListener();
    stmtTwo.addListener(listenerTwo);

    String stmtThreeTxt =
        "select 111 as eventSpecId, A.locationReportId as locationReportId "
            + " from pattern [every A=InZone -> (timer:interval(1 sec) and not OutOfZone(mac=A.mac))]";
    EPStatement stmtThree = epService.getEPAdministrator().createEPL(stmtThreeTxt);
    SupportUpdateListener listener = new SupportUpdateListener();
    stmtThree.addListener(listener);

    // try the alert case with 1 event for the mac in question
    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(0));
    epService.getEPRuntime().sendEvent(new SupportRFIDEvent("LR1", "1", "10"));
    assertFalse(listener.isInvoked());
    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(1000));

    EventBean theEvent = listener.assertOneGetNewAndReset();
    assertEquals("LR1", theEvent.get("locationReportId"));

    listenerOne.reset();
    listenerTwo.reset();

    // try the alert case with 2 events for zone 10 within 1 second for the mac in question
    epService.getEPRuntime().sendEvent(new SupportRFIDEvent("LR2", "2", "10"));
    assertFalse(listener.isInvoked());
    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(1500));
    epService.getEPRuntime().sendEvent(new SupportRFIDEvent("LR3", "2", "10"));
    assertFalse(listener.isInvoked());
    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(2000));

    theEvent = listener.assertOneGetNewAndReset();
    assertEquals("LR2", theEvent.get("locationReportId"));
  }
Ejemplo n.º 3
0
  public void testEnabledDisableRuntime() {
    EPStatement[] statements = new EPStatement[5];
    Configuration config = getConfig(10000, 10000, true);
    epService = EPServiceProviderManager.getProvider("MyURI", config);
    epService.initialize();

    sendTimer(1000);

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

    statements[1] =
        epService
            .getEPAdministrator()
            .createEPL("select * from " + EngineMetric.class.getName(), "enginemetric");
    statements[1].addListener(listenerEngineMetric);

    statements[2] =
        epService
            .getEPAdministrator()
            .createEPL(
                "select * from SupportBean(intPrimitive=1).win:keepall() where MyMetricFunctions.takeCPUTime(longPrimitive)");
    sendEvent("E1", 1, cpuGoalOneNano);

    sendTimer(11000);
    assertTrue(listenerStmtMetric.getAndClearIsInvoked());
    assertTrue(listenerEngineMetric.getAndClearIsInvoked());

    epService.getEPAdministrator().getConfiguration().setMetricsReportingDisabled();
    sendEvent("E2", 2, cpuGoalOneNano);
    sendTimer(21000);
    assertFalse(listenerStmtMetric.getAndClearIsInvoked());
    assertFalse(listenerEngineMetric.getAndClearIsInvoked());

    sendTimer(31000);
    sendEvent("E3", 3, cpuGoalOneNano);
    assertFalse(listenerStmtMetric.getAndClearIsInvoked());
    assertFalse(listenerEngineMetric.getAndClearIsInvoked());

    epService.getEPAdministrator().getConfiguration().setMetricsReportingEnabled();
    sendEvent("E4", 4, cpuGoalOneNano);
    sendTimer(41000);
    assertTrue(listenerStmtMetric.getAndClearIsInvoked());
    assertTrue(listenerEngineMetric.getAndClearIsInvoked());

    statements[2].destroy();
    sendTimer(51000);
    assertTrue(listenerStmtMetric.isInvoked()); // metrics statements reported themselves
    assertTrue(listenerEngineMetric.isInvoked());
  }
Ejemplo n.º 4
0
  public void testWithOutputLimitAndSort() {
    // NOTICE: we are inserting the RSTREAM (removed events)
    String stmtText =
        "insert rstream into StockTicks(mySymbol, myPrice) "
            + "select symbol, price from "
            + SupportMarketDataBean.class.getName()
            + ".win:time(60) "
            + "output every 5 seconds "
            + "order by symbol asc";
    epService.getEPAdministrator().createEPL(stmtText);

    stmtText = "select mySymbol, sum(myPrice) as pricesum from StockTicks.win:length(100)";
    EPStatement statement = epService.getEPAdministrator().createEPL(stmtText);
    statement.addListener(feedListener);

    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(0));
    sendEvent("IBM", 50);
    sendEvent("CSC", 10);
    sendEvent("GE", 20);
    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(10 * 1000));
    sendEvent("DEF", 100);
    sendEvent("ABC", 11);
    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(20 * 1000));
    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(30 * 1000));
    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(40 * 1000));
    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(50 * 1000));
    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(55 * 1000));

    assertFalse(feedListener.isInvoked());
    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(60 * 1000));

    assertTrue(feedListener.isInvoked());
    assertEquals(3, feedListener.getNewDataList().size());
    assertEquals("CSC", feedListener.getNewDataList().get(0)[0].get("mySymbol"));
    assertEquals(10.0, feedListener.getNewDataList().get(0)[0].get("pricesum"));
    assertEquals("GE", feedListener.getNewDataList().get(1)[0].get("mySymbol"));
    assertEquals(30.0, feedListener.getNewDataList().get(1)[0].get("pricesum"));
    assertEquals("IBM", feedListener.getNewDataList().get(2)[0].get("mySymbol"));
    assertEquals(80.0, feedListener.getNewDataList().get(2)[0].get("pricesum"));
    feedListener.reset();

    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(65 * 1000));
    assertFalse(feedListener.isInvoked());

    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(70 * 1000));
    assertEquals("ABC", feedListener.getNewDataList().get(0)[0].get("mySymbol"));
    assertEquals(91.0, feedListener.getNewDataList().get(0)[0].get("pricesum"));
    assertEquals("DEF", feedListener.getNewDataList().get(1)[0].get("mySymbol"));
    assertEquals(191.0, feedListener.getNewDataList().get(1)[0].get("pricesum"));
  }
Ejemplo n.º 5
0
  private void runAssertion() {
    sendMapEvent("MapS0", "a", 1);
    assertFalse(listener.isInvoked());

    sendMapEvent("MapS1", "a", 2);
    EventBean theEvent = listener.assertOneGetNewAndReset();
    assertEquals("a", theEvent.get("S0.id"));
    assertEquals("a", theEvent.get("S1.id"));
    assertEquals(1, theEvent.get("S0.p00"));
    assertEquals(2, theEvent.get("S1.p00"));

    sendMapEvent("MapS1", "b", 3);
    sendMapEvent("MapS0", "c", 4);
    assertFalse(listener.isInvoked());
  }
  public void testLateStartIndex() {
    // prepare
    preloadData(false);

    // test join
    String eplJoin =
        "select * from SupportBean_S0 as s0 unidirectional, AWindow(p00='x') as aw where aw.id = s0.id";
    epService.getEPAdministrator().createEPL(eplJoin).addListener(listener);
    assertEquals(2, MyCountAccessEvent.getAndResetCountGetterCalled());

    epService.getEPRuntime().sendEvent(new SupportBean_S0(-1, "x"));
    assertTrue(listener.getAndClearIsInvoked());

    // test subquery no-index-share
    String eplSubqueryNoIndexShare =
        "select (select id from AWindow(p00='x') as aw where aw.id = s0.id) "
            + "from SupportBean_S0 as s0 unidirectional";
    epService.getEPAdministrator().createEPL(eplSubqueryNoIndexShare).addListener(listener);
    assertEquals(2, MyCountAccessEvent.getAndResetCountGetterCalled());

    epService.getEPRuntime().sendEvent(new SupportBean_S0(-1, "x"));

    // test subquery with index share
    epService.getEPAdministrator().destroyAllStatements();
    preloadData(true);

    String eplSubqueryWithIndexShare =
        "select (select id from AWindow(p00='x') as aw where aw.id = s0.id) "
            + "from SupportBean_S0 as s0 unidirectional";
    epService.getEPAdministrator().createEPL(eplSubqueryWithIndexShare).addListener(listener);
    assertEquals(2, MyCountAccessEvent.getAndResetCountGetterCalled());

    epService.getEPRuntime().sendEvent(new SupportBean_S0(-1, "x"));
    assertTrue(listener.isInvoked());
  }
  public void testAfterNextRow() {
    Configuration config = SupportConfigFactory.getConfiguration();
    config.addEventType("MyEvent", SupportRecogBean.class);
    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(config);
    epService.initialize();

    String[] fields = "a,b0,b1".split(",");
    String text =
        "select * from MyEvent.win:keepall() "
            + "match_recognize ("
            + "  measures A.theString as a, B[0].theString as b0, B[1].theString as b1"
            + "  AFTER MATCH SKIP TO NEXT ROW "
            + "  pattern (A B*) "
            + "  define "
            + "    A as A.theString like 'A%',"
            + "    B as B.theString like 'B%'"
            + ")";

    EPStatement stmt = epService.getEPAdministrator().createEPL(text);
    SupportUpdateListener listener = new SupportUpdateListener();
    stmt.addListener(listener);

    epService.getEPRuntime().sendEvent(new SupportRecogBean("A1", 1));
    EPAssertionUtil.assertPropsPerRow(
        listener.getAndResetLastNewData(), fields, new Object[][] {{"A1", null, null}});
    EPAssertionUtil.assertPropsPerRow(stmt.iterator(), fields, new Object[][] {{"A1", null, null}});

    // since the first match skipped past A, we do not match again
    epService.getEPRuntime().sendEvent(new SupportRecogBean("B1", 2));
    assertFalse(listener.isInvoked()); // incremental skips to next
    EPAssertionUtil.assertPropsPerRow(stmt.iterator(), fields, new Object[][] {{"A1", "B1", null}});
  }
Ejemplo n.º 8
0
  public void testEngineMetrics() {
    epService = EPServiceProviderManager.getProvider("MyURI", getConfig(10000, -1, true));
    epService.initialize();

    String[] engineFields =
        "engineURI,timestamp,inputCount,inputCountDelta,scheduleDepth".split(",");
    sendTimer(1000);

    String text = "select * from " + EngineMetric.class.getName();
    EPStatement stmt = epService.getEPAdministrator().createEPL(text);
    stmt.addListener(listener);

    epService.getEPRuntime().sendEvent(new SupportBean());

    sendTimer(10999);
    assertFalse(listener.isInvoked());

    epService.getEPAdministrator().createEPL("select * from pattern[timer:interval(5 sec)]");

    sendTimer(11000);
    EventBean theEvent = listener.assertOneGetNewAndReset();
    EPAssertionUtil.assertProps(theEvent, engineFields, new Object[] {"MyURI", 11000L, 1L, 1L, 1L});

    epService.getEPRuntime().sendEvent(new SupportBean());
    epService.getEPRuntime().sendEvent(new SupportBean());

    sendTimer(20000);
    sendTimer(21000);
    theEvent = listener.assertOneGetNewAndReset();
    EPAssertionUtil.assertProps(theEvent, engineFields, new Object[] {"MyURI", 21000L, 4L, 3L, 0L});
  }
Ejemplo n.º 9
0
  public void testSchemaXMLWSchemaWithAll() throws Exception {
    Configuration config = SupportConfigFactory.getConfiguration();
    ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM();
    eventTypeMeta.setRootElementName("event-page-visit");
    String schemaUri =
        TestSchemaXMLEvent.class
            .getClassLoader()
            .getResource(CLASSLOADER_SCHEMA_WITH_ALL_URI)
            .toString();
    eventTypeMeta.setSchemaResource(schemaUri);
    eventTypeMeta.addNamespacePrefix("ss", "samples:schemas:simpleSchemaWithAll");
    eventTypeMeta.addXPathProperty("url", "/ss:event-page-visit/ss:url", XPathConstants.STRING);
    config.addEventType("PageVisitEvent", eventTypeMeta);

    epService = EPServiceProviderManager.getProvider("TestSchemaXML", config);
    epService.initialize();
    updateListener = new SupportUpdateListener();

    // url='page4'
    String text = "select a.url as sesja from pattern [ every a=PageVisitEvent(url='page1') ]";
    EPStatement stmt = epService.getEPAdministrator().createEPL(text);
    stmt.addListener(updateListener);

    SupportXML.sendEvent(
        epService.getEPRuntime(),
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<event-page-visit xmlns=\"samples:schemas:simpleSchemaWithAll\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"samples:schemas:simpleSchemaWithAll simpleSchemaWithAll.xsd\">\n"
            + "<url>page1</url>"
            + "</event-page-visit>");
    EventBean theEvent = updateListener.getLastNewData()[0];
    assertEquals("page1", theEvent.get("sesja"));
    updateListener.reset();

    SupportXML.sendEvent(
        epService.getEPRuntime(),
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<event-page-visit xmlns=\"samples:schemas:simpleSchemaWithAll\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"samples:schemas:simpleSchemaWithAll simpleSchemaWithAll.xsd\">\n"
            + "<url>page2</url>"
            + "</event-page-visit>");
    assertFalse(updateListener.isInvoked());

    EventType type =
        epService.getEPAdministrator().createEPL("select * from PageVisitEvent").getEventType();
    EPAssertionUtil.assertEqualsAnyOrder(
        new Object[] {
          new EventPropertyDescriptor(
              "sessionId", Node.class, null, false, false, false, false, true),
          new EventPropertyDescriptor(
              "customerId", Node.class, null, false, false, false, false, true),
          new EventPropertyDescriptor("url", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor("method", Node.class, null, false, false, false, false, true),
        },
        type.getPropertyDescriptors());
  }
  public void testVariableMoreThenOnce() {
    Configuration config = SupportConfigFactory.getConfiguration();
    config.addEventType("MyEvent", SupportRecogBean.class);
    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(config);
    epService.initialize();

    String[] fields = "a0,b,a1".split(",");
    String text =
        "select * from MyEvent.win:keepall() "
            + "match_recognize ("
            + "  measures A[0].theString as a0, B.theString as b, A[1].theString as a1 "
            + "  all matches "
            + "  after match skip to next row "
            + "  pattern ( A B A ) "
            + "  define "
            + "    A as (A.value = 1),"
            + "    B as (B.value = 2)"
            + ")";

    EPStatement stmt = epService.getEPAdministrator().createEPL(text);
    SupportUpdateListener listener = new SupportUpdateListener();
    stmt.addListener(listener);

    epService.getEPRuntime().sendEvent(new SupportRecogBean("E1", 3));
    epService.getEPRuntime().sendEvent(new SupportRecogBean("E2", 1));
    epService.getEPRuntime().sendEvent(new SupportRecogBean("E3", 2));
    epService.getEPRuntime().sendEvent(new SupportRecogBean("E4", 5));
    epService.getEPRuntime().sendEvent(new SupportRecogBean("E5", 1));
    epService.getEPRuntime().sendEvent(new SupportRecogBean("E6", 2));
    assertFalse(listener.isInvoked());
    assertFalse(stmt.iterator().hasNext());

    epService.getEPRuntime().sendEvent(new SupportRecogBean("E7", 1));
    EPAssertionUtil.assertPropsPerRow(
        listener.getAndResetLastNewData(), fields, new Object[][] {{"E5", "E6", "E7"}});
    EPAssertionUtil.assertPropsPerRow(stmt.iterator(), fields, new Object[][] {{"E5", "E6", "E7"}});

    epService.getEPRuntime().sendEvent(new SupportRecogBean("E8", 2));
    epService.getEPRuntime().sendEvent(new SupportRecogBean("E9", 1));
    EPAssertionUtil.assertPropsPerRow(
        listener.getAndResetLastNewData(), fields, new Object[][] {{"E7", "E8", "E9"}});
    EPAssertionUtil.assertPropsPerRow(
        stmt.iterator(), fields, new Object[][] {{"E5", "E6", "E7"}, {"E7", "E8", "E9"}});
  }
  public void testNestedPojo() {
    Pair<String[], Object[]> pair = getTestDefTwo();
    EPServiceProvider epService =
        getEngineInitialized("NestedObjectArr", pair.getFirst(), pair.getSecond());

    String statementText =
        "select "
            + "simple, object, nodefmap, map, "
            + "object.id as a1, nodefmap.key1? as a2, nodefmap.key2? as a3, nodefmap.key3?.key4 as a4, "
            + "map.objectOne as b1, map.simpleOne as b2, map.nodefmapOne.key2? as b3, map.mapOne.simpleTwo? as b4, "
            + "map.objectOne.indexed[1] as c1, map.objectOne.nested.nestedValue as c2,"
            + "map.mapOne.simpleTwo as d1, map.mapOne.objectTwo as d2, map.mapOne.nodefmapTwo as d3, "
            + "map.mapOne.mapTwo as e1, map.mapOne.mapTwo.simpleThree as e2, map.mapOne.mapTwo.objectThree as e3, "
            + "map.mapOne.objectTwo.array[1].mapped('1ma').value as f1, map.mapOne.mapTwo.objectThree.id as f2"
            + " from NestedObjectArr";
    EPStatement statement = epService.getEPAdministrator().createEPL(statementText);
    SupportUpdateListener listener = new SupportUpdateListener();
    statement.addListener(listener);

    Object[] testdata = getTestDataTwo();
    epService.getEPRuntime().sendEvent(testdata, "NestedObjectArr");

    // test all properties exist
    EventBean received = listener.assertOneGetNewAndReset();
    EPAssertionUtil.assertProps(
        received,
        "simple,object,nodefmap,map".split(","),
        new Object[] {"abc", new SupportBean_A("A1"), testdata[2], testdata[3]});
    EPAssertionUtil.assertProps(
        received, "a1,a2,a3,a4".split(","), new Object[] {"A1", "val1", null, null});
    EPAssertionUtil.assertProps(
        received,
        "b1,b2,b3,b4".split(","),
        new Object[] {getNestedKey(testdata, 3, "objectOne"), 10, "val2", 300});
    EPAssertionUtil.assertProps(received, "c1,c2".split(","), new Object[] {2, "nestedValue"});
    EPAssertionUtil.assertProps(
        received,
        "d1,d2,d3".split(","),
        new Object[] {
          300,
          getNestedKey(testdata, 3, "mapOne", "objectTwo"),
          getNestedKey(testdata, 3, "mapOne", "nodefmapTwo")
        });
    EPAssertionUtil.assertProps(
        received,
        "e1,e2,e3".split(","),
        new Object[] {
          getNestedKey(testdata, 3, "mapOne", "mapTwo"), 4000L, new SupportBean_B("B1")
        });
    EPAssertionUtil.assertProps(received, "f1,f2".split(","), new Object[] {"1ma0", "B1"});

    // assert type info
    EPStatement stmt = epService.getEPAdministrator().createEPL(("select * from NestedObjectArr"));
    EventType eventType = stmt.getEventType();

    String[] propertiesReceived = eventType.getPropertyNames();
    String[] propertiesExpected = new String[] {"simple", "object", "nodefmap", "map"};
    EPAssertionUtil.assertEqualsAnyOrder(propertiesReceived, propertiesExpected);
    assertEquals(String.class, eventType.getPropertyType("simple"));
    assertEquals(Map.class, eventType.getPropertyType("map"));
    assertEquals(Map.class, eventType.getPropertyType("nodefmap"));
    assertEquals(SupportBean_A.class, eventType.getPropertyType("object"));

    assertNull(eventType.getPropertyType("map.mapOne.simpleOne"));

    // nested POJO with generic return type
    listener.reset();
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("MyNested", new String[] {"bean"}, new Object[] {MyNested.class});
    EPStatement stmtTwo =
        epService
            .getEPAdministrator()
            .createEPL("select * from MyNested(bean.insides.anyOf(i=>id = 'A'))");
    stmtTwo.addListener(listener);

    epService
        .getEPRuntime()
        .sendEvent(
            new Object[] {new MyNested(Arrays.asList(new MyInside[] {new MyInside("A")}))},
            "MyNested");
    assertTrue(listener.isInvoked());
  }
Ejemplo n.º 12
0
  public void testStatementMetrics() {
    Configuration config = getConfig(-1, -1, true);

    // report on all statements every 10 seconds
    ConfigurationMetricsReporting.StmtGroupMetrics configOne =
        new ConfigurationMetricsReporting.StmtGroupMetrics();
    configOne.setInterval(10000);
    configOne.addIncludeLike("%cpuStmt%");
    configOne.addIncludeLike("%wallStmt%");
    config.getEngineDefaults().getMetricsReporting().addStmtGroup("nonmetrics", configOne);

    // exclude metrics themselves from reporting
    ConfigurationMetricsReporting.StmtGroupMetrics configTwo =
        new ConfigurationMetricsReporting.StmtGroupMetrics();
    configTwo.setInterval(-1);
    configOne.addExcludeLike("%metrics%");
    config.getEngineDefaults().getMetricsReporting().addStmtGroup("metrics", configTwo);

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

    sendTimer(1000);

    EPStatement[] statements = new EPStatement[5];
    statements[0] =
        epService
            .getEPAdministrator()
            .createEPL("select * from " + StatementMetric.class.getName(), "stmt_metrics");
    statements[0].addListener(listener);

    statements[1] =
        epService
            .getEPAdministrator()
            .createEPL(
                "select * from SupportBean(intPrimitive=1).win:keepall() where MyMetricFunctions.takeCPUTime(longPrimitive)",
                "cpuStmtOne");
    statements[1].addListener(listenerTwo);
    statements[2] =
        epService
            .getEPAdministrator()
            .createEPL(
                "select * from SupportBean(intPrimitive=2).win:keepall() where MyMetricFunctions.takeCPUTime(longPrimitive)",
                "cpuStmtTwo");
    statements[2].addListener(listenerTwo);
    statements[3] =
        epService
            .getEPAdministrator()
            .createEPL(
                "select * from SupportBean(intPrimitive=3).win:keepall() where MyMetricFunctions.takeWallTime(longPrimitive)",
                "wallStmtThree");
    statements[3].addListener(listenerTwo);
    statements[4] =
        epService
            .getEPAdministrator()
            .createEPL(
                "select * from SupportBean(intPrimitive=4).win:keepall() where MyMetricFunctions.takeWallTime(longPrimitive)",
                "wallStmtFour");
    statements[4].addListener(listenerTwo);

    sendEvent("E1", 1, cpuGoalOneNano);
    sendEvent("E2", 2, cpuGoalTwoNano);
    sendEvent("E3", 3, wallGoalOneMsec);
    sendEvent("E4", 4, wallGoalTwoMsec);

    sendTimer(10999);
    assertFalse(listener.isInvoked());

    sendTimer(11000);
    runAssertion(11000);

    sendEvent("E1", 1, cpuGoalOneNano);
    sendEvent("E2", 2, cpuGoalTwoNano);
    sendEvent("E3", 3, wallGoalOneMsec);
    sendEvent("E4", 4, wallGoalTwoMsec);

    sendTimer(21000);
    runAssertion(21000);

    // destroy all application stmts
    for (int i = 1; i < 5; i++) {
      statements[i].destroy();
    }
    sendTimer(31000);
    assertFalse(listener.isInvoked());
  }
Ejemplo n.º 13
0
  public void testStatementGroups() {
    Configuration config = getConfig(-1, 7000, true);

    ConfigurationMetricsReporting.StmtGroupMetrics groupOne =
        new ConfigurationMetricsReporting.StmtGroupMetrics();
    groupOne.setInterval(8000);
    groupOne.addIncludeLike("%GroupOne%");
    groupOne.setReportInactive(true);
    config.getEngineDefaults().getMetricsReporting().addStmtGroup("GroupOneStatements", groupOne);

    ConfigurationMetricsReporting.StmtGroupMetrics groupTwo =
        new ConfigurationMetricsReporting.StmtGroupMetrics();
    groupTwo.setInterval(6000);
    groupTwo.setDefaultInclude(true);
    groupTwo.addExcludeLike("%Default%");
    groupTwo.addExcludeLike("%Metrics%");
    config
        .getEngineDefaults()
        .getMetricsReporting()
        .addStmtGroup("GroupTwoNonDefaultStatements", groupTwo);

    ConfigurationMetricsReporting.StmtGroupMetrics groupThree =
        new ConfigurationMetricsReporting.StmtGroupMetrics();
    groupThree.setInterval(-1);
    groupThree.addIncludeLike("%Metrics%");
    config.getEngineDefaults().getMetricsReporting().addStmtGroup("MetricsStatements", groupThree);

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

    sendTimer(0);

    epService
        .getEPAdministrator()
        .createEPL("select * from SupportBean(intPrimitive = 1).win:keepall()", "GroupOne");
    EPStatement stmt =
        epService
            .getEPAdministrator()
            .createEPL("select * from SupportBean(intPrimitive = 2).win:keepall()", "GroupTwo");
    stmt.setSubscriber(new SupportSubscriber());
    epService
        .getEPAdministrator()
        .createEPL(
            "select * from SupportBean(intPrimitive = 3).win:keepall()", "Default"); // no listener

    stmt =
        epService
            .getEPAdministrator()
            .createEPL("select * from " + StatementMetric.class.getName(), "StmtMetrics");
    stmt.addListener(listener);

    sendTimer(6000);
    sendTimer(7000);
    assertFalse(listener.isInvoked());

    sendTimer(8000);
    String[] fields = "statementName,numOutputIStream,numInput".split(",");
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"GroupOne", 0L, 0L});

    sendTimer(12000);
    sendTimer(14000);
    sendTimer(15999);
    assertFalse(listener.isInvoked());

    sendTimer(16000);
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"GroupOne", 0L, 0L});

    // should report as groupTwo
    epService.getEPRuntime().sendEvent(new SupportBean("E1", 2));
    sendTimer(17999);
    assertFalse(listener.isInvoked());

    sendTimer(18000);
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"GroupTwo", 1L, 1L});

    // should report as groupTwo
    epService.getEPRuntime().sendEvent(new SupportBean("E1", 3));
    sendTimer(20999);
    assertFalse(listener.isInvoked());

    sendTimer(21000);
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"Default", 0L, 1L});

    // turn off group 1
    epService
        .getEPAdministrator()
        .getConfiguration()
        .setMetricsReportingInterval("GroupOneStatements", -1);
    sendTimer(24000);
    assertFalse(listener.isInvoked());

    // turn on group 1
    epService
        .getEPAdministrator()
        .getConfiguration()
        .setMetricsReportingInterval("GroupOneStatements", 1000);
    sendTimer(25000);
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"GroupOne", 0L, 0L});
  }