コード例 #1
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));
  }
コード例 #2
0
ファイル: RuntimeConfigMain.java プロジェクト: arberzal/esper
  private void configureImport() {
    // the single-row functions to be called are in this class
    provider.getEPAdministrator().getConfiguration().addImport(this.getClass());

    // Add an event type that has a byte-type property value
    Map<String, Object> typeDefinition = new HashMap<String, Object>();
    typeDefinition.put("byteValue", byte.class);
    provider.getEPAdministrator().getConfiguration().addEventType("MyByteEvent", typeDefinition);

    // keep the last few events from the variant stream
    EPStatement stmt =
        provider
            .getEPAdministrator()
            .createEPL(
                "select RuntimeConfigMain.check2BitSet(byteValue) as check2BitSet from MyByteEvent");

    // send an event
    Map<String, Object> eventData = new HashMap<String, Object>();
    eventData.put("byteValue", 2);
    provider.getEPRuntime().sendEvent(eventData, "MyByteEvent");

    // print results
    System.out.println("\nConfigure Import:");
    System.out.println("Received:" + " check2BitSet=" + stmt.iterator().next().get("check2BitSet"));

    // send a second event
    eventData = new HashMap<String, Object>();
    eventData.put("byteValue", 1);
    provider.getEPRuntime().sendEvent(eventData, "MyByteEvent");

    // print results
    System.out.println("Received:" + " check2BitSet=" + stmt.iterator().next().get("check2BitSet"));
  }
コード例 #3
0
  public void testMultiStmtContributing() {
    runAssertionMultiStmtContributingDifferentAggs(false);
    runAssertionMultiStmtContributingDifferentAggs(true);

    // contribute to the same aggregation
    epService.getEPAdministrator().createEPL("create table sharedagg (total sum(int))");
    epService
        .getEPAdministrator()
        .createEPL(
            "into table sharedagg " + "select p00 as c0, sum(id) as total from SupportBean_S0")
        .addListener(listener);
    epService
        .getEPAdministrator()
        .createEPL(
            "into table sharedagg " + "select p10 as c0, sum(id) as total from SupportBean_S1")
        .addListener(listener);
    epService
        .getEPAdministrator()
        .createEPL("select theString as c0, sharedagg.total as total from SupportBean")
        .addListener(listener);

    epService.getEPRuntime().sendEvent(new SupportBean_S0(10, "A"));
    assertMultiStmtContributingTotal("A", 10);

    epService.getEPRuntime().sendEvent(new SupportBean_S1(-5, "B"));
    assertMultiStmtContributingTotal("B", 5);

    epService.getEPRuntime().sendEvent(new SupportBean_S0(2, "C"));
    assertMultiStmtContributingTotal("C", 7);
  }
コード例 #4
0
  public void testGroupedThreeKeyNoContext() throws Exception {
    String eplDeclare =
        "create table varTotal (key0 string primary key, key1 int primary key,"
            + "key2 long primary key, total sum(double), cnt count(*))";
    epService.getEPAdministrator().createEPL(eplDeclare);

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

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

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

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

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

    epService.getEPRuntime().sendEvent(new SupportBean_S0(10, "E1"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {2001.0, 2L});
  }
コード例 #5
0
  public void testEngineMetrics() {
    epService = EPServiceProviderManager.getProvider("MyURI", getConfig(10000, -1, true));
    epService.initialize();

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

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

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

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

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

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

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

    sendTimer(20000);
    sendTimer(21000);
    event = listener.assertOneGetNewAndReset();
    ArrayAssertionUtil.assertProps(event, engineFields, new Object[] {"MyURI", 21000L, 4L, 3L, 0L});
  }
コード例 #6
0
  private void runAssertionSingleRowFunc(Object[] rowValues) {
    // try join passing of params
    String eplJoin =
        "select "
            + this.getClass().getName()
            + ".myServiceEventBean(mt) as c0, "
            + this.getClass().getName()
            + ".myServiceObjectArray(mt) as c1 "
            + "from SupportBean_S2, MyTable as mt";
    EPStatement stmtJoin = epService.getEPAdministrator().createEPL(eplJoin);
    stmtJoin.addListener(listener);

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

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

    epService.getEPRuntime().sendEvent(new SupportBean_S2(0));
    result = listener.assertOneGetNewAndReset();
    assertEventUnd(result.get("c0"), rowValues);
    stmtSubquery.destroy();
  }
コード例 #7
0
  public void testCorrel() {
    // further math tests can be found in the view unit test
    EPAdministrator admin = epService.getEPAdministrator();
    admin.getConfiguration().addEventType("Market", SupportMarketDataBean.class);
    EPStatement statement =
        admin.createEPL(
            "select * from Market.std:groupwin(symbol).win:length(1000000).stat:correl(price, volume, feed)");
    SupportUpdateListener listener = new SupportUpdateListener();
    statement.addListener(listener);

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

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

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

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

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

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("ABC", 20.0, 2000L, "f4"));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"ABC", 1.0, "f4"});
  }
