Ejemplo n.º 1
0
  public void testJoinSelect() {
    String eventA = SupportBean.class.getName();
    String eventB = SupportBean.class.getName();

    String joinStatement =
        "select s0.doubleBoxed, s1.intPrimitive*s1.intBoxed/2.0 as div from "
            + eventA
            + "(theString='s0').win:length(3) as s0,"
            + eventB
            + "(theString='s1').win:length(3) as s1"
            + " where s0.doubleBoxed = s1.doubleBoxed";

    EPStatement joinView = epService.getEPAdministrator().createEPL(joinStatement);
    joinView.addListener(updateListener);

    EventType result = joinView.getEventType();
    assertEquals(Double.class, result.getPropertyType("s0.doubleBoxed"));
    assertEquals(Double.class, result.getPropertyType("div"));
    assertEquals(2, joinView.getEventType().getPropertyNames().length);

    assertNull(updateListener.getLastNewData());

    sendEvent("s0", 1, 4, 5);
    sendEvent("s1", 1, 3, 2);

    EventBean[] newEvents = updateListener.getLastNewData();
    assertEquals(1d, newEvents[0].get("s0.doubleBoxed"));
    assertEquals(3d, newEvents[0].get("div"));

    Iterator<EventBean> iterator = joinView.iterator();
    EventBean theEvent = iterator.next();
    assertEquals(1d, theEvent.get("s0.doubleBoxed"));
    assertEquals(3d, theEvent.get("div"));
  }
Ejemplo n.º 2
0
 private void assertReceivedFeed(int delta, int product) {
   assertEquals(1, feedListener.getNewDataList().size());
   assertEquals(1, feedListener.getLastNewData().length);
   assertEquals(delta, feedListener.getLastNewData()[0].get("delta"));
   assertEquals(product, feedListener.getLastNewData()[0].get("product"));
   feedListener.reset();
 }
Ejemplo n.º 3
0
  public void testVariantOneWildcard() {
    String stmtText =
        "insert into Event_1 (delta, product) "
            + "select * from "
            + SupportBean.class.getName()
            + ".win:length(100)";

    try {
      epService.getEPAdministrator().createEPL(stmtText);
      fail();
    } catch (EPStatementException ex) {
      // Expected
    }

    // assert statement-type reference
    EPServiceProviderSPI spi = (EPServiceProviderSPI) epService;
    assertFalse(spi.getStatementEventTypeRef().isInUse("Event_1"));

    // test insert wildcard to wildcard
    epService.getEPAdministrator().getConfiguration().addEventType(SupportBean.class);
    SupportUpdateListener listener = new SupportUpdateListener();

    String stmtSelectText = "insert into ABCStream select * from SupportBean";
    EPStatement stmtSelect =
        epService.getEPAdministrator().createEPL(stmtSelectText, "resilient i0");
    stmtSelect.addListener(listener);
    assertTrue(stmtSelect.getEventType() instanceof BeanEventType);

    epService.getEPRuntime().sendEvent(new SupportBean("E1", 1));
    assertEquals("E1", listener.assertOneGetNew().get("theString"));
    assertTrue(listener.assertOneGetNew() instanceof BeanEventBean);
  }
  private void runAssertionSingleRowFunc(Object[] rowValues) {
    // try join passing of params
    String eplJoin =
        "select "
            + this.getClass().getName()
            + ".myServiceEventBean(mt) as c0, "
            + this.getClass().getName()
            + ".myServiceObjectArray(mt) as c1 "
            + "from SupportBean_S2, MyTable as mt";
    EPStatement stmtJoin = epService.getEPAdministrator().createEPL(eplJoin);
    stmtJoin.addListener(listener);

    epService.getEPRuntime().sendEvent(new SupportBean_S2(0));
    EventBean result = listener.assertOneGetNewAndReset();
    assertEventUnd(result.get("c0"), rowValues);
    assertEventUnd(result.get("c1"), rowValues);
    stmtJoin.destroy();

    // try subquery
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addPlugInSingleRowFunction(
            "pluginServiceEventBean", this.getClass().getName(), "myServiceEventBean");
    String eplSubquery =
        "select (select pluginServiceEventBean(mt) from MyTable as mt) as c0 "
            + "from SupportBean_S2";
    EPStatement stmtSubquery = epService.getEPAdministrator().createEPL(eplSubquery);
    stmtSubquery.addListener(listener);

    epService.getEPRuntime().sendEvent(new SupportBean_S2(0));
    result = listener.assertOneGetNewAndReset();
    assertEventUnd(result.get("c0"), rowValues);
    stmtSubquery.destroy();
  }
