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));
  }
示例#2
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"));
  }
  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"));
  }
示例#5
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);
  }
  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"));
    }
  }
示例#7
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 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"));
  }
  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
  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"));
  }
示例#12
0
  public void testVariantOneEPLToOMStmt() throws Exception {
    String epl =
        "insert into Event_1(delta, product) "
            + "select intPrimitive - intBoxed as deltaTag, intPrimitive * intBoxed as productTag "
            + "from "
            + SupportBean.class.getName()
            + ".win:length(100)";

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

    EPStatement stmt = runAsserts(null, model);
    assertEquals(epl, stmt.getText());
  }
示例#13
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());
  }
示例#14
0
  public void testCoalesceDouble() {
    setupCoalesce(
        "coalesce(null, byteBoxed, shortBoxed, intBoxed, longBoxed, floatBoxed, doubleBoxed)");
    assertEquals(Double.class, selectTestView.getEventType().getPropertyType("result"));

    sendEventWithDouble(null, null, null, null, null, null);
    assertEquals(null, testListener.assertOneGetNewAndReset().get("result"));

    sendEventWithDouble(null, Short.parseShort("2"), null, null, null, 1d);
    assertEquals(2d, testListener.assertOneGetNewAndReset().get("result"));

    sendEventWithDouble(null, null, null, null, null, 100d);
    assertEquals(100d, testListener.assertOneGetNewAndReset().get("result"));

    sendEventWithDouble(null, null, null, null, 10f, 100d);
    assertEquals(10d, testListener.assertOneGetNewAndReset().get("result"));

    sendEventWithDouble(null, null, 1, 5l, 10f, 100d);
    assertEquals(1d, testListener.assertOneGetNewAndReset().get("result"));

    sendEventWithDouble(Byte.parseByte("3"), null, null, null, null, null);
    assertEquals(3d, testListener.assertOneGetNewAndReset().get("result"));

    sendEventWithDouble(null, null, null, 5l, 10f, 100d);
    assertEquals(5d, testListener.assertOneGetNewAndReset().get("result"));
  }
示例#15
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");
  }
示例#16
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();
  }
示例#17
0
 public void testMinMaxEventType() {
   setUpMinMax();
   EventType type = selectTestView.getEventType();
   log.debug(".testGetEventType properties=" + Arrays.toString(type.getPropertyNames()));
   assertEquals(Long.class, type.getPropertyType("myMax"));
   assertEquals(Long.class, type.getPropertyType("myMin"));
   assertEquals(Long.class, type.getPropertyType("myMinEx"));
   assertEquals(Long.class, type.getPropertyType("myMaxEx"));
 }
示例#18
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"));
  }
示例#19
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);
 }
示例#20
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);
 }
示例#21
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"));
  }
示例#22
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"));
  }
示例#23
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"));
  }
示例#24
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"));
  }
示例#25
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"));
  }
示例#26
0
  public void testVariantRStreamOMToStmt() throws Exception {
    EPStatementObjectModel model = new EPStatementObjectModel();
    model.setInsertInto(
        InsertIntoClause.create("Event_1", new String[0], StreamSelector.RSTREAM_ONLY));
    model.setSelectClause(SelectClause.create().add("intPrimitive", "intBoxed"));
    model.setFromClause(FromClause.create(FilterStream.create(SupportBean.class.getName())));
    model = (EPStatementObjectModel) SerializableObjectCopier.copy(model);

    EPStatement stmt = epService.getEPAdministrator().create(model, "s1");

    String epl =
        "insert rstream into Event_1 "
            + "select intPrimitive, intBoxed "
            + "from "
            + SupportBean.class.getName();
    assertEquals(epl, model.toEPL());
    assertEquals(epl, stmt.getText());

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

    // assert statement-type reference
    EPServiceProviderSPI spi = (EPServiceProviderSPI) epService;
    assertTrue(spi.getStatementEventTypeRef().isInUse("Event_1"));
    Set<String> stmtNames =
        spi.getStatementEventTypeRef().getStatementNamesForType(SupportBean.class.getName());
    assertTrue(stmtNames.contains("s1"));

    stmt.destroy();

    assertFalse(spi.getStatementEventTypeRef().isInUse("Event_1"));
    stmtNames =
        spi.getStatementEventTypeRef().getStatementNamesForType(SupportBean.class.getName());
    assertFalse(stmtNames.contains("s1"));
  }
示例#27
0
  public void testVariantOneOMToStmt() throws Exception {
    EPStatementObjectModel model = new EPStatementObjectModel();
    model.setInsertInto(InsertIntoClause.create("Event_1", "delta", "product"));
    model.setSelectClause(
        SelectClause.create()
            .add(Expressions.minus("intPrimitive", "intBoxed"), "deltaTag")
            .add(Expressions.multiply("intPrimitive", "intBoxed"), "productTag"));
    model.setFromClause(
        FromClause.create(
            FilterStream.create(SupportBean.class.getName())
                .addView(View.create("win", "length", Expressions.constant(100)))));
    model = (EPStatementObjectModel) SerializableObjectCopier.copy(model);

    EPStatement stmt = runAsserts(null, model);

    String epl =
        "insert into Event_1(delta, product) "
            + "select intPrimitive - intBoxed as deltaTag, intPrimitive * intBoxed as productTag "
            + "from "
            + SupportBean.class.getName()
            + ".win:length(100)";
    assertEquals(epl, model.toEPL());
    assertEquals(epl, stmt.getText());
  }
示例#28
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"));
  }
示例#29
0
  public void testCoalesceLong() {
    setupCoalesce("coalesce(longBoxed, intBoxed, shortBoxed)");
    assertEquals(Long.class, selectTestView.getEventType().getPropertyType("result"));

    sendEvent(1L, 2, (short) 3);
    assertEquals(1L, testListener.assertOneGetNewAndReset().get("result"));

    sendBoxedEvent(null, 2, null);
    assertEquals(2L, testListener.assertOneGetNewAndReset().get("result"));

    sendBoxedEvent(null, null, Short.parseShort("3"));
    assertEquals(3L, testListener.assertOneGetNewAndReset().get("result"));

    sendBoxedEvent(null, null, null);
    assertEquals(null, testListener.assertOneGetNewAndReset().get("result"));
  }
示例#30
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;
  }