コード例 #8
0
  public void testSelfJoin() {
    // ESPER-528
    epService
        .getEPAdministrator()
        .createEPL(
            EventRepresentationEnum.MAP.getAnnotationText()
                + " create schema Product (product string, productsize int)");

    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(0));
    String query =
        " @Hint('reclaim_group_aged=1,reclaim_group_freq=1') select Product.product as product, Product.productsize as productsize from Product unidirectional"
            + " left outer join Product.win:time(3 seconds).std:groupwin(product,productsize).std:size() PrevProduct on Product.product=PrevProduct.product and Product.productsize=PrevProduct.productsize"
            + " having PrevProduct.size<2";
    epService.getEPAdministrator().createEPL(query);

    // Set to larger number of executions and monitor memory
    for (int i = 0; i < 10; i++) {
      sendProductNew(
          "The id of this product is deliberately very very long so that we can use up more memory per instance of this event sent into Esper "
              + i,
          i);
      epService.getEPRuntime().sendEvent(new CurrentTimeEvent(i * 100));
      // if (i % 2000 == 0) {
      //    System.out.println("i=" + i + "; Allocated: " + Runtime.getRuntime().totalMemory() /
      // 1024 / 1024 + "; Free: " + Runtime.getRuntime().freeMemory() / 1024 / 1024);
      // }
    }
  }
コード例 #9
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"));
  }
コード例 #10
0
  public void testReclaimTimeWindow() {
    sendTimer(0);

    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("SupportBean", SupportBean.class);
    epService
        .getEPAdministrator()
        .createEPL(
            "@Hint('reclaim_group_aged=30,reclaim_group_freq=5') "
                + "select longPrimitive, count(*) from SupportBean.std:groupwin(theString).win:time(3000000)");

    for (int i = 0; i < 10; i++) {
      SupportBean theEvent = new SupportBean(Integer.toString(i), i);
      epService.getEPRuntime().sendEvent(theEvent);
    }

    EPServiceProviderSPI spi = (EPServiceProviderSPI) epService;
    int handleCountBefore = spi.getSchedulingService().getScheduleHandleCount();
    assertEquals(10, handleCountBefore);

    sendTimer(1000000);
    epService.getEPRuntime().sendEvent(new SupportBean("E1", 1));

    int handleCountAfter = spi.getSchedulingService().getScheduleHandleCount();
    assertEquals(1, handleCountAfter);
  }
コード例 #11
0
  public void testOnMergeExpressions() {
    epService
        .getEPAdministrator()
        .createEPL("create table the_table (key string primary key, total count(*), value int)");
    epService
        .getEPAdministrator()
        .createEPL(
            "into table the_table select count(*) as total from SupportBean group by theString");
    epService
        .getEPAdministrator()
        .createEPL(
            "on SupportBean_S0 as s0 "
                + "merge the_table as tt "
                + "where s0.p00 = tt.key "
                + "when matched and the_table[s0.p00].total > 0"
                + "  then update set value = 1");
    epService
        .getEPAdministrator()
        .createEPL("select the_table[p10].value as c0 from SupportBean_S1")
        .addListener(listener);

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

    epService.getEPRuntime().sendEvent(new SupportBean_S1(0, "E1"));
    assertEquals(1, listener.assertOneGetNewAndReset().get("c0"));
  }
