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 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(); }
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 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 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 runAssertionSubquerySelectStar(Object[] rowValues) { String eplFiltered = "select (select * from MyTable where key = 'G1') as mt from SupportBean_S2"; runAssertionSubquerySelectStar(rowValues, eplFiltered); String eplUnfiltered = "select (select * from MyTable) as mt from SupportBean_S2"; runAssertionSubquerySelectStar(rowValues, eplUnfiltered); // With @eventbean String eplEventBean = "select (select * from MyTable) @eventbean as mt from SupportBean_S2"; EPStatement stmt = epService.getEPAdministrator().createEPL(eplEventBean); stmt.addListener(listener); assertEquals(Object[][].class, stmt.getEventType().getPropertyType("mt")); assertSame( getTablePublicType("MyTable"), stmt.getEventType().getFragmentType("mt").getFragmentType()); epService.getEPRuntime().sendEvent(new SupportBean_S2(0)); EventBean event = listener.assertOneGetNewAndReset(); Object[][] value = (Object[][]) event.get("mt"); assertEventUnd(value[0], rowValues); assertSame( getTablePublicType("MyTable"), ((EventBean[]) event.getFragment("mt"))[0].getEventType()); stmt.destroy(); }
private void runAssertionOnSelectWindowAgg(Object[][] expectedType, Object[] rowValues) { EPStatement stmt = epService .getEPAdministrator() .createEPL( "on SupportBean_S2 select " + "window(win.*) as c0," + "last(win.*) as c1, " + "first(win.*) as c2, " + "first(p1) as c3," + "window(p1) as c4," + "sorted(p1) as c5," + "minby(p1) as c6" + " from MyTable as win"); stmt.addListener(listener); epService.getEPRuntime().sendEvent(new SupportBean_S2(0)); EventBean event = listener.assertOneGetNewAndReset(); for (String col : "c1,c2,c6".split(",")) { assertEventUnd(event.get(col), rowValues); } for (String col : "c0,c5".split(",")) { assertEventUnd(((Object[][]) event.get(col))[0], rowValues); } assertEquals("b", event.get("c3")); EPAssertionUtil.assertEqualsExactOrder(new String[] {"b"}, (String[]) event.get("c4")); stmt.destroy(); }
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")); }
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); }
private void runAssertionSubquerySelectStar(Object[] rowValues, String epl) { EPStatement stmt = epService.getEPAdministrator().createEPL(epl); stmt.addListener(listener); assertEquals(Object[].class, stmt.getEventType().getPropertyType("mt")); epService.getEPRuntime().sendEvent(new SupportBean_S2(0)); EventBean event = listener.assertOneGetNewAndReset(); assertEventUnd(event.get("mt"), rowValues); stmt.destroy(); }
private void runAssertionSubquerySelectWEnumMethod(Object[] rowValues) { String epl = "select (select * from MyTable).where(v=>v.key = 'G1') as mt from SupportBean_S2"; EPStatement stmt = epService.getEPAdministrator().createEPL(epl); stmt.addListener(listener); assertEquals(Collection.class, stmt.getEventType().getPropertyType("mt")); epService.getEPRuntime().sendEvent(new SupportBean_S2(0)); Collection coll = (Collection) listener.assertOneGetNewAndReset().get("mt"); assertEventUnd(coll.iterator().next(), rowValues); stmt.destroy(); }
public void 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]); } }
private void runAssertionSubqueryWindowAgg(Object[] rowValues) { EPStatement stmt = epService .getEPAdministrator() .createEPL( "select " + "(select window(mt.*) from MyTable as mt) as c0," + "(select first(mt.*) from MyTable as mt) as c1" + " from SupportBean_S2"); stmt.addListener(listener); epService.getEPRuntime().sendEvent(new SupportBean_S2(0)); EventBean event = listener.assertOneGetNewAndReset(); assertEventUnd(((Object[][]) event.get("c0"))[0], rowValues); assertEventUnd(event.get("c1"), rowValues); stmt.destroy(); }
private void runAssertionJoinSelectStreamName(Object[][] expectedType, Object[] rowValues) { String joinEpl = "select mt from MyTable as mt, SupportBean_S2 where key = p20"; EPStatement stmt = epService.getEPAdministrator().createEPL(joinEpl); stmt.addListener(listener); assertEventType(stmt.getEventType().getFragmentType("mt").getFragmentType(), expectedType); epService.getEPRuntime().sendEvent(new SupportBean_S2(0, "G1")); EventBean event = listener.assertOneGetNewAndReset(); assertEventTypeAndEvent( event.getEventType().getFragmentType("mt").getFragmentType(), expectedType, event.get("mt"), rowValues); stmt.destroy(); }
public void testJoinMapEvent() { String joinStatement = "select S0.id, S1.id, S0.p00, S1.p00 from MapS0.win:keepall() as S0, MapS1.win:keepall() as S1" + " where S0.id = S1.id"; EPStatement stmt = epService.getEPAdministrator().createEPL(joinStatement); stmt.addListener(listener); runAssertion(); stmt.destroy(); joinStatement = "select * from MapS0.win:keepall() as S0, MapS1.win:keepall() as S1 where S0.id = S1.id"; stmt = epService.getEPAdministrator().createEPL(joinStatement); stmt.addListener(listener); runAssertion(); }
private void runAssertionJoinSelectStreamStarUnnamed( Object[][] expectedType, Object[] rowValues) { String joinEpl = "select mt.* from MyTable as mt, SupportBean_S2 where key = p20"; EPStatement stmt = epService.getEPAdministrator().createEPL(joinEpl); stmt.addListener(listener); stmt.setSubscriber(subscriber); assertEventType(stmt.getEventType(), expectedType); // listener assertion epService.getEPRuntime().sendEvent(new SupportBean_S2(0, "G1")); EventBean event = listener.assertOneGetNewAndReset(); assertEventTypeAndEvent(event.getEventType(), expectedType, event.getUnderlying(), rowValues); // subscriber assertion Object[][] newData = subscriber.getAndResetIndicateArr().get(0).getFirst(); assertEventUnd(newData[0][0], rowValues); stmt.destroy(); }
public void testVariantRStreamOMToStmt() throws Exception { EPStatementObjectModel model = new EPStatementObjectModel(); model.setInsertInto( InsertIntoClause.create("Event_1", new String[0], StreamSelector.RSTREAM_ONLY)); model.setSelectClause(SelectClause.create().add("intPrimitive", "intBoxed")); model.setFromClause(FromClause.create(FilterStream.create(SupportBean.class.getName()))); model = (EPStatementObjectModel) SerializableObjectCopier.copy(model); EPStatement stmt = epService.getEPAdministrator().create(model, "s1"); String epl = "insert rstream into Event_1 " + "select intPrimitive, intBoxed " + "from " + SupportBean.class.getName(); assertEquals(epl, model.toEPL()); assertEquals(epl, stmt.getText()); EPStatementObjectModel modelTwo = epService.getEPAdministrator().compileEPL(model.toEPL()); model = (EPStatementObjectModel) SerializableObjectCopier.copy(model); assertEquals(epl, modelTwo.toEPL()); // assert statement-type reference EPServiceProviderSPI spi = (EPServiceProviderSPI) epService; assertTrue(spi.getStatementEventTypeRef().isInUse("Event_1")); Set<String> stmtNames = spi.getStatementEventTypeRef().getStatementNamesForType(SupportBean.class.getName()); assertTrue(stmtNames.contains("s1")); stmt.destroy(); assertFalse(spi.getStatementEventTypeRef().isInUse("Event_1")); stmtNames = spi.getStatementEventTypeRef().getStatementNamesForType(SupportBean.class.getName()); assertFalse(stmtNames.contains("s1")); }
public void testAnyType() { assertTrue( epService.getEPAdministrator().getConfiguration().isVariantStreamExists("MyVariantStream")); epService .getEPAdministrator() .createEPL("insert into MyVariantStream select * from " + SupportBean.class.getName()); epService .getEPAdministrator() .createEPL( "insert into MyVariantStream select * from " + SupportBeanVariantStream.class.getName()); epService .getEPAdministrator() .createEPL("insert into MyVariantStream select * from " + SupportBean_A.class.getName()); epService .getEPAdministrator() .createEPL( "insert into MyVariantStream select symbol as theString, volume as intPrimitive, feed as id from " + SupportMarketDataBean.class.getName()); EPStatement stmt = epService.getEPAdministrator().createEPL("select * from MyVariantStream"); stmt.addListener(listener); assertEquals(0, stmt.getEventType().getPropertyNames().length); Object eventOne = new SupportBean("E0", -1); epService.getEPRuntime().sendEvent(eventOne); assertSame(eventOne, listener.assertOneGetNewAndReset().getUnderlying()); Object eventTwo = new SupportBean_A("E1"); epService.getEPRuntime().sendEvent(eventTwo); assertSame(eventTwo, listener.assertOneGetNewAndReset().getUnderlying()); stmt.destroy(); stmt = epService .getEPAdministrator() .createEPL("select theString,id,intPrimitive from MyVariantStream"); stmt.addListener(listener); assertEquals(Object.class, stmt.getEventType().getPropertyType("theString")); assertEquals(Object.class, stmt.getEventType().getPropertyType("id")); assertEquals(Object.class, stmt.getEventType().getPropertyType("intPrimitive")); String[] fields = "theString,id,intPrimitive".split(","); epService.getEPRuntime().sendEvent(new SupportBeanVariantStream("E1")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {"E1", null, null}); epService.getEPRuntime().sendEvent(new SupportBean("E2", 10)); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {"E2", null, 10}); epService.getEPRuntime().sendEvent(new SupportBean_A("E3")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, "E3", null}); epService.getEPRuntime().sendEvent(new SupportMarketDataBean("s1", 100, 1000L, "f1")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {"s1", "f1", 1000L}); epService.getEPAdministrator().destroyAllStatements(); // Test inserting a wrapper of underlying plus properties epService.getEPAdministrator().getConfiguration().addEventType(SupportBean.class); epService.getEPAdministrator().createEPL("create variant schema TheVariantStream as *"); epService .getEPAdministrator() .createEPL( "insert into TheVariantStream select 'test' as eventConfigId, * from SupportBean"); epService .getEPAdministrator() .createEPL("select * from TheVariantStream") .addListener(listener); epService.getEPRuntime().sendEvent(new SupportBean("E1", 1)); EventBean event = listener.assertOneGetNewAndReset(); assertEquals("test", event.get("eventConfigId")); assertEquals(1, event.get("intPrimitive")); }
private void runAssertion( boolean enableIndexShareCreate, boolean disableIndexShareConsumer, boolean createExplicitIndex) { SupportUpdateListener listener = new SupportUpdateListener(); epService .getEPAdministrator() .getConfiguration() .addEventType("SupportBean", SupportBean.class); epService.getEPAdministrator().getConfiguration().addEventType("S0", SupportBean_S0.class); String createEpl = "create window SupportWindow.win:keepall() as select * from SupportBean"; if (enableIndexShareCreate) { createEpl = "@Hint('enable_window_subquery_indexshare') " + createEpl; } epService.getEPAdministrator().createEPL(createEpl); epService.getEPAdministrator().createEPL("insert into SupportWindow select * from SupportBean"); EPStatement indexStmt = null; if (createExplicitIndex) { indexStmt = epService .getEPAdministrator() .createEPL("create index MyIndex on SupportWindow(theString)"); } epService.getEPRuntime().sendEvent(new SupportBean("E1", 1)); epService.getEPRuntime().sendEvent(new SupportBean("E2", -2)); String consumeEpl = "select (select intPrimitive from SupportWindow(intPrimitive<0) sw where s0.p00=sw.theString) as val from S0 s0"; if (disableIndexShareConsumer) { consumeEpl = "@Hint('disable_window_subquery_indexshare') " + consumeEpl; } EPStatement consumeStmt = epService.getEPAdministrator().createEPL(consumeEpl); consumeStmt.addListener(listener); epService.getEPRuntime().sendEvent(new SupportBean_S0(10, "E1")); assertEquals(null, listener.assertOneGetNewAndReset().get("val")); epService.getEPRuntime().sendEvent(new SupportBean_S0(20, "E2")); assertEquals(-2, listener.assertOneGetNewAndReset().get("val")); epService.getEPRuntime().sendEvent(new SupportBean("E3", -3)); epService.getEPRuntime().sendEvent(new SupportBean("E4", 4)); epService.getEPRuntime().sendEvent(new SupportBean_S0(-3, "E3")); assertEquals(-3, listener.assertOneGetNewAndReset().get("val")); epService.getEPRuntime().sendEvent(new SupportBean_S0(20, "E4")); assertEquals(null, listener.assertOneGetNewAndReset().get("val")); consumeStmt.stop(); if (indexStmt != null) { indexStmt.stop(); } consumeStmt.destroy(); if (indexStmt != null) { indexStmt.destroy(); } }
public void testAddRemoveType() { epService = EPServiceProviderManager.getProvider("TestSchemaXML", getConfig(false)); epService.initialize(); updateListener = new SupportUpdateListener(); ConfigurationOperations configOps = epService.getEPAdministrator().getConfiguration(); // test remove type with statement used (no force) configOps.addEventType("MyXMLEvent", getConfigTestType("p01", false)); EPStatement stmt = epService.getEPAdministrator().createEPL("select p01 from MyXMLEvent", "stmtOne"); EPAssertionUtil.assertEqualsExactOrder( configOps.getEventTypeNameUsedBy("MyXMLEvent").toArray(), new String[] {"stmtOne"}); try { configOps.removeEventType("MyXMLEvent", false); } catch (ConfigurationException ex) { assertTrue(ex.getMessage().contains("MyXMLEvent")); } // destroy statement and type stmt.destroy(); assertTrue(configOps.getEventTypeNameUsedBy("MyXMLEvent").isEmpty()); assertTrue(configOps.isEventTypeExists("MyXMLEvent")); assertTrue(configOps.removeEventType("MyXMLEvent", false)); assertFalse(configOps.removeEventType("MyXMLEvent", false)); // try double-remove assertFalse(configOps.isEventTypeExists("MyXMLEvent")); try { epService.getEPAdministrator().createEPL("select p01 from MyXMLEvent"); fail(); } catch (EPException ex) { // expected } // add back the type configOps.addEventType("MyXMLEvent", getConfigTestType("p20", false)); assertTrue(configOps.isEventTypeExists("MyXMLEvent")); assertTrue(configOps.getEventTypeNameUsedBy("MyXMLEvent").isEmpty()); // compile epService.getEPAdministrator().createEPL("select p20 from MyXMLEvent", "stmtTwo"); EPAssertionUtil.assertEqualsExactOrder( configOps.getEventTypeNameUsedBy("MyXMLEvent").toArray(), new String[] {"stmtTwo"}); try { epService.getEPAdministrator().createEPL("select p01 from MyXMLEvent"); fail(); } catch (EPException ex) { // expected } // remove with force try { configOps.removeEventType("MyXMLEvent", false); } catch (ConfigurationException ex) { assertTrue(ex.getMessage().contains("MyXMLEvent")); } assertTrue(configOps.removeEventType("MyXMLEvent", true)); assertFalse(configOps.isEventTypeExists("MyXMLEvent")); assertTrue(configOps.getEventTypeNameUsedBy("MyXMLEvent").isEmpty()); // add back the type configOps.addEventType("MyXMLEvent", getConfigTestType("p03", false)); assertTrue(configOps.isEventTypeExists("MyXMLEvent")); // compile epService.getEPAdministrator().createEPL("select p03 from MyXMLEvent"); try { epService.getEPAdministrator().createEPL("select p20 from MyXMLEvent"); fail(); } catch (EPException ex) { // expected } }
public void testExceptionHandler() throws Exception { epService.getEPAdministrator().getConfiguration().addEventType(SupportBean.class); // test exception by graph source EPStatement stmtGraph = epService .getEPAdministrator() .createEPL( "create dataflow MyDataFlow DefaultSupportSourceOp -> outstream<SupportBean> {}"); DefaultSupportSourceOp op = new DefaultSupportSourceOp(new Object[] {new RuntimeException("My-Exception-Is-Here")}); EPDataFlowInstantiationOptions options = new EPDataFlowInstantiationOptions(); options.operatorProvider(new DefaultSupportGraphOpProvider(op)); MyExceptionHandler handler = new MyExceptionHandler(); options.exceptionHandler(handler); EPDataFlowInstance df = epService.getEPRuntime().getDataFlowRuntime().instantiate("MyDataFlow", options); df.start(); Thread.sleep(100); assertEquals(EPDataFlowState.COMPLETE, df.getState()); assertEquals(1, MyExceptionHandler.getContexts().size()); EPDataFlowExceptionContext context = MyExceptionHandler.getContexts().get(0); assertEquals("MyDataFlow", context.getDataFlowName()); assertEquals("DefaultSupportSourceOp", context.getOperatorName()); assertEquals(0, context.getOperatorNumber()); assertEquals( "DefaultSupportSourceOp#0() -> outstream<SupportBean>", context.getOperatorPrettyPrint()); assertEquals( "Support-graph-source generated exception: My-Exception-Is-Here", context.getThrowable().getMessage()); df.cancel(); stmtGraph.destroy(); MyExceptionHandler.getContexts().clear(); // test exception by operator epService.getEPAdministrator().getConfiguration().addImport(MyExceptionOp.class); epService .getEPAdministrator() .createEPL( "create dataflow MyDataFlow DefaultSupportSourceOp -> outstream<SupportBean> {}" + "MyExceptionOp(outstream) {}"); DefaultSupportSourceOp opTwo = new DefaultSupportSourceOp(new Object[] {new SupportBean("E1", 1)}); EPDataFlowInstantiationOptions optionsTwo = new EPDataFlowInstantiationOptions(); optionsTwo.operatorProvider(new DefaultSupportGraphOpProvider(opTwo)); MyExceptionHandler handlerTwo = new MyExceptionHandler(); optionsTwo.exceptionHandler(handlerTwo); EPDataFlowInstance dfTwo = epService.getEPRuntime().getDataFlowRuntime().instantiate("MyDataFlow", optionsTwo); dfTwo.start(); Thread.sleep(100); assertEquals(1, MyExceptionHandler.getContexts().size()); EPDataFlowExceptionContext contextTwo = MyExceptionHandler.getContexts().get(0); assertEquals("MyDataFlow", contextTwo.getDataFlowName()); assertEquals("MyExceptionOp", contextTwo.getOperatorName()); assertEquals(1, contextTwo.getOperatorNumber()); assertEquals("MyExceptionOp#1(outstream)", contextTwo.getOperatorPrettyPrint()); assertEquals("Operator-thrown-exception", contextTwo.getThrowable().getMessage()); }
public void testTopLevelReadUnGrouped() { epService.getEPAdministrator().getConfiguration().addEventType(AggBean.class); epService.getEPAdministrator().createEPL("create objectarray schema MyEvent(c0 int)"); epService .getEPAdministrator() .createEPL( "create table windowAndTotal (" + "thewindow window(*) @type(MyEvent), thetotal sum(int))"); epService .getEPAdministrator() .createEPL( "into table windowAndTotal " + "select window(*) as thewindow, sum(c0) as thetotal from MyEvent.win:length(2)"); EPStatement stmt = epService .getEPAdministrator() .createEPL("select windowAndTotal as val0 from SupportBean_S0"); stmt.addListener(listener); Object[] e1 = new Object[] {10}; epService.getEPRuntime().sendEvent(e1, "MyEvent"); String[] fieldsInner = "thewindow,thetotal".split(","); epService.getEPRuntime().sendEvent(new SupportBean_S0(0)); EPAssertionUtil.assertPropsMap( (Map) listener.assertOneGetNewAndReset().get("val0"), fieldsInner, new Object[][] {e1}, 10); Object[] e2 = new Object[] {20}; epService.getEPRuntime().sendEvent(e2, "MyEvent"); epService.getEPRuntime().sendEvent(new SupportBean_S0(1)); EPAssertionUtil.assertPropsMap( (Map) listener.assertOneGetNewAndReset().get("val0"), fieldsInner, new Object[][] {e1, e2}, 30); Object[] e3 = new Object[] {30}; epService.getEPRuntime().sendEvent(e3, "MyEvent"); epService.getEPRuntime().sendEvent(new SupportBean_S0(2)); EPAssertionUtil.assertPropsMap( (Map) listener.assertOneGetNewAndReset().get("val0"), fieldsInner, new Object[][] {e2, e3}, 50); // test typable output stmt.destroy(); EPStatement stmtConvert = epService .getEPAdministrator() .createEPL("insert into AggBean select windowAndTotal as val0 from SupportBean_S0"); stmtConvert.addListener(listener); epService.getEPRuntime().sendEvent(new SupportBean_S0(2)); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), "val0.thewindow,val0.thetotal".split(","), new Object[] {new Object[][] {e2, e3}, 50}); }
private void runAssertionTopLevelReadGrouped2Keys(boolean soda) { SupportModelHelper.createByCompileOrParse( epService, soda, "create objectarray schema MyEvent as (c0 int, c1 string, c2 int)"); SupportModelHelper.createByCompileOrParse( epService, soda, "create table windowAndTotal (" + "keyi int primary key, keys string primary key, thewindow window(*) @type('MyEvent'), thetotal sum(int))"); SupportModelHelper.createByCompileOrParse( epService, soda, "into table windowAndTotal " + "select window(*) as thewindow, sum(c2) as thetotal from MyEvent.win:length(2) group by c0, c1"); EPStatement stmtSelect = SupportModelHelper.createByCompileOrParse( epService, soda, "select windowAndTotal[id,p00] as val0 from SupportBean_S0"); stmtSelect.addListener(listener); assertTopLevelTypeInfo(stmtSelect); Object[] e1 = new Object[] {10, "G1", 100}; epService.getEPRuntime().sendEvent(e1, "MyEvent"); String[] fieldsInner = "thewindow,thetotal".split(","); epService.getEPRuntime().sendEvent(new SupportBean_S0(10, "G1")); EPAssertionUtil.assertPropsMap( (Map) listener.assertOneGetNewAndReset().get("val0"), fieldsInner, new Object[][] {e1}, 100); Object[] e2 = new Object[] {20, "G2", 200}; epService.getEPRuntime().sendEvent(e2, "MyEvent"); epService.getEPRuntime().sendEvent(new SupportBean_S0(20, "G2")); EPAssertionUtil.assertPropsMap( (Map) listener.assertOneGetNewAndReset().get("val0"), fieldsInner, new Object[][] {e2}, 200); Object[] e3 = new Object[] {20, "G2", 300}; epService.getEPRuntime().sendEvent(e3, "MyEvent"); epService.getEPRuntime().sendEvent(new SupportBean_S0(10, "G1")); EPAssertionUtil.assertPropsMap( (Map) listener.assertOneGetNewAndReset().get("val0"), fieldsInner, null, null); epService.getEPRuntime().sendEvent(new SupportBean_S0(20, "G2")); EPAssertionUtil.assertPropsMap( (Map) listener.assertOneGetNewAndReset().get("val0"), fieldsInner, new Object[][] {e2, e3}, 500); // test typable output stmtSelect.destroy(); EPStatement stmtConvert = epService .getEPAdministrator() .createEPL( "insert into AggBean select windowAndTotal[20, 'G2'] as val0 from SupportBean_S0"); stmtConvert.addListener(listener); epService.getEPRuntime().sendEvent(new SupportBean_S0(0)); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), "val0.thewindow,val0.thetotal".split(","), new Object[] {new Object[][] {e2, e3}, 500}); epService.getEPAdministrator().destroyAllStatements(); }
public void testAverageScalar() { String[] fields = "val0,val1".split(","); String eplFragment = "select " + "intvals.average() as val0," + "bdvals.average() as val1 " + "from SupportCollection"; EPStatement stmtFragment = epService.getEPAdministrator().createEPL(eplFragment); stmtFragment.addListener(listener); LambdaAssertionUtil.assertTypes( stmtFragment.getEventType(), fields, new Class[] {Double.class, BigDecimal.class}); epService.getEPRuntime().sendEvent(SupportCollection.makeNumeric("1,2,3")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {2d, new BigDecimal(2d)}); epService.getEPRuntime().sendEvent(SupportCollection.makeNumeric("1,null,3")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {2d, new BigDecimal(2d)}); epService.getEPRuntime().sendEvent(SupportCollection.makeNumeric("4")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {4d, new BigDecimal(4d)}); stmtFragment.destroy(); // test average with lambda epService .getEPAdministrator() .getConfiguration() .addPlugInSingleRowFunction( "extractNum", TestEnumMinMax.MyService.class.getName(), "extractNum"); epService .getEPAdministrator() .getConfiguration() .addPlugInSingleRowFunction( "extractBigDecimal", TestEnumMinMax.MyService.class.getName(), "extractBigDecimal"); String[] fieldsLambda = "val0,val1".split(","); String eplLambda = "select " + "strvals.average(v => extractNum(v)) as val0, " + "strvals.average(v => extractBigDecimal(v)) as val1 " + "from SupportCollection"; EPStatement stmtLambda = epService.getEPAdministrator().createEPL(eplLambda); stmtLambda.addListener(listener); LambdaAssertionUtil.assertTypes( stmtLambda.getEventType(), fieldsLambda, new Class[] {Double.class, BigDecimal.class}); epService.getEPRuntime().sendEvent(SupportCollection.makeString("E2,E1,E5,E4")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fieldsLambda, new Object[] {(2 + 1 + 5 + 4) / 4d, new BigDecimal((2 + 1 + 5 + 4) / 4d)}); epService.getEPRuntime().sendEvent(SupportCollection.makeString("E1")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fieldsLambda, new Object[] {1d, new BigDecimal(1)}); epService.getEPRuntime().sendEvent(SupportCollection.makeString(null)); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fieldsLambda, new Object[] {null, null}); epService.getEPRuntime().sendEvent(SupportCollection.makeString("")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fieldsLambda, new Object[] {null, null}); }
public void testEqualsInNullOrNoRows() { // test fixed array case String[] fields = "eall,eany,neall,neany,isin".split(","); String stmtText = "select " + "intBoxed = all ({doubleBoxed, longBoxed}) as eall, " + "intBoxed = any ({doubleBoxed, longBoxed}) as eany, " + "intBoxed != all ({doubleBoxed, longBoxed}) as neall, " + "intBoxed != any ({doubleBoxed, longBoxed}) as neany, " + "intBoxed in ({doubleBoxed, longBoxed}) as isin " + " from SupportBean"; EPStatement stmt = epService.getEPAdministrator().createEPL(stmtText); stmt.addListener(listener); sendEvent("E3", null, null, null); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, null, null, null, null}); sendEvent("E4", 1, null, null); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, null, null, null, null}); sendEvent("E5", null, null, 1L); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, null, null, null, null}); sendEvent("E6", 1, null, 1L); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, true, false, null, true}); sendEvent("E7", 0, null, 1L); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {false, null, null, true, null}); // test non-array case stmt.destroy(); fields = "eall,eany,neall,neany,isin".split(","); stmtText = "select " + "intBoxed = all (doubleBoxed, longBoxed) as eall, " + "intBoxed = any (doubleBoxed, longBoxed) as eany, " + "intBoxed != all (doubleBoxed, longBoxed) as neall, " + "intBoxed != any (doubleBoxed, longBoxed) as neany, " + "intBoxed in (doubleBoxed, longBoxed) as isin " + " from SupportBean"; stmt = epService.getEPAdministrator().createEPL(stmtText); stmt.addListener(listener); sendEvent("E3", null, null, null); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, null, null, null, null}); sendEvent("E4", 1, null, null); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, null, null, null, null}); sendEvent("E5", null, null, 1L); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, null, null, null, null}); sendEvent("E6", 1, null, 1L); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, true, false, null, true}); sendEvent("E7", 0, null, 1L); ArrayAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {false, null, null, true, null}); }