Ejemplo n.º 1
0
  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);
  }
Ejemplo n.º 2
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);
  }
Ejemplo n.º 3
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));
  }
Ejemplo n.º 4
0
  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());
    }
  }
  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");
  }
Ejemplo n.º 6
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"));
  }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
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"));
  }
  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;
  }
Ejemplo n.º 10
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"));
    }
  }
Ejemplo n.º 11
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"));
  }
Ejemplo n.º 12
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"));
  }
Ejemplo n.º 13
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"));
  }
Ejemplo n.º 14
0
  public void testVariantTwoWildcard() throws InterruptedException {
    String stmtText =
        "insert into event1 select * from " + SupportBean.class.getName() + ".win:length(100)";
    String otherText = "select * from default.event1.win:length(10)";

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

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

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

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

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

    stmtTwo.destroy();
    assertFalse(spi.getStatementEventTypeRef().isInUse("event1"));
  }
Ejemplo n.º 15
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"));
  }
Ejemplo n.º 16
0
  public void testWithOutputLimitAndSort() {
    // NOTICE: we are inserting the RSTREAM (removed events)
    String stmtText =
        "insert rstream into StockTicks(mySymbol, myPrice) "
            + "select symbol, price from "
            + SupportMarketDataBean.class.getName()
            + ".win:time(60) "
            + "output every 5 seconds "
            + "order by symbol asc";
    epService.getEPAdministrator().createEPL(stmtText);

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

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

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

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

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

    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(70 * 1000));
    assertEquals("ABC", feedListener.getNewDataList().get(0)[0].get("mySymbol"));
    assertEquals(91.0, feedListener.getNewDataList().get(0)[0].get("pricesum"));
    assertEquals("DEF", feedListener.getNewDataList().get(1)[0].get("mySymbol"));
    assertEquals(191.0, feedListener.getNewDataList().get(1)[0].get("pricesum"));
  }
  public void 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"));
  }
