Example #1
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"));
  }
Example #2
0
  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;
  }
Example #3
0
  public void testVariantTwoWildcard() throws InterruptedException {
    String stmtText =
        "insert into event1 select * from " + SupportBean.class.getName() + ".win:length(100)";
    String otherText = "select * from default.event1.win:length(10)";

    // Attach listener to feed
    EPStatement stmtOne = epService.getEPAdministrator().createEPL(stmtText, "stmt1");
    assertEquals(
        StatementType.INSERT_INTO,
        ((EPStatementSPI) stmtOne).getStatementMetadata().getStatementType());
    SupportUpdateListener listenerOne = new SupportUpdateListener();
    stmtOne.addListener(listenerOne);
    EPStatement stmtTwo = epService.getEPAdministrator().createEPL(otherText, "stmt2");
    SupportUpdateListener listenerTwo = new SupportUpdateListener();
    stmtTwo.addListener(listenerTwo);

    SupportBean theEvent = sendEvent(10, 11);
    assertTrue(listenerOne.getAndClearIsInvoked());
    assertEquals(1, listenerOne.getLastNewData().length);
    assertEquals(10, listenerOne.getLastNewData()[0].get("intPrimitive"));
    assertEquals(11, listenerOne.getLastNewData()[0].get("intBoxed"));
    assertEquals(20, listenerOne.getLastNewData()[0].getEventType().getPropertyNames().length);
    assertSame(theEvent, listenerOne.getLastNewData()[0].getUnderlying());

    assertTrue(listenerTwo.getAndClearIsInvoked());
    assertEquals(1, listenerTwo.getLastNewData().length);
    assertEquals(10, listenerTwo.getLastNewData()[0].get("intPrimitive"));
    assertEquals(11, listenerTwo.getLastNewData()[0].get("intBoxed"));
    assertEquals(20, listenerTwo.getLastNewData()[0].getEventType().getPropertyNames().length);
    assertSame(theEvent, listenerTwo.getLastNewData()[0].getUnderlying());

    // assert statement-type reference
    EPServiceProviderSPI spi = (EPServiceProviderSPI) epService;
    assertTrue(spi.getStatementEventTypeRef().isInUse("event1"));
    Set<String> stmtNames = spi.getStatementEventTypeRef().getStatementNamesForType("event1");
    EPAssertionUtil.assertEqualsAnyOrder(stmtNames.toArray(), new String[] {"stmt1", "stmt2"});
    assertTrue(spi.getStatementEventTypeRef().isInUse(SupportBean.class.getName()));
    stmtNames =
        spi.getStatementEventTypeRef().getStatementNamesForType(SupportBean.class.getName());
    EPAssertionUtil.assertEqualsAnyOrder(stmtNames.toArray(), new String[] {"stmt1"});

    stmtOne.destroy();
    assertTrue(spi.getStatementEventTypeRef().isInUse("event1"));
    stmtNames = spi.getStatementEventTypeRef().getStatementNamesForType("event1");
    EPAssertionUtil.assertEqualsAnyOrder(new String[] {"stmt2"}, stmtNames.toArray());
    assertFalse(spi.getStatementEventTypeRef().isInUse(SupportBean.class.getName()));

    stmtTwo.destroy();
    assertFalse(spi.getStatementEventTypeRef().isInUse("event1"));
  }
Example #4
0
  public void testCoalesceLong_OM() throws Exception {
    String viewExpr =
        "select coalesce(longBoxed, intBoxed, shortBoxed) as result"
            + " from "
            + SupportBean.class.getName()
            + ".win:length(1000)";

    EPStatementObjectModel model = new EPStatementObjectModel();
    model.setSelectClause(
        SelectClause.create()
            .add(Expressions.coalesce("longBoxed", "intBoxed", "shortBoxed"), "result"));
    model.setFromClause(
        FromClause.create(
            FilterStream.create(SupportBean.class.getName())
                .addView("win", "length", Expressions.constant(1000))));
    model = (EPStatementObjectModel) SerializableObjectCopier.copy(model);
    assertEquals(viewExpr, model.toEPL());

    epService.initialize();
    selectTestView = epService.getEPAdministrator().create(model);
    selectTestView.addListener(testListener);
    assertEquals(Long.class, selectTestView.getEventType().getPropertyType("result"));

    runCoalesceLong();
  }
  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"));
  }
