public void testAfterCurrentRow() throws Exception { Configuration config = SupportConfigFactory.getConfiguration(); config.addEventType("MyEvent", SupportRecogBean.class); EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(config); epService.initialize(); String text = "select * from MyEvent.win:keepall() " + "match_recognize (" + " measures A.theString as a, B[0].theString as b0, B[1].theString as b1" + " after match skip to current row" + " pattern (A B*)" + " define" + " A as A.theString like \"A%\"," + " B as B.theString like \"B%\"" + ")"; EPStatement stmt = epService.getEPAdministrator().createEPL(text); SupportUpdateListener listener = new SupportUpdateListener(); stmt.addListener(listener); runAssertion(epService, listener, stmt); stmt.destroy(); EPStatementObjectModel model = epService.getEPAdministrator().compileEPL(text); SerializableObjectCopier.copy(model); assertEquals(text, model.toEPL()); stmt = epService.getEPAdministrator().create(model); stmt.addListener(listener); assertEquals(text, stmt.getText()); runAssertion(epService, listener, stmt); }
public void testSingleMethod() throws Exception { epService .getEPAdministrator() .getConfiguration() .addEventType("SupportBean", SupportBean.class); String text = "select power3(intPrimitive) as val from SupportBean"; EPStatement stmt = epService.getEPAdministrator().createEPL(text); stmt.addListener(listener); runAssertionSingleMethod(); stmt.destroy(); EPStatementObjectModel model = epService.getEPAdministrator().compileEPL(text); assertEquals(text, model.toEPL()); stmt = epService.getEPAdministrator().create(model); assertEquals(text, stmt.getText()); stmt.addListener(listener); runAssertionSingleMethod(); stmt.destroy(); epService .getEPAdministrator() .getConfiguration() .addEventType("SupportBean", SupportBean.class); text = "select power3(2) as val from SupportBean"; stmt = epService.getEPAdministrator().createEPL(text); stmt.addListener(listener); runAssertionSingleMethod(); }
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(); }
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}); }
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 testRelationalOpNullOrNoRows() { // test array String[] fields = "vall,vany".split(","); String stmtText = "select " + "intBoxed >= all ({doubleBoxed, longBoxed}) as vall, " + "intBoxed >= any ({doubleBoxed, longBoxed}) as vany " + " from SupportBean(string like 'E%')"; EPStatement stmt = epService.getEPAdministrator().createEPL(stmtText); stmt.addListener(listener); sendEvent("E3", null, null, null); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, null}); sendEvent("E4", 1, null, null); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, null}); sendEvent("E5", null, 1d, null); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, null}); sendEvent("E6", 1, 1d, null); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, true}); sendEvent("E7", 0, 1d, null); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {false, false}); // test fields stmt.destroy(); fields = "vall,vany".split(","); stmtText = "select " + "intBoxed >= all (doubleBoxed, longBoxed) as vall, " + "intBoxed >= any (doubleBoxed, longBoxed) as vany " + " from SupportBean(string like 'E%')"; stmt = epService.getEPAdministrator().createEPL(stmtText); stmt.addListener(listener); sendEvent("E3", null, null, null); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, null}); sendEvent("E4", 1, null, null); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, null}); sendEvent("E5", null, 1d, null); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, null}); sendEvent("E6", 1, 1d, null); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, true}); sendEvent("E7", 0, 1d, null); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {false, false}); }
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")); }
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 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")); }
public void testRelationalOpAllArray() { String[] fields = "g,ge".split(","); String stmtText = "select " + "longBoxed > all ({1, 2}, intArr, intCol) as g, " + "longBoxed >= all ({1, 2}, intArr, intCol) as ge " + "from ArrayBean"; EPStatement stmt = epService.getEPAdministrator().createEPL(stmtText); stmt.addListener(listener); SupportBeanArrayCollMap arrayBean = new SupportBeanArrayCollMap(new int[] {1, 2}); arrayBean.setIntCol(Arrays.asList(1, 2)); arrayBean.setLongBoxed(3L); epService.getEPRuntime().sendEvent(arrayBean); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {true, true}); arrayBean.setLongBoxed(2L); epService.getEPRuntime().sendEvent(arrayBean); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {false, true}); arrayBean = new SupportBeanArrayCollMap(new int[] {1, 3}); arrayBean.setIntCol(Arrays.asList(1, 2)); arrayBean.setLongBoxed(3L); epService.getEPRuntime().sendEvent(arrayBean); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {false, true}); arrayBean = new SupportBeanArrayCollMap(new int[] {1, 2}); arrayBean.setIntCol(Arrays.asList(1, 3)); arrayBean.setLongBoxed(3L); epService.getEPRuntime().sendEvent(arrayBean); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {false, true}); // test OM stmt.destroy(); EPStatementObjectModel model = epService.getEPAdministrator().compileEPL(stmtText); assertEquals(stmtText.replace("<>", "!="), model.toEPL()); stmt = epService.getEPAdministrator().create(model); stmt.addListener(listener); arrayBean = new SupportBeanArrayCollMap(new int[] {1, 2}); arrayBean.setIntCol(Arrays.asList(1, 2)); arrayBean.setLongBoxed(3L); epService.getEPRuntime().sendEvent(arrayBean); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {true, true}); }
public void testEqualsAll() { String[] fields = "eq,neq,sqlneq,nneq".split(","); String stmtText = "select " + "intPrimitive = all (1, intBoxed) as eq, " + "intPrimitive != all (1, intBoxed) as neq, " + "intPrimitive <> all (1, intBoxed) as sqlneq, " + "not intPrimitive = all (1, intBoxed) as nneq " + "from SupportBean(string like \"E%\")"; EPStatement stmt = epService.getEPAdministrator().createEPL(stmtText); stmt.addListener(listener); // in the format intPrimitive, intBoxed int[][] testdata = { {1, 1}, {1, 2}, {2, 2}, {2, 1}, }; Object[][] result = { {true, false, false, false}, // 1, 1 {false, false, false, true}, // 1, 2 {false, false, false, true}, // 2, 2 {false, true, true, true} // 2, 1 }; for (int i = 0; i < testdata.length; i++) { SupportBean bean = new SupportBean("E", testdata[i][0]); bean.setIntBoxed(testdata[i][1]); epService.getEPRuntime().sendEvent(bean); // System.out.println("line " + i); ArrayAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, result[i]); } // test OM stmt.destroy(); EPStatementObjectModel model = epService.getEPAdministrator().compileEPL(stmtText); assertEquals(stmtText.replace("<>", "!="), model.toEPL()); stmt = epService.getEPAdministrator().create(model); stmt.addListener(listener); for (int i = 0; i < testdata.length; i++) { SupportBean bean = new SupportBean("E", testdata[i][0]); bean.setIntBoxed(testdata[i][1]); epService.getEPRuntime().sendEvent(bean); // System.out.println("line " + i); ArrayAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, result[i]); } }
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")); }
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(); }
public void testConcat() { String viewExpr = "select p00 || p01 as c1, p00 || p01 || p02 as c2, p00 || '|' || p01 as c3" + " from " + SupportBean_S0.class.getName() + ".win:length(10)"; selectTestView = epService.getEPAdministrator().createEPL(viewExpr); selectTestView.addListener(testListener); epService.getEPRuntime().sendEvent(new SupportBean_S0(1, "a", "b", "c")); assertConcat("ab", "abc", "a|b"); epService.getEPRuntime().sendEvent(new SupportBean_S0(1, null, "b", "c")); assertConcat(null, null, null); epService.getEPRuntime().sendEvent(new SupportBean_S0(1, "", "b", "c")); assertConcat("b", "bc", "|b"); epService.getEPRuntime().sendEvent(new SupportBean_S0(1, "123", null, "c")); assertConcat(null, null, null); epService.getEPRuntime().sendEvent(new SupportBean_S0(1, "123", "456", "c")); assertConcat("123456", "123456c", "123|456"); epService.getEPRuntime().sendEvent(new SupportBean_S0(1, "123", "456", null)); assertConcat("123456", null, "123|456"); }
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(); }
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 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"}); }
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 testEqualsAllArray() { String[] fields = "e,ne".split(","); String stmtText = "select " + "longBoxed = all ({1, 1}, intArr, longCol) as e, " + "longBoxed != all ({1, 1}, intArr, longCol) as ne " + "from ArrayBean"; EPStatement stmt = epService.getEPAdministrator().createEPL(stmtText); stmt.addListener(listener); SupportBeanArrayCollMap arrayBean = new SupportBeanArrayCollMap(new int[] {1, 1}); arrayBean.setLongCol(Arrays.asList(1L, 1L)); arrayBean.setLongBoxed(1L); epService.getEPRuntime().sendEvent(arrayBean); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {true, false}); arrayBean.setIntArr(new int[] {1, 1, 0}); epService.getEPRuntime().sendEvent(arrayBean); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {false, false}); arrayBean.setLongBoxed(2L); epService.getEPRuntime().sendEvent(arrayBean); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {false, true}); }
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 testPerformanceCoercionBack() { String stmt = "select A.intPrimitive as value from " + SupportBean.class.getName() + "(theString='A').win:length(1000000) as A," + SupportBean.class.getName() + "(theString='B').win:length(1000000) as B" + " where A.intPrimitive=B.longBoxed"; EPStatement statement = epService.getEPAdministrator().createEPL(stmt); statement.addListener(listener); // preload for (int i = 0; i < 10000; i++) { epService.getEPRuntime().sendEvent(makeSupportEvent("A", i, 0)); } long startTime = System.currentTimeMillis(); for (int i = 0; i < 5000; i++) { int index = 5000 + i % 1000; epService.getEPRuntime().sendEvent(makeSupportEvent("B", 0, index)); assertEquals(index, listener.assertOneGetNewAndReset().get("value")); } long endTime = System.currentTimeMillis(); long delta = endTime - startTime; statement.destroy(); assertTrue("Failed perf test, delta=" + delta, delta < 1500); }
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)); }
// Wie viel Koncurrenten sind unterwegs public void addQueryQ11(DataListener chart) { /** Add Query Q11 */ // Es werden 2 Datenströme erzeugt, die Ströme Noden und Süden aus Q1 weiterverwenden. // Die Datenströme zählen die aktuelle Anzahl der Taxis die im jeweiligen Bereich unterwegs // sind. // Der letzte Strom gibt die aktuelle Anzahl aus. EPStatement stmt01 = epService .getEPAdministrator() .createEPL( "Insert into COUNTN " + "select count(North.hackLicense) as CN from Norden.win:time(1 min) as North" + ""); EPStatement stmt02 = epService .getEPAdministrator() .createEPL( "Insert into COUNTS " + "select count(South.hackLicense) as CS from Sueden.win:time(1 min) as South" + ""); EPStatement stmt03 = epService .getEPAdministrator() .createEPL( "select s.CS as Competition_South, n.CN as Competition_North from COUNTN.win:length(1) as n, COUNTS.win:length(1) as s"); stmt03.addListener(chart); }
// Trend der Durchschnittsgeschwindigkeit public void addQueryQ5(DataListener chart) { /** Add Query Q5 */ // Die aktuelle Geschwindigkeit wird im ersten Stream errechnet. // Im 2ten Datenstrom wird die Funktion Trend aufgerufen, die den // aktullen Trend als Text über Zeit zurück gibt. EPStatement stmt01 = epService .getEPAdministrator() .createEPL( "insert into Speed" + " select detectionTime, avg(tripdistance/(triptime/3600)) As averageSpeed" + " from TaxiTripRawEvent.win:time_batch(1 min).std:lastevent()" + " where triptime > 0.0 and tripdistance > 0.0" + ""); EPStatement stmt02 = epService .getEPAdministrator() .createEPL( "" + " select detectionTime, averageSpeed, querys.Functions.trend( speedTrend.averageSpeed) as Trend from Speed.win:length(1) as speedTrend"); stmt02.addListener(chart); }
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 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")); }
@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); }
public void testRelationalOpAny() { String[] fields = "g,ge,l,le".split(","); String stmtText = "select " + "intPrimitive > any (1, 3, 4) as g, " + "intPrimitive >= some (1, 3, 4) as ge, " + "intPrimitive < any (1, 3, 4) as l, " + "intPrimitive <= some (1, 3, 4) as le " + " from SupportBean(string like 'E%')"; EPStatement stmt = epService.getEPAdministrator().createEPL(stmtText); stmt.addListener(listener); Object[][] result = { {false, false, true, true}, {false, true, true, true}, {true, true, true, true}, {true, true, true, true}, {true, true, false, true}, {true, true, false, false} }; for (int i = 0; i < 6; i++) { epService.getEPRuntime().sendEvent(new SupportBean("E1", i)); // System.out.println("line " + i); ArrayAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, result[i]); } }
public void testAfterNextRow() { Configuration config = SupportConfigFactory.getConfiguration(); config.addEventType("MyEvent", SupportRecogBean.class); EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(config); epService.initialize(); String[] fields = "a,b0,b1".split(","); String text = "select * from MyEvent.win:keepall() " + "match_recognize (" + " measures A.theString as a, B[0].theString as b0, B[1].theString as b1" + " AFTER MATCH SKIP TO NEXT ROW " + " pattern (A B*) " + " define " + " A as A.theString like 'A%'," + " B as B.theString like 'B%'" + ")"; EPStatement stmt = epService.getEPAdministrator().createEPL(text); SupportUpdateListener listener = new SupportUpdateListener(); stmt.addListener(listener); epService.getEPRuntime().sendEvent(new SupportRecogBean("A1", 1)); EPAssertionUtil.assertPropsPerRow( listener.getAndResetLastNewData(), fields, new Object[][] {{"A1", null, null}}); EPAssertionUtil.assertPropsPerRow(stmt.iterator(), fields, new Object[][] {{"A1", null, null}}); // since the first match skipped past A, we do not match again epService.getEPRuntime().sendEvent(new SupportRecogBean("B1", 2)); assertFalse(listener.isInvoked()); // incremental skips to next EPAssertionUtil.assertPropsPerRow(stmt.iterator(), fields, new Object[][] {{"A1", "B1", null}}); }