コード例 #1
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);
      // }
    }
  }
コード例 #2
0
  public void testInvalidConfigure() {
    tryInvalidConfigure("a b", "MyClass", "some");
    tryInvalidConfigure("abc", "My Class", "other s");

    // configured twice
    try {
      epService
          .getEPAdministrator()
          .getConfiguration()
          .addPlugInSingleRowFunction("concatstring", MySingleRowFunction.class.getName(), "xyz");
      epService
          .getEPAdministrator()
          .getConfiguration()
          .addPlugInAggregationFunction(
              "concatstring", MyConcatAggregationFunction.class.getName());
      fail();
    } catch (ConfigurationException ex) {
      // expected
    }

    // configured twice
    try {
      epService
          .getEPAdministrator()
          .getConfiguration()
          .addPlugInAggregationFunction("teststring", MyConcatAggregationFunction.class.getName());
      epService
          .getEPAdministrator()
          .getConfiguration()
          .addPlugInSingleRowFunction("teststring", MySingleRowFunction.class.getName(), "xyz");
      fail();
    } catch (ConfigurationException ex) {
      // expected
    }
  }
コード例 #3
0
  public void testContextContents() throws Exception {
    Configuration configuration = getConfiguration();
    configuration.addPlugInEventRepresentation(
        new URI("type://test/support"), SupportEventRepresentation.class.getName(), "abc");
    epService = EPServiceProviderManager.getDefaultProvider(configuration);
    epService.initialize();

    PlugInEventRepresentationContext initContext = SupportEventRepresentation.getInitContext();
    assertEquals(new URI("type://test/support"), initContext.getEventRepresentationRootURI());
    assertEquals("abc", initContext.getRepresentationInitializer());
    assertNotNull(initContext.getEventAdapterService());

    ConfigurationOperations runtimeConfig = epService.getEPAdministrator().getConfiguration();
    runtimeConfig.addPlugInEventType(
        "TestTypeOne", new URI[] {new URI("type://test/support?a=b&c=d")}, "t1");

    PlugInEventTypeHandlerContext context = SupportEventRepresentation.getAcceptTypeContext();
    assertEquals(new URI("type://test/support?a=b&c=d"), context.getEventTypeResolutionURI());
    assertEquals("t1", context.getTypeInitializer());
    assertEquals("TestTypeOne", context.getEventTypeName());

    context = SupportEventRepresentation.getEventTypeContext();
    assertEquals(new URI("type://test/support?a=b&c=d"), context.getEventTypeResolutionURI());
    assertEquals("t1", context.getTypeInitializer());
    assertEquals("TestTypeOne", context.getEventTypeName());

    epService.getEPRuntime().getEventSender(new URI[] {new URI("type://test/support?a=b")});
    PlugInEventBeanReflectorContext contextBean = SupportEventRepresentation.getEventBeanContext();
    assertEquals("type://test/support?a=b", contextBean.getResolutionURI().toString());
  }
コード例 #4
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});
  }
コード例 #5
0
  private void runAssertionOnSelectWindowAgg(Object[][] expectedType, Object[] rowValues) {
    EPStatement stmt =
        epService
            .getEPAdministrator()
            .createEPL(
                "on SupportBean_S2 select "
                    + "window(win.*) as c0,"
                    + "last(win.*) as c1, "
                    + "first(win.*) as c2, "
                    + "first(p1) as c3,"
                    + "window(p1) as c4,"
                    + "sorted(p1) as c5,"
                    + "minby(p1) as c6"
                    + " from MyTable as win");
    stmt.addListener(listener);

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

    stmt.destroy();
  }
コード例 #6
0
  private void runAssertionSubquerySelectStar(Object[] rowValues) {
    String eplFiltered =
        "select (select * from MyTable where key = 'G1') as mt from SupportBean_S2";
    runAssertionSubquerySelectStar(rowValues, eplFiltered);

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

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

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

    stmt.destroy();
  }
コード例 #7
0
  public void testInvalid() {
    EPServiceProvider epService = getEngineInitialized(null, null, null);

    // can add the same nested type twice
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("ABC", new String[] {"p0"}, new Class[] {int.class});
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("ABC", new String[] {"p0"}, new Class[] {int.class});
    try {
      // changing the definition however stops the compatibility
      epService
          .getEPAdministrator()
          .getConfiguration()
          .addEventType("ABC", new String[] {"p0"}, new Class[] {long.class});
      fail();
    } catch (ConfigurationException ex) {
      assertEquals(
          "Event type named 'ABC' has already been declared with differing column name or type information: Type by name 'ABC' in property 'p0' expected class java.lang.Integer but receives class java.lang.Long",
          ex.getMessage());
    }

    tryInvalid(
        epService,
        new String[] {"a"},
        new Object[] {new SupportBean()},
        "Nestable type configuration encountered an unexpected property type of 'SupportBean' for property 'a', expected java.lang.Class or java.util.Map or the name of a previously-declared Map or ObjectArray type");
  }
