コード例 #1
0
  public void testStartStopStatement() {
    String stmtText = "select id from S0 where (select true from S1.win:length(1000))";

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

    epService.getEPRuntime().sendEvent(new SupportBean_S0(2));
    assertFalse(listener.isInvoked());

    epService.getEPRuntime().sendEvent(new SupportBean_S1(10));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(2));
    assertEquals(2, listener.assertOneGetNewAndReset().get("id"));

    stmt.stop();
    epService.getEPRuntime().sendEvent(new SupportBean_S0(2));
    assertFalse(listener.isInvoked());

    stmt.start();
    epService.getEPRuntime().sendEvent(new SupportBean_S0(2));
    assertFalse(listener.isInvoked());

    epService.getEPRuntime().sendEvent(new SupportBean_S1(10));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(3));
    assertEquals(3, listener.assertOneGetNewAndReset().get("id"));
  }
コード例 #2
0
  public void testCustomFunction() {
    String stmtText =
        "select (select "
            + SupportStaticMethodLib.class.getName()
            + ".minusOne(id) from S1.win:length(1000)) as idS1 from S0";

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

    // check type
    assertEquals(Double.class, stmt.getEventType().getPropertyType("idS1"));

    // test no event, should return null
    epService.getEPRuntime().sendEvent(new SupportBean_S0(0));
    assertEquals(null, listener.assertOneGetNewAndReset().get("idS1"));

    // test one event
    epService.getEPRuntime().sendEvent(new SupportBean_S1(10));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(1));
    assertEquals(9d, listener.assertOneGetNewAndReset().get("idS1"));

    // resend event
    epService.getEPRuntime().sendEvent(new SupportBean_S0(2));
    assertEquals(9d, listener.assertOneGetNewAndReset().get("idS1"));
  }
コード例 #3
0
  private void runAssertMultiRowUnfiltered(String stmtText, String columnName) {
    EPStatement stmt = epService.getEPAdministrator().createEPL(stmtText);
    stmt.addListener(listener);

    // check type
    assertEquals(Integer.class, stmt.getEventType().getPropertyType(columnName));

    // test no event, should return null
    epService.getEPRuntime().sendEvent(new SupportBean_S0(0));
    assertEquals(null, listener.assertOneGetNewAndReset().get(columnName));

    // test one event
    epService.getEPRuntime().sendEvent(new SupportBean_S1(10));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(1));
    assertEquals(10, listener.assertOneGetNewAndReset().get(columnName));

    // resend event
    epService.getEPRuntime().sendEvent(new SupportBean_S0(2));
    assertEquals(10, listener.assertOneGetNewAndReset().get(columnName));

    // test second event
    epService.getEPRuntime().sendEvent(new SupportBean_S1(999));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(3));
    assertEquals(null, listener.assertOneGetNewAndReset().get(columnName));
  }
コード例 #4
0
  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"));
  }
コード例 #5
0
  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"));
  }
コード例 #6
0
ファイル: TestInsertInto.java プロジェクト: jimmyathf/esper
  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"));
  }
コード例 #7
0
ファイル: TestInsertInto.java プロジェクト: jimmyathf/esper
  private EPStatement runAsserts(String stmtText, EPStatementObjectModel model) {
    // Attach listener to feed
    EPStatement stmt = null;
    if (model != null) {
      stmt = epService.getEPAdministrator().create(model, "s1");
    } else {
      stmt = epService.getEPAdministrator().createEPL(stmtText);
    }
    stmt.addListener(feedListener);

    // send event for joins to match on
    epService.getEPRuntime().sendEvent(new SupportBean_A("myId"));

    // Attach delta statement to statement and add listener
    stmtText = "select min(delta) as minD, max(delta) as maxD " + "from Event_1.win:time(60)";
    EPStatement stmtTwo = epService.getEPAdministrator().createEPL(stmtText);
    stmtTwo.addListener(resultListenerDelta);

    // Attach prodict statement to statement and add listener
    stmtText = "select min(product) as minP, max(product) as maxP " + "from Event_1.win:time(60)";
    EPStatement stmtThree = epService.getEPAdministrator().createEPL(stmtText);
    stmtThree.addListener(resultListenerProduct);

    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(0)); // Set the time to 0 seconds

    // send events
    sendEvent(20, 10);
    assertReceivedFeed(10, 200);
    assertReceivedMinMax(10, 10, 200, 200);

    sendEvent(50, 25);
    assertReceivedFeed(25, 25 * 50);
    assertReceivedMinMax(10, 25, 200, 1250);

    sendEvent(5, 2);
    assertReceivedFeed(3, 2 * 5);
    assertReceivedMinMax(3, 25, 10, 1250);

    epService
        .getEPRuntime()
        .sendEvent(new CurrentTimeEvent(10 * 1000)); // Set the time to 10 seconds

    sendEvent(13, 1);
    assertReceivedFeed(12, 13);
    assertReceivedMinMax(3, 25, 10, 1250);

    epService
        .getEPRuntime()
        .sendEvent(new CurrentTimeEvent(61 * 1000)); // Set the time to 61 seconds
    assertReceivedMinMax(12, 12, 13, 13);

    return stmt;
  }