コード例 #12
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"));
  }
コード例 #13
0
ファイル: RuntimeConfigMain.java プロジェクト: arberzal/esper
  private void configureVariantStream() {

    ConfigurationVariantStream variantStream = new ConfigurationVariantStream();
    variantStream.setTypeVariance(
        ConfigurationVariantStream.TypeVariance
            .ANY); // allow any type of event to be inserted into the stream

    // add variant stream
    provider
        .getEPAdministrator()
        .getConfiguration()
        .addVariantStream("MyVariantStream", variantStream);

    // keep the last few events from the variant stream
    EPStatement stmt =
        provider.getEPAdministrator().createEPL("select * from MyVariantStream.win:time(1 min)");

    // insert MyEvent events into the variant stream
    provider.getEPAdministrator().createEPL("insert into MyVariantStream select * from MyEvent");

    // Add a second event type
    Map<String, Object> typeDefinition = new HashMap<String, Object>();
    typeDefinition.put("propertyOther", String.class);
    provider.getEPAdministrator().getConfiguration().addEventType("MyOtherEvent", typeDefinition);

    // insert MyOtherEvent events into the variant stream
    provider
        .getEPAdministrator()
        .createEPL("insert into MyVariantStream select * from MyOtherEvent");

    // send some events
    Map<String, Object> eventData = new HashMap<String, Object>();
    eventData.put("propertyOne", "value");
    eventData.put("propertyTwo", 10);
    provider.getEPRuntime().sendEvent(eventData, "MyEvent");

    eventData = new HashMap<String, Object>();
    eventData.put("propertyOther", "test");
    provider.getEPRuntime().sendEvent(eventData, "MyOtherEvent");

    // print results
    System.out.println("\nConfigure Variant Stream:");
    Iterator<EventBean> iterator = stmt.iterator();
    EventBean first = iterator.next();
    System.out.println(
        "Received (1):"
            + " propertyOne="
            + first.get("propertyOne")
            + " propertyOther="
            + first.get("propertyOther"));

    EventBean second = iterator.next();
    System.out.println(
        "Received (2):"
            + " propertyOne="
            + second.get("propertyOne")
            + " propertyOther="
            + second.get("propertyOther"));
  }
コード例 #14
0
  private void runAssertionGroupedMixedMethodAndAccess(boolean soda) throws Exception {
    String eplDeclare =
        "create table varMyAgg ("
            + "key string primary key, "
            + "c0 count(*), "
            + "c1 count(distinct object), "
            + "c2 window(*) @type('SupportBean'), "
            + "c3 sum(long)"
            + ")";
    SupportModelHelper.createByCompileOrParse(epService, soda, eplDeclare);

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

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

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

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

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

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

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

    epService.getEPAdministrator().destroyAllStatements();
  }
コード例 #15
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"));
  }
コード例 #16
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"));
  }
コード例 #17
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"));
  }
