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); }
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); }
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}); }
public void testVariantOneWildcard() { String stmtText = "insert into Event_1 (delta, product) " + "select * from " + SupportBean.class.getName() + ".win:length(100)"; try { epService.getEPAdministrator().createEPL(stmtText); fail(); } catch (EPStatementException ex) { // Expected } // assert statement-type reference EPServiceProviderSPI spi = (EPServiceProviderSPI) epService; assertFalse(spi.getStatementEventTypeRef().isInUse("Event_1")); // test insert wildcard to wildcard epService.getEPAdministrator().getConfiguration().addEventType(SupportBean.class); SupportUpdateListener listener = new SupportUpdateListener(); String stmtSelectText = "insert into ABCStream select * from SupportBean"; EPStatement stmtSelect = epService.getEPAdministrator().createEPL(stmtSelectText, "resilient i0"); stmtSelect.addListener(listener); assertTrue(stmtSelect.getEventType() instanceof BeanEventType); epService.getEPRuntime().sendEvent(new SupportBean("E1", 1)); assertEquals("E1", listener.assertOneGetNew().get("theString")); assertTrue(listener.assertOneGetNew() instanceof BeanEventBean); }
public void 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); }
public void testMultiStmtContributing() { runAssertionMultiStmtContributingDifferentAggs(false); runAssertionMultiStmtContributingDifferentAggs(true); // contribute to the same aggregation epService.getEPAdministrator().createEPL("create table sharedagg (total sum(int))"); epService .getEPAdministrator() .createEPL( "into table sharedagg " + "select p00 as c0, sum(id) as total from SupportBean_S0") .addListener(listener); epService .getEPAdministrator() .createEPL( "into table sharedagg " + "select p10 as c0, sum(id) as total from SupportBean_S1") .addListener(listener); epService .getEPAdministrator() .createEPL("select theString as c0, sharedagg.total as total from SupportBean") .addListener(listener); epService.getEPRuntime().sendEvent(new SupportBean_S0(10, "A")); assertMultiStmtContributingTotal("A", 10); epService.getEPRuntime().sendEvent(new SupportBean_S1(-5, "B")); assertMultiStmtContributingTotal("B", 5); epService.getEPRuntime().sendEvent(new SupportBean_S0(2, "C")); assertMultiStmtContributingTotal("C", 7); }
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}); }
public void testOnMergeExpressions() { epService .getEPAdministrator() .createEPL("create table the_table (key string primary key, total count(*), value int)"); epService .getEPAdministrator() .createEPL( "into table the_table select count(*) as total from SupportBean group by theString"); epService .getEPAdministrator() .createEPL( "on SupportBean_S0 as s0 " + "merge the_table as tt " + "where s0.p00 = tt.key " + "when matched and the_table[s0.p00].total > 0" + " then update set value = 1"); epService .getEPAdministrator() .createEPL("select the_table[p10].value as c0 from SupportBean_S1") .addListener(listener); epService.getEPRuntime().sendEvent(new SupportBean("E1", -1)); epService.getEPRuntime().sendEvent(new SupportBean_S0(0, "E1")); epService.getEPRuntime().sendEvent(new SupportBean_S1(0, "E1")); assertEquals(1, listener.assertOneGetNewAndReset().get("c0")); }
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"); }
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 } }
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}); }
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()); } }
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")); }
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(); }
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")); }
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); // } } }
public void testScalar() { String[] fields = "val0,val1".split(","); String eplFragment = "select " + "strvals.mostFrequent() as val0, " + "strvals.leastFrequent() as val1 " + "from SupportCollection"; EPStatement stmtFragment = epService.getEPAdministrator().createEPL(eplFragment); stmtFragment.addListener(listener); LambdaAssertionUtil.assertTypes( stmtFragment.getEventType(), fields, new Class[] {String.class, String.class}); epService.getEPRuntime().sendEvent(SupportCollection.makeString("E2,E1,E2,E1,E3,E3,E4,E3")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {"E3", "E4"}); epService.getEPRuntime().sendEvent(SupportCollection.makeString("E1")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {"E1", "E1"}); epService.getEPRuntime().sendEvent(SupportCollection.makeString(null)); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, null}); epService.getEPRuntime().sendEvent(SupportCollection.makeString("")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, null}); stmtFragment.destroy(); epService .getEPAdministrator() .getConfiguration() .addPlugInSingleRowFunction( "extractNum", TestEnumMinMax.MyService.class.getName(), "extractNum"); String eplLambda = "select " + "strvals.mostFrequent(v => extractNum(v)) as val0, " + "strvals.leastFrequent(v => extractNum(v)) as val1 " + "from SupportCollection"; EPStatement stmtLambda = epService.getEPAdministrator().createEPL(eplLambda); stmtLambda.addListener(listener); LambdaAssertionUtil.assertTypes( stmtLambda.getEventType(), fields, new Class[] {Integer.class, Integer.class}); epService.getEPRuntime().sendEvent(SupportCollection.makeString("E2,E1,E2,E1,E3,E3,E4,E3")); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {3, 4}); epService.getEPRuntime().sendEvent(SupportCollection.makeString("E1")); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {1, 1}); epService.getEPRuntime().sendEvent(SupportCollection.makeString(null)); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, null}); epService.getEPRuntime().sendEvent(SupportCollection.makeString("")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, null}); }
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")); }
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); }
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")); }
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); }
public void testArrayProperty() { EPServiceProvider epService = getEngineInitialized(null, null, null); // test map containing first-level property that is an array of primitive or Class String[] props = {"p0", "p1"}; Object[] types = {int[].class, SupportBean[].class}; epService.getEPAdministrator().getConfiguration().addEventType("MyArrayOA", props, types); EPStatement stmt = epService .getEPAdministrator() .createEPL( "select p0[0] as a, p0[1] as b, p1[0].intPrimitive as c, p1[1] as d, p0 as e from MyArrayOA"); SupportUpdateListener listener = new SupportUpdateListener(); stmt.addListener(listener); int[] p0 = new int[] {1, 2, 3}; SupportBean[] beans = new SupportBean[] {new SupportBean("e1", 5), new SupportBean("e2", 6)}; Object[] eventData = new Object[] {p0, beans}; epService.getEPRuntime().sendEvent(eventData, "MyArrayOA"); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), "a,b,c,d,e".split(","), new Object[] {1, 2, 5, beans[1], p0}); assertEquals(int.class, stmt.getEventType().getPropertyType("a")); assertEquals(int.class, stmt.getEventType().getPropertyType("b")); assertEquals(int.class, stmt.getEventType().getPropertyType("c")); assertEquals(SupportBean.class, stmt.getEventType().getPropertyType("d")); assertEquals(int[].class, stmt.getEventType().getPropertyType("e")); stmt.destroy(); // test map at the second level of a nested map that is an array of primitive or Class epService .getEPAdministrator() .getConfiguration() .addEventType("MyArrayOAMapOuter", new String[] {"outer"}, new Object[] {"MyArrayOA"}); stmt = epService .getEPAdministrator() .createEPL( "select outer.p0[0] as a, outer.p0[1] as b, outer.p1[0].intPrimitive as c, outer.p1[1] as d, outer.p0 as e from MyArrayOAMapOuter"); stmt.addListener(listener); epService.getEPRuntime().sendEvent(new Object[] {eventData}, "MyArrayOAMapOuter"); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), "a,b,c,d".split(","), new Object[] {1, 2, 5, beans[1]}); assertEquals(int.class, stmt.getEventType().getPropertyType("a")); assertEquals(int.class, stmt.getEventType().getPropertyType("b")); assertEquals(int.class, stmt.getEventType().getPropertyType("c")); assertEquals(SupportBean.class, stmt.getEventType().getPropertyType("d")); assertEquals(int[].class, stmt.getEventType().getPropertyType("e")); }
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")); }
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()); }
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 runAssertionPerformance(boolean namedWindow, EventRepresentationEnum outputType) { String eplCreate = namedWindow ? outputType.getAnnotationText() + " create window MyWindow.win:keepall() as (c1 string, c2 int)" : "create table MyWindow(c1 string primary key, c2 int)"; EPStatement stmtNamedWindow = epService.getEPAdministrator().createEPL(eplCreate); assertEquals(outputType.getOutputClass(), stmtNamedWindow.getEventType().getUnderlyingType()); // preload events EPStatement stmt = epService .getEPAdministrator() .createEPL( "insert into MyWindow select theString as c1, intPrimitive as c2 from SupportBean"); final int totalUpdated = 5000; for (int i = 0; i < totalUpdated; i++) { epService.getEPRuntime().sendEvent(new SupportBean("E" + i, 0)); } stmt.destroy(); String epl = "on SupportBean sb merge MyWindow nw where nw.c1 = sb.theString " + "when matched then update set nw.c2=sb.intPrimitive"; stmt = epService.getEPAdministrator().createEPL(epl); stmt.addListener(mergeListener); // prime for (int i = 0; i < 100; i++) { epService.getEPRuntime().sendEvent(new SupportBean("E" + i, 1)); } long startTime = System.currentTimeMillis(); for (int i = 0; i < totalUpdated; i++) { epService.getEPRuntime().sendEvent(new SupportBean("E" + i, 1)); } long endTime = System.currentTimeMillis(); long delta = endTime - startTime; // verify Iterator<EventBean> events = stmtNamedWindow.iterator(); int count = 0; for (; events.hasNext(); ) { EventBean next = events.next(); assertEquals(1, next.get("c2")); count++; } assertEquals(totalUpdated, count); assertTrue("Delta=" + delta, delta < 500); epService.getEPAdministrator().destroyAllStatements(); epService.getEPAdministrator().getConfiguration().removeEventType("MyWindow", true); }
public void testEnabledDisableRuntime() { EPStatement[] statements = new EPStatement[5]; Configuration config = getConfig(10000, 10000, true); epService = EPServiceProviderManager.getProvider("MyURI", config); epService.initialize(); sendTimer(1000); statements[0] = epService .getEPAdministrator() .createEPL("select * from " + StatementMetric.class.getName(), "stmtmetric"); statements[0].addListener(listenerStmtMetric); statements[1] = epService .getEPAdministrator() .createEPL("select * from " + EngineMetric.class.getName(), "enginemetric"); statements[1].addListener(listenerEngineMetric); statements[2] = epService .getEPAdministrator() .createEPL( "select * from SupportBean(intPrimitive=1).win:keepall() where MyMetricFunctions.takeCPUTime(longPrimitive)"); sendEvent("E1", 1, cpuGoalOneNano); sendTimer(11000); assertTrue(listenerStmtMetric.getAndClearIsInvoked()); assertTrue(listenerEngineMetric.getAndClearIsInvoked()); epService.getEPAdministrator().getConfiguration().setMetricsReportingDisabled(); sendEvent("E2", 2, cpuGoalOneNano); sendTimer(21000); assertFalse(listenerStmtMetric.getAndClearIsInvoked()); assertFalse(listenerEngineMetric.getAndClearIsInvoked()); sendTimer(31000); sendEvent("E3", 3, cpuGoalOneNano); assertFalse(listenerStmtMetric.getAndClearIsInvoked()); assertFalse(listenerEngineMetric.getAndClearIsInvoked()); epService.getEPAdministrator().getConfiguration().setMetricsReportingEnabled(); sendEvent("E4", 4, cpuGoalOneNano); sendTimer(41000); assertTrue(listenerStmtMetric.getAndClearIsInvoked()); assertTrue(listenerEngineMetric.getAndClearIsInvoked()); statements[2].destroy(); sendTimer(51000); assertTrue(listenerStmtMetric.isInvoked()); // metrics statements reported themselves assertTrue(listenerEngineMetric.isInvoked()); }
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; }
public void testNullType() { String stmtOneTxt = "insert into InZone select null as dummy from java.lang.String"; EPStatement stmtOne = epService.getEPAdministrator().createEPL(stmtOneTxt); assertTrue(stmtOne.getEventType().isProperty("dummy")); String stmtTwoTxt = "select dummy from InZone"; EPStatement stmtTwo = epService.getEPAdministrator().createEPL(stmtTwoTxt); SupportUpdateListener listener = new SupportUpdateListener(); stmtTwo.addListener(listener); epService.getEPRuntime().sendEvent("a"); assertNull(listener.assertOneGetNewAndReset().get("dummy")); }
public void 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"}); }