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(); }
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")); }
private void runAssertionGroupedMixedMethodAndAccess(boolean soda) throws Exception { String eplDeclare = "create table varMyAgg (" + "key string primary key, " + "c0 count(*), " + "c1 count(distinct object), " + "c2 window(*) @type('SupportBean'), " + "c3 sum(long)" + ")"; SupportModelHelper.createByCompileOrParse(epService, soda, eplDeclare); String eplBind = "into table varMyAgg select " + "count(*) as c0, " + "count(distinct intPrimitive) as c1, " + "window(*) as c2, " + "sum(longPrimitive) as c3 " + "from SupportBean.win:length(3) group by theString"; SupportModelHelper.createByCompileOrParse(epService, soda, eplBind); String eplSelect = "select " + "varMyAgg[p00].c0 as c0, " + "varMyAgg[p00].c1 as c1, " + "varMyAgg[p00].c2 as c2, " + "varMyAgg[p00].c3 as c3" + " from SupportBean_S0"; EPStatement stmtSelect = SupportModelHelper.createByCompileOrParse(epService, soda, eplSelect); stmtSelect.addListener(listener); String[] fields = "c0,c1,c2,c3".split(","); assertEquals(Long.class, stmtSelect.getEventType().getPropertyType("c0")); assertEquals(Long.class, stmtSelect.getEventType().getPropertyType("c1")); assertEquals(SupportBean[].class, stmtSelect.getEventType().getPropertyType("c2")); assertEquals(Long.class, stmtSelect.getEventType().getPropertyType("c3")); SupportBean b1 = makeSendBean("E1", 10, 100); SupportBean b2 = makeSendBean("E1", 11, 101); SupportBean b3 = makeSendBean("E1", 10, 102); epService.getEPRuntime().sendEvent(new SupportBean_S0(0, "E1")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {3L, 2L, new SupportBean[] {b1, b2, b3}, 303L}); epService.getEPRuntime().sendEvent(new SupportBean_S0(0, "E2")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, null, null, null}); SupportBean b4 = makeSendBean("E2", 20, 200); epService.getEPRuntime().sendEvent(new SupportBean_S0(0, "E2")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {1L, 1L, new SupportBean[] {b4}, 200L}); epService.getEPAdministrator().destroyAllStatements(); }
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 assertTopLevelTypeInfo(EPStatement stmt) { assertEquals(Map.class, stmt.getEventType().getPropertyType("val0")); FragmentEventType fragType = stmt.getEventType().getFragmentType("val0"); assertFalse(fragType.isIndexed()); assertFalse(fragType.isNative()); assertEquals(Object[][].class, fragType.getFragmentType().getPropertyType("thewindow")); assertEquals(Integer.class, fragType.getFragmentType().getPropertyType("thetotal")); }
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")); }
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)); }
public void testCoalesceDouble() { setupCoalesce( "coalesce(null, byteBoxed, shortBoxed, intBoxed, longBoxed, floatBoxed, doubleBoxed)"); assertEquals(Double.class, selectTestView.getEventType().getPropertyType("result")); sendEventWithDouble(null, null, null, null, null, null); assertEquals(null, testListener.assertOneGetNewAndReset().get("result")); sendEventWithDouble(null, Short.parseShort("2"), null, null, null, 1d); assertEquals(2d, testListener.assertOneGetNewAndReset().get("result")); sendEventWithDouble(null, null, null, null, null, 100d); assertEquals(100d, testListener.assertOneGetNewAndReset().get("result")); sendEventWithDouble(null, null, null, null, 10f, 100d); assertEquals(10d, testListener.assertOneGetNewAndReset().get("result")); sendEventWithDouble(null, null, 1, 5l, 10f, 100d); assertEquals(1d, testListener.assertOneGetNewAndReset().get("result")); sendEventWithDouble(Byte.parseByte("3"), null, null, null, null, null); assertEquals(3d, testListener.assertOneGetNewAndReset().get("result")); sendEventWithDouble(null, null, null, 5l, 10f, 100d); assertEquals(5d, testListener.assertOneGetNewAndReset().get("result")); }
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 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 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 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 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); }
private void runAssertionIterateCreateTable( Object[][] expectedType, Object[] rowValues, EPStatement stmtCreate) { assertEventTypeAndEvent( stmtCreate.getEventType(), expectedType, stmtCreate.iterator().next().getUnderlying(), rowValues); }
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 testMinMaxEventType() { setUpMinMax(); EventType type = selectTestView.getEventType(); log.debug(".testGetEventType properties=" + Arrays.toString(type.getPropertyNames())); assertEquals(Long.class, type.getPropertyType("myMax")); assertEquals(Long.class, type.getPropertyType("myMin")); assertEquals(Long.class, type.getPropertyType("myMinEx")); assertEquals(Long.class, type.getPropertyType("myMaxEx")); }
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(); }
public void testMapNameProperty() { 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 epService .getEPAdministrator() .getConfiguration() .addEventType( "MyOAWithAMap", new String[] {"p0", "p1"}, new Object[] {"MyNamedMap", "MyNamedMap[]"}); EPStatement stmt = epService .getEPAdministrator() .createEPL( "select p0.n0 as a, p1[0].n0 as b, p1[1].n0 as c, p0 as d, p1 as e from MyOAWithAMap"); SupportUpdateListener listener = new SupportUpdateListener(); 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}; epService.getEPRuntime().sendEvent(new Object[] {n0_1, n0_2}, "MyOAWithAMap"); EventBean eventResult = listener.assertOneGetNewAndReset(); EPAssertionUtil.assertProps(eventResult, "a,b,c,d".split(","), new Object[] {1, 2, 3, n0_1}); Map[] valueE = (Map[]) eventResult.get("e"); assertSame(valueE[0], n0_2[0]); assertSame(valueE[1], n0_2[1]); 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")); }
public void testJoinUnfiltered() { String stmtText = "select (select id from S3.win:length(1000)) as idS3, (select id from S4.win:length(1000)) as idS4 from S0.win:keepall() as s0, S1.win:keepall() as s1 where s0.id = s1.id"; EPStatement stmt = epService.getEPAdministrator().createEPL(stmtText); stmt.addListener(listener); // check type assertEquals(Integer.class, stmt.getEventType().getPropertyType("idS3")); assertEquals(Integer.class, stmt.getEventType().getPropertyType("idS4")); // test no event, should return null epService.getEPRuntime().sendEvent(new SupportBean_S0(0)); epService.getEPRuntime().sendEvent(new SupportBean_S1(0)); EventBean event = listener.assertOneGetNewAndReset(); assertEquals(null, event.get("idS3")); assertEquals(null, event.get("idS4")); // send one event epService.getEPRuntime().sendEvent(new SupportBean_S3(-1)); epService.getEPRuntime().sendEvent(new SupportBean_S0(1)); epService.getEPRuntime().sendEvent(new SupportBean_S1(1)); event = listener.assertOneGetNewAndReset(); assertEquals(-1, event.get("idS3")); assertEquals(null, event.get("idS4")); // send one event epService.getEPRuntime().sendEvent(new SupportBean_S4(-2)); epService.getEPRuntime().sendEvent(new SupportBean_S0(2)); epService.getEPRuntime().sendEvent(new SupportBean_S1(2)); event = listener.assertOneGetNewAndReset(); assertEquals(-1, event.get("idS3")); assertEquals(-2, event.get("idS4")); // send second event epService.getEPRuntime().sendEvent(new SupportBean_S4(-2)); epService.getEPRuntime().sendEvent(new SupportBean_S0(3)); epService.getEPRuntime().sendEvent(new SupportBean_S1(3)); event = listener.assertOneGetNewAndReset(); assertEquals(-1, event.get("idS3")); assertEquals(null, event.get("idS4")); epService.getEPRuntime().sendEvent(new SupportBean_S3(-2)); epService.getEPRuntime().sendEvent(new SupportBean_S0(3)); epService.getEPRuntime().sendEvent(new SupportBean_S1(3)); EventBean[] events = listener.getNewDataListFlattened(); assertEquals(3, events.length); for (int i = 0; i < events.length; i++) { assertEquals(null, events[i].get("idS3")); assertEquals(null, events[i].get("idS4")); } }
public void testNullType() { String stmtOneTxt = "insert into InZone select null as dummy from java.lang.String"; EPStatement stmtOne = epService.getEPAdministrator().createEPL(stmtOneTxt); assertTrue(stmtOne.getEventType().isProperty("dummy")); String stmtTwoTxt = "select dummy from InZone"; EPStatement stmtTwo = epService.getEPAdministrator().createEPL(stmtTwoTxt); SupportUpdateListener listener = new SupportUpdateListener(); stmtTwo.addListener(listener); epService.getEPRuntime().sendEvent("a"); assertNull(listener.assertOneGetNewAndReset().get("dummy")); }
private void runAssertionSubquerySelectWEnumMethod(Object[] rowValues) { String epl = "select (select * from MyTable).where(v=>v.key = 'G1') as mt from SupportBean_S2"; EPStatement stmt = epService.getEPAdministrator().createEPL(epl); stmt.addListener(listener); assertEquals(Collection.class, stmt.getEventType().getPropertyType("mt")); epService.getEPRuntime().sendEvent(new SupportBean_S2(0)); Collection coll = (Collection) listener.assertOneGetNewAndReset().get("mt"); assertEventUnd(coll.iterator().next(), rowValues); stmt.destroy(); }
private void runAssertionOutputSnapshot( Object[][] expectedType, Object[] rowValues, AtomicLong currentTime) { EPStatement stmt = epService .getEPAdministrator() .createEPL("select * from MyTable output snapshot every 1 second"); stmt.addListener(listener); assertEventType(stmt.getEventType(), expectedType); currentTime.set(currentTime.get() + 1000L); epService.getEPRuntime().sendEvent(new CurrentTimeEvent(currentTime.get())); EventBean event = listener.assertOneGetNewAndReset(); assertEventTypeAndEvent(event.getEventType(), expectedType, event.getUnderlying(), rowValues); }
public void testCoalesceLong() { setupCoalesce("coalesce(longBoxed, intBoxed, shortBoxed)"); assertEquals(Long.class, selectTestView.getEventType().getPropertyType("result")); sendEvent(1L, 2, (short) 3); assertEquals(1L, testListener.assertOneGetNewAndReset().get("result")); sendBoxedEvent(null, 2, null); assertEquals(2L, testListener.assertOneGetNewAndReset().get("result")); sendBoxedEvent(null, null, Short.parseShort("3")); assertEquals(3L, testListener.assertOneGetNewAndReset().get("result")); sendBoxedEvent(null, null, null); assertEquals(null, testListener.assertOneGetNewAndReset().get("result")); }
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()); }
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 testCoalesceLong_Compile() { String viewExpr = "select coalesce(longBoxed, intBoxed, shortBoxed) as result" + " from " + SupportBean.class.getName() + ".win:length(1000)"; EPStatementObjectModel model = epService.getEPAdministrator().compileEPL(viewExpr); assertEquals(viewExpr, model.toEPL()); epService.initialize(); selectTestView = epService.getEPAdministrator().create(model); selectTestView.addListener(testListener); assertEquals(Long.class, selectTestView.getEventType().getPropertyType("result")); runCoalesceLong(); }
public void testConfiguredViaPropsAndXML() { Configuration configuration = SupportConfigFactory.getConfiguration(); configuration .getEngineDefaults() .getEventMeta() .setDefaultEventRepresentation(Configuration.EventRepresentation.OBJECTARRAY); configuration.addEventType( "MyOAType", "bean,theString,map".split(","), new Object[] {SupportBean.class.getName(), "string", "java.util.Map"}); EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(configuration); epService.initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.startTest(epService, this.getClass(), getName()); } EventType eventType = epService.getEPAdministrator().getConfiguration().getEventType("MyOAType"); assertEquals(Object[].class, eventType.getUnderlyingType()); assertEquals(String.class, eventType.getPropertyType("theString")); assertEquals(Map.class, eventType.getPropertyType("map")); assertEquals(SupportBean.class, eventType.getPropertyType("bean")); EPStatement stmt = epService .getEPAdministrator() .createEPL("select bean, theString, map('key'), bean.theString from MyOAType"); SupportUpdateListener listener = new SupportUpdateListener(); stmt.addListener(listener); assertEquals(Object[].class, stmt.getEventType().getUnderlyingType()); SupportBean bean = new SupportBean("E1", 1); epService .getEPRuntime() .sendEvent( new Object[] {bean, "abc", Collections.singletonMap("key", "value")}, "MyOAType"); EPAssertionUtil.assertProps( listener.assertOneGetNew(), "bean,theString,map('key'),bean.theString".split(","), new Object[] {bean, "abc", "value", "E1"}); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.endTest(); } }
public void testCoalesceInvalid() { String viewExpr = "select coalesce(null, null) as result" + " from " + SupportBean.class.getName() + ".win:length(3) "; selectTestView = epService.getEPAdministrator().createEPL(viewExpr); assertEquals(null, selectTestView.getEventType().getPropertyType("result")); tryCoalesceInvalid("coalesce(intPrimitive)"); tryCoalesceInvalid("coalesce(intPrimitive, string)"); tryCoalesceInvalid("coalesce(intPrimitive, xxx)"); tryCoalesceInvalid("coalesce(intPrimitive, booleanBoxed)"); tryCoalesceInvalid("coalesce(charPrimitive, longBoxed)"); tryCoalesceInvalid("coalesce(charPrimitive, string, string)"); tryCoalesceInvalid("coalesce(string, longBoxed)"); tryCoalesceInvalid("coalesce(null, longBoxed, string)"); tryCoalesceInvalid("coalesce(null, null, boolBoxed, 1l)"); }
public void testAverageEvents() { String[] fields = "val0,val1,val2,val3".split(","); String eplFragment = "select " + "beans.average(x => intBoxed) as val0," + "beans.average(x => doubleBoxed) as val1," + "beans.average(x => longBoxed) as val2," + "beans.average(x => bigDecimal) as val3 " + "from Bean"; EPStatement stmtFragment = epService.getEPAdministrator().createEPL(eplFragment); stmtFragment.addListener(listener); LambdaAssertionUtil.assertTypes( stmtFragment.getEventType(), fields, new Class[] {Double.class, Double.class, Double.class, BigDecimal.class}); epService.getEPRuntime().sendEvent(new SupportBean_Container(null)); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, null, null, null}); epService .getEPRuntime() .sendEvent(new SupportBean_Container(Collections.<SupportBean>emptyList())); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {null, null, null, null}); List<SupportBean> list = new ArrayList<SupportBean>(); list.add(make(2, 3d, 4l, 5)); epService.getEPRuntime().sendEvent(new SupportBean_Container(list)); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {2d, 3d, 4d, new BigDecimal(5.0d)}); list.add(make(4, 6d, 8l, 10)); epService.getEPRuntime().sendEvent(new SupportBean_Container(list)); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {(2 + 4) / 2d, (3d + 6d) / 2d, (4L + 8L) / 2d, new BigDecimal((5 + 10) / 2d)}); }