コード例 #8
0
ファイル: TestPerRowFunc.java プロジェクト: arberzal/esper
  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();
  }
コード例 #9
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();
  }
コード例 #10
0
ファイル: RuntimeConfigMain.java プロジェクト: arberzal/esper
  private void configureVariables() {

    provider.getEPAdministrator().getConfiguration().addVariable("myintvar", int.class, 5);

    EPStatement stmt =
        provider
            .getEPAdministrator()
            .createEPL("select propertyOne, propertyTwo, myintvar from MyEvent");

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

    // the statement above keeps the last event for iterating
    EventBean received = stmt.iterator().next();
    System.out.println("\nConfigure Variables:");
    System.out.println(
        "Received:"
            + " propertyOne="
            + received.get("propertyOne")
            + " propertyTwo="
            + received.get("propertyTwo")
            + " myintvar="
            + received.get("myintvar"));
  }
コード例 #11
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);
  }
コード例 #12
0
ファイル: TestInsertInto.java プロジェクト: jimmyathf/esper
  public void testStaggeredWithWildcard() {
    String statementOne =
        "insert into streamA select * from " + SupportBeanSimple.class.getName() + ".win:length(5)";
    String statementTwo =
        "insert into streamB select *, myInt+myInt as summed, myString||myString as concat from streamA.win:length(5)";
    String statementThree = "insert into streamC select * from streamB.win:length(5)";

    SupportUpdateListener listenerOne = new SupportUpdateListener();
    SupportUpdateListener listenerTwo = new SupportUpdateListener();
    SupportUpdateListener listenerThree = new SupportUpdateListener();

    epService.getEPAdministrator().createEPL(statementOne).addListener(listenerOne);
    epService.getEPAdministrator().createEPL(statementTwo).addListener(listenerTwo);
    epService.getEPAdministrator().createEPL(statementThree).addListener(listenerThree);

    sendSimpleEvent("one", 1);
    assertSimple(listenerOne, "one", 1, null, 0);
    assertSimple(listenerTwo, "one", 1, "oneone", 2);
    assertSimple(listenerThree, "one", 1, "oneone", 2);

    sendSimpleEvent("two", 2);
    assertSimple(listenerOne, "two", 2, null, 0);
    assertSimple(listenerTwo, "two", 2, "twotwo", 4);
    assertSimple(listenerThree, "two", 2, "twotwo", 4);
  }
コード例 #13
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"));
  }
コード例 #14
0
ファイル: TestInsertInto.java プロジェクト: jimmyathf/esper
  public void testInvalidStreamUsed() {
    String stmtText =
        "insert into Event_1 (delta, product) "
            + "select intPrimitive - intBoxed as deltaTag, intPrimitive * intBoxed as productTag "
            + "from "
            + SupportBean.class.getName()
            + ".win:length(100)";
    epService.getEPAdministrator().createEPL(stmtText);

    try {
      stmtText =
          "insert into Event_1(delta) "
              + "select (intPrimitive - intBoxed) as deltaTag "
              + "from "
              + SupportBean.class.getName()
              + ".win:length(100)";
      epService.getEPAdministrator().createEPL(stmtText);
      fail();
    } catch (EPStatementException ex) {
      // expected
      assertEquals(
          "Error starting statement: Event type named 'Event_1' has already been declared with differing column name or type information: Type by name 'Event_1' expects 2 properties but receives 1 properties [insert into Event_1(delta) select (intPrimitive - intBoxed) as deltaTag from com.espertech.esper.support.bean.SupportBean.win:length(100)]",
          ex.getMessage());
    }
  }
コード例 #15
0
ファイル: TestInsertInto.java プロジェクト: jimmyathf/esper
  public void testVariantOneWildcard() {
    String stmtText =
        "insert into Event_1 (delta, product) "
            + "select * from "
            + SupportBean.class.getName()
            + ".win:length(100)";

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

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

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

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

    epService.getEPRuntime().sendEvent(new SupportBean("E1", 1));
    assertEquals("E1", listener.assertOneGetNew().get("theString"));
    assertTrue(listener.assertOneGetNew() instanceof BeanEventBean);
  }
コード例 #16
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));
  }
コード例 #17
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});
  }
コード例 #18
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"});
  }