Ejemplo n.º 5
0
  public void testGroupedThreeKeyNoContext() throws Exception {
    String eplDeclare =
        "create table varTotal (key0 string primary key, key1 int primary key,"
            + "key2 long primary key, total sum(double), cnt count(*))";
    epService.getEPAdministrator().createEPL(eplDeclare);

    String eplBind =
        "into table varTotal "
            + "select sum(doublePrimitive) as total, count(*) as cnt "
            + "from SupportBean group by theString, intPrimitive, longPrimitive";
    epService.getEPAdministrator().createEPL(eplBind);

    String[] fields = "c0,c1".split(",");
    String eplUse =
        "select varTotal[p00, id, 100L].total as c0, varTotal[p00, id, 100L].cnt as c1 from SupportBean_S0";
    epService.getEPAdministrator().createEPL(eplUse).addListener(listener);

    makeSendBean("E1", 10, 100, 1000);

    epService.getEPRuntime().sendEvent(new SupportBean_S0(10, "E1"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {1000.0, 1L});

    makeSendBean("E1", 10, 100, 1001);

    epService.getEPRuntime().sendEvent(new SupportBean_S0(10, "E1"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {2001.0, 2L});
  }
  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());
  }
Ejemplo n.º 7
0
  public void testCorrel() {
    // further math tests can be found in the view unit test
    EPAdministrator admin = epService.getEPAdministrator();
    admin.getConfiguration().addEventType("Market", SupportMarketDataBean.class);
    EPStatement statement =
        admin.createEPL(
            "select * from Market.std:groupwin(symbol).win:length(1000000).stat:correl(price, volume, feed)");
    SupportUpdateListener listener = new SupportUpdateListener();
    statement.addListener(listener);

    assertEquals(Double.class, statement.getEventType().getPropertyType("correlation"));

    String[] fields = new String[] {"symbol", "correlation", "feed"};

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("ABC", 10.0, 1000L, "f1"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"ABC", Double.NaN, "f1"});

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("DEF", 1.0, 2L, "f2"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"DEF", Double.NaN, "f2"});

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("DEF", 2.0, 4L, "f3"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"DEF", 1.0, "f3"});

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("ABC", 20.0, 2000L, "f4"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"ABC", 1.0, "f4"});
  }
Ejemplo n.º 8
0
  public void testSchemaXMLWSchemaWithRestriction() throws Exception {
    Configuration config = SupportConfigFactory.getConfiguration();
    ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM();
    eventTypeMeta.setRootElementName("order");
    InputStream schemaStream =
        TestSchemaXMLEvent.class
            .getClassLoader()
            .getResourceAsStream(CLASSLOADER_SCHEMA_WITH_RESTRICTION_URI);
    assertNotNull(schemaStream);
    String schemaText = ParserTool.linesToText(ParserTool.readFile(schemaStream));
    eventTypeMeta.setSchemaText(schemaText);
    config.addEventType("OrderEvent", eventTypeMeta);

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

    String text = "select order_amount from OrderEvent";
    EPStatement stmt = epService.getEPAdministrator().createEPL(text);
    stmt.addListener(updateListener);

    SupportXML.sendEvent(
        epService.getEPRuntime(),
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<order>\n"
            + "<order_amount>202.1</order_amount>"
            + "</order>");
    EventBean theEvent = updateListener.getLastNewData()[0];
    assertEquals(Double.class, theEvent.get("order_amount").getClass());
    assertEquals(202.1d, theEvent.get("order_amount"));
    updateListener.reset();
  }