コード例 #8
0
  public void testWhereClauseWithExpression() {
    String stmtText = "select id from S0 where (select p10='X' from S1.win:length(1000))";

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

    epService.getEPRuntime().sendEvent(new SupportBean_S0(0));
    assertFalse(listener.isInvoked());

    epService.getEPRuntime().sendEvent(new SupportBean_S1(10, "X"));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(0));
    assertEquals(0, listener.assertOneGetNewAndReset().get("id"));
  }
コード例 #9
0
  public void testFilterInside() {
    String stmtText = "select (select id from S1(p10='A').win:length(1000)) as idS1 from S0";

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

    epService.getEPRuntime().sendEvent(new SupportBean_S1(1, "X"));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(1));
    assertEquals(null, listener.assertOneGetNewAndReset().get("idS1"));

    epService.getEPRuntime().sendEvent(new SupportBean_S1(1, "A"));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(1));
    assertEquals(1, listener.assertOneGetNewAndReset().get("idS1"));
  }
コード例 #10
0
  public void testSelfSubselect() {
    String stmtTextOne = "insert into MyCount select count(*) as cnt from S0";
    epService.getEPAdministrator().createEPL(stmtTextOne);

    String stmtTextTwo = "select (select cnt from MyCount.std:lastevent()) as value from S0";
    EPStatement stmt = epService.getEPAdministrator().createEPL(stmtTextTwo);
    stmt.addListener(listener);

    epService.getEPRuntime().sendEvent(new SupportBean_S0(1));
    assertEquals(null, listener.assertOneGetNewAndReset().get("value"));

    epService.getEPRuntime().sendEvent(new SupportBean_S0(2));
    assertEquals(1L, listener.assertOneGetNewAndReset().get("value"));
  }
コード例 #11
0
ファイル: TestInsertInto.java プロジェクト: jimmyathf/esper
  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);
  }
コード例 #12
0
  public void testObjectArrayNested() {
    EPServiceProvider epService = getEngineInitialized(null, null, null);
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("TypeLev1", new String[] {"p1id"}, new Object[] {int.class});
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType(
            "TypeLev0", new String[] {"p0id", "p1"}, new Object[] {int.class, "TypeLev1"});
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType(
            "TypeRoot", new String[] {"rootId", "p0"}, new Object[] {int.class, "TypeLev0"});

    EPStatement stmt =
        epService.getEPAdministrator().createEPL("select * from TypeRoot.std:lastevent()");
    Object[] dataLev1 = {1000};
    Object[] dataLev0 = {100, dataLev1};
    epService.getEPRuntime().sendEvent(new Object[] {10, dataLev0}, "TypeRoot");
    EventBean theEvent = stmt.iterator().next();
    EPAssertionUtil.assertProps(
        theEvent, "rootId,p0.p0id,p0.p1.p1id".split(","), new Object[] {10, 100, 1000});
  }