コード例 #19
0
  public void testExprSelectClauseRenderingUnnamedCol() {
    epService
        .getEPAdministrator()
        .createEPL(
            "create table varagg ("
                + "key string primary key, theEvents window(*) @type(SupportBean))");

    EPStatement stmtSelect =
        epService
            .getEPAdministrator()
            .createEPL(
                "select "
                    + "varagg.keys(),"
                    + "varagg[p00].theEvents,"
                    + "varagg[p00],"
                    + "varagg[p00].theEvents.last(*),"
                    + "varagg[p00].theEvents.window(*).take(1) from SupportBean_S0");

    Object[][] expectedAggType =
        new Object[][] {
          {"varagg.keys()", Object[].class},
          {"varagg[p00].theEvents", SupportBean[].class},
          {"varagg[p00]", Map.class},
          {"varagg[p00].theEvents.last(*)", SupportBean.class},
          {"varagg[p00].theEvents.window(*).take(1)", Collection.class},
        };
    EventTypeAssertionUtil.assertEventTypeProperties(
        expectedAggType,
        stmtSelect.getEventType(),
        EventTypeAssertionEnum.NAME,
        EventTypeAssertionEnum.TYPE);
  }
コード例 #20
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();
  }
コード例 #21
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"));
  }
コード例 #22
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();
  }
コード例 #23
0
 public void testUnfilteredStreamPrior_Compile() throws Exception {
   String stmtText = "select (select prior(0, id) from S1.win:length(1000)) as idS1 from S0";
   EPStatementObjectModel model = epService.getEPAdministrator().compileEPL(stmtText);
   model = (EPStatementObjectModel) SerializableObjectCopier.copy(model);
   assertEquals(stmtText, model.toEPL());
   EPStatement stmt = epService.getEPAdministrator().create(model);
   runUnfilteredStreamPrior(stmt);
 }
コード例 #24
0
 public void setUp() {
   Configuration config = SupportConfigFactory.getConfiguration();
   epService = EPServiceProviderManager.getDefaultProvider(config);
   epService.initialize();
   epService
       .getEPAdministrator()
       .getConfiguration()
       .addEventType("SupportBean", SupportBean.class);
   epService.getEPAdministrator().getConfiguration().addEventType("ABean", SupportBean_S0.class);
 }
コード例 #25
0
  /*
   * Use case 3: dynamic event type resolution
   *   a) Register all representations with URI via configuration
   *   b) Via configuration, set a list of URIs to use for resolving new event type names
   *   c) Compile statement with an event type name that is not defined yet, each of the representations are asked to accept, in URI hierarchy order
   *     admin.createEPL("select a, b, c from MyEventType");
   *    // engine asks each event representation to create an EventType, takes the first valid one
   *   d) Get EventSender to send in that specific type of event, or a URI-list dynamic reflection sender
   */
  public void testRuntimeConfigDynamicTypeResolution() throws Exception {
    Configuration configuration = getConfiguration();
    epService = EPServiceProviderManager.getDefaultProvider(configuration);
    epService.initialize();

    URI[] uriList = new URI[] {new URI("type://properties/test2/myresolver")};
    epService.getEPAdministrator().getConfiguration().setPlugInEventTypeResolutionURIs(uriList);

    runAssertionCaseDynamic(epService);
  }
コード例 #26
0
  public void testWhereClauseReturningTrue() {
    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_S1(10));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(2));
    assertEquals(2, listener.assertOneGetNewAndReset().get("id"));
  }
コード例 #27
0
  private void runAssertionInsertIntoBean(Object[] rowValues) {
    epService.getEPAdministrator().getConfiguration().addEventType(MyBeanCtor.class);
    String epl = "insert into MyBeanCtor select * from SupportBean_S2, MyTable";
    EPStatement stmt = epService.getEPAdministrator().createEPL(epl);
    stmt.addListener(listener);

    epService.getEPRuntime().sendEvent(new SupportBean_S2(0));
    assertEventUnd(listener.assertOneGetNewAndReset().get("arr"), rowValues);

    stmt.destroy();
  }
コード例 #28
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());
  }
コード例 #29
0
  private EPServiceProvider getEngineInitialized(
      String name, String[] propertyNames, Object[] propertyTypes) {
    Configuration configuration = SupportConfigFactory.getConfiguration();
    if (name != null) {
      configuration.addEventType(name, propertyNames, propertyTypes);
    }

    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(configuration);
    epService.initialize();
    return epService;
  }
コード例 #30
0
ファイル: TestPerRowFunc.java プロジェクト: arberzal/esper
 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);
 }