コード例 #18
0
  public void testSchemaXMLWSchemaWithAll() throws Exception {
    Configuration config = SupportConfigFactory.getConfiguration();
    ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM();
    eventTypeMeta.setRootElementName("event-page-visit");
    String schemaUri =
        TestSchemaXMLEvent.class
            .getClassLoader()
            .getResource(CLASSLOADER_SCHEMA_WITH_ALL_URI)
            .toString();
    eventTypeMeta.setSchemaResource(schemaUri);
    eventTypeMeta.addNamespacePrefix("ss", "samples:schemas:simpleSchemaWithAll");
    eventTypeMeta.addXPathProperty("url", "/ss:event-page-visit/ss:url", XPathConstants.STRING);
    config.addEventType("PageVisitEvent", eventTypeMeta);

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

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

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

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

    EventType type =
        epService.getEPAdministrator().createEPL("select * from PageVisitEvent").getEventType();
    EPAssertionUtil.assertEqualsAnyOrder(
        new Object[] {
          new EventPropertyDescriptor(
              "sessionId", Node.class, null, false, false, false, false, true),
          new EventPropertyDescriptor(
              "customerId", Node.class, null, false, false, false, false, true),
          new EventPropertyDescriptor("url", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor("method", Node.class, null, false, false, false, false, true),
        },
        type.getPropertyDescriptors());
  }
コード例 #19
0
  private void runAssertionPerformance(boolean namedWindow, EventRepresentationEnum outputType) {

    String eplCreate =
        namedWindow
            ? outputType.getAnnotationText()
                + " create window MyWindow.win:keepall() as (c1 string, c2 int)"
            : "create table MyWindow(c1 string primary key, c2 int)";
    EPStatement stmtNamedWindow = epService.getEPAdministrator().createEPL(eplCreate);
    assertEquals(outputType.getOutputClass(), stmtNamedWindow.getEventType().getUnderlyingType());

    // preload events
    EPStatement stmt =
        epService
            .getEPAdministrator()
            .createEPL(
                "insert into MyWindow select theString as c1, intPrimitive as c2 from SupportBean");
    final int totalUpdated = 5000;
    for (int i = 0; i < totalUpdated; i++) {
      epService.getEPRuntime().sendEvent(new SupportBean("E" + i, 0));
    }
    stmt.destroy();

    String epl =
        "on SupportBean sb merge MyWindow nw where nw.c1 = sb.theString "
            + "when matched then update set nw.c2=sb.intPrimitive";
    stmt = epService.getEPAdministrator().createEPL(epl);
    stmt.addListener(mergeListener);

    // prime
    for (int i = 0; i < 100; i++) {
      epService.getEPRuntime().sendEvent(new SupportBean("E" + i, 1));
    }
    long startTime = System.currentTimeMillis();
    for (int i = 0; i < totalUpdated; i++) {
      epService.getEPRuntime().sendEvent(new SupportBean("E" + i, 1));
    }
    long endTime = System.currentTimeMillis();
    long delta = endTime - startTime;

    // verify
    Iterator<EventBean> events = stmtNamedWindow.iterator();
    int count = 0;
    for (; events.hasNext(); ) {
      EventBean next = events.next();
      assertEquals(1, next.get("c2"));
      count++;
    }
    assertEquals(totalUpdated, count);
    assertTrue("Delta=" + delta, delta < 500);

    epService.getEPAdministrator().destroyAllStatements();
    epService.getEPAdministrator().getConfiguration().removeEventType("MyWindow", true);
  }
コード例 #20
0
  private void runQuery(
      String epl, String fields, Object[][] expected, ContextPartitionSelector[] selectors) {
    // try FAF without prepare
    EPOnDemandQueryResult result = epService.getEPRuntime().executeQuery(epl, selectors);
    EPAssertionUtil.assertPropsPerRowAnyOrder(result.getArray(), fields.split(","), expected);

    // test prepare and execute
    EPOnDemandPreparedQuery preparedQuery = epService.getEPRuntime().prepareQuery(epl);
    EPOnDemandQueryResult resultPrepared = preparedQuery.execute(selectors);
    EPAssertionUtil.assertPropsPerRowAnyOrder(
        resultPrepared.getArray(), fields.split(","), expected);
  }
コード例 #21
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;
  }
コード例 #22
0
  private void runAssertionFireAndForgetInsertUpdateDelete(Object[][] expectedType) {
    EPOnDemandQueryResult result =
        epService.getEPRuntime().executeQuery("insert into MyTable(key) values ('dummy')");
    assertEventType(result.getEventType(), expectedType);

    result = epService.getEPRuntime().executeQuery("delete from MyTable where key = 'dummy'");
    assertEventType(result.getEventType(), expectedType);

    result =
        epService.getEPRuntime().executeQuery("update MyTable set key='dummy' where key='dummy'");
    assertEventType(result.getEventType(), expectedType);
  }