Ejemplo n.º 9
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();
  }
  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.º 11
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.º 12
0
  private void runAssertionGroupedMixedMethodAndAccess(boolean soda) throws Exception {
    String eplDeclare =
        "create table varMyAgg ("
            + "key string primary key, "
            + "c0 count(*), "
            + "c1 count(distinct object), "
            + "c2 window(*) @type('SupportBean'), "
            + "c3 sum(long)"
            + ")";
    SupportModelHelper.createByCompileOrParse(epService, soda, eplDeclare);

    String eplBind =
        "into table varMyAgg select "
            + "count(*) as c0, "
            + "count(distinct intPrimitive) as c1, "
            + "window(*) as c2, "
            + "sum(longPrimitive) as c3 "
            + "from SupportBean.win:length(3) group by theString";
    SupportModelHelper.createByCompileOrParse(epService, soda, eplBind);

    String eplSelect =
        "select "
            + "varMyAgg[p00].c0 as c0, "
            + "varMyAgg[p00].c1 as c1, "
            + "varMyAgg[p00].c2 as c2, "
            + "varMyAgg[p00].c3 as c3"
            + " from SupportBean_S0";
    EPStatement stmtSelect = SupportModelHelper.createByCompileOrParse(epService, soda, eplSelect);
    stmtSelect.addListener(listener);
    String[] fields = "c0,c1,c2,c3".split(",");

    assertEquals(Long.class, stmtSelect.getEventType().getPropertyType("c0"));
    assertEquals(Long.class, stmtSelect.getEventType().getPropertyType("c1"));
    assertEquals(SupportBean[].class, stmtSelect.getEventType().getPropertyType("c2"));
    assertEquals(Long.class, stmtSelect.getEventType().getPropertyType("c3"));

    SupportBean b1 = makeSendBean("E1", 10, 100);
    SupportBean b2 = makeSendBean("E1", 11, 101);
    SupportBean b3 = makeSendBean("E1", 10, 102);

    epService.getEPRuntime().sendEvent(new SupportBean_S0(0, "E1"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(),
        fields,
        new Object[] {3L, 2L, new SupportBean[] {b1, b2, b3}, 303L});

    epService.getEPRuntime().sendEvent(new SupportBean_S0(0, "E2"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {null, null, null, null});

    SupportBean b4 = makeSendBean("E2", 20, 200);
    epService.getEPRuntime().sendEvent(new SupportBean_S0(0, "E2"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(),
        fields,
        new Object[] {1L, 1L, new SupportBean[] {b4}, 200L});

    epService.getEPAdministrator().destroyAllStatements();
  }
  public void testMapNamePropertyNested() {
    EPServiceProvider epService = getEngineInitialized(null, null, null);

    // create a named map
    Map<String, Object> namedDef = makeMap(new Object[][] {{"n0", int.class}});
    epService.getEPAdministrator().getConfiguration().addEventType("MyNamedMap", namedDef);

    // create a map using the name
    Map<String, Object> eventDef =
        makeMap(new Object[][] {{"p0", "MyNamedMap"}, {"p1", "MyNamedMap[]"}});
    epService.getEPAdministrator().getConfiguration().addEventType("MyMapWithAMap", eventDef);

    // test named-map at the second level of a nested map
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("MyObjectArrayMapOuter", new String[] {"outer"}, new Object[] {eventDef});

    SupportUpdateListener listener = new SupportUpdateListener();
    EPStatement stmt =
        epService
            .getEPAdministrator()
            .createEPL(
                "select outer.p0.n0 as a, outer.p1[0].n0 as b, outer.p1[1].n0 as c, outer.p0 as d, outer.p1 as e from MyObjectArrayMapOuter");
    stmt.addListener(listener);

    Map<String, Object> n0_1 = makeMap(new Object[][] {{"n0", 1}});
    Map<String, Object> n0_21 = makeMap(new Object[][] {{"n0", 2}});
    Map<String, Object> n0_22 = makeMap(new Object[][] {{"n0", 3}});
    Map[] n0_2 = new Map[] {n0_21, n0_22};
    Map<String, Object> theEvent = makeMap(new Object[][] {{"p0", n0_1}, {"p1", n0_2}});
    epService.getEPRuntime().sendEvent(new Object[] {theEvent}, "MyObjectArrayMapOuter");

    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(),
        "a,b,c,d,e".split(","),
        new Object[] {1, 2, 3, n0_1, n0_2});
    assertEquals(int.class, stmt.getEventType().getPropertyType("a"));
    assertEquals(int.class, stmt.getEventType().getPropertyType("b"));
    assertEquals(int.class, stmt.getEventType().getPropertyType("c"));
    assertEquals(Map.class, stmt.getEventType().getPropertyType("d"));
    assertEquals(Map[].class, stmt.getEventType().getPropertyType("e"));

    stmt.destroy();
    stmt =
        epService
            .getEPAdministrator()
            .createEPL(
                "select outer.p0.n0? as a, outer.p1[0].n0? as b, outer.p1[1]?.n0 as c, outer.p0? as d, outer.p1? as e from MyObjectArrayMapOuter");
    stmt.addListener(listener);
    epService.getEPRuntime().sendEvent(new Object[] {theEvent}, "MyObjectArrayMapOuter");

    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(),
        "a,b,c,d,e".split(","),
        new Object[] {1, 2, 3, n0_1, n0_2});
    assertEquals(int.class, stmt.getEventType().getPropertyType("a"));
  }
Ejemplo n.º 14
0
  private void assertMultiStmtContributingTotal(String c0, int total) {
    String[] fields = "c0,total".split(",");
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {c0, total});

    epService.getEPRuntime().sendEvent(new SupportBean(c0, 0));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {c0, total});
  }