Ejemplo n.º 18
0
  public void testInsertFromPattern() {
    String stmtOneText =
        "insert into streamA select * from pattern [every " + SupportBean.class.getName() + "]";
    SupportUpdateListener listenerOne = new SupportUpdateListener();
    EPStatement stmtOne = epService.getEPAdministrator().createEPL(stmtOneText);
    stmtOne.addListener(listenerOne);

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

    EventType eventType = stmtOne.getEventType();
    assertEquals(Map.class, eventType.getUnderlyingType());
  }
  public void testObjectArrayInheritanceInitTime() {
    Configuration configuration = SupportConfigFactory.getConfiguration();

    configuration.addEventType("RootEvent", new String[] {"base"}, new Object[] {String.class});
    configuration.addEventType("Sub1Event", new String[] {"sub1"}, new Object[] {String.class});
    configuration.addEventType("Sub2Event", new String[] {"sub2"}, new Object[] {String.class});
    configuration.addEventType("SubAEvent", new String[] {"suba"}, new Object[] {String.class});
    configuration.addEventType("SubBEvent", new String[] {"subb"}, new Object[] {String.class});

    configuration.addObjectArraySuperType("Sub1Event", "RootEvent");
    configuration.addObjectArraySuperType("Sub2Event", "RootEvent");
    configuration.addObjectArraySuperType("SubAEvent", "Sub1Event");
    configuration.addObjectArraySuperType("SubBEvent", "SubAEvent");

    try {
      configuration.addObjectArraySuperType("SubBEvent", "Sub2Event");
      fail();
    } catch (ConfigurationException ex) {
      assertEquals("Object-array event types may not have multiple supertypes", ex.getMessage());
    }

    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(configuration);
    epService.initialize();
    if (InstrumentationHelper.ENABLED) {
      InstrumentationHelper.startTest(epService, this.getClass(), getName());
    }

    EPAssertionUtil.assertEqualsExactOrder(
        new Object[] {
          new EventPropertyDescriptor(
              "base", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor(
              "sub1", String.class, null, false, false, false, false, false),
          new EventPropertyDescriptor(
              "suba", String.class, null, false, false, false, false, false),
        },
        ((EPServiceProviderSPI) epService)
            .getEventAdapterService()
            .getExistsTypeByName("SubAEvent")
            .getPropertyDescriptors());

    runObjectArrInheritanceAssertion(epService);

    if (InstrumentationHelper.ENABLED) {
      InstrumentationHelper.endTest();
    }
  }
  public void testConfiguredViaPropsAndXML() {
    Configuration configuration = SupportConfigFactory.getConfiguration();
    configuration
        .getEngineDefaults()
        .getEventMeta()
        .setDefaultEventRepresentation(Configuration.EventRepresentation.OBJECTARRAY);
    configuration.addEventType(
        "MyOAType",
        "bean,theString,map".split(","),
        new Object[] {SupportBean.class.getName(), "string", "java.util.Map"});

    EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(configuration);
    epService.initialize();
    if (InstrumentationHelper.ENABLED) {
      InstrumentationHelper.startTest(epService, this.getClass(), getName());
    }

    EventType eventType =
        epService.getEPAdministrator().getConfiguration().getEventType("MyOAType");
    assertEquals(Object[].class, eventType.getUnderlyingType());
    assertEquals(String.class, eventType.getPropertyType("theString"));
    assertEquals(Map.class, eventType.getPropertyType("map"));
    assertEquals(SupportBean.class, eventType.getPropertyType("bean"));

    EPStatement stmt =
        epService
            .getEPAdministrator()
            .createEPL("select bean, theString, map('key'), bean.theString from MyOAType");
    SupportUpdateListener listener = new SupportUpdateListener();
    stmt.addListener(listener);
    assertEquals(Object[].class, stmt.getEventType().getUnderlyingType());

    SupportBean bean = new SupportBean("E1", 1);
    epService
        .getEPRuntime()
        .sendEvent(
            new Object[] {bean, "abc", Collections.singletonMap("key", "value")}, "MyOAType");
    EPAssertionUtil.assertProps(
        listener.assertOneGetNew(),
        "bean,theString,map('key'),bean.theString".split(","),
        new Object[] {bean, "abc", "value", "E1"});

    if (InstrumentationHelper.ENABLED) {
      InstrumentationHelper.endTest();
    }
  }
Ejemplo n.º 21
0
 private void tryInvalid(String stmtText, String expectedMsg) {
   try {
     epService.getEPAdministrator().createEPL(stmtText);
     fail();
   } catch (EPStatementException ex) {
     assertEquals(expectedMsg, ex.getMessage());
   }
 }
Ejemplo n.º 22
0
 private SupportBean sendEvent(int intPrimitive, int intBoxed) {
   SupportBean bean = new SupportBean();
   bean.setTheString("myId");
   bean.setIntPrimitive(intPrimitive);
   bean.setIntBoxed(intBoxed);
   epService.getEPRuntime().sendEvent(bean);
   return bean;
 }
Ejemplo n.º 23
0
 public void setUp() {
   epService =
       EPServiceProviderManager.getDefaultProvider(SupportConfigFactory.getConfiguration());
   epService.initialize();
   feedListener = new SupportUpdateListener();
   resultListenerDelta = new SupportUpdateListener();
   resultListenerProduct = new SupportUpdateListener();
 }
Ejemplo n.º 24
0
  public void testInsertIntoPlusPattern() {
    String stmtOneTxt =
        "insert into InZone "
            + "select 111 as statementId, mac, locationReportId "
            + "from "
            + SupportRFIDEvent.class.getName()
            + " "
            + "where mac in ('1','2','3') "
            + "and zoneID = '10'";
    EPStatement stmtOne = epService.getEPAdministrator().createEPL(stmtOneTxt);
    SupportUpdateListener listenerOne = new SupportUpdateListener();
    stmtOne.addListener(listenerOne);

    String stmtTwoTxt =
        "insert into OutOfZone "
            + "select 111 as statementId, mac, locationReportId "
            + "from "
            + SupportRFIDEvent.class.getName()
            + " "
            + "where mac in ('1','2','3') "
            + "and zoneID != '10'";
    EPStatement stmtTwo = epService.getEPAdministrator().createEPL(stmtTwoTxt);
    SupportUpdateListener listenerTwo = new SupportUpdateListener();
    stmtTwo.addListener(listenerTwo);

    String stmtThreeTxt =
        "select 111 as eventSpecId, A.locationReportId as locationReportId "
            + " from pattern [every A=InZone -> (timer:interval(1 sec) and not OutOfZone(mac=A.mac))]";
    EPStatement stmtThree = epService.getEPAdministrator().createEPL(stmtThreeTxt);
    SupportUpdateListener listener = new SupportUpdateListener();
    stmtThree.addListener(listener);

    // try the alert case with 1 event for the mac in question
    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(0));
    epService.getEPRuntime().sendEvent(new SupportRFIDEvent("LR1", "1", "10"));
    assertFalse(listener.isInvoked());
    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(1000));

    EventBean theEvent = listener.assertOneGetNewAndReset();
    assertEquals("LR1", theEvent.get("locationReportId"));

    listenerOne.reset();
    listenerTwo.reset();

    // try the alert case with 2 events for zone 10 within 1 second for the mac in question
    epService.getEPRuntime().sendEvent(new SupportRFIDEvent("LR2", "2", "10"));
    assertFalse(listener.isInvoked());
    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(1500));
    epService.getEPRuntime().sendEvent(new SupportRFIDEvent("LR3", "2", "10"));
    assertFalse(listener.isInvoked());
    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(2000));

    theEvent = listener.assertOneGetNewAndReset();
    assertEquals("LR2", theEvent.get("locationReportId"));
  }