コード例 #13
0
  public void testJoinUnfiltered() {
    String stmtText =
        "select (select id from S3.win:length(1000)) as idS3, (select id from S4.win:length(1000)) as idS4 from S0.win:keepall() as s0, S1.win:keepall() as s1 where s0.id = s1.id";

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

    // check type
    assertEquals(Integer.class, stmt.getEventType().getPropertyType("idS3"));
    assertEquals(Integer.class, stmt.getEventType().getPropertyType("idS4"));

    // test no event, should return null
    epService.getEPRuntime().sendEvent(new SupportBean_S0(0));
    epService.getEPRuntime().sendEvent(new SupportBean_S1(0));
    EventBean event = listener.assertOneGetNewAndReset();
    assertEquals(null, event.get("idS3"));
    assertEquals(null, event.get("idS4"));

    // send one event
    epService.getEPRuntime().sendEvent(new SupportBean_S3(-1));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(1));
    epService.getEPRuntime().sendEvent(new SupportBean_S1(1));
    event = listener.assertOneGetNewAndReset();
    assertEquals(-1, event.get("idS3"));
    assertEquals(null, event.get("idS4"));

    // send one event
    epService.getEPRuntime().sendEvent(new SupportBean_S4(-2));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(2));
    epService.getEPRuntime().sendEvent(new SupportBean_S1(2));
    event = listener.assertOneGetNewAndReset();
    assertEquals(-1, event.get("idS3"));
    assertEquals(-2, event.get("idS4"));

    // send second event
    epService.getEPRuntime().sendEvent(new SupportBean_S4(-2));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(3));
    epService.getEPRuntime().sendEvent(new SupportBean_S1(3));
    event = listener.assertOneGetNewAndReset();
    assertEquals(-1, event.get("idS3"));
    assertEquals(null, event.get("idS4"));

    epService.getEPRuntime().sendEvent(new SupportBean_S3(-2));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(3));
    epService.getEPRuntime().sendEvent(new SupportBean_S1(3));
    EventBean[] events = listener.getNewDataListFlattened();
    assertEquals(3, events.length);
    for (int i = 0; i < events.length; i++) {
      assertEquals(null, events[i].get("idS3"));
      assertEquals(null, events[i].get("idS4"));
    }
  }
コード例 #14
0
ファイル: TestInsertInto.java プロジェクト: jimmyathf/esper
 private SupportBean sendEvent(int intPrimitive, int intBoxed) {
   SupportBean bean = new SupportBean();
   bean.setTheString("myId");
   bean.setIntPrimitive(intPrimitive);
   bean.setIntBoxed(intBoxed);
   epService.getEPRuntime().sendEvent(bean);
   return bean;
 }
コード例 #15
0
  public void testUnfilteredExpression() {
    String stmtText = "select (select p10 || p11 from S1.std:lastevent()) as value from S0";

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

    // check type
    assertEquals(String.class, stmt.getEventType().getPropertyType("value"));

    // test no event, should return null
    epService.getEPRuntime().sendEvent(new SupportBean_S0(1));
    EventBean event = listener.assertOneGetNewAndReset();
    assertEquals(null, event.get("value"));

    // test one event
    epService.getEPRuntime().sendEvent(new SupportBean_S1(-1, "a", "b"));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(1));
    event = listener.assertOneGetNewAndReset();
    assertEquals("ab", event.get("value"));
  }
コード例 #16
0
ファイル: TestInsertInto.java プロジェクト: jimmyathf/esper
  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"));
  }
コード例 #17
0
ファイル: TestInsertInto.java プロジェクト: jimmyathf/esper
  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"));
  }
コード例 #18
0
  public void testComputedResult() {
    String stmtText = "select 100*(select id from S1.win:length(1000)) as idS1 from S0";

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

    // check type
    assertEquals(Integer.class, stmt.getEventType().getPropertyType("idS1"));

    // test no event, should return null
    epService.getEPRuntime().sendEvent(new SupportBean_S0(0));
    assertEquals(null, listener.assertOneGetNewAndReset().get("idS1"));

    // test one event
    epService.getEPRuntime().sendEvent(new SupportBean_S1(10));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(1));
    assertEquals(1000, listener.assertOneGetNewAndReset().get("idS1"));

    // resend event
    epService.getEPRuntime().sendEvent(new SupportBean_S0(2));
    assertEquals(1000, listener.assertOneGetNewAndReset().get("idS1"));
  }
コード例 #19
0
  public void testMultiColumnSelect() {
    String stmtText =
        "select (select id+1 as myId from S1.std:lastevent()) as idS1_0, "
            + "(select id+2 as myId from S1.std:lastevent()) as idS1_1 from S0";

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

    // check type
    assertEquals(Integer.class, stmt.getEventType().getPropertyType("idS1_0"));
    assertEquals(Integer.class, stmt.getEventType().getPropertyType("idS1_1"));

    // test no event, should return null
    epService.getEPRuntime().sendEvent(new SupportBean_S0(1));
    EventBean event = listener.assertOneGetNewAndReset();
    assertEquals(null, event.get("idS1_0"));
    assertEquals(null, event.get("idS1_1"));

    // test one event
    epService.getEPRuntime().sendEvent(new SupportBean_S1(10));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(1));
    event = listener.assertOneGetNewAndReset();
    assertEquals(11, event.get("idS1_0"));
    assertEquals(12, event.get("idS1_1"));

    // resend event
    epService.getEPRuntime().sendEvent(new SupportBean_S0(2));
    event = listener.assertOneGetNewAndReset();
    assertEquals(11, event.get("idS1_0"));
    assertEquals(12, event.get("idS1_1"));

    // test second event
    epService.getEPRuntime().sendEvent(new SupportBean_S1(999));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(3));
    event = listener.assertOneGetNewAndReset();
    assertEquals(1000, event.get("idS1_0"));
    assertEquals(1001, event.get("idS1_1"));
  }