Ejemplo n.º 15
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"));
  }
  public void testArrayProperty() {
    EPServiceProvider epService = getEngineInitialized(null, null, null);

    // test map containing first-level property that is an array of primitive or Class
    String[] props = {"p0", "p1"};
    Object[] types = {int[].class, SupportBean[].class};
    epService.getEPAdministrator().getConfiguration().addEventType("MyArrayOA", props, types);

    EPStatement stmt =
        epService
            .getEPAdministrator()
            .createEPL(
                "select p0[0] as a, p0[1] as b, p1[0].intPrimitive as c, p1[1] as d, p0 as e from MyArrayOA");
    SupportUpdateListener listener = new SupportUpdateListener();
    stmt.addListener(listener);

    int[] p0 = new int[] {1, 2, 3};
    SupportBean[] beans = new SupportBean[] {new SupportBean("e1", 5), new SupportBean("e2", 6)};
    Object[] eventData = new Object[] {p0, beans};
    epService.getEPRuntime().sendEvent(eventData, "MyArrayOA");

    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(),
        "a,b,c,d,e".split(","),
        new Object[] {1, 2, 5, beans[1], p0});
    assertEquals(int.class, stmt.getEventType().getPropertyType("a"));
    assertEquals(int.class, stmt.getEventType().getPropertyType("b"));
    assertEquals(int.class, stmt.getEventType().getPropertyType("c"));
    assertEquals(SupportBean.class, stmt.getEventType().getPropertyType("d"));
    assertEquals(int[].class, stmt.getEventType().getPropertyType("e"));
    stmt.destroy();

    // test map at the second level of a nested map that is an array of primitive or Class
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("MyArrayOAMapOuter", new String[] {"outer"}, new Object[] {"MyArrayOA"});

    stmt =
        epService
            .getEPAdministrator()
            .createEPL(
                "select outer.p0[0] as a, outer.p0[1] as b, outer.p1[0].intPrimitive as c, outer.p1[1] as d, outer.p0 as e from MyArrayOAMapOuter");
    stmt.addListener(listener);

    epService.getEPRuntime().sendEvent(new Object[] {eventData}, "MyArrayOAMapOuter");

    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), "a,b,c,d".split(","), new Object[] {1, 2, 5, beans[1]});
    assertEquals(int.class, stmt.getEventType().getPropertyType("a"));
    assertEquals(int.class, stmt.getEventType().getPropertyType("b"));
    assertEquals(int.class, stmt.getEventType().getPropertyType("c"));
    assertEquals(SupportBean.class, stmt.getEventType().getPropertyType("d"));
    assertEquals(int[].class, stmt.getEventType().getPropertyType("e"));
  }
Ejemplo n.º 17
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());
  }
Ejemplo n.º 18
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.º 19
0
  public void testNullType() {
    String stmtOneTxt = "insert into InZone select null as dummy from java.lang.String";
    EPStatement stmtOne = epService.getEPAdministrator().createEPL(stmtOneTxt);
    assertTrue(stmtOne.getEventType().isProperty("dummy"));

    String stmtTwoTxt = "select dummy from InZone";
    EPStatement stmtTwo = epService.getEPAdministrator().createEPL(stmtTwoTxt);
    SupportUpdateListener listener = new SupportUpdateListener();
    stmtTwo.addListener(listener);

    epService.getEPRuntime().sendEvent("a");
    assertNull(listener.assertOneGetNewAndReset().get("dummy"));
  }
  public void testScalar() {

    String[] fields = "val0,val1".split(",");
    String eplFragment =
        "select "
            + "strvals.mostFrequent() as val0, "
            + "strvals.leastFrequent() as val1 "
            + "from SupportCollection";
    EPStatement stmtFragment = epService.getEPAdministrator().createEPL(eplFragment);
    stmtFragment.addListener(listener);
    LambdaAssertionUtil.assertTypes(
        stmtFragment.getEventType(), fields, new Class[] {String.class, String.class});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString("E2,E1,E2,E1,E3,E3,E4,E3"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"E3", "E4"});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString("E1"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"E1", "E1"});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString(null));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {null, null});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString(""));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {null, null});
    stmtFragment.destroy();

    epService
        .getEPAdministrator()
        .getConfiguration()
        .addPlugInSingleRowFunction(
            "extractNum", TestEnumMinMax.MyService.class.getName(), "extractNum");
    String eplLambda =
        "select "
            + "strvals.mostFrequent(v => extractNum(v)) as val0, "
            + "strvals.leastFrequent(v => extractNum(v)) as val1 "
            + "from SupportCollection";
    EPStatement stmtLambda = epService.getEPAdministrator().createEPL(eplLambda);
    stmtLambda.addListener(listener);
    LambdaAssertionUtil.assertTypes(
        stmtLambda.getEventType(), fields, new Class[] {Integer.class, Integer.class});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString("E2,E1,E2,E1,E3,E3,E4,E3"));
    EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {3, 4});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString("E1"));
    EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {1, 1});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString(null));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {null, null});

    epService.getEPRuntime().sendEvent(SupportCollection.makeString(""));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {null, null});
  }