Ejemplo n.º 25
0
 private void tryInvalidConfig(
     String name, ConfigurationRevisionEventType config, String message) {
   try {
     epService.getEPAdministrator().getConfiguration().addRevisionEventType(name, config);
     fail();
   } catch (ConfigurationException ex) {
     assertEquals(message, ex.getMessage());
   }
 }
Ejemplo n.º 26
0
  private EPStatement runAsserts(String stmtText, EPStatementObjectModel model) {
    // Attach listener to feed
    EPStatement stmt = null;
    if (model != null) {
      stmt = epService.getEPAdministrator().create(model, "s1");
    } else {
      stmt = epService.getEPAdministrator().createEPL(stmtText);
    }
    stmt.addListener(feedListener);

    // send event for joins to match on
    epService.getEPRuntime().sendEvent(new SupportBean_A("myId"));

    // Attach delta statement to statement and add listener
    stmtText = "select min(delta) as minD, max(delta) as maxD " + "from Event_1.win:time(60)";
    EPStatement stmtTwo = epService.getEPAdministrator().createEPL(stmtText);
    stmtTwo.addListener(resultListenerDelta);

    // Attach prodict statement to statement and add listener
    stmtText = "select min(product) as minP, max(product) as maxP " + "from Event_1.win:time(60)";
    EPStatement stmtThree = epService.getEPAdministrator().createEPL(stmtText);
    stmtThree.addListener(resultListenerProduct);

    epService.getEPRuntime().sendEvent(new CurrentTimeEvent(0)); // Set the time to 0 seconds

    // send events
    sendEvent(20, 10);
    assertReceivedFeed(10, 200);
    assertReceivedMinMax(10, 10, 200, 200);

    sendEvent(50, 25);
    assertReceivedFeed(25, 25 * 50);
    assertReceivedMinMax(10, 25, 200, 1250);

    sendEvent(5, 2);
    assertReceivedFeed(3, 2 * 5);
    assertReceivedMinMax(3, 25, 10, 1250);

    epService
        .getEPRuntime()
        .sendEvent(new CurrentTimeEvent(10 * 1000)); // Set the time to 10 seconds

    sendEvent(13, 1);
    assertReceivedFeed(12, 13);
    assertReceivedMinMax(3, 25, 10, 1250);

    epService
        .getEPRuntime()
        .sendEvent(new CurrentTimeEvent(61 * 1000)); // Set the time to 61 seconds
    assertReceivedMinMax(12, 12, 13, 13);

    return stmt;
  }