コード例 #20
0
  private void runUnfilteredStreamPrior(EPStatement stmt) {
    stmt.addListener(listener);

    // check type
    assertEquals(Integer.class, stmt.getEventType().getPropertyType("idS1"));

    // test no event, should return null
    epService.getEPRuntime().sendEvent(new SupportBean_S0(0));
    assertEquals(null, listener.assertOneGetNewAndReset().get("idS1"));

    // test one event
    epService.getEPRuntime().sendEvent(new SupportBean_S1(10));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(1));
    assertEquals(10, listener.assertOneGetNewAndReset().get("idS1"));

    // resend event
    epService.getEPRuntime().sendEvent(new SupportBean_S0(2));
    assertEquals(10, listener.assertOneGetNewAndReset().get("idS1"));

    // test second event
    epService.getEPRuntime().sendEvent(new SupportBean_S0(3));
    assertEquals(10, listener.assertOneGetNewAndReset().get("idS1"));
  }
コード例 #21
0
  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();
    }
  }
コード例 #22
0
ファイル: TestInsertInto.java プロジェクト: jimmyathf/esper
  public void testVariantTwoJoinWildcard() {
    String textOne =
        "insert into event2 select * "
            + "from "
            + SupportBean.class.getName()
            + ".win:length(100) as s0, "
            + SupportBean_A.class.getName()
            + ".win:length(5) as s1 "
            + "where s0.theString = s1.id";
    String textTwo = "select * from event2.win:length(10)";

    // Attach listener to feed
    EPStatement stmtOne = epService.getEPAdministrator().createEPL(textOne);
    SupportUpdateListener listenerOne = new SupportUpdateListener();
    stmtOne.addListener(listenerOne);
    EPStatement stmtTwo = epService.getEPAdministrator().createEPL(textTwo);
    SupportUpdateListener listenerTwo = new SupportUpdateListener();
    stmtTwo.addListener(listenerTwo);

    // send event for joins to match on
    SupportBean_A eventA = new SupportBean_A("myId");
    epService.getEPRuntime().sendEvent(eventA);

    SupportBean eventOne = sendEvent(10, 11);
    assertTrue(listenerOne.getAndClearIsInvoked());
    assertEquals(1, listenerOne.getLastNewData().length);
    assertEquals(2, listenerOne.getLastNewData()[0].getEventType().getPropertyNames().length);
    assertTrue(listenerOne.getLastNewData()[0].getEventType().isProperty("s0"));
    assertTrue(listenerOne.getLastNewData()[0].getEventType().isProperty("s1"));
    assertSame(eventOne, listenerOne.getLastNewData()[0].get("s0"));
    assertSame(eventA, listenerOne.getLastNewData()[0].get("s1"));

    assertTrue(listenerTwo.getAndClearIsInvoked());
    assertEquals(1, listenerTwo.getLastNewData().length);
    assertEquals(2, listenerTwo.getLastNewData()[0].getEventType().getPropertyNames().length);
    assertTrue(listenerTwo.getLastNewData()[0].getEventType().isProperty("s0"));
    assertTrue(listenerTwo.getLastNewData()[0].getEventType().isProperty("s1"));
    assertSame(eventOne, listenerOne.getLastNewData()[0].get("s0"));
    assertSame(eventA, listenerOne.getLastNewData()[0].get("s1"));
  }
コード例 #23
0
  public void testMapNameProperty() {
    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
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType(
            "MyOAWithAMap", new String[] {"p0", "p1"}, new Object[] {"MyNamedMap", "MyNamedMap[]"});

    EPStatement stmt =
        epService
            .getEPAdministrator()
            .createEPL(
                "select p0.n0 as a, p1[0].n0 as b, p1[1].n0 as c, p0 as d, p1 as e from MyOAWithAMap");
    SupportUpdateListener listener = new SupportUpdateListener();
    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};
    epService.getEPRuntime().sendEvent(new Object[] {n0_1, n0_2}, "MyOAWithAMap");

    EventBean eventResult = listener.assertOneGetNewAndReset();
    EPAssertionUtil.assertProps(eventResult, "a,b,c,d".split(","), new Object[] {1, 2, 3, n0_1});
    Map[] valueE = (Map[]) eventResult.get("e");
    assertSame(valueE[0], n0_2[0]);
    assertSame(valueE[1], n0_2[1]);

    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"));
  }