Example #6
0
  public void testInsertFromPattern() {
    String stmtOneText =
        "insert into streamA select * from pattern [every " + SupportBean.class.getName() + "]";
    SupportUpdateListener listenerOne = new SupportUpdateListener();
    EPStatement stmtOne = epService.getEPAdministrator().createEPL(stmtOneText);
    stmtOne.addListener(listenerOne);

    String stmtTwoText =
        "insert into streamA select * from pattern [every " + SupportBean.class.getName() + "]";
    SupportUpdateListener listenerTwo = new SupportUpdateListener();
    EPStatement stmtTwo = epService.getEPAdministrator().createEPL(stmtTwoText);
    stmtTwo.addListener(listenerTwo);

    EventType eventType = stmtOne.getEventType();
    assertEquals(Map.class, eventType.getUnderlyingType());
  }
  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));
  }
  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"));
  }
Example #9
0
  public void testConcat() {
    String viewExpr =
        "select p00 || p01 as c1, p00 || p01 || p02 as c2, p00 || '|' || p01 as c3"
            + " from "
            + SupportBean_S0.class.getName()
            + ".win:length(10)";
    selectTestView = epService.getEPAdministrator().createEPL(viewExpr);
    selectTestView.addListener(testListener);

    epService.getEPRuntime().sendEvent(new SupportBean_S0(1, "a", "b", "c"));
    assertConcat("ab", "abc", "a|b");

    epService.getEPRuntime().sendEvent(new SupportBean_S0(1, null, "b", "c"));
    assertConcat(null, null, null);

    epService.getEPRuntime().sendEvent(new SupportBean_S0(1, "", "b", "c"));
    assertConcat("b", "bc", "|b");

    epService.getEPRuntime().sendEvent(new SupportBean_S0(1, "123", null, "c"));
    assertConcat(null, null, null);

    epService.getEPRuntime().sendEvent(new SupportBean_S0(1, "123", "456", "c"));
    assertConcat("123456", "123456c", "123|456");

    epService.getEPRuntime().sendEvent(new SupportBean_S0(1, "123", "456", null));
    assertConcat("123456", null, "123|456");
  }
Example #10
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);
  }
Example #11
0
 private void setupCoalesce(String coalesceExpr) {
   epService.initialize();
   String viewExpr =
       "select "
           + coalesceExpr
           + " as result"
           + " from "
           + SupportBean.class.getName()
           + ".win:length(1000) ";
   selectTestView = epService.getEPAdministrator().createEPL(viewExpr);
   selectTestView.addListener(testListener);
 }
Example #12
0
 private void setUpMinMax() {
   String viewExpr =
       "select max(longBoxed, intBoxed) as myMax, "
           + "max(longBoxed, intBoxed, shortBoxed) as myMaxEx,"
           + "min(longBoxed, intBoxed) as myMin,"
           + "min(longBoxed, intBoxed, shortBoxed) as myMinEx"
           + " from "
           + SupportBean.class.getName()
           + ".win:length(3) ";
   selectTestView = epService.getEPAdministrator().createEPL(viewExpr);
   selectTestView.addListener(testListener);
 }
Example #13
0
  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"));
  }
  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"));
    }
  }
  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"));
  }
Example #16
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"));
  }
Example #17
0
  public void testWithOutputLimitAndSort() {
    // NOTICE: we are inserting the RSTREAM (removed events)
    String stmtText =
        "insert rstream into StockTicks(mySymbol, myPrice) "
            + "select symbol, price from "
            + SupportMarketDataBean.class.getName()
            + ".win:time(60) "
            + "output every 5 seconds "
            + "order by symbol asc";
    epService.getEPAdministrator().createEPL(stmtText);

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

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

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

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

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

    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(70 * 1000));
    assertEquals("ABC", feedListener.getNewDataList().get(0)[0].get("mySymbol"));
    assertEquals(91.0, feedListener.getNewDataList().get(0)[0].get("pricesum"));
    assertEquals("DEF", feedListener.getNewDataList().get(1)[0].get("mySymbol"));
    assertEquals(191.0, feedListener.getNewDataList().get(1)[0].get("pricesum"));
  }
  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"));
  }
  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"));
  }
