Пример #1
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"});
  }
  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();
  }
Пример #3
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);
  }
Пример #4
0
  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"));
  }
Пример #5
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();
  }
Пример #6
0
  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"));
  }
Пример #7
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();
  }
Пример #8
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);
  }
Пример #9
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));
  }
Пример #10
0
  public void testJoinSelect() {
    String eventA = SupportBean.class.getName();
    String eventB = SupportBean.class.getName();

    String joinStatement =
        "select s0.doubleBoxed, s1.intPrimitive*s1.intBoxed/2.0 as div from "
            + eventA
            + "(theString='s0').win:length(3) as s0,"
            + eventB
            + "(theString='s1').win:length(3) as s1"
            + " where s0.doubleBoxed = s1.doubleBoxed";

    EPStatement joinView = epService.getEPAdministrator().createEPL(joinStatement);
    joinView.addListener(updateListener);

    EventType result = joinView.getEventType();
    assertEquals(Double.class, result.getPropertyType("s0.doubleBoxed"));
    assertEquals(Double.class, result.getPropertyType("div"));
    assertEquals(2, joinView.getEventType().getPropertyNames().length);

    assertNull(updateListener.getLastNewData());

    sendEvent("s0", 1, 4, 5);
    sendEvent("s1", 1, 3, 2);

    EventBean[] newEvents = updateListener.getLastNewData();
    assertEquals(1d, newEvents[0].get("s0.doubleBoxed"));
    assertEquals(3d, newEvents[0].get("div"));

    Iterator<EventBean> iterator = joinView.iterator();
    EventBean theEvent = iterator.next();
    assertEquals(1d, theEvent.get("s0.doubleBoxed"));
    assertEquals(3d, theEvent.get("div"));
  }
  public void testObjectArrayNested() {
    EPServiceProvider epService = getEngineInitialized(null, null, null);
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("TypeLev1", new String[] {"p1id"}, new Object[] {int.class});
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType(
            "TypeLev0", new String[] {"p0id", "p1"}, new Object[] {int.class, "TypeLev1"});
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType(
            "TypeRoot", new String[] {"rootId", "p0"}, new Object[] {int.class, "TypeLev0"});

    EPStatement stmt =
        epService.getEPAdministrator().createEPL("select * from TypeRoot.std:lastevent()");
    Object[] dataLev1 = {1000};
    Object[] dataLev0 = {100, dataLev1};
    epService.getEPRuntime().sendEvent(new Object[] {10, dataLev0}, "TypeRoot");
    EventBean theEvent = stmt.iterator().next();
    EPAssertionUtil.assertProps(
        theEvent, "rootId,p0.p0id,p0.p1.p1id".split(","), new Object[] {10, 100, 1000});
  }
Пример #12
0
  @Test
  public void timebatch() {
    final EPStatement eps =
        epService
            .getEPAdministrator()
            .createEPL("select avg(cost) as avg from StockTick.win:time_batch(3 sec)");
    eps.addListener(
        new UpdateListener() {
          @Override
          public void update(EventBean[] newEvents, EventBean[] oldEvents) {
            for (EventBean eb : newEvents) {
              System.out.printf("UPD\t%5.2fL\t%f\n", esperRunner.elapsedTime(), eb.get("avg"));
            }
          }
        });

    List<ScheduledEvent> seList = new ArrayList<>();
    seList.add(new ScheduledEvent(0, new StockTick("name", "code1", 1000, 0, 0.0)));
    seList.add(new ScheduledEvent(500, new StockTick("name", "code1", 2000, 0, 0.0)));
    seList.add(new ScheduledEvent(1500, new StockTick("name", "code2", 200, 0, 0.0)));
    seList.add(new ScheduledEvent(2500, new StockTick("name", "code1", 4000, 0, 0.0)));

    seList.add(new ScheduledEvent(3500, new StockTick("name", "code1", 5000, 0, 0.0)));
    seList.add(new ScheduledEvent(4500, new StockTick("name", "code1", 6000, 0, 0.0)));
    seList.add(new ScheduledEvent(5500, new StockTick("name", "code2", 300, 0, 0.0)));

    seList.add(new ScheduledEvent(9800, new StockTick("name", "code3", 7000, 0, 0.0)));
    seList.add(new ScheduledEvent(10000, new StockTick("name", "code1", 7000, 0, 0.0)));

    seList.add(new ScheduledEvent(20000, new StockTick("name", "code1", 7000, 0, 0.0)));
    esperRunner.startSendingAndSleepAndStop(seList, 24);
  }