コード例 #24
0
  public void testObjectArrayTypeUpdate() {
    Configuration configuration = SupportConfigFactory.getConfiguration();
    configuration
        .getEngineDefaults()
        .getEventMeta()
        .setDefaultEventRepresentation(Configuration.EventRepresentation.OBJECTARRAY);

    String[] names = {"base1", "base2"};
    Object[] types = {String.class, makeMap(new Object[][] {{"n1", int.class}})};
    configuration.addEventType("MyOAEvent", names, types);

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

    EPStatement statementOne =
        epService
            .getEPAdministrator()
            .createEPL(
                "select base1 as v1, base2.n1 as v2, base3? as v3, base2.n2? as v4 from MyOAEvent");
    assertEquals(Object[].class, statementOne.getEventType().getUnderlyingType());
    EPStatement statementOneSelectAll =
        epService.getEPAdministrator().createEPL("select * from MyOAEvent");
    assertEquals(
        "[base1, base2]", Arrays.toString(statementOneSelectAll.getEventType().getPropertyNames()));
    SupportUpdateListener listenerOne = new SupportUpdateListener();
    statementOne.addListener(listenerOne);
    String[] fields = "v1,v2,v3,v4".split(",");

    epService
        .getEPRuntime()
        .sendEvent(new Object[] {"abc", makeMap(new Object[][] {{"n1", 10}}), ""}, "MyOAEvent");
    EPAssertionUtil.assertProps(
        listenerOne.assertOneGetNewAndReset(), fields, new Object[] {"abc", 10, null, null});

    // update type
    String[] namesNew = {"base3", "base2"};
    Object[] typesNew = new Object[] {Long.class, makeMap(new Object[][] {{"n2", String.class}})};
    epService
        .getEPAdministrator()
        .getConfiguration()
        .updateObjectArrayEventType("MyOAEvent", namesNew, typesNew);

    EPStatement statementTwo =
        epService
            .getEPAdministrator()
            .createEPL(
                "select base1 as v1, base2.n1 as v2, base3 as v3, base2.n2 as v4 from MyOAEvent");
    EPStatement statementTwoSelectAll =
        epService.getEPAdministrator().createEPL("select * from MyOAEvent");
    SupportUpdateListener listenerTwo = new SupportUpdateListener();
    statementTwo.addListener(listenerTwo);

    epService
        .getEPRuntime()
        .sendEvent(
            new Object[] {"def", makeMap(new Object[][] {{"n1", 9}, {"n2", "xyz"}}), 20L},
            "MyOAEvent");
    EPAssertionUtil.assertProps(
        listenerOne.assertOneGetNewAndReset(), fields, new Object[] {"def", 9, 20L, "xyz"});
    EPAssertionUtil.assertProps(
        listenerTwo.assertOneGetNewAndReset(), fields, new Object[] {"def", 9, 20L, "xyz"});

    // assert event type
    assertEquals(
        "[base1, base2, base3]",
        Arrays.toString(statementOneSelectAll.getEventType().getPropertyNames()));
    assertEquals(
        "[base1, base2, base3]",
        Arrays.toString(statementTwoSelectAll.getEventType().getPropertyNames()));

    EPAssertionUtil.assertEqualsAnyOrder(
        new Object[] {
          new EventPropertyDescriptor("base3", Long.class, null, false, false, false, false, false),
          new EventPropertyDescriptor("base2", Map.class, null, false, false, false, true, false),
          new EventPropertyDescriptor(
              "base1", String.class, null, false, false, false, false, false),
        },
        statementTwoSelectAll.getEventType().getPropertyDescriptors());

    try {
      epService
          .getEPAdministrator()
          .getConfiguration()
          .updateObjectArrayEventType("dummy", new String[0], new Object[0]);
      fail();
    } catch (ConfigurationException ex) {
      assertEquals(
          "Error updating Object-array event type: Event type named 'dummy' has not been declared",
          ex.getMessage());
    }

    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("SupportBean", SupportBean.class);
    try {
      epService
          .getEPAdministrator()
          .getConfiguration()
          .updateObjectArrayEventType("SupportBean", new String[0], new Object[0]);
      fail();
    } catch (ConfigurationException ex) {
      assertEquals(
          "Error updating Object-array event type: Event type by name 'SupportBean' is not an Object-array event type",
          ex.getMessage());
    }

    if (InstrumentationHelper.ENABLED) {
      InstrumentationHelper.endTest();
    }
  }