Example #20
0
  private void tryCoalesceBeans(String viewExpr) {
    epService.initialize();
    selectTestView = epService.getEPAdministrator().createEPL(viewExpr);
    selectTestView.addListener(testListener);

    SupportBean event = sendEvent("s0");
    EventBean eventReceived = testListener.assertOneGetNewAndReset();
    assertEquals("s0", eventReceived.get("myString"));
    assertSame(event, eventReceived.get("myBean"));

    event = sendEvent("s1");
    eventReceived = testListener.assertOneGetNewAndReset();
    assertEquals("s1", eventReceived.get("myString"));
    assertSame(event, eventReceived.get("myBean"));
  }
Example #21
0
  public void testCoalesceLong_Compile() {
    String viewExpr =
        "select coalesce(longBoxed, intBoxed, shortBoxed) as result"
            + " from "
            + SupportBean.class.getName()
            + ".win:length(1000)";

    EPStatementObjectModel model = epService.getEPAdministrator().compileEPL(viewExpr);
    assertEquals(viewExpr, model.toEPL());

    epService.initialize();
    selectTestView = epService.getEPAdministrator().create(model);
    selectTestView.addListener(testListener);
    assertEquals(Long.class, selectTestView.getEventType().getPropertyType("result"));

    runCoalesceLong();
  }
  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"));
  }
Example #23
0
  public void testMinMaxWindowStats_Compile() throws Exception {
    String viewExpr =
        "select max(longBoxed, intBoxed) as myMax, "
            + "max(longBoxed, intBoxed, shortBoxed) as myMaxEx, "
            + "min(longBoxed, intBoxed) as myMin, "
            + "min(longBoxed, intBoxed, shortBoxed) as myMinEx"
            + " from "
            + SupportBean.class.getName()
            + ".win:length(3)";

    EPStatementObjectModel model = epService.getEPAdministrator().compileEPL(viewExpr);
    model = (EPStatementObjectModel) SerializableObjectCopier.copy(model);
    assertEquals(viewExpr, model.toEPL());

    selectTestView = epService.getEPAdministrator().create(model);
    selectTestView.addListener(testListener);
    testListener.reset();

    runMinMaxWindowStats();
  }
Example #24
0
  public void testOperators() {
    String viewExpr =
        "select longBoxed % intBoxed as myMod "
            + " from "
            + SupportBean.class.getName()
            + ".win:length(3) where not(longBoxed > intBoxed)";
    selectTestView = epService.getEPAdministrator().createEPL(viewExpr);
    selectTestView.addListener(testListener);

    sendEvent(1, 1, (short) 0);
    assertEquals(0l, testListener.getLastNewData()[0].get("myMod"));
    testListener.reset();

    sendEvent(2, 1, (short) 0);
    assertFalse(testListener.getAndClearIsInvoked());

    sendEvent(2, 3, (short) 0);
    assertEquals(2l, testListener.getLastNewData()[0].get("myMod"));
    testListener.reset();
  }
Example #25
0
  public void testMinMaxWindowStats_OM() throws Exception {
    String viewExpr =
        "select max(longBoxed, intBoxed) as myMax, "
            + "max(longBoxed, intBoxed, shortBoxed) as myMaxEx, "
            + "min(longBoxed, intBoxed) as myMin, "
            + "min(longBoxed, intBoxed, shortBoxed) as myMinEx"
            + " from "
            + SupportBean.class.getName()
            + ".win:length(3)";

    EPStatementObjectModel model = new EPStatementObjectModel();
    model.setSelectClause(
        SelectClause.create()
            .add(Expressions.max("longBoxed", "intBoxed"), "myMax")
            .add(
                Expressions.max(
                    Expressions.property("longBoxed"),
                    Expressions.property("intBoxed"),
                    Expressions.property("shortBoxed")),
                "myMaxEx")
            .add(Expressions.min("longBoxed", "intBoxed"), "myMin")
            .add(
                Expressions.min(
                    Expressions.property("longBoxed"),
                    Expressions.property("intBoxed"),
                    Expressions.property("shortBoxed")),
                "myMinEx"));
    model.setFromClause(
        FromClause.create(
            FilterStream.create(SupportBean.class.getName())
                .addView("win", "length", Expressions.constant(3))));
    model = (EPStatementObjectModel) SerializableObjectCopier.copy(model);
    assertEquals(viewExpr, model.toEPL());

    selectTestView = epService.getEPAdministrator().create(model);
    selectTestView.addListener(testListener);
    testListener.reset();

    runMinMaxWindowStats();
  }
  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"));
  }
  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"));
  }
  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"));
  }