public void testObjectArrayNested() { EPServiceProvider epService = getEngineInitialized(null, null, null); epService .getEPAdministrator() .getConfiguration() .addEventType("TypeLev1", new String[] {"p1id"}, new Object[] {int.class}); epService .getEPAdministrator() .getConfiguration() .addEventType( "TypeLev0", new String[] {"p0id", "p1"}, new Object[] {int.class, "TypeLev1"}); epService .getEPAdministrator() .getConfiguration() .addEventType( "TypeRoot", new String[] {"rootId", "p0"}, new Object[] {int.class, "TypeLev0"}); EPStatement stmt = epService.getEPAdministrator().createEPL("select * from TypeRoot.std:lastevent()"); Object[] dataLev1 = {1000}; Object[] dataLev0 = {100, dataLev1}; epService.getEPRuntime().sendEvent(new Object[] {10, dataLev0}, "TypeRoot"); EventBean theEvent = stmt.iterator().next(); EPAssertionUtil.assertProps( theEvent, "rootId,p0.p0id,p0.p1.p1id".split(","), new Object[] {10, 100, 1000}); }
public void testReclaimTimeWindow() { sendTimer(0); epService .getEPAdministrator() .getConfiguration() .addEventType("SupportBean", SupportBean.class); epService .getEPAdministrator() .createEPL( "@Hint('reclaim_group_aged=30,reclaim_group_freq=5') " + "select longPrimitive, count(*) from SupportBean.std:groupwin(theString).win:time(3000000)"); for (int i = 0; i < 10; i++) { SupportBean theEvent = new SupportBean(Integer.toString(i), i); epService.getEPRuntime().sendEvent(theEvent); } EPServiceProviderSPI spi = (EPServiceProviderSPI) epService; int handleCountBefore = spi.getSchedulingService().getScheduleHandleCount(); assertEquals(10, handleCountBefore); sendTimer(1000000); epService.getEPRuntime().sendEvent(new SupportBean("E1", 1)); int handleCountAfter = spi.getSchedulingService().getScheduleHandleCount(); assertEquals(1, handleCountAfter); }
public void testInvalid() { EPServiceProvider epService = getEngineInitialized(null, null, null); // can add the same nested type twice epService .getEPAdministrator() .getConfiguration() .addEventType("ABC", new String[] {"p0"}, new Class[] {int.class}); epService .getEPAdministrator() .getConfiguration() .addEventType("ABC", new String[] {"p0"}, new Class[] {int.class}); try { // changing the definition however stops the compatibility epService .getEPAdministrator() .getConfiguration() .addEventType("ABC", new String[] {"p0"}, new Class[] {long.class}); fail(); } catch (ConfigurationException ex) { assertEquals( "Event type named 'ABC' has already been declared with differing column name or type information: Type by name 'ABC' in property 'p0' expected class java.lang.Integer but receives class java.lang.Long", ex.getMessage()); } tryInvalid( epService, new String[] {"a"}, new Object[] {new SupportBean()}, "Nestable type configuration encountered an unexpected property type of 'SupportBean' for property 'a', expected java.lang.Class or java.util.Map or the name of a previously-declared Map or ObjectArray type"); }
public void testSelfJoin() { // ESPER-528 epService .getEPAdministrator() .createEPL( EventRepresentationEnum.MAP.getAnnotationText() + " create schema Product (product string, productsize int)"); epService.getEPRuntime().sendEvent(new CurrentTimeEvent(0)); String query = " @Hint('reclaim_group_aged=1,reclaim_group_freq=1') select Product.product as product, Product.productsize as productsize from Product unidirectional" + " left outer join Product.win:time(3 seconds).std:groupwin(product,productsize).std:size() PrevProduct on Product.product=PrevProduct.product and Product.productsize=PrevProduct.productsize" + " having PrevProduct.size<2"; epService.getEPAdministrator().createEPL(query); // Set to larger number of executions and monitor memory for (int i = 0; i < 10; i++) { sendProductNew( "The id of this product is deliberately very very long so that we can use up more memory per instance of this event sent into Esper " + i, i); epService.getEPRuntime().sendEvent(new CurrentTimeEvent(i * 100)); // if (i % 2000 == 0) { // System.out.println("i=" + i + "; Allocated: " + Runtime.getRuntime().totalMemory() / // 1024 / 1024 + "; Free: " + Runtime.getRuntime().freeMemory() / 1024 / 1024); // } } }
public void 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 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 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 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 testLengthWindowGrouped() { String stmtText = "select symbol, price from " + SupportMarketDataBean.class.getName() + ".std:groupwin(symbol).win:length(2)"; EPStatement stmt = epService.getEPAdministrator().createEPL(stmtText); SupportUpdateListener listener = new SupportUpdateListener(); stmt.addListener(listener); sendEvent("IBM", 100); }
private void tryInvalid( EPServiceProvider epService, String[] names, Object[] types, String message) { try { epService.getEPAdministrator().getConfiguration().addEventType("NestedMap", names, types); fail(); } catch (Exception ex) { log.error(ex, ex); assertTrue( "expected '" + message + "' but received '" + ex.getMessage(), ex.getMessage().contains(message)); } }
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 testInvalidGroupByNoChild() { String stmtText = "select avg(price), symbol from " + SupportMarketDataBean.class.getName() + ".win:length(100).std:groupwin(symbol)"; try { epService.getEPAdministrator().createEPL(stmtText); } catch (EPStatementException ex) { assertEquals( "Error starting statement: Invalid use of the 'std:groupwin' view, the view requires one or more child views to group, or consider using the group-by clause [select avg(price), symbol from com.espertech.esper.support.bean.SupportMarketDataBean.win:length(100).std:groupwin(symbol)]", ex.getMessage()); } }
public void testReclaimAgedHint() { epService.getEPRuntime().sendEvent(new CurrentTimeEvent(0)); epService .getEPAdministrator() .getConfiguration() .addEventType("SupportBean", SupportBean.class); String epl = "@Hint('reclaim_group_aged=5,reclaim_group_freq=1') " + "select * from SupportBean.std:groupwin(theString).win:keepall()"; EPStatement stmt = epService.getEPAdministrator().createEPL(epl); int maxSlots = 10; int maxEventsPerSlot = 1000; for (int timeSlot = 0; timeSlot < maxSlots; timeSlot++) { epService.getEPRuntime().sendEvent(new CurrentTimeEvent(timeSlot * 1000 + 1)); for (int i = 0; i < maxEventsPerSlot; i++) { epService.getEPRuntime().sendEvent(new SupportBean("E" + timeSlot, 0)); } } EventBean[] iterator = EPAssertionUtil.iteratorToArray(stmt.iterator()); assertTrue(iterator.length <= 6 * maxEventsPerSlot); }
public void testObjectArrayEvent() { String[] fields = "p1,sp2".split(","); epService .getEPAdministrator() .getConfiguration() .addEventType( "MyOAEvent", new String[] {"p1", "p2"}, new Object[] {String.class, int.class}); epService .getEPAdministrator() .createEPL("select p1,sum(p2) as sp2 from MyOAEvent.std:groupwin(p1).win:length(2)") .addListener(listener); epService.getEPRuntime().sendEvent(new Object[] {"A", 10}, "MyOAEvent"); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {"A", 10}); epService.getEPRuntime().sendEvent(new Object[] {"B", 11}, "MyOAEvent"); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {"B", 21}); epService.getEPRuntime().sendEvent(new Object[] {"A", 12}, "MyOAEvent"); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {"A", 33}); epService.getEPRuntime().sendEvent(new Object[] {"A", 13}, "MyOAEvent"); EPAssertionUtil.assertProps(listener.assertOneGetNewAndReset(), fields, new Object[] {"A", 36}); }
public void testObjectArrayInheritanceRuntime() { Configuration configuration = SupportConfigFactory.getConfiguration(); EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(configuration); epService.initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.startTest(epService, this.getClass(), getName()); } ConfigurationOperations configOps = epService.getEPAdministrator().getConfiguration(); configOps.addEventType("RootEvent", new String[] {"base"}, new Object[] {String.class}); configOps.addEventType( "Sub1Event", new String[] {"sub1"}, new Object[] {String.class}, new ConfigurationEventTypeObjectArray(Collections.singleton("RootEvent"))); configOps.addEventType( "Sub2Event", new String[] {"sub2"}, new Object[] {String.class}, new ConfigurationEventTypeObjectArray(Collections.singleton("RootEvent"))); configOps.addEventType( "SubAEvent", new String[] {"suba"}, new Object[] {String.class}, new ConfigurationEventTypeObjectArray(Collections.singleton("Sub1Event"))); configOps.addEventType( "SubBEvent", new String[] {"subb"}, new Object[] {String.class}, new ConfigurationEventTypeObjectArray(Collections.singleton("SubAEvent"))); runObjectArrInheritanceAssertion(epService); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.endTest(); } }
public void testObjectArrayTypeUpdate() { Configuration configuration = SupportConfigFactory.getConfiguration(); configuration .getEngineDefaults() .getEventMeta() .setDefaultEventRepresentation(Configuration.EventRepresentation.OBJECTARRAY); String[] names = {"base1", "base2"}; Object[] types = {String.class, makeMap(new Object[][] {{"n1", int.class}})}; configuration.addEventType("MyOAEvent", names, types); EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(configuration); epService.initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.startTest(epService, this.getClass(), getName()); } EPStatement statementOne = epService .getEPAdministrator() .createEPL( "select base1 as v1, base2.n1 as v2, base3? as v3, base2.n2? as v4 from MyOAEvent"); assertEquals(Object[].class, statementOne.getEventType().getUnderlyingType()); EPStatement statementOneSelectAll = epService.getEPAdministrator().createEPL("select * from MyOAEvent"); assertEquals( "[base1, base2]", Arrays.toString(statementOneSelectAll.getEventType().getPropertyNames())); SupportUpdateListener listenerOne = new SupportUpdateListener(); statementOne.addListener(listenerOne); String[] fields = "v1,v2,v3,v4".split(","); epService .getEPRuntime() .sendEvent(new Object[] {"abc", makeMap(new Object[][] {{"n1", 10}}), ""}, "MyOAEvent"); EPAssertionUtil.assertProps( listenerOne.assertOneGetNewAndReset(), fields, new Object[] {"abc", 10, null, null}); // update type String[] namesNew = {"base3", "base2"}; Object[] typesNew = new Object[] {Long.class, makeMap(new Object[][] {{"n2", String.class}})}; epService .getEPAdministrator() .getConfiguration() .updateObjectArrayEventType("MyOAEvent", namesNew, typesNew); EPStatement statementTwo = epService .getEPAdministrator() .createEPL( "select base1 as v1, base2.n1 as v2, base3 as v3, base2.n2 as v4 from MyOAEvent"); EPStatement statementTwoSelectAll = epService.getEPAdministrator().createEPL("select * from MyOAEvent"); SupportUpdateListener listenerTwo = new SupportUpdateListener(); statementTwo.addListener(listenerTwo); epService .getEPRuntime() .sendEvent( new Object[] {"def", makeMap(new Object[][] {{"n1", 9}, {"n2", "xyz"}}), 20L}, "MyOAEvent"); EPAssertionUtil.assertProps( listenerOne.assertOneGetNewAndReset(), fields, new Object[] {"def", 9, 20L, "xyz"}); EPAssertionUtil.assertProps( listenerTwo.assertOneGetNewAndReset(), fields, new Object[] {"def", 9, 20L, "xyz"}); // assert event type assertEquals( "[base1, base2, base3]", Arrays.toString(statementOneSelectAll.getEventType().getPropertyNames())); assertEquals( "[base1, base2, base3]", Arrays.toString(statementTwoSelectAll.getEventType().getPropertyNames())); EPAssertionUtil.assertEqualsAnyOrder( new Object[] { new EventPropertyDescriptor("base3", Long.class, null, false, false, false, false, false), new EventPropertyDescriptor("base2", Map.class, null, false, false, false, true, false), new EventPropertyDescriptor( "base1", String.class, null, false, false, false, false, false), }, statementTwoSelectAll.getEventType().getPropertyDescriptors()); try { epService .getEPAdministrator() .getConfiguration() .updateObjectArrayEventType("dummy", new String[0], new Object[0]); fail(); } catch (ConfigurationException ex) { assertEquals( "Error updating Object-array event type: Event type named 'dummy' has not been declared", ex.getMessage()); } epService .getEPAdministrator() .getConfiguration() .addEventType("SupportBean", SupportBean.class); try { epService .getEPAdministrator() .getConfiguration() .updateObjectArrayEventType("SupportBean", new String[0], new Object[0]); fail(); } catch (ConfigurationException ex) { assertEquals( "Error updating Object-array event type: Event type by name 'SupportBean' is not an Object-array event type", ex.getMessage()); } if (InstrumentationHelper.ENABLED) { InstrumentationHelper.endTest(); } }
public void testNestedPojo() { Pair<String[], Object[]> pair = getTestDefTwo(); EPServiceProvider epService = getEngineInitialized("NestedObjectArr", pair.getFirst(), pair.getSecond()); String statementText = "select " + "simple, object, nodefmap, map, " + "object.id as a1, nodefmap.key1? as a2, nodefmap.key2? as a3, nodefmap.key3?.key4 as a4, " + "map.objectOne as b1, map.simpleOne as b2, map.nodefmapOne.key2? as b3, map.mapOne.simpleTwo? as b4, " + "map.objectOne.indexed[1] as c1, map.objectOne.nested.nestedValue as c2," + "map.mapOne.simpleTwo as d1, map.mapOne.objectTwo as d2, map.mapOne.nodefmapTwo as d3, " + "map.mapOne.mapTwo as e1, map.mapOne.mapTwo.simpleThree as e2, map.mapOne.mapTwo.objectThree as e3, " + "map.mapOne.objectTwo.array[1].mapped('1ma').value as f1, map.mapOne.mapTwo.objectThree.id as f2" + " from NestedObjectArr"; EPStatement statement = epService.getEPAdministrator().createEPL(statementText); SupportUpdateListener listener = new SupportUpdateListener(); statement.addListener(listener); Object[] testdata = getTestDataTwo(); epService.getEPRuntime().sendEvent(testdata, "NestedObjectArr"); // test all properties exist EventBean received = listener.assertOneGetNewAndReset(); EPAssertionUtil.assertProps( received, "simple,object,nodefmap,map".split(","), new Object[] {"abc", new SupportBean_A("A1"), testdata[2], testdata[3]}); EPAssertionUtil.assertProps( received, "a1,a2,a3,a4".split(","), new Object[] {"A1", "val1", null, null}); EPAssertionUtil.assertProps( received, "b1,b2,b3,b4".split(","), new Object[] {getNestedKey(testdata, 3, "objectOne"), 10, "val2", 300}); EPAssertionUtil.assertProps(received, "c1,c2".split(","), new Object[] {2, "nestedValue"}); EPAssertionUtil.assertProps( received, "d1,d2,d3".split(","), new Object[] { 300, getNestedKey(testdata, 3, "mapOne", "objectTwo"), getNestedKey(testdata, 3, "mapOne", "nodefmapTwo") }); EPAssertionUtil.assertProps( received, "e1,e2,e3".split(","), new Object[] { getNestedKey(testdata, 3, "mapOne", "mapTwo"), 4000L, new SupportBean_B("B1") }); EPAssertionUtil.assertProps(received, "f1,f2".split(","), new Object[] {"1ma0", "B1"}); // assert type info EPStatement stmt = epService.getEPAdministrator().createEPL(("select * from NestedObjectArr")); EventType eventType = stmt.getEventType(); String[] propertiesReceived = eventType.getPropertyNames(); String[] propertiesExpected = new String[] {"simple", "object", "nodefmap", "map"}; EPAssertionUtil.assertEqualsAnyOrder(propertiesReceived, propertiesExpected); assertEquals(String.class, eventType.getPropertyType("simple")); assertEquals(Map.class, eventType.getPropertyType("map")); assertEquals(Map.class, eventType.getPropertyType("nodefmap")); assertEquals(SupportBean_A.class, eventType.getPropertyType("object")); assertNull(eventType.getPropertyType("map.mapOne.simpleOne")); // nested POJO with generic return type listener.reset(); epService .getEPAdministrator() .getConfiguration() .addEventType("MyNested", new String[] {"bean"}, new Object[] {MyNested.class}); EPStatement stmtTwo = epService .getEPAdministrator() .createEPL("select * from MyNested(bean.insides.anyOf(i=>id = 'A'))"); stmtTwo.addListener(listener); epService .getEPRuntime() .sendEvent( new Object[] {new MyNested(Arrays.asList(new MyInside[] {new MyInside("A")}))}, "MyNested"); assertTrue(listener.isInvoked()); }
public void testLinest() { // 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:linest(price, volume, feed)"); SupportUpdateListener listener = new SupportUpdateListener(); statement.addListener(listener); assertEquals(Double.class, statement.getEventType().getPropertyType("slope")); assertEquals(Double.class, statement.getEventType().getPropertyType("YIntercept")); assertEquals(Double.class, statement.getEventType().getPropertyType("XAverage")); assertEquals(Double.class, statement.getEventType().getPropertyType("XStandardDeviationPop")); assertEquals( Double.class, statement.getEventType().getPropertyType("XStandardDeviationSample")); assertEquals(Double.class, statement.getEventType().getPropertyType("XSum")); assertEquals(Double.class, statement.getEventType().getPropertyType("XVariance")); assertEquals(Double.class, statement.getEventType().getPropertyType("YAverage")); assertEquals(Double.class, statement.getEventType().getPropertyType("YStandardDeviationPop")); assertEquals( Double.class, statement.getEventType().getPropertyType("YStandardDeviationSample")); assertEquals(Double.class, statement.getEventType().getPropertyType("YSum")); assertEquals(Double.class, statement.getEventType().getPropertyType("YVariance")); assertEquals(Long.class, statement.getEventType().getPropertyType("dataPoints")); assertEquals(Long.class, statement.getEventType().getPropertyType("n")); assertEquals(Double.class, statement.getEventType().getPropertyType("sumX")); assertEquals(Double.class, statement.getEventType().getPropertyType("sumXSq")); assertEquals(Double.class, statement.getEventType().getPropertyType("sumXY")); assertEquals(Double.class, statement.getEventType().getPropertyType("sumY")); assertEquals(Double.class, statement.getEventType().getPropertyType("sumYSq")); String[] fields = new String[] {"symbol", "slope", "YIntercept", "feed"}; epService.getEPRuntime().sendEvent(new SupportMarketDataBean("ABC", 10.0, 50000L, "f1")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {"ABC", Double.NaN, Double.NaN, "f1"}); epService.getEPRuntime().sendEvent(new SupportMarketDataBean("DEF", 1.0, 1L, "f2")); EventBean theEvent = listener.assertOneGetNewAndReset(); EPAssertionUtil.assertProps( theEvent, fields, new Object[] {"DEF", Double.NaN, Double.NaN, "f2"}); assertEquals(1d, theEvent.get("XAverage")); assertEquals(0d, theEvent.get("XStandardDeviationPop")); assertEquals(Double.NaN, theEvent.get("XStandardDeviationSample")); assertEquals(1d, theEvent.get("XSum")); assertEquals(Double.NaN, theEvent.get("XVariance")); assertEquals(1d, theEvent.get("YAverage")); assertEquals(0d, theEvent.get("YStandardDeviationPop")); assertEquals(Double.NaN, theEvent.get("YStandardDeviationSample")); assertEquals(1d, theEvent.get("YSum")); assertEquals(Double.NaN, theEvent.get("YVariance")); assertEquals(1L, theEvent.get("dataPoints")); assertEquals(1L, theEvent.get("n")); assertEquals(1d, theEvent.get("sumX")); assertEquals(1d, theEvent.get("sumXSq")); assertEquals(1d, theEvent.get("sumXY")); assertEquals(1d, theEvent.get("sumY")); assertEquals(1d, theEvent.get("sumYSq")); // above computed values tested in more detail in RegressionBean test epService.getEPRuntime().sendEvent(new SupportMarketDataBean("DEF", 2.0, 2L, "f3")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {"DEF", 1.0, 0.0, "f3"}); epService.getEPRuntime().sendEvent(new SupportMarketDataBean("ABC", 11.0, 50100L, "f4")); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), fields, new Object[] {"ABC", 100.0, 49000.0, "f4"}); }
public void testMappedProperty() { EPServiceProvider epService = getEngineInitialized(null, null, null); // test map containing first-level property that is an array of primitive or Class Map<String, Object> mappedDef = makeMap(new Object[][] {{"p0", Map.class}}); epService .getEPAdministrator() .getConfiguration() .addEventType("MyMappedPropertyMap", mappedDef); EPStatement stmt = epService.getEPAdministrator().createEPL("select p0('k1') as a from MyMappedPropertyMap"); SupportUpdateListener listener = new SupportUpdateListener(); stmt.addListener(listener); Map<String, Object> eventVal = new HashMap<String, Object>(); eventVal.put("k1", "v1"); Map<String, Object> theEvent = makeMap(new Object[][] {{"p0", eventVal}}); epService.getEPRuntime().sendEvent(theEvent, "MyMappedPropertyMap"); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), "a".split(","), new Object[] {"v1"}); assertEquals(Object.class, stmt.getEventType().getPropertyType("a")); stmt.destroy(); // test map at the second level of a nested map that is an array of primitive or Class Map<String, Object> mappedDefOuter = makeMap(new Object[][] {{"outer", mappedDef}}); epService .getEPAdministrator() .getConfiguration() .addEventType("MyMappedPropertyMapOuter", mappedDefOuter); stmt = epService .getEPAdministrator() .createEPL("select outer.p0('k1') as a from MyMappedPropertyMapOuter"); stmt.addListener(listener); Map<String, Object> eventOuter = makeMap(new Object[][] {{"outer", theEvent}}); epService.getEPRuntime().sendEvent(eventOuter, "MyMappedPropertyMapOuter"); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), "a".split(","), new Object[] {"v1"}); assertEquals(Object.class, stmt.getEventType().getPropertyType("a")); // test map that contains a bean which has a map property Map<String, Object> mappedDefOuterTwo = makeMap(new Object[][] {{"outerTwo", SupportBeanComplexProps.class}}); epService .getEPAdministrator() .getConfiguration() .addEventType("MyMappedPropertyMapOuterTwo", mappedDefOuterTwo); stmt = epService .getEPAdministrator() .createEPL("select outerTwo.mapProperty('xOne') as a from MyMappedPropertyMapOuterTwo"); stmt.addListener(listener); Map<String, Object> eventOuterTwo = makeMap(new Object[][] {{"outerTwo", SupportBeanComplexProps.makeDefaultBean()}}); epService.getEPRuntime().sendEvent(eventOuterTwo, "MyMappedPropertyMapOuterTwo"); EPAssertionUtil.assertProps( listener.assertOneGetNewAndReset(), "a".split(","), new Object[] {"yOne"}); assertEquals(String.class, stmt.getEventType().getPropertyType("a")); }
private void runObjectArrInheritanceAssertion(EPServiceProvider epService) { SupportUpdateListener listeners[] = new SupportUpdateListener[5]; String[] statements = { "select base as vbase, sub1? as v1, sub2? as v2, suba? as va, subb? as vb from RootEvent", // 0 "select base as vbase, sub1 as v1, sub2? as v2, suba? as va, subb? as vb from Sub1Event", // 1 "select base as vbase, sub1? as v1, sub2 as v2, suba? as va, subb? as vb from Sub2Event", // 2 "select base as vbase, sub1 as v1, sub2? as v2, suba as va, subb? as vb from SubAEvent", // 3 "select base as vbase, sub1? as v1, sub2? as v2, suba? as va, subb as vb from SubBEvent" // 4 }; for (int i = 0; i < statements.length; i++) { EPStatement statement = epService.getEPAdministrator().createEPL(statements[i]); listeners[i] = new SupportUpdateListener(); statement.addListener(listeners[i]); } String[] fields = "vbase,v1,v2,va,vb".split(","); EventType type = epService.getEPAdministrator().getConfiguration().getEventType("SubAEvent"); assertEquals("base", type.getPropertyDescriptors()[0].getPropertyName()); assertEquals("sub1", type.getPropertyDescriptors()[1].getPropertyName()); assertEquals("suba", type.getPropertyDescriptors()[2].getPropertyName()); assertEquals(3, type.getPropertyDescriptors().length); type = epService.getEPAdministrator().getConfiguration().getEventType("SubBEvent"); assertEquals("[base, sub1, suba, subb]", Arrays.toString(type.getPropertyNames())); assertEquals(4, type.getPropertyDescriptors().length); type = epService.getEPAdministrator().getConfiguration().getEventType("Sub1Event"); assertEquals("[base, sub1]", Arrays.toString(type.getPropertyNames())); assertEquals(2, type.getPropertyDescriptors().length); type = epService.getEPAdministrator().getConfiguration().getEventType("Sub2Event"); assertEquals("[base, sub2]", Arrays.toString(type.getPropertyNames())); assertEquals(2, type.getPropertyDescriptors().length); epService .getEPRuntime() .sendEvent(new Object[] {"a", "b", "x"}, "SubAEvent"); // base, sub1, suba EPAssertionUtil.assertProps( listeners[0].assertOneGetNewAndReset(), fields, new Object[] {"a", "b", null, "x", null}); assertFalse(listeners[2].isInvoked() || listeners[4].isInvoked()); EPAssertionUtil.assertProps( listeners[1].assertOneGetNewAndReset(), fields, new Object[] {"a", "b", null, "x", null}); EPAssertionUtil.assertProps( listeners[3].assertOneGetNewAndReset(), fields, new Object[] {"a", "b", null, "x", null}); epService.getEPRuntime().sendEvent(new Object[] {"f1", "f2", "f4"}, "SubAEvent"); EPAssertionUtil.assertProps( listeners[0].assertOneGetNewAndReset(), fields, new Object[] {"f1", "f2", null, "f4", null}); assertFalse(listeners[2].isInvoked() || listeners[4].isInvoked()); EPAssertionUtil.assertProps( listeners[1].assertOneGetNewAndReset(), fields, new Object[] {"f1", "f2", null, "f4", null}); EPAssertionUtil.assertProps( listeners[3].assertOneGetNewAndReset(), fields, new Object[] {"f1", "f2", null, "f4", null}); epService.getEPRuntime().sendEvent(new Object[] {"XBASE", "X1", "X2", "XY"}, "SubBEvent"); Object[] values = new Object[] {"XBASE", "X1", null, "X2", "XY"}; EPAssertionUtil.assertProps(listeners[0].assertOneGetNewAndReset(), fields, values); assertFalse(listeners[2].isInvoked()); EPAssertionUtil.assertProps(listeners[1].assertOneGetNewAndReset(), fields, values); EPAssertionUtil.assertProps(listeners[3].assertOneGetNewAndReset(), fields, values); EPAssertionUtil.assertProps(listeners[4].assertOneGetNewAndReset(), fields, values); epService.getEPRuntime().sendEvent(new Object[] {"YBASE", "Y1"}, "Sub1Event"); values = new Object[] {"YBASE", "Y1", null, null, null}; EPAssertionUtil.assertProps(listeners[0].assertOneGetNewAndReset(), fields, values); assertFalse(listeners[2].isInvoked() || listeners[3].isInvoked() || listeners[4].isInvoked()); EPAssertionUtil.assertProps(listeners[1].assertOneGetNewAndReset(), fields, values); epService.getEPRuntime().sendEvent(new Object[] {"YBASE", "Y2"}, "Sub2Event"); values = new Object[] {"YBASE", null, "Y2", null, null}; EPAssertionUtil.assertProps(listeners[0].assertOneGetNewAndReset(), fields, values); assertFalse(listeners[1].isInvoked() || listeners[3].isInvoked() || listeners[4].isInvoked()); EPAssertionUtil.assertProps(listeners[2].assertOneGetNewAndReset(), fields, values); epService.getEPRuntime().sendEvent(new Object[] {"ZBASE"}, "RootEvent"); values = new Object[] {"ZBASE", null, null, null, null}; EPAssertionUtil.assertProps(listeners[0].assertOneGetNewAndReset(), fields, values); assertFalse( listeners[1].isInvoked() || listeners[2].isInvoked() || listeners[3].isInvoked() || listeners[4].isInvoked()); // try property not available try { epService.getEPAdministrator().createEPL("select suba from Sub1Event"); fail(); } catch (EPStatementException ex) { assertEquals( "Error starting statement: Failed to validate select-clause expression 'suba': Property named 'suba' is not valid in any stream (did you mean 'sub1'?) [select suba from Sub1Event]", ex.getMessage()); } // try supertype not exists try { epService .getEPAdministrator() .getConfiguration() .addEventType("Sub1Event", makeMap(""), new String[] {"doodle"}); fail(); } catch (ConfigurationException ex) { assertEquals("Supertype by name 'doodle' could not be found", ex.getMessage()); } }
public void testStats() { EPAdministrator epAdmin = epService.getEPAdministrator(); String filter = "select * from " + SupportMarketDataBean.class.getName(); EPStatement priceLast3Stats = epAdmin.createEPL(filter + ".std:groupwin(symbol).win:length(3).stat:uni(price)"); priceLast3Stats.addListener(priceLast3StatsListener); EPStatement volumeLast3Stats = epAdmin.createEPL(filter + ".std:groupwin(symbol).win:length(3).stat:uni(volume)"); volumeLast3Stats.addListener(volumeLast3StatsListener); EPStatement priceAllStats = epAdmin.createEPL(filter + ".std:groupwin(symbol).stat:uni(price)"); priceAllStats.addListener(priceAllStatsListener); EPStatement volumeAllStats = epAdmin.createEPL(filter + ".std:groupwin(symbol).stat:uni(volume)"); volumeAllStats.addListener(volumeAllStatsListener); Vector<Map<String, Object>> expectedList = new Vector<Map<String, Object>>(); for (int i = 0; i < 3; i++) { expectedList.add(new HashMap<String, Object>()); } sendEvent(SYMBOL_CISCO, 25, 50000); sendEvent(SYMBOL_CISCO, 26, 60000); sendEvent(SYMBOL_IBM, 10, 8000); sendEvent(SYMBOL_IBM, 10.5, 8200); sendEvent(SYMBOL_GE, 88, 1000); EPAssertionUtil.assertPropsPerRow( priceLast3StatsListener.getLastNewData(), makeMap(SYMBOL_GE, 88)); EPAssertionUtil.assertPropsPerRow( priceAllStatsListener.getLastNewData(), makeMap(SYMBOL_GE, 88)); EPAssertionUtil.assertPropsPerRow( volumeLast3StatsListener.getLastNewData(), makeMap(SYMBOL_GE, 1000)); EPAssertionUtil.assertPropsPerRow( volumeAllStatsListener.getLastNewData(), makeMap(SYMBOL_GE, 1000)); sendEvent(SYMBOL_CISCO, 27, 70000); sendEvent(SYMBOL_CISCO, 28, 80000); EPAssertionUtil.assertPropsPerRow( priceAllStatsListener.getLastNewData(), makeMap(SYMBOL_CISCO, 26.5d)); EPAssertionUtil.assertPropsPerRow( volumeAllStatsListener.getLastNewData(), makeMap(SYMBOL_CISCO, 65000d)); EPAssertionUtil.assertPropsPerRow( priceLast3StatsListener.getLastNewData(), makeMap(SYMBOL_CISCO, 27d)); EPAssertionUtil.assertPropsPerRow( volumeLast3StatsListener.getLastNewData(), makeMap(SYMBOL_CISCO, 70000d)); sendEvent(SYMBOL_IBM, 11, 8700); sendEvent(SYMBOL_IBM, 12, 8900); EPAssertionUtil.assertPropsPerRow( priceAllStatsListener.getLastNewData(), makeMap(SYMBOL_IBM, 10.875d)); EPAssertionUtil.assertPropsPerRow( volumeAllStatsListener.getLastNewData(), makeMap(SYMBOL_IBM, 8450d)); EPAssertionUtil.assertPropsPerRow( priceLast3StatsListener.getLastNewData(), makeMap(SYMBOL_IBM, 11d + 1 / 6d)); EPAssertionUtil.assertPropsPerRow( volumeLast3StatsListener.getLastNewData(), makeMap(SYMBOL_IBM, 8600d)); sendEvent(SYMBOL_GE, 85.5, 950); sendEvent(SYMBOL_GE, 85.75, 900); sendEvent(SYMBOL_GE, 89, 1250); sendEvent(SYMBOL_GE, 86, 1200); sendEvent(SYMBOL_GE, 85, 1150); double averageGE = (88d + 85.5d + 85.75d + 89d + 86d + 85d) / 6d; EPAssertionUtil.assertPropsPerRow( priceAllStatsListener.getLastNewData(), makeMap(SYMBOL_GE, averageGE)); EPAssertionUtil.assertPropsPerRow( volumeAllStatsListener.getLastNewData(), makeMap(SYMBOL_GE, 1075d)); EPAssertionUtil.assertPropsPerRow( priceLast3StatsListener.getLastNewData(), makeMap(SYMBOL_GE, 86d + 2d / 3d)); EPAssertionUtil.assertPropsPerRow( volumeLast3StatsListener.getLastNewData(), makeMap(SYMBOL_GE, 1200d)); // Check iterator results expectedList.get(0).put("symbol", SYMBOL_CISCO); expectedList.get(0).put("average", 26.5d); expectedList.get(1).put("symbol", SYMBOL_IBM); expectedList.get(1).put("average", 10.875d); expectedList.get(2).put("symbol", SYMBOL_GE); expectedList.get(2).put("average", averageGE); EPAssertionUtil.assertPropsPerRow(priceAllStats.iterator(), expectedList); expectedList.get(0).put("symbol", SYMBOL_CISCO); expectedList.get(0).put("average", 27d); expectedList.get(1).put("symbol", SYMBOL_IBM); expectedList.get(1).put("average", 11d + 1 / 6d); expectedList.get(2).put("symbol", SYMBOL_GE); expectedList.get(2).put("average", 86d + 2d / 3d); EPAssertionUtil.assertPropsPerRow(priceLast3Stats.iterator(), expectedList); }