コード例 #25
0
  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());
  }
コード例 #26
0
ファイル: TestInsertInto.java プロジェクト: jimmyathf/esper
 private void sendSimpleEvent(String theString, int val) {
   epService.getEPRuntime().sendEvent(new SupportBeanSimple(theString, val));
 }
コード例 #27
0
  private void runObjectArrInheritanceAssertion(EPServiceProvider epService) {
    SupportUpdateListener listeners[] = new SupportUpdateListener[5];
    String[] statements = {
      "select base as vbase, sub1? as v1, sub2? as v2, suba? as va, subb? as vb from RootEvent", // 0
      "select base as vbase, sub1 as v1, sub2? as v2, suba? as va, subb? as vb from Sub1Event", // 1
      "select base as vbase, sub1? as v1, sub2 as v2, suba? as va, subb? as vb from Sub2Event", // 2
      "select base as vbase, sub1 as v1, sub2? as v2, suba as va, subb? as vb from SubAEvent", // 3
      "select base as vbase, sub1? as v1, sub2? as v2, suba? as va, subb as vb from SubBEvent" // 4
    };
    for (int i = 0; i < statements.length; i++) {
      EPStatement statement = epService.getEPAdministrator().createEPL(statements[i]);
      listeners[i] = new SupportUpdateListener();
      statement.addListener(listeners[i]);
    }
    String[] fields = "vbase,v1,v2,va,vb".split(",");

    EventType type = epService.getEPAdministrator().getConfiguration().getEventType("SubAEvent");
    assertEquals("base", type.getPropertyDescriptors()[0].getPropertyName());
    assertEquals("sub1", type.getPropertyDescriptors()[1].getPropertyName());
    assertEquals("suba", type.getPropertyDescriptors()[2].getPropertyName());
    assertEquals(3, type.getPropertyDescriptors().length);

    type = epService.getEPAdministrator().getConfiguration().getEventType("SubBEvent");
    assertEquals("[base, sub1, suba, subb]", Arrays.toString(type.getPropertyNames()));
    assertEquals(4, type.getPropertyDescriptors().length);

    type = epService.getEPAdministrator().getConfiguration().getEventType("Sub1Event");
    assertEquals("[base, sub1]", Arrays.toString(type.getPropertyNames()));
    assertEquals(2, type.getPropertyDescriptors().length);

    type = epService.getEPAdministrator().getConfiguration().getEventType("Sub2Event");
    assertEquals("[base, sub2]", Arrays.toString(type.getPropertyNames()));
    assertEquals(2, type.getPropertyDescriptors().length);

    epService
        .getEPRuntime()
        .sendEvent(new Object[] {"a", "b", "x"}, "SubAEvent"); // base, sub1, suba
    EPAssertionUtil.assertProps(
        listeners[0].assertOneGetNewAndReset(), fields, new Object[] {"a", "b", null, "x", null});
    assertFalse(listeners[2].isInvoked() || listeners[4].isInvoked());
    EPAssertionUtil.assertProps(
        listeners[1].assertOneGetNewAndReset(), fields, new Object[] {"a", "b", null, "x", null});
    EPAssertionUtil.assertProps(
        listeners[3].assertOneGetNewAndReset(), fields, new Object[] {"a", "b", null, "x", null});

    epService.getEPRuntime().sendEvent(new Object[] {"f1", "f2", "f4"}, "SubAEvent");
    EPAssertionUtil.assertProps(
        listeners[0].assertOneGetNewAndReset(),
        fields,
        new Object[] {"f1", "f2", null, "f4", null});
    assertFalse(listeners[2].isInvoked() || listeners[4].isInvoked());
    EPAssertionUtil.assertProps(
        listeners[1].assertOneGetNewAndReset(),
        fields,
        new Object[] {"f1", "f2", null, "f4", null});
    EPAssertionUtil.assertProps(
        listeners[3].assertOneGetNewAndReset(),
        fields,
        new Object[] {"f1", "f2", null, "f4", null});

    epService.getEPRuntime().sendEvent(new Object[] {"XBASE", "X1", "X2", "XY"}, "SubBEvent");
    Object[] values = new Object[] {"XBASE", "X1", null, "X2", "XY"};
    EPAssertionUtil.assertProps(listeners[0].assertOneGetNewAndReset(), fields, values);
    assertFalse(listeners[2].isInvoked());
    EPAssertionUtil.assertProps(listeners[1].assertOneGetNewAndReset(), fields, values);
    EPAssertionUtil.assertProps(listeners[3].assertOneGetNewAndReset(), fields, values);
    EPAssertionUtil.assertProps(listeners[4].assertOneGetNewAndReset(), fields, values);

    epService.getEPRuntime().sendEvent(new Object[] {"YBASE", "Y1"}, "Sub1Event");
    values = new Object[] {"YBASE", "Y1", null, null, null};
    EPAssertionUtil.assertProps(listeners[0].assertOneGetNewAndReset(), fields, values);
    assertFalse(listeners[2].isInvoked() || listeners[3].isInvoked() || listeners[4].isInvoked());
    EPAssertionUtil.assertProps(listeners[1].assertOneGetNewAndReset(), fields, values);

    epService.getEPRuntime().sendEvent(new Object[] {"YBASE", "Y2"}, "Sub2Event");
    values = new Object[] {"YBASE", null, "Y2", null, null};
    EPAssertionUtil.assertProps(listeners[0].assertOneGetNewAndReset(), fields, values);
    assertFalse(listeners[1].isInvoked() || listeners[3].isInvoked() || listeners[4].isInvoked());
    EPAssertionUtil.assertProps(listeners[2].assertOneGetNewAndReset(), fields, values);

    epService.getEPRuntime().sendEvent(new Object[] {"ZBASE"}, "RootEvent");
    values = new Object[] {"ZBASE", null, null, null, null};
    EPAssertionUtil.assertProps(listeners[0].assertOneGetNewAndReset(), fields, values);
    assertFalse(
        listeners[1].isInvoked()
            || listeners[2].isInvoked()
            || listeners[3].isInvoked()
            || listeners[4].isInvoked());

    // try property not available
    try {
      epService.getEPAdministrator().createEPL("select suba from Sub1Event");
      fail();
    } catch (EPStatementException ex) {
      assertEquals(
          "Error starting statement: Failed to validate select-clause expression 'suba': Property named 'suba' is not valid in any stream (did you mean 'sub1'?) [select suba from Sub1Event]",
          ex.getMessage());
    }

    // try supertype not exists
    try {
      epService
          .getEPAdministrator()
          .getConfiguration()
          .addEventType("Sub1Event", makeMap(""), new String[] {"doodle"});
      fail();
    } catch (ConfigurationException ex) {
      assertEquals("Supertype by name 'doodle' could not be found", ex.getMessage());
    }
  }