Ejemplo n.º 21
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());
  }
  private void runAssertion(
      EPServiceProvider epService, SupportUpdateListener listener, EPStatement stmt) {
    String[] fields = "a,b0,b1".split(",");

    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));
    EPAssertionUtil.assertPropsPerRow(
        listener.getAndResetLastNewData(), fields, new Object[][] {{"A1", "B1", null}});
    EPAssertionUtil.assertPropsPerRow(stmt.iterator(), fields, new Object[][] {{"A1", "B1", null}});
  }
Ejemplo n.º 23
0
 private void assertSimple(
     SupportUpdateListener listener,
     String myString,
     int myInt,
     String additionalString,
     int additionalInt) {
   assertTrue(listener.getAndClearIsInvoked());
   EventBean eventBean = listener.getLastNewData()[0];
   assertEquals(myString, eventBean.get("myString"));
   assertEquals(myInt, eventBean.get("myInt"));
   if (additionalString != null) {
     assertEquals(additionalString, eventBean.get("concat"));
     assertEquals(additionalInt, eventBean.get("summed"));
   }
 }
Ejemplo n.º 24
0
 private void sendEventsAndAssert(String theString, int intPrimitive, String p00, int total) {
   String[] fields = "c0,c1".split(",");
   epService.getEPRuntime().sendEvent(new SupportBean(theString, intPrimitive));
   epService.getEPRuntime().sendEvent(new SupportBean_S0(0, p00));
   EPAssertionUtil.assertProps(
       listener.assertOneGetNewAndReset(), fields, new Object[] {p00, total});
 }
  private void runAssertionSubquerySelectStar(Object[] rowValues) {
    String eplFiltered =
        "select (select * from MyTable where key = 'G1') as mt from SupportBean_S2";
    runAssertionSubquerySelectStar(rowValues, eplFiltered);

    String eplUnfiltered = "select (select * from MyTable) as mt from SupportBean_S2";
    runAssertionSubquerySelectStar(rowValues, eplUnfiltered);

    // With @eventbean
    String eplEventBean = "select (select * from MyTable) @eventbean as mt from SupportBean_S2";
    EPStatement stmt = epService.getEPAdministrator().createEPL(eplEventBean);
    stmt.addListener(listener);
    assertEquals(Object[][].class, stmt.getEventType().getPropertyType("mt"));
    assertSame(
        getTablePublicType("MyTable"), stmt.getEventType().getFragmentType("mt").getFragmentType());

    epService.getEPRuntime().sendEvent(new SupportBean_S2(0));
    EventBean event = listener.assertOneGetNewAndReset();
    Object[][] value = (Object[][]) event.get("mt");
    assertEventUnd(value[0], rowValues);
    assertSame(
        getTablePublicType("MyTable"), ((EventBean[]) event.getFragment("mt"))[0].getEventType());

    stmt.destroy();
  }