コード例 #23
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"));
  }
コード例 #24
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"));
  }
コード例 #25
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"));
  }
コード例 #26
0
  public void testScalar() {

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

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

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

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

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

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

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

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

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

    epService.getEPRuntime().sendEvent(SupportCollection.makeString(""));
    EPAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {null, null});
  }
コード例 #27
0
  public void testAnyTypeStaggered() {
    // test insert into staggered with map
    ConfigurationVariantStream configVariantStream = new ConfigurationVariantStream();
    configVariantStream.setTypeVariance(ConfigurationVariantStream.TypeVariance.ANY);
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addVariantStream("VarStream", configVariantStream);
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("SupportBean", SupportBean.class);
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("SupportMarketDataBean", SupportMarketDataBean.class);

    epService
        .getEPAdministrator()
        .createEPL("insert into MyStream select theString, intPrimitive from SupportBean");
    epService
        .getEPAdministrator()
        .createEPL("insert into VarStream select theString as abc from MyStream");
    epService
        .getEPAdministrator()
        .createEPL("@Name('Target') select * from VarStream.win:keepall()");

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

    EventBean[] arr =
        EPAssertionUtil.iteratorToArray(
            epService.getEPAdministrator().getStatement("Target").iterator());
    EPAssertionUtil.assertPropsPerRow(arr, new String[] {"abc"}, new Object[][] {{"E1"}});

    epService
        .getEPAdministrator()
        .createEPL("insert into MyStream2 select feed from SupportMarketDataBean");
    epService
        .getEPAdministrator()
        .createEPL("insert into VarStream select feed as abc from MyStream2");

    epService.getEPRuntime().sendEvent(new SupportMarketDataBean("IBM", 1, 1L, "E2"));

    arr =
        EPAssertionUtil.iteratorToArray(
            epService.getEPAdministrator().getStatement("Target").iterator());
    EPAssertionUtil.assertPropsPerRow(arr, new String[] {"abc"}, new Object[][] {{"E1"}, {"E2"}});
  }
コード例 #28
0
  private void runAssertionSingleMethod() {
    String fields[] = new String[] {"val"};
    epService.getEPRuntime().sendEvent(new SupportBean("a", 2));
    ArrayAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {8});

    listener.reset();
  }
コード例 #29
0
  public void testSchemaXMLWSchemaWithRestriction() throws Exception {
    Configuration config = SupportConfigFactory.getConfiguration();
    ConfigurationEventTypeXMLDOM eventTypeMeta = new ConfigurationEventTypeXMLDOM();
    eventTypeMeta.setRootElementName("order");
    InputStream schemaStream =
        TestSchemaXMLEvent.class
            .getClassLoader()
            .getResourceAsStream(CLASSLOADER_SCHEMA_WITH_RESTRICTION_URI);
    assertNotNull(schemaStream);
    String schemaText = ParserTool.linesToText(ParserTool.readFile(schemaStream));
    eventTypeMeta.setSchemaText(schemaText);
    config.addEventType("OrderEvent", eventTypeMeta);

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

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

    SupportXML.sendEvent(
        epService.getEPRuntime(),
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<order>\n"
            + "<order_amount>202.1</order_amount>"
            + "</order>");
    EventBean theEvent = updateListener.getLastNewData()[0];
    assertEquals(Double.class, theEvent.get("order_amount").getClass());
    assertEquals(202.1d, theEvent.get("order_amount"));
    updateListener.reset();
  }
コード例 #30
0
ファイル: TestPerRowFunc.java プロジェクト: arberzal/esper
 private void sendBoxedEvent(Long longBoxed, Integer intBoxed, Short shortBoxed) {
   SupportBean bean = new SupportBean();
   bean.setLongBoxed(longBoxed);
   bean.setIntBoxed(intBoxed);
   bean.setShortBoxed(shortBoxed);
   epService.getEPRuntime().sendEvent(bean);
 }