コード例 #28
0
  public void testMappedProperty() {
    EPServiceProvider epService = getEngineInitialized(null, null, null);

    // test map containing first-level property that is an array of primitive or Class
    Map<String, Object> mappedDef = makeMap(new Object[][] {{"p0", Map.class}});
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("MyMappedPropertyMap", mappedDef);

    EPStatement stmt =
        epService.getEPAdministrator().createEPL("select p0('k1') as a from MyMappedPropertyMap");
    SupportUpdateListener listener = new SupportUpdateListener();
    stmt.addListener(listener);

    Map<String, Object> eventVal = new HashMap<String, Object>();
    eventVal.put("k1", "v1");
    Map<String, Object> theEvent = makeMap(new Object[][] {{"p0", eventVal}});
    epService.getEPRuntime().sendEvent(theEvent, "MyMappedPropertyMap");

    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), "a".split(","), new Object[] {"v1"});
    assertEquals(Object.class, stmt.getEventType().getPropertyType("a"));
    stmt.destroy();

    // test map at the second level of a nested map that is an array of primitive or Class
    Map<String, Object> mappedDefOuter = makeMap(new Object[][] {{"outer", mappedDef}});
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("MyMappedPropertyMapOuter", mappedDefOuter);

    stmt =
        epService
            .getEPAdministrator()
            .createEPL("select outer.p0('k1') as a from MyMappedPropertyMapOuter");
    stmt.addListener(listener);

    Map<String, Object> eventOuter = makeMap(new Object[][] {{"outer", theEvent}});
    epService.getEPRuntime().sendEvent(eventOuter, "MyMappedPropertyMapOuter");

    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), "a".split(","), new Object[] {"v1"});
    assertEquals(Object.class, stmt.getEventType().getPropertyType("a"));

    // test map that contains a bean which has a map property
    Map<String, Object> mappedDefOuterTwo =
        makeMap(new Object[][] {{"outerTwo", SupportBeanComplexProps.class}});
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("MyMappedPropertyMapOuterTwo", mappedDefOuterTwo);

    stmt =
        epService
            .getEPAdministrator()
            .createEPL("select outerTwo.mapProperty('xOne') as a from MyMappedPropertyMapOuterTwo");
    stmt.addListener(listener);

    Map<String, Object> eventOuterTwo =
        makeMap(new Object[][] {{"outerTwo", SupportBeanComplexProps.makeDefaultBean()}});
    epService.getEPRuntime().sendEvent(eventOuterTwo, "MyMappedPropertyMapOuterTwo");

    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), "a".split(","), new Object[] {"yOne"});
    assertEquals(String.class, stmt.getEventType().getPropertyType("a"));
  }