Ejemplo n.º 26
0
  public void testOnMergeExpressions() {
    epService
        .getEPAdministrator()
        .createEPL("create table the_table (key string primary key, total count(*), value int)");
    epService
        .getEPAdministrator()
        .createEPL(
            "into table the_table select count(*) as total from SupportBean group by theString");
    epService
        .getEPAdministrator()
        .createEPL(
            "on SupportBean_S0 as s0 "
                + "merge the_table as tt "
                + "where s0.p00 = tt.key "
                + "when matched and the_table[s0.p00].total > 0"
                + "  then update set value = 1");
    epService
        .getEPAdministrator()
        .createEPL("select the_table[p10].value as c0 from SupportBean_S1")
        .addListener(listener);

    epService.getEPRuntime().sendEvent(new SupportBean("E1", -1));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(0, "E1"));

    epService.getEPRuntime().sendEvent(new SupportBean_S1(0, "E1"));
    assertEquals(1, listener.assertOneGetNewAndReset().get("c0"));
  }
  public void testPerformanceCoercionBack() {
    String stmt =
        "select A.intPrimitive as value from "
            + SupportBean.class.getName()
            + "(theString='A').win:length(1000000) as A,"
            + SupportBean.class.getName()
            + "(theString='B').win:length(1000000) as B"
            + " where A.intPrimitive=B.longBoxed";

    EPStatement statement = epService.getEPAdministrator().createEPL(stmt);
    statement.addListener(listener);

    // preload
    for (int i = 0; i < 10000; i++) {
      epService.getEPRuntime().sendEvent(makeSupportEvent("A", i, 0));
    }

    long startTime = System.currentTimeMillis();
    for (int i = 0; i < 5000; i++) {
      int index = 5000 + i % 1000;
      epService.getEPRuntime().sendEvent(makeSupportEvent("B", 0, index));
      assertEquals(index, listener.assertOneGetNewAndReset().get("value"));
    }
    long endTime = System.currentTimeMillis();
    long delta = endTime - startTime;

    statement.destroy();
    assertTrue("Failed perf test, delta=" + delta, delta < 1500);
  }
  private void runAssertionOnSelectWindowAgg(Object[][] expectedType, Object[] rowValues) {
    EPStatement stmt =
        epService
            .getEPAdministrator()
            .createEPL(
                "on SupportBean_S2 select "
                    + "window(win.*) as c0,"
                    + "last(win.*) as c1, "
                    + "first(win.*) as c2, "
                    + "first(p1) as c3,"
                    + "window(p1) as c4,"
                    + "sorted(p1) as c5,"
                    + "minby(p1) as c6"
                    + " from MyTable as win");
    stmt.addListener(listener);

    epService.getEPRuntime().sendEvent(new SupportBean_S2(0));
    EventBean event = listener.assertOneGetNewAndReset();
    for (String col : "c1,c2,c6".split(",")) {
      assertEventUnd(event.get(col), rowValues);
    }
    for (String col : "c0,c5".split(",")) {
      assertEventUnd(((Object[][]) event.get(col))[0], rowValues);
    }
    assertEquals("b", event.get("c3"));
    EPAssertionUtil.assertEqualsExactOrder(new String[] {"b"}, (String[]) event.get("c4"));

    stmt.destroy();
  }
  public void testConfiguredViaPropsAndXML() {
    Configuration configuration = SupportConfigFactory.getConfiguration();
    configuration
        .getEngineDefaults()
        .getEventMeta()
        .setDefaultEventRepresentation(Configuration.EventRepresentation.OBJECTARRAY);
    configuration.addEventType(
        "MyOAType",
        "bean,theString,map".split(","),
        new Object[] {SupportBean.class.getName(), "string", "java.util.Map"});

    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(configuration);
    epService.initialize();
    if (InstrumentationHelper.ENABLED) {
      InstrumentationHelper.startTest(epService, this.getClass(), getName());
    }

    EventType eventType =
        epService.getEPAdministrator().getConfiguration().getEventType("MyOAType");
    assertEquals(Object[].class, eventType.getUnderlyingType());
    assertEquals(String.class, eventType.getPropertyType("theString"));
    assertEquals(Map.class, eventType.getPropertyType("map"));
    assertEquals(SupportBean.class, eventType.getPropertyType("bean"));

    EPStatement stmt =
        epService
            .getEPAdministrator()
            .createEPL("select bean, theString, map('key'), bean.theString from MyOAType");
    SupportUpdateListener listener = new SupportUpdateListener();
    stmt.addListener(listener);
    assertEquals(Object[].class, stmt.getEventType().getUnderlyingType());

    SupportBean bean = new SupportBean("E1", 1);
    epService
        .getEPRuntime()
        .sendEvent(
            new Object[] {bean, "abc", Collections.singletonMap("key", "value")}, "MyOAType");
    EPAssertionUtil.assertProps(
        listener.assertOneGetNew(),
        "bean,theString,map('key'),bean.theString".split(","),
        new Object[] {bean, "abc", "value", "E1"});

    if (InstrumentationHelper.ENABLED) {
      InstrumentationHelper.endTest();
    }
  }
  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"}});
  }