Пример #13
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"));
  }
  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();
  }
Пример #15
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"));
  }
Пример #16
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});
  }
Пример #17
0
  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"));
  }
Пример #18
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();
  }
Пример #19
0
 private void assertTopLevelTypeInfo(EPStatement stmt) {
   assertEquals(Map.class, stmt.getEventType().getPropertyType("val0"));
   FragmentEventType fragType = stmt.getEventType().getFragmentType("val0");
   assertFalse(fragType.isIndexed());
   assertFalse(fragType.isNative());
   assertEquals(Object[][].class, fragType.getFragmentType().getPropertyType("thewindow"));
   assertEquals(Integer.class, fragType.getFragmentType().getPropertyType("thetotal"));
 }
 private void runAssertionIterateCreateTable(
     Object[][] expectedType, Object[] rowValues, EPStatement stmtCreate) {
   assertEventTypeAndEvent(
       stmtCreate.getEventType(),
       expectedType,
       stmtCreate.iterator().next().getUnderlying(),
       rowValues);
 }
Пример #21
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());
  }
Пример #22
0
  public void testLengthWindowGrouped() {
    String stmtText =
        "select symbol, price from "
            + SupportMarketDataBean.class.getName()
            + ".std:groupwin(symbol).win:length(2)";
    EPStatement stmt = epService.getEPAdministrator().createEPL(stmtText);
    SupportUpdateListener listener = new SupportUpdateListener();
    stmt.addListener(listener);

    sendEvent("IBM", 100);
  }
  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();
  }
  private void runAssertionSubquerySelectStar(Object[] rowValues, String epl) {
    EPStatement stmt = epService.getEPAdministrator().createEPL(epl);
    stmt.addListener(listener);

    assertEquals(Object[].class, stmt.getEventType().getPropertyType("mt"));

    epService.getEPRuntime().sendEvent(new SupportBean_S2(0));
    EventBean event = listener.assertOneGetNewAndReset();
    assertEventUnd(event.get("mt"), rowValues);

    stmt.destroy();
  }
Пример #25
0
  public void testJoinUnfiltered() {
    String stmtText =
        "select (select id from S3.win:length(1000)) as idS3, (select id from S4.win:length(1000)) as idS4 from S0.win:keepall() as s0, S1.win:keepall() as s1 where s0.id = s1.id";

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

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

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

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

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

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

    epService.getEPRuntime().sendEvent(new SupportBean_S3(-2));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(3));
    epService.getEPRuntime().sendEvent(new SupportBean_S1(3));
    EventBean[] events = listener.getNewDataListFlattened();
    assertEquals(3, events.length);
    for (int i = 0; i < events.length; i++) {
      assertEquals(null, events[i].get("idS3"));
      assertEquals(null, events[i].get("idS4"));
    }
  }
Пример #26
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"));
  }
Пример #27
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"));
  }
  private void runAssertionSubquerySelectWEnumMethod(Object[] rowValues) {
    String epl = "select (select * from MyTable).where(v=>v.key = 'G1') as mt from SupportBean_S2";
    EPStatement stmt = epService.getEPAdministrator().createEPL(epl);
    stmt.addListener(listener);

    assertEquals(Collection.class, stmt.getEventType().getPropertyType("mt"));

    epService.getEPRuntime().sendEvent(new SupportBean_S2(0));
    Collection coll = (Collection) listener.assertOneGetNewAndReset().get("mt");
    assertEventUnd(coll.iterator().next(), rowValues);

    stmt.destroy();
  }
  public void testPropertyOrSingleRowMethod() throws Exception {
    epService
        .getEPAdministrator()
        .getConfiguration()
        .addEventType("SupportBean", SupportBean.class);
    String text = "select surroundx('test') as val from SupportBean";
    EPStatement stmt = epService.getEPAdministrator().createEPL(text);
    stmt.addListener(listener);

    String fields[] = new String[] {"val"};
    epService.getEPRuntime().sendEvent(new SupportBean("a", 3));
    ArrayAssertionUtil.assertProps(
        listener.assertOneGetNewAndReset(), fields, new Object[] {"XtestX"});
  }
Пример #30
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"));
  }