コード例 #29
0
ファイル: TestInsertInto.java プロジェクト: jimmyathf/esper
 private void sendEvent(String symbol, double price) {
   SupportMarketDataBean bean = new SupportMarketDataBean(symbol, price, null, null);
   epService.getEPRuntime().sendEvent(bean);
 }
コード例 #30
0
  public void testRevisionGen() {
    Random random = new Random();
    Map<String, Map<String, String>> last = new HashMap<String, Map<String, String>>();
    int count = 0;
    String[] groups = new String[] {"K0", "K1", "K2", "K4"};

    EPStatement consumerOne = epService.getEPAdministrator().createEPL("select * from RevQuote");
    consumerOne.addListener(listenerOne);

    for (int i = 0; i < groups.length; i++) {
      String key = groups[i];
      Object event =
          new SupportRevisionFull(
              key,
              "0-" + next(count),
              "1-" + next(count),
              "2-" + next(count),
              "3-" + next(count),
              "4-" + next(count),
              "5-" + next(count));
      add(
          last,
          key,
          "0-" + next(count),
          "1-" + next(count),
          "2-" + next(count),
          "3-" + next(count),
          "4-" + next(count),
          "5-" + next(count));
      epService.getEPRuntime().sendEvent(event);
    }
    listenerOne.reset();

    for (int i = 0; i < 10000; i++) {
      if (i % 20000 == 0) {
        log.debug(".testRevisionGen Loop " + i);
      }
      int typeNum = random.nextInt(6);
      String key = groups[random.nextInt(groups.length)];
      count++;

      Object event;
      if (typeNum == 0) {
        event =
            new SupportRevisionFull(
                key,
                "0-" + next(count),
                "1-" + next(count),
                "2-" + next(count),
                "3-" + next(count),
                "4-" + next(count),
                "5-" + next(count));
        add(
            last,
            key,
            "0-" + next(count),
            "1-" + next(count),
            "2-" + next(count),
            "3-" + next(count),
            "4-" + next(count),
            "5-" + next(count));
      } else if (typeNum == 1) {
        event = new SupportDeltaOne(key, "1-" + next(count), "5-" + next(count));
        add(last, key, null, "1-" + next(count), null, null, null, "5-" + next(count));
      } else if (typeNum == 2) {
        event =
            new SupportDeltaTwo(key, "0-" + next(count), "2-" + next(count), "3-" + next(count));
        add(
            last,
            key,
            "0-" + next(count),
            null,
            "2-" + next(count),
            "3-" + next(count),
            null,
            null);
      } else if (typeNum == 3) {
        event = new SupportDeltaThree(key, "0-" + next(count), "4-" + next(count));
        add(last, key, "0-" + next(count), null, null, null, "4-" + next(count), null);
      } else if (typeNum == 4) {
        event =
            new SupportDeltaFour(key, "0-" + next(count), "2-" + next(count), "5-" + next(count));
        add(
            last,
            key,
            "0-" + next(count),
            null,
            "2-" + next(count),
            null,
            null,
            "5-" + next(count));
      } else if (typeNum == 5) {
        event = new SupportDeltaFive(key, "1-" + next(count), "5-" + next(count));
        add(last, key, null, "1-" + next(count), null, null, null, "5-" + next(count));
      } else {
        throw new IllegalStateException();
      }

      epService.getEPRuntime().sendEvent(event);
      assertEvent(last, listenerOne.assertOneGetNewAndReset(), count);
    }
  }