Ejemplo n.º 27
0
  public void testUnfilteredExpression() {
    String stmtText = "select (select p10 || p11 from S1.std:lastevent()) as value from S0";

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

    // check type
    assertEquals(String.class, stmt.getEventType().getPropertyType("value"));

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

    // test one event
    epService.getEPRuntime().sendEvent(new SupportBean_S1(-1, "a", "b"));
    epService.getEPRuntime().sendEvent(new SupportBean_S0(1));
    event = listener.assertOneGetNewAndReset();
    assertEquals("ab", event.get("value"));
  }
 private void tryInvalid(
     EPServiceProvider epService, String[] names, Object[] types, String message) {
   try {
     epService.getEPAdministrator().getConfiguration().addEventType("NestedMap", names, types);
     fail();
   } catch (Exception ex) {
     log.error(ex, ex);
     assertTrue(
         "expected '" + message + "' but received '" + ex.getMessage(),
         ex.getMessage().contains(message));
   }
 }
Ejemplo n.º 29
0
 public void setUp() {
   Configuration config = SupportConfigFactory.getConfiguration();
   config.addEventType("S0", SupportBean_S0.class);
   config.addEventType("S1", SupportBean_S1.class);
   config.addEventType("S2", SupportBean_S2.class);
   config.addEventType("S3", SupportBean_S3.class);
   config.addEventType("S4", SupportBean_S4.class);
   config.addEventType("S5", SupportBean_S5.class);
   epService = EPServiceProviderManager.getDefaultProvider(config);
   epService.initialize();
   listener = new SupportUpdateListener();
 }
Ejemplo n.º 30
0
  public void testVariantTwoJoinWildcard() {
    String textOne =
        "insert into event2 select * "
            + "from "
            + SupportBean.class.getName()
            + ".win:length(100) as s0, "
            + SupportBean_A.class.getName()
            + ".win:length(5) as s1 "
            + "where s0.theString = s1.id";
    String textTwo = "select * from event2.win:length(10)";

    // Attach listener to feed
    EPStatement stmtOne = epService.getEPAdministrator().createEPL(textOne);
    SupportUpdateListener listenerOne = new SupportUpdateListener();
    stmtOne.addListener(listenerOne);
    EPStatement stmtTwo = epService.getEPAdministrator().createEPL(textTwo);
    SupportUpdateListener listenerTwo = new SupportUpdateListener();
    stmtTwo.addListener(listenerTwo);

    // send event for joins to match on
    SupportBean_A eventA = new SupportBean_A("myId");
    epService.getEPRuntime().sendEvent(eventA);

    SupportBean eventOne = sendEvent(10, 11);
    assertTrue(listenerOne.getAndClearIsInvoked());
    assertEquals(1, listenerOne.getLastNewData().length);
    assertEquals(2, listenerOne.getLastNewData()[0].getEventType().getPropertyNames().length);
    assertTrue(listenerOne.getLastNewData()[0].getEventType().isProperty("s0"));
    assertTrue(listenerOne.getLastNewData()[0].getEventType().isProperty("s1"));
    assertSame(eventOne, listenerOne.getLastNewData()[0].get("s0"));
    assertSame(eventA, listenerOne.getLastNewData()[0].get("s1"));

    assertTrue(listenerTwo.getAndClearIsInvoked());
    assertEquals(1, listenerTwo.getLastNewData().length);
    assertEquals(2, listenerTwo.getLastNewData()[0].getEventType().getPropertyNames().length);
    assertTrue(listenerTwo.getLastNewData()[0].getEventType().isProperty("s0"));
    assertTrue(listenerTwo.getLastNewData()[0].getEventType().isProperty("s1"));
    assertSame(eventOne, listenerOne.getLastNewData()[0].get("s0"));
    assertSame(eventA, listenerOne.getLastNewData()[0].get("s1"));
  }