private void RunAssertionMultirowGroupedUncorrelatedIteratorAndExpressionDef(EPServiceProvider epService) { string[] fields = "c0,c1".Split(','); string epl = "expression getGroups {" + "(select TheString as c0, sum(IntPrimitive) as c1 " + " from SupportBean#keepall group by TheString)" + "}" + "select getGroups() as e1, getGroups().take(10) as e2 from S0#lastevent()"; EPStatement stmt = epService.EPAdministrator.CreateEPL(epl); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; SendSBEventAndTrigger(epService, "E1", 20); foreach (EventBean @event in new EventBean[] { listener.AssertOneGetNew(), stmt.First() }) { AssertMapField("e1", @event, fields, new object[] { "E1", 20 }); AssertMapMultiRow("e2", @event, "c0", fields, new object[][] { new object[] { "E1", 20 } }); } listener.Reset(); SendSBEventAndTrigger(epService, "E2", 30); foreach (EventBean @event in new EventBean[] { listener.AssertOneGetNew(), stmt.First() }) { AssertMapField("e1", @event, fields, null); AssertMapMultiRow("e2", @event, "c0", fields, new object[][] { new object[] { "E1", 20 }, new object[] { "E2", 30 } }); } listener.Reset(); stmt.Dispose(); }
private void RunAssertionMultirowGroupedUncorrelatedIteratorAndExpressionDef() { var fields = "c0,c1".SplitCsv(); var epl = "expression getGroups {" + "(select theString as c0, sum(intPrimitive) as c1 " + " from SupportBean#keepall group by theString)" + "}" + "select getGroups() as e1, getGroups().take(10) as e2 from S0#lastevent()"; var stmt = _epService.EPAdministrator.CreateEPL(epl); stmt.AddListener(_listener); SendSBEventAndTrigger("E1", 20); foreach (var @event in new EventBean[] { _listener.AssertOneGetNew(), stmt.First() }) { AssertMapField("e1", @event, fields, new object[] { "E1", 20 }); AssertMapMultiRow("e2", @event, "c0", fields, new object[][] { new object[] { "E1", 20 } }); } _listener.Reset(); SendSBEventAndTrigger("E2", 30); foreach (var @event in new EventBean[] { _listener.AssertOneGetNew(), stmt.First() }) { AssertMapField("e1", @event, fields, null); AssertMapMultiRow("e2", @event, "c0", fields, new object[][] { new object[] { "E1", 20 }, new object[] { "E2", 30 } }); } _listener.Reset(); stmt.Dispose(); }
private void RunAssertionFirstLastNoPred(EPServiceProvider epService) { string eplFragment = "select " + "Contained.firstOf() as val0, " + "Contained.lastOf() as val1 " + " from Bean"; EPStatement stmtFragment = epService.EPAdministrator.CreateEPL(eplFragment); var listener = new SupportUpdateListener(); stmtFragment.Events += listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, "val0,val1".Split(','), new Type[] { typeof(SupportBean_ST0), typeof(SupportBean_ST0) }); epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value("E1,1", "E3,9", "E2,9")); AssertId(listener, "val0", "E1"); AssertId(listener, "val1", "E2"); listener.Reset(); epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value("E2,2")); AssertId(listener, "val0", "E2"); AssertId(listener, "val1", "E2"); listener.Reset(); epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value(null)); Assert.IsNull(listener.AssertOneGetNew().Get("val0")); Assert.IsNull(listener.AssertOneGetNewAndReset().Get("val1")); epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value()); Assert.IsNull(listener.AssertOneGetNew().Get("val0")); Assert.IsNull(listener.AssertOneGetNewAndReset().Get("val1")); stmtFragment.Dispose(); }
private void RunAssertionVariantOneWildcard(EPServiceProvider epService) { string stmtText = "insert into Event_1W (delta, product) " + "select * from " + typeof(SupportBean).FullName + "#length(100)"; try { epService.EPAdministrator.CreateEPL(stmtText); Assert.Fail(); } catch (EPStatementException) { // Expected } // assert statement-type reference EPServiceProviderSPI spi = (EPServiceProviderSPI)epService; Assert.IsFalse(spi.StatementEventTypeRef.IsInUse("Event_1W")); // test insert wildcard to wildcard epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); var listener = new SupportUpdateListener(); string stmtSelectText = "insert into ABCStream select * from SupportBean"; EPStatement stmtSelect = epService.EPAdministrator.CreateEPL(stmtSelectText, "resilient i0"); stmtSelect.Events += listener.Update; Assert.IsTrue(stmtSelect.EventType is BeanEventType); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); Assert.AreEqual("E1", listener.AssertOneGetNew().Get("TheString")); Assert.IsTrue(listener.AssertOneGetNew().Underlying is SupportBean); stmtSelect.Dispose(); }
public void TestUncorrelatedIteratorAndExpressionDef() { var fields = "c0,c1".Split(','); const string epl = "expression getGroups {" + "(select TheString as c0, sum(IntPrimitive) as c1 " + " from SupportBean.win:keepall() group by TheString)" + "}" + "select getGroups() as e1, getGroups().Take(10) as e2 from S0.std:lastevent()"; var stmt = _epService.EPAdministrator.CreateEPL(epl); stmt.Events += _listener.Update; SendSBEventAndTrigger("E1", 20); foreach (var @event in new EventBean[] { _listener.AssertOneGetNew(), stmt.First() }) { AssertMapField("e1", @event, fields, new Object[] { "E1", 20 }); AssertMapMultiRow("e2", @event, "c0", fields, new Object[][] { new Object[] { "E1", 20 } }); } _listener.Reset(); SendSBEventAndTrigger("E2", 30); foreach (var @event in new EventBean[] { _listener.AssertOneGetNew(), stmt.First() }) { AssertMapField("e1", @event, fields, null); AssertMapMultiRow("e2", @event, "c0", fields, new Object[][] { new Object[] { "E1", 20 }, new Object[] { "E2", 30 } }); } _listener.Reset(); }
// test Map event with ObjectArrayType and ObjectArrayType[] properties private void RunAssertionMapWithObjectArray(EPServiceProvider epService) { epService.EPAdministrator.Configuration.AddEventType("OAType", "p0,p1".Split(','), new object[] { typeof(string), typeof(int?) }); var def = new Dictionary <string, Object>(); def.Put("oa1", "OAType"); def.Put("oa2", "OAType[]"); epService.EPAdministrator.Configuration.AddEventType("MapType", def); EPStatement stmt = epService.EPAdministrator.CreateEPL("select oa1.p0 as c0, oa1.p1 as c1, oa2[0].p0 as c2, oa2[1].p1 as c3 from MapType"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; var data = new Dictionary <string, Object>(); data.Put("oa1", new object[] { "A", 100 }); data.Put("oa2", new object[][] { new object[] { "B", 200 }, new object[] { "C", 300 } }); epService.EPRuntime.SendEvent(data, "MapType"); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), "c0,c1,c2,c3".Split(','), new object[] { "A", 100, "B", 300 }); epService.EPAdministrator.DestroyAllStatements(); // test inserting from map to array epService.EPAdministrator.CreateEPL("insert into OAType select 'a' as p0, 1 as p1 from MapType").Events += listener.Update; epService.EPRuntime.SendEvent(data, "MapType"); Assert.IsTrue(listener.AssertOneGetNew() is ObjectArrayBackedEventBean); Assert.AreEqual("a", listener.AssertOneGetNew().Get("p0")); Assert.AreEqual(1, listener.AssertOneGetNewAndReset().Get("p1")); }
private void RunAssertionBatchWindow(EPServiceProvider epService) { string epl = "select irstream " + "first(TheString) as fs, " + "window(TheString) as ws, " + "last(TheString) as ls " + "from SupportBean#length_batch(2) as sb"; EPStatement stmt = epService.EPAdministrator.CreateEPL(epl); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; string[] fields = "fs,ws,ls".Split(','); epService.EPRuntime.SendEvent(new SupportBean("E1", 0)); epService.EPRuntime.SendEvent(new SupportBean("E2", 0)); EPAssertionUtil.AssertProps(listener.AssertOneGetOld(), fields, new object[] { null, null, null }); EPAssertionUtil.AssertProps(listener.AssertOneGetNew(), fields, new[] { "E1", Split("E1,E2"), "E2" }); listener.Reset(); epService.EPRuntime.SendEvent(new SupportBean("E3", 0)); epService.EPRuntime.SendEvent(new SupportBean("E4", 0)); EPAssertionUtil.AssertProps(listener.AssertOneGetOld(), fields, new[] { "E1", Split("E1,E2"), "E2" }); EPAssertionUtil.AssertProps(listener.AssertOneGetNew(), fields, new[] { "E3", Split("E3,E4"), "E4" }); listener.Reset(); epService.EPRuntime.SendEvent(new SupportBean("E5", 0)); epService.EPRuntime.SendEvent(new SupportBean("E6", 0)); EPAssertionUtil.AssertProps(listener.AssertOneGetOld(), fields, new[] { "E3", Split("E3,E4"), "E4" }); EPAssertionUtil.AssertProps(listener.AssertOneGetNew(), fields, new[] { "E5", Split("E5,E6"), "E6" }); listener.Reset(); stmt.Dispose(); }
private void RunAssertionCorrelatedSubqueryOrder(EPServiceProvider epService) { // ESPER-564 epService.EPAdministrator.Configuration.AddEventType("TradeEvent", typeof(TradeEvent)); var listener = new SupportUpdateListener(); epService.EPAdministrator.CreateEPL("select * from TradeEvent#lastevent"); epService.EPAdministrator.CreateEPL( "select window(tl.*) as longItems, " + " (SELECT window(ts.*) AS shortItems FROM TradeEvent#time(20 minutes) as ts WHERE ts.securityID=tl.securityID) " + "from TradeEvent#time(20 minutes) as tl " + "where tl.securityID = 1000" + "group by tl.securityID " ).Events += listener.Update; epService.EPRuntime.SendEvent(new TradeEvent(DateTimeHelper.CurrentTimeMillis, 1000, 50, 1)); Assert.AreEqual(1, ((object[])listener.AssertOneGetNew().Get("longItems")).Length); Assert.AreEqual(1, ((object[])listener.AssertOneGetNew().Get("shortItems")).Length); listener.Reset(); epService.EPRuntime.SendEvent(new TradeEvent(DateTimeHelper.CurrentTimeMillis + 10, 1000, 50, 1)); Assert.AreEqual(2, ((object[])listener.AssertOneGetNew().Get("longItems")).Length); Assert.AreEqual(2, ((object[])listener.AssertOneGetNew().Get("shortItems")).Length); epService.EPAdministrator.DestroyAllStatements(); }
public void TestFirstLastNoPred() { String eplFragment = "select " + "Contained.firstOf() as val0, " + "Contained.lastOf() as val1 " + " from Bean"; EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment); stmtFragment.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, "val0,val1".Split(','), new Type[] { typeof(SupportBean_ST0), typeof(SupportBean_ST0) }); _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value("E1,1", "E3,9", "E2,9")); AssertId(_listener, "val0", "E1"); AssertId(_listener, "val1", "E2"); _listener.Reset(); _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value("E2,2")); AssertId(_listener, "val0", "E2"); AssertId(_listener, "val1", "E2"); _listener.Reset(); _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value(null)); Assert.IsNull(_listener.AssertOneGetNew().Get("val0")); Assert.IsNull(_listener.AssertOneGetNewAndReset().Get("val1")); _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value()); Assert.IsNull(_listener.AssertOneGetNew().Get("val0")); Assert.IsNull(_listener.AssertOneGetNewAndReset().Get("val1")); }
public void TestVariantOneWildcard() { var stmtText = "insert into Event_1 (delta, product) " + "select * from " + typeof(SupportBean).FullName + ".win:length(100)"; try { _epService.EPAdministrator.CreateEPL(stmtText); Assert.Fail(); } catch (EPStatementException ex) { // Expected } // assert statement-type reference var spi = (EPServiceProviderSPI)_epService; Assert.IsFalse(spi.StatementEventTypeRef.IsInUse("Event_1")); // test insert wildcard to wildcard _epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); var listener = new SupportUpdateListener(); var stmtSelectText = "insert into ABCStream select * from SupportBean"; var stmtSelect = _epService.EPAdministrator.CreateEPL(stmtSelectText, "resilient i0"); stmtSelect.Events += listener.Update; Assert.IsTrue(stmtSelect.EventType is BeanEventType); _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); Assert.AreEqual("E1", listener.AssertOneGetNew().Get("TheString")); Assert.That(listener.AssertOneGetNew().Underlying, Is.InstanceOf <SupportBean>()); }
private void RunAssertionIntersectGroupBy(EPServiceProvider epService) { var fields = new string[] { "TheString" }; string text = "select irstream TheString from SupportBean#groupwin(IntPrimitive)#length(2)#unique(IntBoxed) retain-intersection"; EPStatement stmt = epService.EPAdministrator.CreateEPL(text); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; SendEvent(epService, "E1", 1, 10); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E1" }); SendEvent(epService, "E2", 2, 10); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E2" }); SendEvent(epService, "E3", 1, 20); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2", "E3")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E3" }); SendEvent(epService, "E4", 1, 30); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E2", "E3", "E4")); EPAssertionUtil.AssertProps(listener.AssertOneGetOld(), fields, new object[] { "E1" }); EPAssertionUtil.AssertProps(listener.AssertOneGetNew(), fields, new object[] { "E4" }); listener.Reset(); SendEvent(epService, "E5", 2, 10); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E3", "E4", "E5")); EPAssertionUtil.AssertProps(listener.AssertOneGetOld(), fields, new object[] { "E2" }); EPAssertionUtil.AssertProps(listener.AssertOneGetNew(), fields, new object[] { "E5" }); listener.Reset(); SendEvent(epService, "E6", 1, 20); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E4", "E5", "E6")); EPAssertionUtil.AssertProps(listener.AssertOneGetOld(), fields, new object[] { "E3" }); EPAssertionUtil.AssertProps(listener.AssertOneGetNew(), fields, new object[] { "E6" }); listener.Reset(); SendEvent(epService, "E7", 1, 10); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E5", "E6", "E7")); EPAssertionUtil.AssertProps(listener.AssertOneGetOld(), fields, new object[] { "E4" }); EPAssertionUtil.AssertProps(listener.AssertOneGetNew(), fields, new object[] { "E7" }); listener.Reset(); SendEvent(epService, "E8", 2, 10); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E6", "E7", "E8")); EPAssertionUtil.AssertProps(listener.AssertOneGetOld(), fields, new object[] { "E5" }); EPAssertionUtil.AssertProps(listener.AssertOneGetNew(), fields, new object[] { "E8" }); listener.Reset(); // another combination stmt.Dispose(); epService.EPAdministrator.CreateEPL("select * from SupportBean#groupwin(TheString)#time(.0083 sec)#firstevent").Dispose(); }
public static void AssertValuesArrayScalar(SupportUpdateListener listener, String field, params object[] expected) { if (expected == null) { Assert.IsNull(listener.AssertOneGetNew().Get(field)); return; } object[] arr = listener.AssertOneGetNew().Get(field).UnwrapIntoArray <object>(); EPAssertionUtil.AssertEqualsExactOrder(expected, arr); }
private void TryAssertionTimeWinUnique(EPServiceProvider epService, SupportUpdateListener listener, EPStatement stmt) { var fields = new string[] { "TheString" }; SendTimer(epService, 1000); SendEvent(epService, "E1", 1); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E1" }); SendTimer(epService, 2000); SendEvent(epService, "E2", 2); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E2" }); SendTimer(epService, 3000); SendEvent(epService, "E3", 1); EPAssertionUtil.AssertProps(listener.AssertOneGetOld(), fields, new object[] { "E1" }); EPAssertionUtil.AssertProps(listener.AssertOneGetNew(), fields, new object[] { "E3" }); listener.Reset(); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E2", "E3")); SendTimer(epService, 4000); SendEvent(epService, "E4", 3); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E4" }); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E2", "E3", "E4")); SendEvent(epService, "E5", 3); EPAssertionUtil.AssertProps(listener.AssertOneGetOld(), fields, new object[] { "E4" }); EPAssertionUtil.AssertProps(listener.AssertOneGetNew(), fields, new object[] { "E5" }); listener.Reset(); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E2", "E3", "E5")); SendTimer(epService, 11999); Assert.IsFalse(listener.IsInvoked); SendTimer(epService, 12000); EPAssertionUtil.AssertProps(listener.AssertOneGetOldAndReset(), fields, new object[] { "E2" }); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E3", "E5")); SendTimer(epService, 12999); Assert.IsFalse(listener.IsInvoked); SendTimer(epService, 13000); EPAssertionUtil.AssertProps(listener.AssertOneGetOldAndReset(), fields, new object[] { "E3" }); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E5")); SendTimer(epService, 13999); Assert.IsFalse(listener.IsInvoked); SendTimer(epService, 14000); EPAssertionUtil.AssertProps(listener.AssertOneGetOldAndReset(), fields, new object[] { "E5" }); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr()); }
private void RunAssertionChainedUnparameterized(EPServiceProvider epService) { epService.EPAdministrator.Configuration.AddEventType( "SupportBeanComplexProps", typeof(SupportBeanComplexProps)); var epl = "select " + "nested.NestedValue, " + "nested.NestedNested.NestedNestedValue " + "from SupportBeanComplexProps"; var stmt = epService.EPAdministrator.CreateEPL(epl); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; var bean = SupportBeanComplexProps.MakeDefaultBean(); var rows = new[] { new object[] {"nested.NestedValue", typeof(string)} }; for (var i = 0; i < rows.Length; i++) { var prop = stmt.EventType.PropertyDescriptors[i]; Assert.AreEqual(rows[i][0], prop.PropertyName); Assert.AreEqual(rows[i][1], prop.PropertyType); } epService.EPRuntime.SendEvent(bean); EPAssertionUtil.AssertProps( listener.AssertOneGetNew(), "nested.NestedValue".Split(','), new object[] {bean.Nested.NestedValue}); stmt.Dispose(); }
// test ObjectArray event with Map, Map[], MapType and MapType[] properties private void RunAssertionObjectArrayWithMap(EPServiceProvider epService) { epService.EPAdministrator.Configuration.AddEventType("MapType", Collections.SingletonDataMap("im", typeof(string))); epService.EPAdministrator.Configuration.AddEventType("OAType", "p0,p1,p2,p3".Split(','), new object[] { typeof(string), "MapType", "MapType[]", Collections.SingletonDataMap("om", typeof(string)) }); EPStatement stmt = epService.EPAdministrator.CreateEPL("select p0 as c0, p1.im as c1, p2[0].im as c2, p3.om as c3 from OAType"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent( new object[] { "E1", Collections.SingletonMap("im", "IM1"), new Map[] { Collections.SingletonDataMap("im", "IM2") }, Collections.SingletonDataMap("om", "OM1") }, "OAType"); EPAssertionUtil.AssertProps( listener.AssertOneGetNewAndReset(), "c0,c1,c2,c3".Split(','), new object[] { "E1", "IM1", "IM2", "OM1" }); epService.EPAdministrator.DestroyAllStatements(); // test inserting from array to map epService.EPAdministrator.CreateEPL("insert into MapType(im) select p0 from OAType").Events += listener.Update; epService.EPRuntime.SendEvent(new object[] { "E1", null, null, null }, "OAType"); Assert.IsTrue(listener.AssertOneGetNew() is MappedEventBean); Assert.AreEqual("E1", listener.AssertOneGetNewAndReset().Get("im")); epService.EPAdministrator.DestroyAllStatements(); epService.EPAdministrator.Configuration.RemoveEventType("MapType", false); epService.EPAdministrator.Configuration.RemoveEventType("OAType", false); }
private void RunAssertionChainedStatic(EPServiceProvider epService) { var subexp = "SupportChainTop.Make().GetChildOne(\"abc\",1).GetChildTwo(\"def\").GetText()"; var statementText = "select " + subexp + " from SupportBean"; var stmtOne = epService.EPAdministrator.CreateEPL(statementText); var listener = new SupportUpdateListener(); stmtOne.Events += listener.Update; var rows = new object[][] { new object[] { subexp, typeof(string) } }; for (var i = 0; i < rows.Length; i++) { var prop = stmtOne.EventType.PropertyDescriptors[i]; Assert.AreEqual(rows[i][0], prop.PropertyName); Assert.AreEqual(rows[i][1], prop.PropertyType); } epService.EPRuntime.SendEvent(new SupportBean()); EPAssertionUtil.AssertProps(listener.AssertOneGetNew(), new string[] { subexp }, new object[] { SupportChainTop.Make().GetChildOne("abc", 1).GetChildTwo("def").GetText() }); stmtOne.Dispose(); }
private void RunAssertionUnionPattern(EPServiceProvider epService) { var fields = new string[] { "string" }; string text = "select irstream a.p00||b.p10 as string from pattern [every a=SupportBean_S0 -> b=SupportBean_S1]#unique(a.id)#unique(b.id) retain-union"; EPStatement stmt = epService.EPAdministrator.CreateEPL(text); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean_S0(1, "E1")); epService.EPRuntime.SendEvent(new SupportBean_S1(2, "E2")); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1E2")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E1E2" }); epService.EPRuntime.SendEvent(new SupportBean_S0(10, "E3")); epService.EPRuntime.SendEvent(new SupportBean_S1(20, "E4")); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1E2", "E3E4")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E3E4" }); epService.EPRuntime.SendEvent(new SupportBean_S0(1, "E5")); epService.EPRuntime.SendEvent(new SupportBean_S1(2, "E6")); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E3E4", "E5E6")); EPAssertionUtil.AssertProps(listener.AssertOneGetOld(), fields, new object[] { "E1E2" }); EPAssertionUtil.AssertProps(listener.AssertOneGetNew(), fields, new object[] { "E5E6" }); stmt.Dispose(); }
private void RunAssertionUnionThreeUnique(EPServiceProvider epService) { var fields = new string[] { "TheString" }; EPStatement stmt = epService.EPAdministrator.CreateEPL("select irstream TheString from SupportBean#unique(IntPrimitive)#unique(IntBoxed)#unique(DoublePrimitive) retain-union"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; SendEvent(epService, "E1", 1, 10, 100d); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E1" }); SendEvent(epService, "E2", 2, 10, 200d); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E2" }); SendEvent(epService, "E3", 2, 20, 100d); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2", "E3")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E3" }); SendEvent(epService, "E4", 1, 30, 300d); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E2", "E3", "E4")); EPAssertionUtil.AssertProps(listener.AssertOneGetOld(), fields, new object[] { "E1" }); EPAssertionUtil.AssertProps(listener.AssertOneGetNew(), fields, new object[] { "E4" }); listener.Reset(); stmt.Dispose(); }
public void TestChainedStatic() { _epService.EPAdministrator.Configuration.AddEventType("SupportBean", typeof(SupportBean)); _epService.EPAdministrator.Configuration.AddEventType("SupportChainTop", typeof(SupportChainTop)); _epService.EPAdministrator.Configuration.AddImport(typeof(SupportChainTop)); var subexp = "SupportChainTop.Make().GetChildOne(\"abc\",1).GetChildTwo(\"def\").GetText()"; _statementText = "select " + subexp + " from SupportBean"; var stmtOne = _epService.EPAdministrator.CreateEPL(_statementText); _listener = new SupportUpdateListener(); stmtOne.Events += _listener.Update; var rows = new Object[][] { new Object[] { subexp, typeof(String) } }; for (var i = 0; i < rows.Length; i++) { var prop = stmtOne.EventType.PropertyDescriptors[i]; Assert.AreEqual(rows[i][0], prop.PropertyName); Assert.AreEqual(rows[i][1], prop.PropertyType); } _epService.EPRuntime.SendEvent(new SupportBean()); EPAssertionUtil.AssertProps(_listener.AssertOneGetNew(), new String[] { subexp }, new Object[] { SupportChainTop.Make().GetChildOne("abc", 1).GetChildTwo("def").GetText() }); }
private void RunAssertionArrayPropertySizeAndGetChained(EPServiceProvider epService) { epService.EPAdministrator.Configuration.AddEventType( "SupportBeanCombinedProps", typeof(SupportBeanCombinedProps)); var epl = "select " + "(abc).GetArray().size() as size, " + "(abc).GetArray().get(0).GetNestLevOneVal() as get0 " + "from SupportBeanCombinedProps as abc"; var stmt = epService.EPAdministrator.CreateEPL(epl); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; var bean = SupportBeanCombinedProps.MakeDefaultBean(); var rows = new[] { new object[] {"size", typeof(int?)}, new object[] {"get0", typeof(string)} }; for (var i = 0; i < rows.Length; i++) { var prop = stmt.EventType.PropertyDescriptors[i]; Assert.AreEqual(rows[i][0], prop.PropertyName); Assert.AreEqual(rows[i][1], prop.PropertyType); } epService.EPRuntime.SendEvent(bean); EPAssertionUtil.AssertProps( listener.AssertOneGetNew(), "size,get0".Split(','), new object[] {bean.Array.Length, bean.Array[0].NestLevOneVal}); stmt.Dispose(); }
private void RunAssertionUnionSorted(EPServiceProvider epService) { var fields = new string[] { "TheString" }; EPStatement stmt = epService.EPAdministrator.CreateEPL("select irstream TheString from SupportBean#sort(2, IntPrimitive)#sort(2, IntBoxed) retain-union"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; SendEvent(epService, "E1", 1, 10); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E1" }); SendEvent(epService, "E2", 2, 9); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E2" }); SendEvent(epService, "E3", 0, 0); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2", "E3")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E3" }); SendEvent(epService, "E4", -1, -1); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E3", "E4")); Assert.AreEqual(2, listener.LastOldData.Length); object[] result = { listener.LastOldData[0].Get("TheString"), listener.LastOldData[1].Get("TheString") }; EPAssertionUtil.AssertEqualsAnyOrder(result, new string[] { "E1", "E2" }); EPAssertionUtil.AssertProps(listener.AssertOneGetNew(), fields, new object[] { "E4" }); listener.Reset(); SendEvent(epService, "E5", 1, 1); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E3", "E4")); Assert.AreEqual(1, listener.LastOldData.Length); EPAssertionUtil.AssertProps(listener.AssertOneGetOld(), fields, new object[] { "E5" }); EPAssertionUtil.AssertProps(listener.AssertOneGetNew(), fields, new object[] { "E5" }); listener.Reset(); SendEvent(epService, "E6", 0, 0); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E4", "E6")); Assert.AreEqual(1, listener.LastOldData.Length); EPAssertionUtil.AssertProps(listener.AssertOneGetOld(), fields, new object[] { "E3" }); EPAssertionUtil.AssertProps(listener.AssertOneGetNew(), fields, new object[] { "E6" }); listener.Reset(); stmt.Dispose(); }
public void TestObjectArrayWithMap() { _epService.EPAdministrator.Configuration.AddEventType("MapType", Collections.SingletonDataMap("im", typeof(String))); _epService.EPAdministrator.Configuration.AddEventType("OAType", "p0,p1,p2,p3".Split(','), new Object[] { typeof(String), "MapType", "MapType[]", Collections.SingletonDataMap("om", typeof(String)) }); EPStatement stmt = _epService.EPAdministrator.CreateEPL("select p0 as c0, p1.im as c1, p2[0].im as c2, p3.om as c3 from OAType"); stmt.Events += _listener.Update; _epService.EPRuntime.SendEvent(new Object[] { "E1", Collections.SingletonDataMap("im", "IM1"), new Map[] { Collections.SingletonDataMap("im", "IM2") }, Collections.SingletonDataMap("om", "OM1") }, "OAType"); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), "c0,c1,c2,c3".Split(','), new Object[] { "E1", "IM1", "IM2", "OM1" }); _epService.EPAdministrator.DestroyAllStatements(); // test inserting from array to map _epService.EPAdministrator.CreateEPL("insert into MapType(im) select p0 from OAType").Events += _listener.Update; _epService.EPRuntime.SendEvent(new Object[] { "E1", null, null, null }, "OAType"); Assert.That(_listener.AssertOneGetNew(), Is.InstanceOf <MappedEventBean>()); Assert.AreEqual("E1", _listener.AssertOneGetNew().Get("im")); }
public void TestCorrelatedSubqueryOrder() { // ESPER-564 Configuration config = new Configuration(); config.EngineDefaults.ViewResourcesConfig.IsShareViews = true; _epService = EPServiceProviderManager.GetDefaultProvider(config); _epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(_epService, GetType(), GetType().FullName); } _epService.EPAdministrator.Configuration.AddEventType <TradeEvent>("TradeEvent"); _listener = new SupportUpdateListener(); _epService.EPAdministrator.CreateEPL("select * from TradeEvent.std:lastevent()"); _epService.EPAdministrator.CreateEPL( "select window(tl.*) as longItems, " + " (SELECT window(ts.*) AS shortItems FROM TradeEvent.win:time(20 minutes) as ts WHERE ts.SecurityID=tl.SecurityID) " + "from TradeEvent.win:time(20 minutes) as tl " + "where tl.SecurityID = 1000" + "group by tl.SecurityID " ).Events += _listener.Update; _epService.EPRuntime.SendEvent(new TradeEvent(PerformanceObserver.MilliTime, 1000, 50, 1)); Assert.AreEqual(1, ((Object[])_listener.AssertOneGetNew().Get("longItems")).Length); Assert.AreEqual(1, ((Object[])_listener.AssertOneGetNew().Get("shortItems")).Length); _listener.Reset(); _epService.EPRuntime.SendEvent(new TradeEvent(PerformanceObserver.MilliTime + 10, 1000, 50, 1)); Assert.AreEqual(2, ((Object[])_listener.AssertOneGetNew().Get("longItems")).Length); Assert.AreEqual(2, ((Object[])_listener.AssertOneGetNew().Get("shortItems")).Length); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
public override void Run(EPServiceProvider epService) { /// <summary>Regular algorithm to find separated luggage and new owner.</summary> var theEvent = LocationReportFactory.MakeLarge(); var separatedLuggage = LocationReportFactory.FindSeparatedLuggage(theEvent); foreach (var item in separatedLuggage) { //Log.Info("Luggage that are separated (dist>20): " + item); var newOwner = LocationReportFactory.FindPotentialNewOwner(theEvent, item); //Log.Info("Found new owner " + newOwner); } var eplFragment = "" + "expression lostLuggage {" + " lr => lr.items.where(l => l.type='L' and " + " lr.items.anyof(p => p.type='P' and p.assetId=l.assetIdPassenger and LRUtil.Distance(l.location.x, l.location.y, p.location.x, p.location.y) > 20))" + "}" + "expression passengers {" + " lr => lr.items.where(l => l.type='P')" + "}" + "" + "expression nearestOwner {" + " lr => lostLuggage(lr).toMap(key => key.assetId, " + " value => passengers(lr).minBy(p => LRUtil.Distance(value.location.x, value.location.y, p.location.x, p.location.y)))" + "}" + "" + "select lostLuggage(lr) as val1, nearestOwner(lr) as val2 from LocationReport lr"; var stmtFragment = epService.EPAdministrator.CreateEPL(eplFragment); var listener = new SupportUpdateListener(); stmtFragment.Events += listener.Update; var bean = LocationReportFactory.MakeLarge(); epService.EPRuntime.SendEvent(bean); var val1 = listener.AssertOneGetNew().Get("val1").UnwrapIntoArray <Item>(); Assert.AreEqual(3, val1.Length); Assert.AreEqual("L00000", val1[0].AssetId); Assert.AreEqual("L00007", val1[1].AssetId); Assert.AreEqual("L00008", val1[2].AssetId); var val2 = listener.AssertOneGetNewAndReset().Get("val2").UnwrapDictionary(); Assert.AreEqual(3, val2.Count); Assert.AreEqual("P00008", ((Item)val2.Get("L00000")).AssetId); Assert.AreEqual("P00001", ((Item)val2.Get("L00007")).AssetId); Assert.AreEqual("P00001", ((Item)val2.Get("L00008")).AssetId); }
private void RunAssertionEscape(EPServiceProvider epService) { var statementText = "select SupportStaticMethodLib.`Join`(abcstream) as value from SupportBean abcstream"; var stmtOne = epService.EPAdministrator.CreateEPL(statementText); var listener = new SupportUpdateListener(); stmtOne.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 99)); EPAssertionUtil.AssertProps(listener.AssertOneGetNew(), "value".Split(','), new object[] { "E1 99" }); stmtOne.Dispose(); }
public void TestMissingLuggage() { // Regular algorithm to find separated luggage and new owner. LocationReport theEvent = LocationReportFactory.MakeLarge(); IList <Item> separatedLuggage = LocationReportFactory.FindSeparatedLuggage(theEvent); foreach (Item item in separatedLuggage) { //log.info("Luggage that are separated (dist>20): " + item); Item newOwner = LocationReportFactory.FindPotentialNewOwner(theEvent, item); //log.info("Found new owner " + newOwner); } string eplFragment = "" + "expression lostLuggage {" + " lr => lr.items.where(l => l.type='L' and " + " lr.items.anyof(p => p.type='P' and p.assetId=l.assetIdPassenger and LRUtil.Distance(l.location.x, l.location.y, p.location.x, p.location.y) > 20))" + "}" + "expression passengers {" + " lr => lr.items.where(l => l.type='P')" + "}" + "" + "expression nearestOwner {" + " lr => lostLuggage(lr).toMap(key => key.assetId, " + " value => passengers(lr).minBy(p => LRUtil.Distance(value.location.x, value.location.y, p.location.x, p.location.y)))" + "}" + "" + "select lostLuggage(lr) as val1, nearestOwner(lr) as val2 from LocationReport lr"; EPStatement stmtFragment = epService.EPAdministrator.CreateEPL(eplFragment); stmtFragment.AddListener(listener); LocationReport bean = LocationReportFactory.MakeLarge(); epService.EPRuntime.SendEvent(bean); Item[] val1 = ItemArray(listener.AssertOneGetNew().Get("val1").Unwrap <Item>()); Assert.AreEqual(3, val1.Length); Assert.AreEqual("L00000", val1[0].AssetId); Assert.AreEqual("L00007", val1[1].AssetId); Assert.AreEqual("L00008", val1[2].AssetId); var val2 = (IDictionary <object, object>)listener.AssertOneGetNewAndReset().Get("val2"); Assert.AreEqual(3, val2.Count); Assert.AreEqual("P00008", ((Item)val2.Get("L00000")).AssetId); Assert.AreEqual("P00001", ((Item)val2.Get("L00007")).AssetId); Assert.AreEqual("P00001", ((Item)val2.Get("L00008")).AssetId); }
private void RunAssertionBatchWindow(EPServiceProvider epService) { var fields = new string[] { "TheString" }; EPStatement stmt = epService.EPAdministrator.CreateEPL("select irstream TheString from SupportBean#length_batch(3)#unique(IntPrimitive) retain-union"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; SendEvent(epService, "E1", 1); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E1" }); SendEvent(epService, "E2", 2); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E2" }); SendEvent(epService, "E3", 3); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2", "E3")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E3" }); SendEvent(epService, "E4", 4); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2", "E3", "E4")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E4" }); SendEvent(epService, "E5", 4); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2", "E3", "E4", "E5")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E5" }); SendEvent(epService, "E6", 4); // remove stream is E1, E2, E3 EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2", "E3", "E4", "E5", "E6")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E6" }); SendEvent(epService, "E7", 5); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2", "E3", "E4", "E5", "E6", "E7")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E7" }); SendEvent(epService, "E8", 6); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2", "E3", "E5", "E4", "E6", "E7", "E8")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E8" }); SendEvent(epService, "E9", 7); // remove stream is E4, E5, E6; E4 and E5 get removed as their EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), fields, ToArr("E1", "E2", "E3", "E6", "E7", "E8", "E9")); EPAssertionUtil.AssertPropsPerRow(listener.LastOldData, fields, new object[][] { new object[] { "E4" }, new object[] { "E5" } }); EPAssertionUtil.AssertProps(listener.AssertOneGetNew(), fields, new object[] { "E9" }); listener.Reset(); stmt.Dispose(); }
public void TestEscape() { _epService.EPAdministrator.Configuration.AddEventType("SupportBean", typeof(SupportBean)); _epService.EPAdministrator.Configuration.AddImport(typeof(SupportStaticMethodLib).FullName); _statementText = "select SupportStaticMethodLib.`Join`(abcstream) as value from SupportBean abcstream"; var stmtOne = _epService.EPAdministrator.CreateEPL(_statementText); _listener = new SupportUpdateListener(); stmtOne.Events += _listener.Update; _epService.EPRuntime.SendEvent(new SupportBean("E1", 99)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNew(), "value".Split(','), new Object[] { "E1 99" }); }
public void TestConfiguredViaPropsAndXML() { var configuration = SupportConfigFactory.GetConfiguration(); configuration.EngineDefaults.EventMetaConfig.DefaultEventRepresentation = EventRepresentation.OBJECTARRAY; configuration.AddEventType( "MyOAType", "bean,TheString,map".Split(','), new Object[] { typeof(SupportBean).FullName, typeof(String).FullName, typeof(Map).FullName }); var epService = EPServiceProviderManager.GetDefaultProvider(configuration); epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName); } var eventType = epService.EPAdministrator.Configuration.GetEventType("MyOAType"); Assert.AreEqual(typeof(Object[]), eventType.UnderlyingType); Assert.AreEqual(typeof(String), eventType.GetPropertyType("TheString")); Assert.AreEqual(typeof(Map), eventType.GetPropertyType("map")); Assert.AreEqual(typeof(SupportBean), eventType.GetPropertyType("bean")); var stmt = epService.EPAdministrator.CreateEPL("select bean, TheString, map('key'), bean.TheString from MyOAType"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; Assert.AreEqual(typeof(Object[]), stmt.EventType.UnderlyingType); var bean = new SupportBean("E1", 1); epService.EPRuntime.SendEvent(new Object[] { bean, "abc", Collections.SingletonDataMap("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 static void AssertST0Id(SupportUpdateListener listener, String property, String expectedList) { SupportBean_ST0[] arr = listener.AssertOneGetNew().Get(property).UnwrapIntoArray <SupportBean_ST0>(); if (expectedList == null && arr == null) { return; } if ((expectedList.Length == 0) && (arr.Length == 0)) { return; } String[] expected = expectedList.Split(','); Assert.AreEqual(expected.Length, arr.Length); for (int i = 0; i < expected.Length; i++) { Assert.AreEqual(expected[i], arr[i].Id); } }