public void TestSelectFrom() { String[] fields = "val0".Split(','); String eplFragment = "select contained.SelectFrom(x => key0).sequenceEqual(contained.SelectFrom(y => id)) as val0 " + "from SupportBean_ST0_Container"; EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment); stmtFragment.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, "val0".Split(','), new Type[] { typeof(bool) }); _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make3Value("I1,E1,0", "I2,E2,0")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { false }); _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make3Value("I3,I3,0", "X4,X4,0")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { true }); _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make3Value("I3,I3,0", "X4,Y4,0")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { false }); _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make3Value("I3,I3,0", "Y4,X4,0")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { false }); }
public void TestMergeDeclared() { IDictionary <String, Object> fullType = MakeMap(new Object[][] { new Object[] { "P1", typeof(string) }, new Object[] { "P2", typeof(string) }, new Object[] { "P3", typeof(string) }, new Object[] { "Pf", typeof(string) } }); _epService.EPAdministrator.Configuration.AddEventType("FullType", fullType); IDictionary <String, Object> deltaType = MakeMap(new Object[][] { new Object[] { "P1", typeof(string) }, new Object[] { "P2", typeof(string) }, new Object[] { "P3", typeof(string) }, new Object[] { "Pd", typeof(string) } }); _epService.EPAdministrator.Configuration.AddEventType("DeltaType", deltaType); ConfigurationRevisionEventType revEvent = new ConfigurationRevisionEventType(); revEvent.AddNameBaseEventType("FullType"); revEvent.AddNameDeltaEventType("DeltaType"); revEvent.PropertyRevision = PropertyRevisionEnum.MERGE_DECLARED; revEvent.KeyPropertyNames = (new String[] { "P1" }); _epService.EPAdministrator.Configuration.AddRevisionEventType("MyExistsRevision", revEvent); _epService.EPAdministrator.CreateEPL("create window MyWin#time(10 sec) as select * from MyExistsRevision"); _epService.EPAdministrator.CreateEPL("insert into MyWin select * from FullType"); _epService.EPAdministrator.CreateEPL("insert into MyWin select * from DeltaType"); String[] fields = "P1,P2,P3,Pf,Pd".Split(','); EPStatement consumerOne = _epService.EPAdministrator.CreateEPL("select irstream * from MyWin"); consumerOne.Events += _listenerOne.Update; EPAssertionUtil.AssertEqualsAnyOrder(consumerOne.EventType.PropertyNames, fields); _epService.EPRuntime.SendEvent(MakeMap("P1,P2,P3,Pf", "10,20,30,f0"), "FullType"); EPAssertionUtil.AssertProps(_listenerOne.AssertOneGetNewAndReset(), fields, new Object[] { "10", "20", "30", "f0", null }); _epService.EPRuntime.SendEvent(MakeMap("P1,P2", "10,21"), "DeltaType"); EPAssertionUtil.AssertProps(_listenerOne.LastOldData[0], fields, new Object[] { "10", "20", "30", "f0", null }); EPAssertionUtil.AssertProps(_listenerOne.LastNewData[0], fields, new Object[] { "10", "21", null, "f0", null }); _listenerOne.Reset(); _epService.EPRuntime.SendEvent(MakeMap("P1,P3,Pf", "10,32,f1"), "FullType"); EPAssertionUtil.AssertProps(_listenerOne.LastOldData[0], fields, new Object[] { "10", "21", null, "f0", null }); EPAssertionUtil.AssertProps(_listenerOne.LastNewData[0], fields, new Object[] { "10", null, "32", "f1", null }); _listenerOne.Reset(); _epService.EPRuntime.SendEvent(MakeMap("P1,P3,Pd", "10,33,pd3"), "DeltaType"); EPAssertionUtil.AssertProps(_listenerOne.LastOldData[0], fields, new Object[] { "10", null, "32", "f1", null }); EPAssertionUtil.AssertProps(_listenerOne.LastNewData[0], fields, new Object[] { "10", null, "33", "f1", "pd3" }); _listenerOne.Reset(); _epService.EPRuntime.SendEvent(MakeMap("P1,P2,P3,Pf", "10,22,34,f2"), "FullType"); EPAssertionUtil.AssertProps(_listenerOne.LastOldData[0], fields, new Object[] { "10", null, "33", "f1", "pd3" }); EPAssertionUtil.AssertProps(_listenerOne.LastNewData[0], fields, new Object[] { "10", "22", "34", "f2", "pd3" }); _listenerOne.Reset(); _epService.EPRuntime.SendEvent(MakeMap("P1", "10"), "FullType"); EPAssertionUtil.AssertProps(_listenerOne.LastOldData[0], fields, new Object[] { "10", "22", "34", "f2", "pd3" }); EPAssertionUtil.AssertProps(_listenerOne.LastNewData[0], fields, new Object[] { "10", null, null, null, "pd3" }); _listenerOne.Reset(); _epService.EPRuntime.SendEvent(MakeMap("P1,P2,P3,Pf,Pd", "10,23,35,pfx,pd4"), "DeltaType"); EPAssertionUtil.AssertProps(_listenerOne.LastOldData[0], fields, new Object[] { "10", null, null, null, "pd3" }); EPAssertionUtil.AssertProps(_listenerOne.LastNewData[0], fields, new Object[] { "10", "23", "35", null, "pd4" }); _listenerOne.Reset(); _epService.EPRuntime.SendEvent(MakeMap("P1,P2", "10,null"), "DeltaType"); EPAssertionUtil.AssertProps(_listenerOne.LastOldData[0], fields, new Object[] { "10", "23", "35", null, "pd4" }); EPAssertionUtil.AssertProps(_listenerOne.LastNewData[0], fields, new Object[] { "10", null, null, null, null }); _listenerOne.Reset(); _epService.EPRuntime.SendEvent(MakeMap("P1,P3,Pd,Pf", "10,36,pdx,f4"), "FullType"); EPAssertionUtil.AssertProps(_listenerOne.LastOldData[0], fields, new Object[] { "10", null, null, null, null }); EPAssertionUtil.AssertProps(_listenerOne.LastNewData[0], fields, new Object[] { "10", null, "36", "f4", null }); _listenerOne.Reset(); _epService.EPRuntime.SendEvent(MakeMap("P1,P3,Pd", "10,null,pd5"), "DeltaType"); EPAssertionUtil.AssertProps(_listenerOne.LastOldData[0], fields, new Object[] { "10", null, "36", "f4", null }); EPAssertionUtil.AssertProps(_listenerOne.LastNewData[0], fields, new Object[] { "10", null, null, "f4", "pd5" }); _listenerOne.Reset(); }
private void AssertReceived(SupportBean[] beans, int[] indexesAll, int[] indexesWhere, string[] mapKeys, object[] mapValues) { var received = _listenerStmtOne.AssertOneGetNewAndReset(); EPAssertionUtil.AssertEqualsExactOrder(SupportBean.GetBeansPerIndex(beans, indexesAll), (object[])received.Get("c0")); EPAssertionUtil.AssertEqualsExactOrder(SupportBean.GetBeansPerIndex(beans, indexesWhere), received.Get("c1").Unwrap <object>()); EPAssertionUtil.AssertPropsMap((IDictionary <object, object>)received.Get("c2"), mapKeys, mapValues); }
private void RunAssertionTimeAccum(EPServiceProvider epService, SupportMarketDataBean[] events) { long startTime = 1000; SendTimer(epService, startTime); EPStatement stmt = epService.EPAdministrator.CreateEPL( "select irstream * from " + typeof(SupportMarketDataBean).FullName + "#time_accum(10 sec)"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; EPRuntime engine = epService.EPRuntime; SendTimer(epService, startTime + 10000); Assert.IsFalse(listener.IsInvoked); // 1st at 10 sec engine.SendEvent(events[0]); Assert.AreSame(listener.AssertOneGetNewAndReset().Underlying, events[0]); // 2nd event at 14 sec SendTimer(epService, startTime + 14000); engine.SendEvent(events[1]); Assert.AreSame(listener.AssertOneGetNewAndReset().Underlying, events[1]); // 3nd event at 14 sec SendTimer(epService, startTime + 14000); engine.SendEvent(events[2]); Assert.AreSame(listener.AssertOneGetNewAndReset().Underlying, events[2]); // 3rd event at 23 sec SendTimer(epService, startTime + 23000); engine.SendEvent(events[3]); Assert.AreSame(listener.AssertOneGetNewAndReset().Underlying, events[3]); // no event till 33 sec SendTimer(epService, startTime + 32999); Assert.IsFalse(listener.IsInvoked); SendTimer(epService, startTime + 33000); Assert.IsNull(listener.LastNewData); Assert.AreEqual(1, listener.OldDataList.Count); Assert.AreEqual(4, listener.LastOldData.Length); EPAssertionUtil.AssertEqualsExactOrderUnderlying(new object[] { events[0], events[1], events[2], events[3] }, listener.GetOldDataListFlattened()); listener.Reset(); // no events till 50 sec SendTimer(epService, startTime + 50000); Assert.IsFalse(listener.IsInvoked); // next two events at 55 sec SendTimer(epService, startTime + 55000); engine.SendEvent(events[4]); Assert.AreSame(listener.AssertOneGetNewAndReset().Underlying, events[4]); engine.SendEvent(events[5]); Assert.AreSame(listener.AssertOneGetNewAndReset().Underlying, events[5]); // no event till 65 sec SendTimer(epService, startTime + 64999); Assert.IsFalse(listener.IsInvoked); SendTimer(epService, startTime + 65000); Assert.IsNull(listener.LastNewData); Assert.AreEqual(1, listener.OldDataList.Count); Assert.AreEqual(2, listener.LastOldData.Length); EPAssertionUtil.AssertEqualsExactOrderUnderlying(new object[] { events[4], events[5] }, listener.GetOldDataListFlattened()); listener.Reset(); // next window engine.SendEvent(events[6]); Assert.AreSame(listener.AssertOneGetNewAndReset().Underlying, events[6]); SendTimer(epService, startTime + 74999); engine.SendEvent(events[7]); Assert.AreSame(listener.AssertOneGetNewAndReset().Underlying, events[7]); SendTimer(epService, startTime + 74999 + 10000); Assert.IsNull(listener.LastNewData); Assert.AreEqual(1, listener.OldDataList.Count); Assert.AreEqual(2, listener.LastOldData.Length); EPAssertionUtil.AssertEqualsExactOrderUnderlying(new object[] { events[6], events[7] }, listener.GetOldDataListFlattened()); listener.Reset(); stmt.Dispose(); }
public void TestFirstLastScalar() { String[] fields = "val0,val1,val2,val3".Split(','); String eplFragment = "select " + "Strvals.firstOf() as val0, " + "Strvals.lastOf() as val1, " + "Strvals.firstOf(x => x like '%1%') as val2, " + "Strvals.lastOf(x => x like '%1%') as val3 " + " from SupportCollection"; EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment); stmtFragment.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, fields, new Type[] { typeof(string), typeof(string), typeof(string), typeof(string) }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1,E2,E3")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "E1", "E3", "E1", "E1" }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "E1", "E1", "E1", "E1" }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E2,E3,E4")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "E2", "E4", null, null }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null, null, null, null }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString(null)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null, null, null, null }); }
public void RunAssertionOnDeleteAndUpdate(bool namedWindow) { epService.EPAdministrator.CreateEPL("@Name('context') create context SegmentedByString " + "partition by TheString from SupportBean, p00 from SupportBean_S0, p10 from SupportBean_S1"); string[] fieldsNW = new string[] { "TheString", "IntPrimitive" }; string eplCreate = namedWindow ? "@Name('named window') context SegmentedByString create window MyInfra.win:keepall() as SupportBean" : "@Name('named window') context SegmentedByString create table MyInfra(TheString string primary key, IntPrimitive int primary key)"; epService.EPAdministrator.CreateEPL(eplCreate); string eplInsert = namedWindow ? "@Name('insert') insert into MyInfra select TheString, IntPrimitive from SupportBean" : "@Name('insert') context SegmentedByString insert into MyInfra select TheString, IntPrimitive from SupportBean"; epService.EPAdministrator.CreateEPL(eplInsert); epService.EPAdministrator.CreateEPL("@Name('selectit') context SegmentedByString select irstream * from MyInfra").AddListener(listenerSelect); // Delete testing EPStatement stmtDelete = epService.EPAdministrator.CreateEPL("@Name('on-delete') context SegmentedByString on SupportBean_S0 delete from MyInfra"); epService.EPRuntime.SendEvent(new SupportBean("G1", 1)); if (namedWindow) { EPAssertionUtil.AssertProps(listenerSelect.AssertOneGetNewAndReset(), fieldsNW, new object[] { "G1", 1 }); } else { Assert.IsFalse(listenerSelect.IsInvoked); } epService.EPRuntime.SendEvent(new SupportBean_S0(0, "G0")); epService.EPRuntime.SendEvent(new SupportBean_S0(0, "G2")); Assert.IsFalse(listenerSelect.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean_S0(0, "G1")); if (namedWindow) { EPAssertionUtil.AssertProps(listenerSelect.AssertOneGetOldAndReset(), fieldsNW, new object[] { "G1", 1 }); } epService.EPRuntime.SendEvent(new SupportBean("G2", 20)); if (namedWindow) { EPAssertionUtil.AssertProps(listenerSelect.AssertOneGetNewAndReset(), fieldsNW, new object[] { "G2", 20 }); } epService.EPRuntime.SendEvent(new SupportBean("G3", 3)); if (namedWindow) { EPAssertionUtil.AssertProps(listenerSelect.AssertOneGetNewAndReset(), fieldsNW, new object[] { "G3", 3 }); } epService.EPRuntime.SendEvent(new SupportBean("G2", 21)); if (namedWindow) { EPAssertionUtil.AssertProps(listenerSelect.AssertOneGetNewAndReset(), fieldsNW, new object[] { "G2", 21 }); } epService.EPRuntime.SendEvent(new SupportBean_S0(0, "G2")); if (namedWindow) { EPAssertionUtil.AssertPropsPerRow(listenerSelect.LastOldData, fieldsNW, new object[][] { new object[] { "G2", 20 }, new object[] { "G2", 21 } }); } listenerSelect.Reset(); stmtDelete.Dispose(); // update testing EPStatement stmtUpdate = epService.EPAdministrator.CreateEPL("@Name('on-merge') context SegmentedByString on SupportBean_S0 update MyInfra set IntPrimitive = IntPrimitive + 1"); epService.EPRuntime.SendEvent(new SupportBean("G4", 4)); if (namedWindow) { EPAssertionUtil.AssertProps(listenerSelect.AssertOneGetNewAndReset(), fieldsNW, new object[] { "G4", 4 }); } epService.EPRuntime.SendEvent(new SupportBean_S0(0, "G0")); epService.EPRuntime.SendEvent(new SupportBean_S0(0, "G1")); epService.EPRuntime.SendEvent(new SupportBean_S0(0, "G2")); Assert.IsFalse(listenerSelect.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean_S0(0, "G4")); if (namedWindow) { EPAssertionUtil.AssertProps(listenerSelect.LastNewData[0], fieldsNW, new object[] { "G4", 5 }); EPAssertionUtil.AssertProps(listenerSelect.LastOldData[0], fieldsNW, new object[] { "G4", 4 }); listenerSelect.Reset(); } epService.EPRuntime.SendEvent(new SupportBean("G5", 5)); if (namedWindow) { EPAssertionUtil.AssertProps(listenerSelect.AssertOneGetNewAndReset(), fieldsNW, new object[] { "G5", 5 }); } epService.EPRuntime.SendEvent(new SupportBean_S0(0, "G5")); if (namedWindow) { EPAssertionUtil.AssertProps(listenerSelect.LastNewData[0], fieldsNW, new object[] { "G5", 6 }); EPAssertionUtil.AssertProps(listenerSelect.LastOldData[0], fieldsNW, new object[] { "G5", 5 }); listenerSelect.Reset(); } stmtUpdate.Dispose(); epService.EPAdministrator.DestroyAllStatements(); epService.EPAdministrator.Configuration.RemoveEventType("MyInfra", false); }
public void TestDifferentReturnTypes() { // test scalar only var fieldsScalar = "c0,c1".Split(','); const string eplScalar = "select ss(TheString) as c0, ss(IntPrimitive) as c1 from SupportBean"; var stmtScalar = _epService.EPAdministrator.CreateEPL(eplScalar); stmtScalar.Events += _listener.Update; var expectedScalar = new Object[][] { new Object[] { "c0", typeof(string), null, null }, new Object[] { "c1", typeof(int?), null, null } }; EventTypeAssertionUtil.AssertEventTypeProperties(expectedScalar, stmtScalar.EventType, EventTypeAssertionEnumExtensions.GetSetWithFragment()); _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsScalar, new Object[] { "E1", 1 }); _epService.EPRuntime.SendEvent(new SupportBean("E2", 2)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsScalar, new Object[] { "E2", 2 }); stmtScalar.Dispose(); // test scalar-array only var fieldsScalarArray = "c0,c1,c2,c3".Split(','); const string eplScalarArray = "select " + "sa(TheString) as c0, " + "sa(IntPrimitive) as c1, " + "sa(TheString).AllOf(v => v = 'E1') as c2, " + "sa(IntPrimitive).AllOf(v => v = 1) as c3 " + "from SupportBean"; var stmtScalarArray = _epService.EPAdministrator.CreateEPL(eplScalarArray); stmtScalarArray.Events += _listener.Update; var expectedScalarArray = new Object[][] { new Object[] { "c0", typeof(string[]), null, null }, new Object[] { "c1", typeof(int?[]), null, null }, new Object[] { "c2", typeof(bool), null, null }, new Object[] { "c3", typeof(bool), null, null } }; EventTypeAssertionUtil.AssertEventTypeProperties(expectedScalarArray, stmtScalarArray.EventType, EventTypeAssertionEnumExtensions.GetSetWithFragment()); _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsScalarArray, new Object[] { new String[] { "E1" }, new int[] { 1 }, true, true }); _epService.EPRuntime.SendEvent(new SupportBean("E2", 2)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsScalarArray, new Object[] { new String[] { "E1", "E2" }, new int[] { 1, 2 }, false, false }); stmtScalarArray.Dispose(); // test scalar-collection only var fieldsScalarColl = "c2,c3".Split(','); const string eplScalarColl = "select " + "sc(TheString) as c0, " + "sc(IntPrimitive) as c1, " + "sc(TheString).AllOf(v => v = 'E1') as c2, " + "sc(IntPrimitive).AllOf(v => v = 1) as c3 " + "from SupportBean"; var stmtScalarColl = _epService.EPAdministrator.CreateEPL(eplScalarColl); stmtScalarColl.Events += _listener.Update; var expectedScalarColl = new Object[][] { new Object[] { "c0", typeof(ICollection <object>), null, null }, new Object[] { "c1", typeof(ICollection <object>), null, null }, new Object[] { "c2", typeof(bool), null, null }, new Object[] { "c3", typeof(bool), null, null } }; EventTypeAssertionUtil.AssertEventTypeProperties(expectedScalarColl, stmtScalarColl.EventType, EventTypeAssertionEnumExtensions.GetSetWithFragment()); _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); EPAssertionUtil.AssertEqualsExactOrder(new Object[] { "E1" }, (ICollection <object>)_listener.AssertOneGetNew().Get("c0")); EPAssertionUtil.AssertEqualsExactOrder(new Object[] { 1 }, (ICollection <object>)_listener.AssertOneGetNew().Get("c1")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsScalarColl, new Object[] { true, true }); _epService.EPRuntime.SendEvent(new SupportBean("E2", 2)); EPAssertionUtil.AssertEqualsExactOrder(new Object[] { "E1", "E2" }, (ICollection <object>)_listener.AssertOneGetNew().Get("c0")); EPAssertionUtil.AssertEqualsExactOrder(new Object[] { 1, 2 }, (ICollection <object>)_listener.AssertOneGetNew().Get("c1")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsScalarColl, new Object[] { false, false }); stmtScalarColl.Dispose(); // test single-event return var fieldsSingleEvent = "c0,c1,c2,c3,c4".Split(','); const string eplSingleEvent = "select " + "se1() as c0, " + "se1().AllOf(v => v.TheString = 'E1') as c1, " + "se1().AllOf(v => v.IntPrimitive = 1) as c2, " + "se1().TheString as c3, " + "se1().IntPrimitive as c4 " + "from SupportBean"; var stmtSingleEvent = _epService.EPAdministrator.CreateEPL(eplSingleEvent); stmtSingleEvent.Events += _listener.Update; var expectedSingleEvent = new Object[][] { new Object[] { "c0", typeof(SupportBean), "SupportBean", false }, new Object[] { "c1", typeof(Boolean), null, null }, new Object[] { "c2", typeof(Boolean), null, null }, new Object[] { "c3", typeof(String), null, null }, new Object[] { "c4", typeof(int?), null, null } }; EventTypeAssertionUtil.AssertEventTypeProperties(expectedSingleEvent, stmtSingleEvent.EventType, EventTypeAssertionEnumExtensions.GetSetWithFragment()); var eventOne = new SupportBean("E1", 1); _epService.EPRuntime.SendEvent(eventOne); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsSingleEvent, new Object[] { eventOne, true, true, "E1", 1 }); var eventTwo = new SupportBean("E2", 2); _epService.EPRuntime.SendEvent(eventTwo); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsSingleEvent, new Object[] { eventTwo, false, false, "E2", 2 }); stmtSingleEvent.Dispose(); // test single-event return var fieldsEnumEvent = "c0,c1,c2".Split(','); const string eplEnumEvent = "select " + "ee() as c0, " + "ee().AllOf(v => v.TheString = 'E1') as c1, " + "ee().AllOf(v => v.IntPrimitive = 1) as c2 " + "from SupportBean"; var stmtEnumEvent = _epService.EPAdministrator.CreateEPL(eplEnumEvent); stmtEnumEvent.Events += _listener.Update; var expectedEnumEvent = new Object[][] { new Object[] { "c0", typeof(SupportBean[]), "SupportBean", true }, new Object[] { "c1", typeof(Boolean), null, null }, new Object[] { "c2", typeof(Boolean), null, null } }; EventTypeAssertionUtil.AssertEventTypeProperties(expectedEnumEvent, stmtEnumEvent.EventType, EventTypeAssertionEnumExtensions.GetSetWithFragment()); var eventEnumOne = new SupportBean("E1", 1); _epService.EPRuntime.SendEvent(eventEnumOne); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsEnumEvent, new Object[] { new SupportBean[] { eventEnumOne }, true, true }); var eventEnumTwo = new SupportBean("E2", 2); _epService.EPRuntime.SendEvent(eventEnumTwo); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsEnumEvent, new Object[] { new SupportBean[] { eventEnumOne, eventEnumTwo }, false, false }); }
private void RunAssertion_A_Bstar_or_C() { EPServiceProviderIsolated isolated = _epService.GetEPServiceIsolated("I1"); SendTimer(isolated, 0); String[] fields = "a,b0,b1,b2,c".Split(','); String text = "select * from MyEvent#keepall " + "match_recognize (" + " measures A.TheString as a, B[0].TheString as b0, B[1].TheString as b1, B[2].TheString as b2, C.TheString as c " + " pattern (A (B* | C))" + " interval 10 seconds or terminated" + " define" + " A as A.TheString like 'A%'," + " B as B.TheString like 'B%'," + " C as C.TheString like 'C%'" + ")"; EPStatement stmt = isolated.EPAdministrator.CreateEPL(text, "stmt1", null); stmt.Events += _listener.Update; isolated.EPRuntime.SendEvent(new SupportRecogBean("A1")); isolated.EPRuntime.SendEvent(new SupportRecogBean("C1")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "A1", null, null, null, "C1" }); isolated.EPRuntime.SendEvent(new SupportRecogBean("A2")); Assert.IsFalse(_listener.IsInvoked); isolated.EPRuntime.SendEvent(new SupportRecogBean("B1")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "A2", null, null, null, null }); isolated.EPRuntime.SendEvent(new SupportRecogBean("B2")); Assert.IsFalse(_listener.IsInvoked); isolated.EPRuntime.SendEvent(new SupportRecogBean("X1")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "A2", "B1", "B2", null, null }); isolated.EPRuntime.SendEvent(new SupportRecogBean("A3")); SendTimer(isolated, 10000); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "A3", null, null, null, null }); SendTimer(isolated, int.MaxValue); Assert.IsFalse(_listener.IsInvoked); // destroy stmt.Dispose(); isolated.Dispose(); }
public void TestHowToUse() { String eplFragment = "select items.where(i => i.Location.X = 0 and i.Location.Y = 0) as zeroloc from LocationReport"; EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment); stmtFragment.Events += _listener.Update; _epService.EPRuntime.SendEvent(LocationReportFactory.MakeSmall()); Item[] items = _listener.AssertOneGetNewAndReset().Get("zeroloc").UnwrapIntoArray <Item>(); Assert.AreEqual(1, items.Length); Assert.AreEqual("P00020", items[0].AssetId); stmtFragment.Dispose(); eplFragment = "select items.where(i => i.Location.X = 0).where(i => i.Location.Y = 0) as zeroloc from LocationReport"; stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment); stmtFragment.Events += _listener.Update; _epService.EPRuntime.SendEvent(LocationReportFactory.MakeSmall()); items = _listener.AssertOneGetNewAndReset().Get("zeroloc").UnwrapIntoArray <Item>(); Assert.AreEqual(1, items.Length); Assert.AreEqual("P00020", items[0].AssetId); }
public void TestSelfSubselect() { var stmtTextOne = "insert into MyCount select Count(*) as cnt from S0"; _epService.EPAdministrator.CreateEPL(stmtTextOne); var stmtTextTwo = "select (select cnt from MyCount.std:lastevent()) as value from S0"; var stmt = _epService.EPAdministrator.CreateEPL(stmtTextTwo); stmt.Events += _listener.Update; _epService.EPRuntime.SendEvent(new SupportBean_S0(1)); Assert.AreEqual(null, _listener.AssertOneGetNewAndReset().Get("value")); _epService.EPRuntime.SendEvent(new SupportBean_S0(2)); Assert.AreEqual(1L, _listener.AssertOneGetNewAndReset().Get("value")); }
public void TestTypableAndCaseNew() { _epService.EPAdministrator.CreateEPL("create objectarray schema Nested(p0 string, p1 int)"); _epService.EPAdministrator.CreateEPL("create objectarray schema OuterType(n0 Nested)"); var fields = "n0.p0,n0.p1".Split(','); _epService.EPAdministrator.CreateEPL("@Name('out') " + "expression computeNested {\n" + " sb => case\n" + " when IntPrimitive = 1 \n" + " then new { p0 = 'a', p1 = 1}\n" + " else new { p0 = 'b', p1 = 2 }\n" + " end\n" + "}\n" + "insert into OuterType select computeNested(sb) as n0 from SupportBean as sb"); _epService.EPAdministrator.GetStatement("out").Events += _listener.Update; _epService.EPRuntime.SendEvent(new SupportBean("E1", 2)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "b", 2 }); _epService.EPRuntime.SendEvent(new SupportBean("E2", 1)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "a", 1 }); }
private void TryAssertionFull(EPServiceProvider epService, string expression) { string[] fields = "s0.id, s0.p00, s1.id, s1.p10, s2.id, s2.p20".Split(','); EPStatement joinView = epService.EPAdministrator.CreateEPL(expression); var listener = new SupportUpdateListener(); joinView.Events += listener.Update; // s1, s2, s0 epService.EPRuntime.SendEvent(new SupportBean_S1(100, "A_1")); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean_S2(200, "A_1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, 100, "A_1", 200, "A_1" }); epService.EPRuntime.SendEvent(new SupportBean_S0(0, "A_1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 0, "A_1", 100, "A_1", 200, "A_1" }); // s1, s0, s2 epService.EPRuntime.SendEvent(new SupportBean_S1(103, "D_1")); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean_S2(203, "D_1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, 103, "D_1", 203, "D_1" }); epService.EPRuntime.SendEvent(new SupportBean_S0(3, "D_1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 3, "D_1", 103, "D_1", 203, "D_1" }); // s2, s1, s0 epService.EPRuntime.SendEvent(new SupportBean_S2(201, "B_1")); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean_S1(101, "B_1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, 101, "B_1", 201, "B_1" }); epService.EPRuntime.SendEvent(new SupportBean_S0(1, "B_1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 1, "B_1", 101, "B_1", 201, "B_1" }); // s2, s0, s1 epService.EPRuntime.SendEvent(new SupportBean_S2(202, "C_1")); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean_S0(2, "C_1")); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean_S1(102, "C_1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 2, "C_1", 102, "C_1", 202, "C_1" }); // s0, s1, s2 epService.EPRuntime.SendEvent(new SupportBean_S0(4, "E_1")); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean_S1(104, "E_1")); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean_S2(204, "E_1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 4, "E_1", 104, "E_1", 204, "E_1" }); // s0, s2, s1 epService.EPRuntime.SendEvent(new SupportBean_S0(5, "F_1")); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean_S2(205, "F_1")); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean_S1(105, "F_1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 5, "F_1", 105, "F_1", 205, "F_1" }); }
public void TestSumEvents() { String[] fields = "val0,val1,val2,val3".Split(','); String eplFragment = "select " + "Beans.sumOf(x => IntBoxed) as val0," + "Beans.sumOf(x => DoubleBoxed) as val1," + "Beans.sumOf(x => LongBoxed) as val2," + "Beans.sumOf(x => DecimalBoxed) as val3 " + "from Bean"; EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment); stmtFragment.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, fields, new Type[] { typeof(int?), typeof(double?), typeof(long?), typeof(decimal?) }); _epService.EPRuntime.SendEvent(new SupportBean_Container(null)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null, null, null, null }); _epService.EPRuntime.SendEvent(new SupportBean_Container(new SupportBean[0])); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { null, null, null, null }); List <SupportBean> list = new List <SupportBean>(); list.Add(Make(2, 3d, 4l, 5)); _epService.EPRuntime.SendEvent(new SupportBean_Container(list)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 2, 3d, 4L, 5m }); list.Add(Make(4, 6d, 8l, 10)); _epService.EPRuntime.SendEvent(new SupportBean_Container(list)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { 2 + 4, 3d + 6d, 4L + 8L, 5m + 10m }); }
private void RunAssertion(EPServiceProvider epService, bool namedWindow, bool enableIndexShareCreate, bool disableIndexShareConsumer, bool createExplicitIndex) { epService.EPAdministrator.CreateEPL("create schema EventSchema(e0 string, e1 int, e2 string)"); epService.EPAdministrator.CreateEPL("create schema WindowSchema(col0 string, col1 long, col2 string)"); string createEpl = namedWindow ? "create window MyInfra#keepall as WindowSchema" : "create table MyInfra (col0 string primary key, col1 long, col2 string)"; if (enableIndexShareCreate) { createEpl = "@Hint('enable_window_subquery_indexshare') " + createEpl; } epService.EPAdministrator.CreateEPL(createEpl); epService.EPAdministrator.CreateEPL("insert into MyInfra select * from WindowSchema"); EPStatement stmtIndex = null; if (createExplicitIndex) { stmtIndex = epService.EPAdministrator.CreateEPL("create index MyIndex on MyInfra (col2, col1)"); } string[] fields = "e0,val".Split(','); string consumeEpl = "select e0, (select col0 from MyInfra where col2 = es.e2 and col1 = es.e1) as val from EventSchema es"; if (disableIndexShareConsumer) { consumeEpl = "@Hint('disable_window_subquery_indexshare') " + consumeEpl; } EPStatement consumeStmt = epService.EPAdministrator.CreateEPL(consumeEpl); var listener = new SupportUpdateListener(); consumeStmt.Events += listener.Update; SendWindow(epService, "W1", 10L, "c31"); SendEvent(epService, "E1", 10, "c31"); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E1", "W1" }); SendEvent(epService, "E2", 11, "c32"); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E2", null }); SendWindow(epService, "W2", 11L, "c32"); SendEvent(epService, "E3", 11, "c32"); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E3", "W2" }); SendWindow(epService, "W3", 11L, "c31"); SendWindow(epService, "W4", 10L, "c32"); SendEvent(epService, "E4", 11, "c31"); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E4", "W3" }); SendEvent(epService, "E5", 10, "c31"); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E5", "W1" }); SendEvent(epService, "E6", 10, "c32"); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E6", "W4" }); // test late start consumeStmt.Dispose(); consumeStmt = epService.EPAdministrator.CreateEPL(consumeEpl); consumeStmt.Events += listener.Update; SendEvent(epService, "E6", 10, "c32"); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E6", "W4" }); if (stmtIndex != null) { stmtIndex.Dispose(); } consumeStmt.Dispose(); epService.EPAdministrator.DestroyAllStatements(); epService.EPAdministrator.Configuration.RemoveEventType("MyInfra", false); }
private void RunAssertionAudit(EPServiceProvider epService) { // stream, and test audit callback var callback = new SupportAuditCallback(); AuditPath.AuditCallback = callback.Audit; AUDITLOG.Info("*** Stream: "); EPStatement stmtInput = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('stream') select * from SupportBean(TheString = 'E1')"); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); Assert.AreEqual(1, callback.Audits.Count); AuditContext cb = callback.Audits[0]; Assert.AreEqual("SupportBean(TheString=...) inserted SupportBean[SupportBean(E1, 1)]", cb.Message); Assert.AreEqual("ABC", cb.StatementName); Assert.AreEqual(EPServiceProviderConstants.DEFAULT_ENGINE_URI, cb.EngineURI); Assert.AreEqual(AuditEnum.STREAM, cb.Category); AuditPath.AuditCallback = null; stmtInput.Dispose(); AUDITLOG.Info("*** Named Window And Insert-Into: "); EPStatement stmtNW = epService.EPAdministrator.CreateEPL("@Name('create') @Audit create window WinOne#keepall as SupportBean"); EPStatement stmtInsertNW = epService.EPAdministrator.CreateEPL("@Name('insert') @Audit insert into WinOne select * from SupportBean"); EPStatement stmtConsumeNW = epService.EPAdministrator.CreateEPL("@Name('select') @Audit select * from WinOne"); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); stmtNW.Dispose(); stmtInsertNW.Dispose(); stmtConsumeNW.Dispose(); AUDITLOG.Info("*** Insert-Into: "); EPStatement stmtInsertInto = epService.EPAdministrator.CreateEPL("@Name('insert') @Audit insert into ABC select * from SupportBean"); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); stmtInsertInto.Dispose(); AUDITLOG.Info("*** Schedule: "); epService.EPRuntime.SendEvent(new CurrentTimeEvent(0)); EPStatement stmtSchedule = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('schedule') select irstream * from SupportBean#time(1 sec)"); var listener = new SupportUpdateListener(); stmtSchedule.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); listener.Reset(); Log.Info("Sending time"); epService.EPRuntime.SendEvent(new CurrentTimeEvent(2000)); Assert.IsTrue(listener.IsInvoked); listener.Reset(); stmtSchedule.Dispose(); // exprdef-instances AUDITLOG.Info("*** Expression-Def: "); EPStatement stmtExprDef = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('exprdef') " + "expression DEF { 1 } " + "expression INN { x => x.TheString }" + "expression OUT { x => INN(x) } " + "select DEF(), OUT(sb) from SupportBean sb"); stmtExprDef.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); Assert.AreEqual(1, listener.AssertOneGetNewAndReset().Get("DEF()")); stmtExprDef.Dispose(); // pattern-instances AUDITLOG.Info("*** Pattern-Lifecycle: "); EPStatement stmtPatternLife = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('pattern-instances') select a.IntPrimitive as val0 from pattern [every a=SupportBean -> (b=SupportBean_ST0 and not SupportBean_ST1)]"); stmtPatternLife.Events += listener.Update; Log.Info("Sending E1"); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); Log.Info("Sending E2"); epService.EPRuntime.SendEvent(new SupportBean("E2", 2)); Log.Info("Sending E3"); epService.EPRuntime.SendEvent(new SupportBean_ST1("E3", 3)); stmtPatternLife.Dispose(); // pattern AUDITLOG.Info("*** Pattern: "); EPStatement stmtPattern = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('pattern') select a.IntPrimitive as val0 from pattern [a=SupportBean -> b=SupportBean_ST0]"); stmtPattern.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); epService.EPRuntime.SendEvent(new SupportBean_ST0("E2", 2)); Assert.AreEqual(1, listener.AssertOneGetNewAndReset().Get("val0")); stmtPattern.Dispose(); // view AUDITLOG.Info("*** View: "); EPStatement stmtView = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('view') select IntPrimitive from SupportBean#lastevent"); stmtView.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 50)); Assert.AreEqual(50, listener.AssertOneGetNewAndReset().Get("IntPrimitive")); stmtView.Dispose(); EPStatement stmtGroupedView = epService.EPAdministrator.CreateEPL("@Audit Select * From SupportBean#groupwin(TheString)#length(2)"); stmtGroupedView.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 50)); listener.Reset(); stmtGroupedView.Dispose(); EPStatement stmtGroupedWIntersectionView = epService.EPAdministrator.CreateEPL("@Audit Select * From SupportBean#groupwin(TheString)#length(2)#unique(IntPrimitive)"); stmtGroupedWIntersectionView.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 50)); listener.Reset(); stmtGroupedWIntersectionView.Dispose(); // expression AUDITLOG.Info("*** Expression: "); EPStatement stmtExpr = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('expression') select IntPrimitive*100 as val0, sum(IntPrimitive) as val1 from SupportBean"); stmtExpr.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 50)); Assert.AreEqual(5000, listener.AssertOneGetNew().Get("val0")); Assert.AreEqual(50, listener.AssertOneGetNewAndReset().Get("val1")); stmtExpr.Dispose(); // expression-detail AUDITLOG.Info("*** Expression-Nested: "); EPStatement stmtExprNested = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('expression-nested') select ('A'||TheString)||'X' as val0 from SupportBean"); stmtExprNested.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 50)); Assert.AreEqual("AE1X", listener.AssertOneGetNewAndReset().Get("val0")); stmtExprNested.Dispose(); // property AUDITLOG.Info("*** Property: "); EPStatement stmtProp = epService.EPAdministrator.CreateEPL("@Name('ABC') @Audit('property') select IntPrimitive from SupportBean"); stmtProp.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 50)); Assert.AreEqual(50, listener.AssertOneGetNewAndReset().Get("IntPrimitive")); stmtProp.Dispose(); // with aggregation epService.EPAdministrator.CreateEPL("@Audit @Name ('create') create window MyWindow#keepall as SupportBean"); string eplWithAgg = "@Audit @Name('S0') on SupportBean as sel select count(*) from MyWindow as win having count(*)=3 order by win.IntPrimitive"; EPStatement stmtWithAgg = epService.EPAdministrator.CreateEPL(eplWithAgg); stmtWithAgg.Dispose(); // data flow EPStatement stmtDataflow = epService.EPAdministrator.CreateEPL("@Audit @Name('df') create dataflow MyFlow " + "EventBusSource -> a<SupportBean> {filter:TheString like 'I%'} " + "Filter(a) -> b {filter: true}" + "LogSink(b) {log:false}"); EPDataFlowInstance df = epService.EPRuntime.DataFlowRuntime.Instantiate("MyFlow"); df.Start(); epService.EPRuntime.SendEvent(new SupportBean("I1", 1)); df.Cancel(); // context partitions epService.EPAdministrator.CreateEPL("create context WhenEventArrives " + "initiated by SupportBean_ST0 as st0 " + "terminated by SupportBean_ST1(id=st0.id)"); epService.EPAdministrator.CreateEPL("@Audit('ContextPartition') context WhenEventArrives select * from SupportBean"); epService.EPRuntime.SendEvent(new SupportBean_ST0("E1", 0)); epService.EPRuntime.SendEvent(new SupportBean_ST1("E1", 0)); stmtDataflow.Dispose(); // table AUDITLOG.Info("*** Table And Insert-Into and Into-table: "); EPStatement stmtTable = epService.EPAdministrator.CreateEPL("@Name('create-table') @Audit create table TableOne(c0 string primary key, cnt count(*))"); EPStatement stmtIntoTable = epService.EPAdministrator.CreateEPL("@Name('into-table') @Audit into table TableOne select count(*) as cnt from SupportBean group by TheString"); EPStatement stmtAccessTable = epService.EPAdministrator.CreateEPL("@Name('access-table') @Audit select TableOne[id].cnt from SupportBean_ST0"); stmtAccessTable.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); epService.EPRuntime.SendEvent(new SupportBean_ST0("E1", 0)); stmtTable.Dispose(); stmtIntoTable.Dispose(); stmtAccessTable.Dispose(); }
private void RunAssertionAllAggFunctions(EPServiceProvider epService) { string[] fields = "cavedev,cavg,cmax,cmedian,cmin,cstddev,csum,cfmaxever,cfminever".Split(','); EPStatementSPI stmt = (EPStatementSPI)epService.EPAdministrator.CreateEPL("select " + "avedev(IntBoxed, BoolPrimitive) as cavedev," + "avg(IntBoxed, BoolPrimitive) as cavg, " + "fmax(IntBoxed, BoolPrimitive) as cmax, " + "median(IntBoxed, BoolPrimitive) as cmedian, " + "fmin(IntBoxed, BoolPrimitive) as cmin, " + "stddev(IntBoxed, BoolPrimitive) as cstddev, " + "sum(IntBoxed, BoolPrimitive) as csum," + "fmaxever(IntBoxed, BoolPrimitive) as cfmaxever, " + "fminever(IntBoxed, BoolPrimitive) as cfminever " + "from SupportBean#length(3)"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(MakeBean(100, false)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, null, null, null, null, null, null }); epService.EPRuntime.SendEvent(MakeBean(10, true)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 0.0d, 10.0, 10, 10.0, 10, null, 10, 10, 10 }); epService.EPRuntime.SendEvent(MakeBean(11, false)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 0.0d, 10.0, 10, 10.0, 10, null, 10, 10, 10 }); epService.EPRuntime.SendEvent(MakeBean(20, true)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 5.0d, 15.0, 20, 15.0, 10, 7.0710678118654755, 30, 20, 10 }); epService.EPRuntime.SendEvent(MakeBean(30, true)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 5.0d, 25.0, 30, 25.0, 20, 7.0710678118654755, 50, 30, 10 }); // Test all remaining types of "sum" stmt.Dispose(); fields = "c1,c2,c3,c4".Split(','); stmt = (EPStatementSPI)epService.EPAdministrator.CreateEPL("select " + "sum(FloatPrimitive, BoolPrimitive) as c1," + "sum(DoublePrimitive, BoolPrimitive) as c2, " + "sum(LongPrimitive, BoolPrimitive) as c3, " + "sum(ShortPrimitive, BoolPrimitive) as c4 " + "from SupportBean#length(2)"); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(MakeBean(2f, 3d, 4L, (short)5, false)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { null, null, null, null }); epService.EPRuntime.SendEvent(MakeBean(3f, 4d, 5L, (short)6, true)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 3f, 4d, 5L, 6 }); epService.EPRuntime.SendEvent(MakeBean(4f, 5d, 6L, (short)7, true)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 7f, 9d, 11L, 13 }); epService.EPRuntime.SendEvent(MakeBean(1f, 1d, 1L, (short)1, true)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 5f, 6d, 7L, 8 }); // Test min/max-ever stmt.Dispose(); fields = "c1,c2".Split(','); stmt = (EPStatementSPI)epService.EPAdministrator.CreateEPL("select " + "fmax(IntBoxed, BoolPrimitive) as c1," + "fmin(IntBoxed, BoolPrimitive) as c2 " + "from SupportBean"); stmt.Events += listener.Update; Assert.IsFalse(stmt.StatementContext.IsStatelessSelect); epService.EPRuntime.SendEvent(MakeBean(10, true)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 10, 10 }); epService.EPRuntime.SendEvent(MakeBean(20, true)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 20, 10 }); epService.EPRuntime.SendEvent(MakeBean(8, false)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 20, 10 }); epService.EPRuntime.SendEvent(MakeBean(7, true)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 20, 7 }); epService.EPRuntime.SendEvent(MakeBean(30, false)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 20, 7 }); epService.EPRuntime.SendEvent(MakeBean(40, true)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 40, 7 }); // test big decimal big integer stmt.Dispose(); fields = "c1,c2,c3".Split(','); stmt = (EPStatementSPI)epService.EPAdministrator.CreateEPL("select " + "avg(DecimalOne, BigInt < 100) as c1," + "sum(DecimalOne, BigInt < 100) as c2, " + "sum(BigInt, BigInt < 100) as c3 " + "from SupportBeanNumeric#length(2)"); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBeanNumeric(new BigInteger(10), new decimal(20))); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { new decimal(20), new decimal(20), new BigInteger(10) }); epService.EPRuntime.SendEvent(new SupportBeanNumeric(new BigInteger(101), new decimal(101))); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { new decimal(20), new decimal(20), new BigInteger(10) }); epService.EPRuntime.SendEvent(new SupportBeanNumeric(new BigInteger(20), new decimal(40))); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { new decimal(40), new decimal(40), new BigInteger(20) }); epService.EPRuntime.SendEvent(new SupportBeanNumeric(new BigInteger(30), new decimal(50))); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { new decimal(45), new decimal(90), new BigInteger(50) }); stmt.Dispose(); string epl = "select " + "avedev(distinct IntBoxed,BoolPrimitive) as cavedev, " + "avg(distinct IntBoxed,BoolPrimitive) as cavg, " + "fmax(distinct IntBoxed,BoolPrimitive) as cmax, " + "median(distinct IntBoxed,BoolPrimitive) as cmedian, " + "fmin(distinct IntBoxed,BoolPrimitive) as cmin, " + "stddev(distinct IntBoxed,BoolPrimitive) as cstddev, " + "sum(distinct IntBoxed,BoolPrimitive) as csum " + "from SupportBean#length(3)"; stmt = (EPStatementSPI)epService.EPAdministrator.CreateEPL(epl); stmt.Events += listener.Update; TryAssertionDistinct(epService, listener); // test SODA stmt.Dispose(); EPStatementObjectModel model = epService.EPAdministrator.CompileEPL(epl); Assert.AreEqual(epl, model.ToEPL()); stmt = (EPStatementSPI)epService.EPAdministrator.Create(model); stmt.Events += listener.Update; Assert.AreEqual(epl, stmt.Text); TryAssertionDistinct(epService, listener); stmt.Dispose(); }
public void TestExample() { var stmtTextOne = "select orderId, items.item[0].itemId from MediaOrder"; var stmtOne = _epService.EPAdministrator.CreateEPL(stmtTextOne); var listenerOne = new SupportUpdateListener(); stmtOne.AddListener(listenerOne); var stmtTextTwo = "select * from MediaOrder[books.book]"; var stmtTwo = _epService.EPAdministrator.CreateEPL(stmtTextTwo); var listenerTwo = new SupportUpdateListener(); stmtTwo.AddListener(listenerTwo); var stmtTextThree = "select * from MediaOrder(orderId='PO200901')[books.book]"; var stmtThree = _epService.EPAdministrator.CreateEPL(stmtTextThree); var listenerThree = new SupportUpdateListener(); stmtThree.AddListener(listenerThree); var stmtTextFour = "select count(*) from MediaOrder[books.book]#unique(bookId)"; var stmtFour = _epService.EPAdministrator.CreateEPL(stmtTextFour); var listenerFour = new SupportUpdateListener(); stmtFour.AddListener(listenerFour); var stmtTextFive = "select * from MediaOrder[books.book][review]"; var stmtFive = _epService.EPAdministrator.CreateEPL(stmtTextFive); var listenerFive = new SupportUpdateListener(); stmtFive.AddListener(listenerFive); var stmtTextSix = "select * from pattern [c=Cancel -> o=MediaOrder(orderId = c.orderId)[books.book]]"; var stmtSix = _epService.EPAdministrator.CreateEPL(stmtTextSix); var listenerSix = new SupportUpdateListener(); stmtSix.AddListener(listenerSix); var stmtTextSeven = "select * from MediaOrder[select orderId, bookId from books.book][select * from review]"; var stmtSeven = _epService.EPAdministrator.CreateEPL(stmtTextSeven); var listenerSeven = new SupportUpdateListener(); stmtSeven.AddListener(listenerSeven); var stmtTextEight = "select * from MediaOrder[select * from books.book][select reviewId, comment from review]"; var stmtEight = _epService.EPAdministrator.CreateEPL(stmtTextEight); var listenerEight = new SupportUpdateListener(); stmtEight.AddListener(listenerEight); var stmtTextNine = "select * from MediaOrder[books.book as book][select book.*, reviewId, comment from review]"; var stmtNine = _epService.EPAdministrator.CreateEPL(stmtTextNine); var listenerNine = new SupportUpdateListener(); stmtNine.AddListener(listenerNine); var stmtTextTen = "select * from MediaOrder[books.book as book][select mediaOrder.*, bookId, reviewId from review] as mediaOrder"; var stmtTen = _epService.EPAdministrator.CreateEPL(stmtTextTen); var listenerTen = new SupportUpdateListener(); stmtTen.AddListener(listenerTen); var stmtTextEleven_0 = "insert into ReviewStream select * from MediaOrder[books.book as book]\n" + " [select mediaOrder.* as mediaOrder, book.* as book, review.* as review from review as review] as mediaOrder"; _epService.EPAdministrator.CreateEPL(stmtTextEleven_0); var stmtTextEleven_1 = "select mediaOrder.orderId, book.bookId, review.reviewId from ReviewStream"; var stmtEleven_1 = _epService.EPAdministrator.CreateEPL(stmtTextEleven_1); var listenerEleven = new SupportUpdateListener(); stmtEleven_1.AddListener(listenerEleven); var stmtTextTwelve = "select * from MediaOrder[books.book where author = 'Orson Scott Card'][review]"; var stmtTwelve = _epService.EPAdministrator.CreateEPL(stmtTextTwelve); var listenerTwelve = new SupportUpdateListener(); stmtTwelve.AddListener(listenerTwelve); _epService.EPRuntime.SendEvent(_eventDocOne); EPAssertionUtil.AssertProps(listenerOne.AssertOneGetNewAndReset(), "orderId,items.item[0].itemId".Split(','), new object[] { "PO200901", "100001" }); EPAssertionUtil.AssertPropsPerRow(listenerTwo.LastNewData, "bookId".Split(','), new object[][] { new object[] { "B001" }, new object[] { "B002" } }); EPAssertionUtil.AssertPropsPerRow(listenerThree.LastNewData, "bookId".Split(','), new object[][] { new object[] { "B001" }, new object[] { "B002" } }); EPAssertionUtil.AssertPropsPerRow(listenerFour.LastNewData, "count(*)".Split(','), new object[][] { new object[] { 2L } }); EPAssertionUtil.AssertPropsPerRow(listenerFive.LastNewData, "reviewId".Split(','), new object[][] { new object[] { "1" } }); Assert.IsFalse(listenerSix.IsInvoked); EPAssertionUtil.AssertPropsPerRow(listenerSeven.LastNewData, "orderId,bookId,reviewId".Split(','), new object[][] { new object[] { "PO200901", "B001", "1" } }); EPAssertionUtil.AssertPropsPerRow(listenerEight.LastNewData, "reviewId,bookId".Split(','), new object[][] { new object[] { "1", "B001" } }); EPAssertionUtil.AssertPropsPerRow(listenerNine.LastNewData, "reviewId,bookId".Split(','), new object[][] { new object[] { "1", "B001" } }); EPAssertionUtil.AssertPropsPerRow(listenerTen.LastNewData, "reviewId,bookId".Split(','), new object[][] { new object[] { "1", "B001" } }); EPAssertionUtil.AssertPropsPerRow(listenerEleven.LastNewData, "mediaOrder.orderId,book.bookId,review.reviewId".Split(','), new object[][] { new object[] { "PO200901", "B001", "1" } }); EPAssertionUtil.AssertPropsPerRow(listenerTwelve.LastNewData, "reviewId".Split(','), new object[][] { new object[] { "1" } }); }
private void RunAssertionFullJoin_2sides_multicolumn(EventRepresentationEnum eventRepresentationEnum) { String[] fields = "s0.id, s0.P00, s0.p01, s1.id, s1.p10, s1.p11, s2.id, s2.p20, s2.p21".Split(','); String joinStatement = eventRepresentationEnum.GetAnnotationText() + " select * from " + EVENT_S0 + ".win:length(1000) as s0 " + " full outer join " + EVENT_S1 + ".win:length(1000) as s1 on s0.P00 = s1.p10 and s0.p01 = s1.p11" + " full outer join " + EVENT_S2 + ".win:length(1000) as s2 on s0.P00 = s2.p20 and s0.p01 = s2.p21"; EPStatement joinView = _epService.EPAdministrator.CreateEPL(joinStatement); joinView.Events += _updateListener.Update; _epService.EPRuntime.SendEvent(new SupportBean_S1(10, "A_1", "B_1")); EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new Object[] { null, null, null, 10, "A_1", "B_1", null, null, null }); _epService.EPRuntime.SendEvent(new SupportBean_S1(11, "A_2", "B_1")); EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new Object[] { null, null, null, 11, "A_2", "B_1", null, null, null }); _epService.EPRuntime.SendEvent(new SupportBean_S1(12, "A_1", "B_2")); EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new Object[] { null, null, null, 12, "A_1", "B_2", null, null, null }); _epService.EPRuntime.SendEvent(new SupportBean_S1(13, "A_2", "B_2")); EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new Object[] { null, null, null, 13, "A_2", "B_2", null, null, null }); _epService.EPRuntime.SendEvent(new SupportBean_S2(20, "A_1", "B_1")); EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new Object[] { null, null, null, null, null, null, 20, "A_1", "B_1" }); _epService.EPRuntime.SendEvent(new SupportBean_S2(21, "A_2", "B_1")); EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new Object[] { null, null, null, null, null, null, 21, "A_2", "B_1" }); _epService.EPRuntime.SendEvent(new SupportBean_S2(22, "A_1", "B_2")); EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new Object[] { null, null, null, null, null, null, 22, "A_1", "B_2" }); _epService.EPRuntime.SendEvent(new SupportBean_S2(23, "A_2", "B_2")); EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new Object[] { null, null, null, null, null, null, 23, "A_2", "B_2" }); _epService.EPRuntime.SendEvent(new SupportBean_S0(1, "A_3", "B_3")); EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new Object[] { 1, "A_3", "B_3", null, null, null, null, null, null }); _epService.EPRuntime.SendEvent(new SupportBean_S0(2, "A_1", "B_3")); EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new Object[] { 2, "A_1", "B_3", null, null, null, null, null, null }); _epService.EPRuntime.SendEvent(new SupportBean_S0(3, "A_3", "B_1")); EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new Object[] { 3, "A_3", "B_1", null, null, null, null, null, null }); _epService.EPRuntime.SendEvent(new SupportBean_S0(4, "A_2", "B_2")); EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new Object[] { 4, "A_2", "B_2", 13, "A_2", "B_2", 23, "A_2", "B_2" }); _epService.EPRuntime.SendEvent(new SupportBean_S0(5, "A_2", "B_1")); EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new Object[] { 5, "A_2", "B_1", 11, "A_2", "B_1", 21, "A_2", "B_1" }); _epService.EPRuntime.SendEvent(new SupportBean_S1(14, "A_4", "B_3")); EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new Object[] { null, null, null, 14, "A_4", "B_3", null, null, null }); _epService.EPRuntime.SendEvent(new SupportBean_S1(15, "A_1", "B_3")); EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new Object[] { 2, "A_1", "B_3", 15, "A_1", "B_3", null, null, null }); _epService.EPRuntime.SendEvent(new SupportBean_S2(24, "A_1", "B_3")); EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new Object[] { 2, "A_1", "B_3", 15, "A_1", "B_3", 24, "A_1", "B_3" }); _epService.EPRuntime.SendEvent(new SupportBean_S2(25, "A_2", "B_3")); EPAssertionUtil.AssertProps(_updateListener.AssertOneGetNewAndReset(), fields, new Object[] { null, null, null, null, null, null, 25, "A_2", "B_3" }); _epService.EPAdministrator.DestroyAllStatements(); }
public void TestKeySelectorOnly() { // - duplicate key allowed, creates a list of values // - null key & value allowed String eplFragment = "select contained.GroupBy(c => id) as val from Bean"; EPStatement stmtFragment = _epService.EPAdministrator.CreateEPL(eplFragment); stmtFragment.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtFragment.EventType, "val".Split(','), new Type[] { typeof(GroupMap) }); EPAssertionUtil.AssertionCollectionValueString extractorEvents = new EPAssertionUtil.ProxyAssertionCollectionValueString( collectionItem => { int p00 = ((SupportBean_ST0)collectionItem).P00; return(Convert.ToString(p00)); }); _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value("E1,1", "E1,2", "E2,5")); EPAssertionUtil.AssertMapOfCollection( (GroupMap)_listener.AssertOneGetNewAndReset().Get("val"), new string[] { "E1", "E2" }, new string[] { "1,2", "5" }, extractorEvents); _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value(null)); Assert.IsNull(_listener.AssertOneGetNewAndReset().Get("val")); _epService.EPRuntime.SendEvent(SupportBean_ST0_Container.Make2Value()); Assert.AreEqual(0, ((GroupMap)_listener.AssertOneGetNewAndReset().Get("val")).Count); stmtFragment.Dispose(); // test scalar _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("extractAfterUnderscore", this.GetType().FullName, "ExtractAfterUnderscore"); String eplScalar = "select Strvals.GroupBy(c => extractAfterUnderscore(c)) as val from SupportCollection"; EPStatement stmtScalar = _epService.EPAdministrator.CreateEPL(eplScalar); stmtScalar.Events += _listener.Update; LambdaAssertionUtil.AssertTypes(stmtScalar.EventType, "val".Split(','), new Type[] { typeof(GroupMap) }); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("E1_2,E2_1,E3_2")); EPAssertionUtil.AssertMapOfCollection((GroupMap)_listener.AssertOneGetNewAndReset().Get("val"), "2,1".Split(','), new String[] { "E1_2,E3_2", "E2_1" }, GetExtractorScalar()); _epService.EPRuntime.SendEvent(SupportCollection.MakeString(null)); Assert.IsNull(_listener.AssertOneGetNewAndReset().Get("val")); _epService.EPRuntime.SendEvent(SupportCollection.MakeString("")); Assert.AreEqual(0, ((GroupMap)_listener.AssertOneGetNewAndReset().Get("val")).Count); }
public void TestSelectArray() { EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(_config); epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName); } String stmt = "select a, b, a[0] as a0, a[0].id as a0Id, a[1] as a1, a[1].id as a1Id, a[2] as a2, a[2].id as a2Id from pattern [a=A until b=B]"; SupportUpdateListener listener = new SupportUpdateListener(); EPStatement statement = epService.EPAdministrator.CreateEPL(stmt); statement.Events += listener.Update; Object eventA1 = new SupportBean_A("A1"); epService.EPRuntime.SendEvent(eventA1); Object eventA2 = new SupportBean_A("A2"); epService.EPRuntime.SendEvent(eventA2); Assert.IsFalse(listener.IsInvoked); Object eventB1 = new SupportBean_B("B1"); epService.EPRuntime.SendEvent(eventB1); EventBean theEvent = listener.AssertOneGetNewAndReset(); EPAssertionUtil.AssertEqualsExactOrder((Object[])theEvent.Get("a"), new Object[] { eventA1, eventA2 }); Assert.AreSame(eventA1, theEvent.Get("a0")); Assert.AreSame(eventA2, theEvent.Get("a1")); Assert.IsNull(theEvent.Get("a2")); Assert.AreEqual("A1", theEvent.Get("a0Id")); Assert.AreEqual("A2", theEvent.Get("a1Id")); Assert.IsNull(theEvent.Get("a2Id")); Assert.AreSame(eventB1, theEvent.Get("b")); // try wildcard stmt = "select * from pattern [a=A until b=B]"; statement = epService.EPAdministrator.CreateEPL(stmt); statement.Events += listener.Update; epService.EPRuntime.SendEvent(eventA1); epService.EPRuntime.SendEvent(eventA2); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(eventB1); theEvent = listener.AssertOneGetNewAndReset(); EPAssertionUtil.AssertEqualsExactOrder((Object[])theEvent.Get("a"), new Object[] { eventA1, eventA2 }); Assert.AreSame(eventA1, theEvent.Get("a[0]")); Assert.AreSame(eventA2, theEvent.Get("a[1]")); Assert.IsNull(theEvent.Get("a[2]")); Assert.AreEqual("A1", theEvent.Get("a[0].id")); Assert.AreEqual("A2", theEvent.Get("a[1].id")); Assert.IsNull(theEvent.Get("a[2].id")); Assert.AreSame(eventB1, theEvent.Get("b")); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
private void RunAssertionGroupedWindow(EPServiceProvider epService, SupportMarketDataBean[] events) { long startTime = 1000; SendTimer(epService, startTime); EPStatement stmt = epService.EPAdministrator.CreateEPL( "select irstream * from " + typeof(SupportMarketDataBean).FullName + "#groupwin(symbol)#time_accum(10 sec)"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; EPRuntime engine = epService.EPRuntime; // 1st S1 event SendTimer(epService, startTime + 10000); engine.SendEvent(events[1]); Assert.AreSame(listener.AssertOneGetNewAndReset().Underlying, events[1]); // 1st S2 event SendTimer(epService, startTime + 12000); engine.SendEvent(events[2]); Assert.AreSame(listener.AssertOneGetNewAndReset().Underlying, events[2]); // 2nd S1 event SendTimer(epService, startTime + 15000); engine.SendEvent(events[11]); Assert.AreSame(listener.AssertOneGetNewAndReset().Underlying, events[11]); // 2nd S2 event SendTimer(epService, startTime + 18000); engine.SendEvent(events[12]); Assert.AreSame(listener.AssertOneGetNewAndReset().Underlying, events[12]); // 3rd S1 event SendTimer(epService, startTime + 21000); engine.SendEvent(events[21]); Assert.AreSame(listener.AssertOneGetNewAndReset().Underlying, events[21]); SendTimer(epService, startTime + 28000); Assert.IsNull(listener.LastNewData); Assert.AreEqual(1, listener.OldDataList.Count); Assert.AreEqual(2, listener.LastOldData.Length); EPAssertionUtil.AssertEqualsExactOrderUnderlying(new object[] { events[2], events[12] }, listener.GetOldDataListFlattened()); listener.Reset(); // 3rd S2 event SendTimer(epService, startTime + 29000); engine.SendEvent(events[32]); Assert.AreSame(listener.AssertOneGetNewAndReset().Underlying, events[32]); SendTimer(epService, startTime + 31000); Assert.IsNull(listener.LastNewData); Assert.AreEqual(1, listener.OldDataList.Count); Assert.AreEqual(3, listener.LastOldData.Length); EPAssertionUtil.AssertEqualsExactOrderUnderlying(new object[] { events[1], events[11], events[21] }, listener.GetOldDataListFlattened()); listener.Reset(); SendTimer(epService, startTime + 39000); Assert.IsNull(listener.LastNewData); Assert.AreEqual(1, listener.LastOldData.Length); EPAssertionUtil.AssertEqualsExactOrderUnderlying(new object[] { events[32] }, listener.GetOldDataListFlattened()); listener.Reset(); stmt.Dispose(); }
public void TestUseFilter() { EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(_config); epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName); } String stmt; SupportUpdateListener listener; EPStatement statement; EventBean theEvent; stmt = "select * from pattern [a=A until b=B -> c=C(id = ('C' || a[0].id || a[1].id || b.id))]"; listener = new SupportUpdateListener(); statement = epService.EPAdministrator.CreateEPL(stmt); statement.Events += listener.Update; Object eventA1 = new SupportBean_A("A1"); epService.EPRuntime.SendEvent(eventA1); Object eventA2 = new SupportBean_A("A2"); epService.EPRuntime.SendEvent(eventA2); Object eventB1 = new SupportBean_B("B1"); epService.EPRuntime.SendEvent(eventB1); epService.EPRuntime.SendEvent(new SupportBean_C("C1")); Assert.IsFalse(listener.IsInvoked); Object eventC1 = new SupportBean_C("CA1A2B1"); epService.EPRuntime.SendEvent(eventC1); theEvent = listener.AssertOneGetNewAndReset(); Assert.AreSame(eventA1, theEvent.Get("a[0]")); Assert.AreSame(eventA2, theEvent.Get("a[1]")); Assert.IsNull(theEvent.Get("a[2]")); Assert.AreSame(eventB1, theEvent.Get("b")); Assert.AreSame(eventC1, theEvent.Get("c")); statement.Dispose(); // Test equals-optimization with array event stmt = "select * from pattern [a=A until b=B -> c=SupportBean(TheString = a[1].id)]"; listener = new SupportUpdateListener(); statement = epService.EPAdministrator.CreateEPL(stmt); statement.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean_A("A1")); epService.EPRuntime.SendEvent(new SupportBean_A("A2")); epService.EPRuntime.SendEvent(new SupportBean_B("B1")); epService.EPRuntime.SendEvent(new SupportBean("A3", 20)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean("A2", 10)); theEvent = listener.AssertOneGetNewAndReset(); Assert.AreEqual(10, theEvent.Get("c.IntPrimitive")); statement.Dispose(); // Test in-optimization stmt = "select * from pattern [a=A until b=B -> c=SupportBean(TheString in(a[2].id))]"; listener = new SupportUpdateListener(); statement = epService.EPAdministrator.CreateEPL(stmt); statement.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean_A("A1")); epService.EPRuntime.SendEvent(new SupportBean_A("A2")); epService.EPRuntime.SendEvent(new SupportBean_A("A3")); epService.EPRuntime.SendEvent(new SupportBean_B("B1")); epService.EPRuntime.SendEvent(new SupportBean("A2", 20)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean("A3", 5)); theEvent = listener.AssertOneGetNewAndReset(); Assert.AreEqual(5, theEvent.Get("c.IntPrimitive")); statement.Dispose(); // Test not-in-optimization stmt = "select * from pattern [a=A until b=B -> c=SupportBean(TheString!=a[0].id and TheString!=a[1].id and TheString!=a[2].id)]"; listener = new SupportUpdateListener(); statement = epService.EPAdministrator.CreateEPL(stmt); statement.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean_A("A1")); epService.EPRuntime.SendEvent(new SupportBean_A("A2")); epService.EPRuntime.SendEvent(new SupportBean_A("A3")); epService.EPRuntime.SendEvent(new SupportBean_B("B1")); epService.EPRuntime.SendEvent(new SupportBean("A2", 20)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean("A1", 20)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean("A6", 5)); theEvent = listener.AssertOneGetNewAndReset(); Assert.AreEqual(5, theEvent.Get("c.IntPrimitive")); statement.Dispose(); // Test range-optimization stmt = "select * from pattern [a=SupportBean(TheString like 'A%') until b=SupportBean(TheString like 'B%') -> c=SupportBean(IntPrimitive between a[0].IntPrimitive and a[1].IntPrimitive)]"; listener = new SupportUpdateListener(); statement = epService.EPAdministrator.CreateEPL(stmt); statement.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("A1", 5)); epService.EPRuntime.SendEvent(new SupportBean("A2", 8)); epService.EPRuntime.SendEvent(new SupportBean("B1", -1)); epService.EPRuntime.SendEvent(new SupportBean("E1", 20)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean("E2", 3)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean("E3", 5)); theEvent = listener.AssertOneGetNewAndReset(); Assert.AreEqual(5, theEvent.Get("c.IntPrimitive")); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
public void TestMapTypeUpdate() { var configuration = SupportConfigFactory.GetConfiguration(); var type = MakeMap(new Object[][] { new Object[] { "base1", typeof(string) }, new Object[] { "base2", MakeMap(new Object[][] { new Object[] { "n1", typeof(int) } }) } }); configuration.AddEventType("MyEvent", type); var epService = EPServiceProviderManager.GetDefaultProvider(configuration); epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName); } var statementOne = epService.EPAdministrator.CreateEPL( "select base1 as v1, base2.n1 as v2, base3? as v3, base2.n2? as v4 from MyEvent"); var statementOneSelectAll = epService.EPAdministrator.CreateEPL("select * from MyEvent"); Assert.AreEqual("[base1, base2]", statementOneSelectAll.EventType.PropertyNames.Render(", ", "[]")); var listenerOne = new SupportUpdateListener(); statementOne.Events += listenerOne.Update; var fields = "v1,v2,v3,v4".Split(','); epService.EPRuntime.SendEvent(MakeMap(new Object[][] { new Object[] { "base1", "abc" }, new Object[] { "base2", MakeMap(new Object[][] { new Object[] { "n1", 10 } }) } }), "MyEvent"); EPAssertionUtil.AssertProps(listenerOne.AssertOneGetNewAndReset(), fields, new Object[] { "abc", 10, null, null }); // Update type var typeNew = MakeMap(new Object[][] { new Object[] { "base3", typeof(long) }, new Object[] { "base2", MakeMap(new Object[][] { new Object[] { "n2", typeof(string) } }) } }); epService.EPAdministrator.Configuration.UpdateMapEventType("MyEvent", typeNew); var statementTwo = epService.EPAdministrator.CreateEPL("select base1 as v1, base2.n1 as v2, base3 as v3, base2.n2 as v4 from MyEvent"); var statementTwoSelectAll = epService.EPAdministrator.CreateEPL("select * from MyEvent"); var listenerTwo = new SupportUpdateListener(); statementTwo.Events += listenerTwo.Update; epService.EPRuntime.SendEvent(MakeMap(new Object[][] { new Object[] { "base1", "def" }, new Object[] { "base2", MakeMap(new Object[][] { new Object[] { "n1", 9 }, new Object[] { "n2", "xyz" } }) }, new Object[] { "base3", 20L }, }), "MyEvent"); 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 Assert.AreEqual("[base1, base2, base3]", statementOneSelectAll.EventType.PropertyNames.Render(", ", "[]")); Assert.AreEqual("[base1, base2, base3]", statementTwoSelectAll.EventType.PropertyNames.Render(", ", "[]")); EPAssertionUtil.AssertEqualsAnyOrder(new[] { new EventPropertyDescriptor("base3", typeof(long), null, false, false, false, false, false), new EventPropertyDescriptor("base2", typeof(Map), null, false, false, false, true, false), new EventPropertyDescriptor("base1", typeof(string), typeof(char), false, false, true, false, false), }, statementTwoSelectAll.EventType.PropertyDescriptors); try { epService.EPAdministrator.Configuration.UpdateMapEventType("dummy", typeNew); Assert.Fail(); } catch (ConfigurationException ex) { Assert.AreEqual("Error updating Map event type: Event type named 'dummy' has not been declared", ex.Message); } epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); try { epService.EPAdministrator.Configuration.UpdateMapEventType("SupportBean", typeNew); Assert.Fail(); } catch (ConfigurationException ex) { Assert.AreEqual("Error updating Map event type: Event type by name 'SupportBean' is not a Map event type", ex.Message); } if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
public void TestExpressionBounds() { EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(_config); epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName); } SupportUpdateListener listener = new SupportUpdateListener(); epService.EPAdministrator.Configuration.AddVariable("lower", typeof(int), null); epService.EPAdministrator.Configuration.AddVariable("upper", typeof(int), null); epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); epService.EPAdministrator.Configuration.AddEventType <SupportBean_S0>(); // test variables - closed bounds epService.EPRuntime.SetVariableValue("lower", 2); epService.EPRuntime.SetVariableValue("upper", 3); String stmtOne = "[lower:upper] a=SupportBean (TheString = 'A') until b=SupportBean (TheString = 'B')"; ValidateStmt(epService, stmtOne, 0, false, null); ValidateStmt(epService, stmtOne, 1, false, null); ValidateStmt(epService, stmtOne, 2, true, 2); ValidateStmt(epService, stmtOne, 3, true, 3); ValidateStmt(epService, stmtOne, 4, true, 3); ValidateStmt(epService, stmtOne, 5, true, 3); // test variables - half open epService.EPRuntime.SetVariableValue("lower", 3); epService.EPRuntime.SetVariableValue("upper", null); String stmtTwo = "[lower:] a=SupportBean (TheString = 'A') until b=SupportBean (TheString = 'B')"; ValidateStmt(epService, stmtTwo, 0, false, null); ValidateStmt(epService, stmtTwo, 1, false, null); ValidateStmt(epService, stmtTwo, 2, false, null); ValidateStmt(epService, stmtTwo, 3, true, 3); ValidateStmt(epService, stmtTwo, 4, true, 4); ValidateStmt(epService, stmtTwo, 5, true, 5); // test variables - half closed epService.EPRuntime.SetVariableValue("lower", null); epService.EPRuntime.SetVariableValue("upper", 2); String stmtThree = "[:upper] a=SupportBean (TheString = 'A') until b=SupportBean (TheString = 'B')"; ValidateStmt(epService, stmtThree, 0, true, null); ValidateStmt(epService, stmtThree, 1, true, 1); ValidateStmt(epService, stmtThree, 2, true, 2); ValidateStmt(epService, stmtThree, 3, true, 2); ValidateStmt(epService, stmtThree, 4, true, 2); ValidateStmt(epService, stmtThree, 5, true, 2); // test followed-by - bounded epService.EPAdministrator.CreateEPL("@Name('S1') select * from pattern [s0=SupportBean_S0 -> [s0.id] b=SupportBean]").Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean_S0(2)); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean("E2", 2)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), "b[0].TheString,b[1].TheString".Split(','), new Object[] { "E1", "E2" }); // test substitution parameter String epl = "select * from pattern[[?] SupportBean]"; EPPreparedStatement prepared = epService.EPAdministrator.PrepareEPL(epl); prepared.SetObject(1, 2); EPStatement stmt = epService.EPAdministrator.Create(prepared); // test exactly-1 epService.EPRuntime.SendEvent(new CurrentTimeEvent(0)); String eplExact1 = "select * from pattern [a=A -> [1] every (timer:interval(10) and not B)]"; EPStatement stmtExact1 = epService.EPAdministrator.CreateEPL(eplExact1); stmtExact1.Events += listener.Update; epService.EPRuntime.SendEvent(new CurrentTimeEvent(5000)); epService.EPRuntime.SendEvent(new SupportBean_A("A1")); epService.EPRuntime.SendEvent(new CurrentTimeEvent(6000)); epService.EPRuntime.SendEvent(new SupportBean_B("B1")); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new CurrentTimeEvent(15999)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new CurrentTimeEvent(16000)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), "a.Id".Split(','), new Object[] { "A1" }); epService.EPRuntime.SendEvent(new CurrentTimeEvent(999999)); Assert.IsFalse(listener.IsInvoked); stmtExact1.Dispose(); // test until epService.EPRuntime.SendEvent(new CurrentTimeEvent(1000000)); String eplUntilOne = "select * from pattern [a=A -> b=B until ([1] every (timer:interval(10) and not C))]"; epService.EPAdministrator.CreateEPL(eplUntilOne).Events += listener.Update; epService.EPRuntime.SendEvent(new CurrentTimeEvent(1005000)); epService.EPRuntime.SendEvent(new SupportBean_A("A1")); epService.EPRuntime.SendEvent(new CurrentTimeEvent(1006000)); epService.EPRuntime.SendEvent(new SupportBean_B("B1")); epService.EPRuntime.SendEvent(new CurrentTimeEvent(1014999)); epService.EPRuntime.SendEvent(new SupportBean_B("B2")); epService.EPRuntime.SendEvent(new SupportBean_C("C1")); epService.EPRuntime.SendEvent(new CurrentTimeEvent(1015000)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new CurrentTimeEvent(1024998)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new CurrentTimeEvent(1024999)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), "a.Id,b[0].Id,b[1].Id".Split(','), new Object[] { "A1", "B1", "B2" }); epService.EPRuntime.SendEvent(new CurrentTimeEvent(1999999)); Assert.IsFalse(listener.IsInvoked); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
public void TestIncludeEndpoints() { String startTime = "2002-05-30 09:00:00.000"; _epService.EPRuntime.SendEvent(new CurrentTimeEvent(DateTimeParser.ParseDefaultMSec(startTime))); String[] fieldsCurrentTs = "val0,val1,val2,val3,val4,val5,val6".Split(','); String eplCurrentTS = "select " + "current_timestamp.After(longdateStart) as val0, " + "current_timestamp.Between(longdateStart, longdateEnd) as val1, " + "current_timestamp.Between(utildateStart, caldateEnd) as val2, " + "current_timestamp.Between(caldateStart, utildateEnd) as val3, " + "current_timestamp.Between(utildateStart, utildateEnd) as val4, " + "current_timestamp.Between(caldateStart, caldateEnd) as val5, " + "current_timestamp.Between(caldateEnd, caldateStart) as val6 " + "from SupportTimeStartEndA"; EPStatement stmtCurrentTs = _epService.EPAdministrator.CreateEPL(eplCurrentTS); stmtCurrentTs.Events += _listener.Update; LambdaAssertionUtil.AssertTypesAllSame(stmtCurrentTs.EventType, fieldsCurrentTs, typeof(bool?)); _epService.EPRuntime.SendEvent(SupportTimeStartEndA.Make("E1", "2002-05-30 08:59:59.999", 0)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsCurrentTs, new Object[] { true, false, false, false, false, false, false }); _epService.EPRuntime.SendEvent(SupportTimeStartEndA.Make("E1", "2002-05-30 08:59:59.999", 1)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsCurrentTs, new Object[] { true, true, true, true, true, true, true }); _epService.EPRuntime.SendEvent(SupportTimeStartEndA.Make("E1", "2002-05-30 08:59:59.999", 100)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsCurrentTs, new Object[] { true, true, true, true, true, true, true }); _epService.EPRuntime.SendEvent(SupportTimeStartEndA.Make("E1", "2002-05-30 09:00:00.000", 0)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsCurrentTs, new Object[] { false, true, true, true, true, true, true }); _epService.EPRuntime.SendEvent(SupportTimeStartEndA.Make("E1", "2002-05-30 09:00:00.000", 100)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsCurrentTs, new Object[] { false, true, true, true, true, true, true }); _epService.EPRuntime.SendEvent(SupportTimeStartEndA.Make("E1", "2002-05-30 09:00:00.001", 100)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsCurrentTs, new Object[] { false, false, false, false, false, false, false }); stmtCurrentTs.Dispose(); // test calendar field and constants _epService.EPAdministrator.Configuration.AddImport(typeof(DateTimeParser)); String[] fieldsConstants = "val0,val1,val2,val3".Split(','); String eplConstants = "select " + "longdateStart.between(DateTimeParser.ParseDefault('2002-05-30 09:00:00.000'), DateTimeParser.ParseDefault('2002-05-30 09:01:00.000')) as val0, " + "utildateStart.between(DateTimeParser.ParseDefault('2002-05-30 09:00:00.000'), DateTimeParser.ParseDefault('2002-05-30 09:01:00.000')) as val1, " + "caldateStart.between(DateTimeParser.ParseDefault('2002-05-30 09:00:00.000'), DateTimeParser.ParseDefault('2002-05-30 09:01:00.000')) as val2, " + "longdateStart.between(DateTimeParser.ParseDefault('2002-05-30 09:01:00.000'), DateTimeParser.ParseDefault('2002-05-30 09:00:00.000')) as val3 " + "from SupportTimeStartEndA"; EPStatement stmtConstants = _epService.EPAdministrator.CreateEPL(eplConstants); stmtConstants.Events += _listener.Update; LambdaAssertionUtil.AssertTypesAllSame(stmtConstants.EventType, fieldsConstants, typeof(bool?)); _epService.EPRuntime.SendEvent(SupportTimeStartEndA.Make("E1", "2002-05-30 8:59:59.999", 0)); EPAssertionUtil.AssertPropsAllValuesSame(_listener.AssertOneGetNewAndReset(), fieldsConstants, false); _epService.EPRuntime.SendEvent(SupportTimeStartEndA.Make("E2", "2002-05-30 9:00:00.000", 0)); EPAssertionUtil.AssertPropsAllValuesSame(_listener.AssertOneGetNewAndReset(), fieldsConstants, true); _epService.EPRuntime.SendEvent(SupportTimeStartEndA.Make("E2", "2002-05-30 9:00:05.000", 0)); EPAssertionUtil.AssertPropsAllValuesSame(_listener.AssertOneGetNewAndReset(), fieldsConstants, true); _epService.EPRuntime.SendEvent(SupportTimeStartEndA.Make("E2", "2002-05-30 9:00:59.999", 0)); EPAssertionUtil.AssertPropsAllValuesSame(_listener.AssertOneGetNewAndReset(), fieldsConstants, true); _epService.EPRuntime.SendEvent(SupportTimeStartEndA.Make("E2", "2002-05-30 9:01:00.000", 0)); EPAssertionUtil.AssertPropsAllValuesSame(_listener.AssertOneGetNewAndReset(), fieldsConstants, true); _epService.EPRuntime.SendEvent(SupportTimeStartEndA.Make("E2", "2002-05-30 9:01:00.001", 0)); EPAssertionUtil.AssertPropsAllValuesSame(_listener.AssertOneGetNewAndReset(), fieldsConstants, false); stmtConstants.Dispose(); }
private void RunAssertionLinest(EPServiceProvider epService) { // further math tests can be found in the view unit test EPAdministrator admin = epService.EPAdministrator; admin.Configuration.AddEventType("Market", typeof(SupportMarketDataBean)); EPStatement statement = admin.CreateEPL ("select * from Market#groupwin(symbol)#length(1000000)#linest(Price, Volume, Feed)"); var listener = new SupportUpdateListener(); statement.Events += listener.Update; Assert.AreEqual(typeof(double?), statement.EventType.GetPropertyType("slope")); Assert.AreEqual(typeof(double?), statement.EventType.GetPropertyType("YIntercept")); Assert.AreEqual(typeof(double?), statement.EventType.GetPropertyType("XAverage")); Assert.AreEqual(typeof(double?), statement.EventType.GetPropertyType("XStandardDeviationPop")); Assert.AreEqual(typeof(double?), statement.EventType.GetPropertyType("XStandardDeviationSample")); Assert.AreEqual(typeof(double?), statement.EventType.GetPropertyType("XSum")); Assert.AreEqual(typeof(double?), statement.EventType.GetPropertyType("XVariance")); Assert.AreEqual(typeof(double?), statement.EventType.GetPropertyType("YAverage")); Assert.AreEqual(typeof(double?), statement.EventType.GetPropertyType("YStandardDeviationPop")); Assert.AreEqual(typeof(double?), statement.EventType.GetPropertyType("YStandardDeviationSample")); Assert.AreEqual(typeof(double?), statement.EventType.GetPropertyType("YSum")); Assert.AreEqual(typeof(double?), statement.EventType.GetPropertyType("YVariance")); Assert.AreEqual(typeof(long?), statement.EventType.GetPropertyType("dataPoints")); Assert.AreEqual(typeof(long?), statement.EventType.GetPropertyType("n")); Assert.AreEqual(typeof(double?), statement.EventType.GetPropertyType("sumX")); Assert.AreEqual(typeof(double?), statement.EventType.GetPropertyType("sumXSq")); Assert.AreEqual(typeof(double?), statement.EventType.GetPropertyType("sumXY")); Assert.AreEqual(typeof(double?), statement.EventType.GetPropertyType("sumY")); Assert.AreEqual(typeof(double?), statement.EventType.GetPropertyType("sumYSq")); var fields = new string[] { "symbol", "slope", "YIntercept", "Feed" }; epService.EPRuntime.SendEvent(new SupportMarketDataBean("ABC", 10.0, 50000L, "f1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "ABC", Double.NaN, Double.NaN, "f1" }); epService.EPRuntime.SendEvent(new SupportMarketDataBean("DEF", 1.0, 1L, "f2")); EventBean theEvent = listener.AssertOneGetNewAndReset(); EPAssertionUtil.AssertProps(theEvent, fields, new object[] { "DEF", Double.NaN, Double.NaN, "f2" }); Assert.AreEqual(1d, theEvent.Get("XAverage")); Assert.AreEqual(0d, theEvent.Get("XStandardDeviationPop")); Assert.AreEqual(Double.NaN, theEvent.Get("XStandardDeviationSample")); Assert.AreEqual(1d, theEvent.Get("XSum")); Assert.AreEqual(Double.NaN, theEvent.Get("XVariance")); Assert.AreEqual(1d, theEvent.Get("YAverage")); Assert.AreEqual(0d, theEvent.Get("YStandardDeviationPop")); Assert.AreEqual(Double.NaN, theEvent.Get("YStandardDeviationSample")); Assert.AreEqual(1d, theEvent.Get("YSum")); Assert.AreEqual(Double.NaN, theEvent.Get("YVariance")); Assert.AreEqual(1L, theEvent.Get("dataPoints")); Assert.AreEqual(1L, theEvent.Get("n")); Assert.AreEqual(1d, theEvent.Get("sumX")); Assert.AreEqual(1d, theEvent.Get("sumXSq")); Assert.AreEqual(1d, theEvent.Get("sumXY")); Assert.AreEqual(1d, theEvent.Get("sumY")); Assert.AreEqual(1d, theEvent.Get("sumYSq")); // above computed values tested in more detail in RegressionBean test epService.EPRuntime.SendEvent(new SupportMarketDataBean("DEF", 2.0, 2L, "f3")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "DEF", 1.0, 0.0, "f3" }); epService.EPRuntime.SendEvent(new SupportMarketDataBean("ABC", 11.0, 50100L, "f4")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "ABC", 100.0, 49000.0, "f4" }); statement.Dispose(); }
private void RunAssertionDistinctOverlappingMultiKey(EPServiceProvider epService) { string epl = "create context MyContext as " + "initiated by distinct(TheString, IntPrimitive) SupportBean as sb " + "terminated SupportBean_S1"; // any S1 ends the contexts EPStatementObjectModel model = epService.EPAdministrator.CompileEPL(epl); Assert.AreEqual(epl, model.ToEPL()); EPStatement stmtContext = epService.EPAdministrator.Create(model); Assert.AreEqual(stmtContext.Text, model.ToEPL()); string[] fields = "id,p00,p01,cnt".Split(','); EPStatement stmt = epService.EPAdministrator.CreateEPL( "context MyContext " + "select id, p00, p01, count(*) as cnt " + "from SupportBean_S0(id = context.sb.IntPrimitive and p00 = context.sb.TheString)"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean_S0(1, "A")); epService.EPRuntime.SendEvent(new SupportBean("A", 1)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean_S0(1, "A", "E1")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 1, "A", "E1", 1L }); epService.EPRuntime.SendEvent(new SupportBean_S0(1, "A", "E2")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 1, "A", "E2", 2L }); epService.EPRuntime.SendEvent(new SupportBean_S1(-1)); // terminate all epService.EPRuntime.SendEvent(new SupportBean_S0(1, "A", "E3")); epService.EPRuntime.SendEvent(new SupportBean("A", 1)); epService.EPRuntime.SendEvent(new SupportBean("B", 2)); epService.EPRuntime.SendEvent(new SupportBean("B", 1)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean_S0(1, "A", "E4")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 1, "A", "E4", 1L }); epService.EPRuntime.SendEvent(new SupportBean_S0(2, "B", "E5")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 2, "B", "E5", 1L }); epService.EPRuntime.SendEvent(new SupportBean_S0(1, "B", "E6")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 1, "B", "E6", 1L }); epService.EPRuntime.SendEvent(new SupportBean_S0(2, "B", "E7")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 2, "B", "E7", 2L }); epService.EPRuntime.SendEvent(new SupportBean_S1(-1)); // terminate all epService.EPRuntime.SendEvent(new SupportBean_S0(2, "B", "E8")); epService.EPRuntime.SendEvent(new SupportBean("B", 2)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean_S0(2, "B", "E9")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 2, "B", "E9", 1L }); epService.EPRuntime.SendEvent(new SupportBean_S0(2, "B", "E10")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 2, "B", "E10", 2L }); // destroy context partition, should forget about the distinct key if (GetSpi(epService).IsSupportsExtract) { GetSpi(epService).DestroyContextPartitions("MyContext", new ContextPartitionSelectorAll()); epService.EPRuntime.SendEvent(new SupportBean_S0(2, "B", "E11")); epService.EPRuntime.SendEvent(new SupportBean("B", 2)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean_S0(2, "B", "E12")); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { 2, "B", "E12", 1L }); } epService.EPAdministrator.DestroyAllStatements(); }
public void TestFullOuterJoin() { var outerJoinView = SetupStatement("full"); // Send S0[0] SendEvent(_eventsS0[0]); CompareEvent(_listener.AssertOneGetNewAndReset(), 100, "0", null, null); EPAssertionUtil.AssertPropsPerRowAnyOrder(outerJoinView.GetEnumerator(), Fields, new object[][] { new object[] { 100, "0", null, null } }); // Send S1[1] SendEvent(_eventsS1[1]); CompareEvent(_listener.AssertOneGetNewAndReset(), null, null, 201, "1"); EPAssertionUtil.AssertPropsPerRowAnyOrder(outerJoinView.GetEnumerator(), Fields, new object[][] { new object[] { 100, "0", null, null }, new object[] { null, null, 201, "1" } }); // Send S1[2] and S0[2] SendEvent(_eventsS1[2]); CompareEvent(_listener.AssertOneGetNewAndReset(), null, null, 202, "2"); EPAssertionUtil.AssertPropsPerRowAnyOrder(outerJoinView.GetEnumerator(), Fields, new object[][] { new object[] { 100, "0", null, null }, new object[] { null, null, 201, "1" }, new object[] { null, null, 202, "2" } }); SendEvent(_eventsS0[2]); CompareEvent(_listener.AssertOneGetNewAndReset(), 102, "2", 202, "2"); EPAssertionUtil.AssertPropsPerRowAnyOrder(outerJoinView.GetEnumerator(), Fields, new object[][] { new object[] { 100, "0", null, null }, new object[] { null, null, 201, "1" }, new object[] { 102, "2", 202, "2" } }); // Send S0[3] and S1[3] SendEvent(_eventsS0[3]); CompareEvent(_listener.AssertOneGetNewAndReset(), 103, "3", null, null); EPAssertionUtil.AssertPropsPerRowAnyOrder(outerJoinView.GetEnumerator(), Fields, new object[][] { new object[] { 100, "0", null, null }, new object[] { null, null, 201, "1" }, new object[] { 102, "2", 202, "2" }, new object[] { 103, "3", null, null } }); SendEvent(_eventsS1[3]); CompareEvent(_listener.AssertOneGetNewAndReset(), 103, "3", 203, "3"); EPAssertionUtil.AssertPropsPerRowAnyOrder(outerJoinView.GetEnumerator(), Fields, new object[][] { new object[] { 100, "0", null, null }, new object[] { null, null, 201, "1" }, new object[] { 102, "2", 202, "2" }, new object[] { 103, "3", 203, "3" } }); // Send S0[4], pushes S0[0] out of window SendEvent(_eventsS0[4]); var oldEvent = _listener.LastOldData[0]; var newEvent = _listener.LastNewData[0]; CompareEvent(oldEvent, 100, "0", null, null); CompareEvent(newEvent, 104, "4", null, null); _listener.Reset(); EPAssertionUtil.AssertPropsPerRowAnyOrder(outerJoinView.GetEnumerator(), Fields, new object[][] { new object[] { null, null, 201, "1" }, new object[] { 102, "2", 202, "2" }, new object[] { 103, "3", 203, "3" }, new object[] { 104, "4", null, null } }); // Send S1[4] SendEvent(_eventsS1[4]); CompareEvent(_listener.AssertOneGetNewAndReset(), 104, "4", 204, "4"); EPAssertionUtil.AssertPropsPerRowAnyOrder(outerJoinView.GetEnumerator(), Fields, new object[][] { new object[] { null, null, 201, "1" }, new object[] { 102, "2", 202, "2" }, new object[] { 103, "3", 203, "3" }, new object[] { 104, "4", 204, "4" } }); // Send S1[5] SendEvent(_eventsS1[5]); CompareEvent(_listener.AssertOneGetNewAndReset(), null, null, 205, "5"); EPAssertionUtil.AssertPropsPerRowAnyOrder(outerJoinView.GetEnumerator(), Fields, new object[][] { new object[] { null, null, 201, "1" }, new object[] { 102, "2", 202, "2" }, new object[] { 103, "3", 203, "3" }, new object[] { 104, "4", 204, "4" }, new object[] { null, null, 205, "5" } }); // Send S1[6], pushes S1[1] out of window SendEvent(_eventsS1[5]); oldEvent = _listener.LastOldData[0]; newEvent = _listener.LastNewData[0]; CompareEvent(oldEvent, null, null, 201, "1"); CompareEvent(newEvent, null, null, 205, "5"); EPAssertionUtil.AssertPropsPerRowAnyOrder(outerJoinView.GetEnumerator(), Fields, new object[][] { new object[] { 102, "2", 202, "2" }, new object[] { 103, "3", 203, "3" }, new object[] { 104, "4", 204, "4" }, new object[] { null, null, 205, "5" }, new object[] { null, null, 205, "5" } }); }
private void RunAssertionFullOuterJoin(EPServiceProvider epService) { var listener = new SupportUpdateListener(); EPStatement stmt = SetupStatement(epService, listener, "full"); // Send S0[0] SendEvent(EVENTS_S0[0], epService); CompareEvent(listener.AssertOneGetNewAndReset(), 100, "0", null, null); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), FIELDS, new object[][] { new object[] { 100, "0", null, null } }); // Send S1[1] SendEvent(EVENTS_S1[1], epService); CompareEvent(listener.AssertOneGetNewAndReset(), null, null, 201, "1"); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), FIELDS, new object[][] { new object[] { 100, "0", null, null }, new object[] { null, null, 201, "1" } }); // Send S1[2] and S0[2] SendEvent(EVENTS_S1[2], epService); CompareEvent(listener.AssertOneGetNewAndReset(), null, null, 202, "2"); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), FIELDS, new object[][] { new object[] { 100, "0", null, null }, new object[] { null, null, 201, "1" }, new object[] { null, null, 202, "2" } }); SendEvent(EVENTS_S0[2], epService); CompareEvent(listener.AssertOneGetNewAndReset(), 102, "2", 202, "2"); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), FIELDS, new object[][] { new object[] { 100, "0", null, null }, new object[] { null, null, 201, "1" }, new object[] { 102, "2", 202, "2" } }); // Send S0[3] and S1[3] SendEvent(EVENTS_S0[3], epService); CompareEvent(listener.AssertOneGetNewAndReset(), 103, "3", null, null); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), FIELDS, new object[][] { new object[] { 100, "0", null, null }, new object[] { null, null, 201, "1" }, new object[] { 102, "2", 202, "2" }, new object[] { 103, "3", null, null } }); SendEvent(EVENTS_S1[3], epService); CompareEvent(listener.AssertOneGetNewAndReset(), 103, "3", 203, "3"); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), FIELDS, new object[][] { new object[] { 100, "0", null, null }, new object[] { null, null, 201, "1" }, new object[] { 102, "2", 202, "2" }, new object[] { 103, "3", 203, "3" } }); // Send S0[4], pushes S0[0] out of window SendEvent(EVENTS_S0[4], epService); EventBean oldEvent = listener.LastOldData[0]; EventBean newEvent = listener.LastNewData[0]; CompareEvent(oldEvent, 100, "0", null, null); CompareEvent(newEvent, 104, "4", null, null); listener.Reset(); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), FIELDS, new object[][] { new object[] { null, null, 201, "1" }, new object[] { 102, "2", 202, "2" }, new object[] { 103, "3", 203, "3" }, new object[] { 104, "4", null, null } }); // Send S1[4] SendEvent(EVENTS_S1[4], epService); CompareEvent(listener.AssertOneGetNewAndReset(), 104, "4", 204, "4"); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), FIELDS, new object[][] { new object[] { null, null, 201, "1" }, new object[] { 102, "2", 202, "2" }, new object[] { 103, "3", 203, "3" }, new object[] { 104, "4", 204, "4" } }); // Send S1[5] SendEvent(EVENTS_S1[5], epService); CompareEvent(listener.AssertOneGetNewAndReset(), null, null, 205, "5"); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), FIELDS, new object[][] { new object[] { null, null, 201, "1" }, new object[] { 102, "2", 202, "2" }, new object[] { 103, "3", 203, "3" }, new object[] { 104, "4", 204, "4" }, new object[] { null, null, 205, "5" } }); // Send S1[6], pushes S1[1] out of window SendEvent(EVENTS_S1[5], epService); oldEvent = listener.LastOldData[0]; newEvent = listener.LastNewData[0]; CompareEvent(oldEvent, null, null, 201, "1"); CompareEvent(newEvent, null, null, 205, "5"); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmt.GetEnumerator(), FIELDS, new object[][] { new object[] { 102, "2", 202, "2" }, new object[] { 103, "3", 203, "3" }, new object[] { 104, "4", 204, "4" }, new object[] { null, null, 205, "5" }, new object[] { null, null, 205, "5" } }); stmt.Dispose(); }
public void TestFragment() { var config = SupportConfigFactory.GetConfiguration(); config.AddEventType("A", typeof(SupportBean_A).FullName); config.AddEventType("B", typeof(SupportBean_B).FullName); var epService = EPServiceProviderManager.GetDefaultProvider(config); epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName); } var stmtTxtOne = "select * from pattern [[2] a=A -> b=B]"; var stmt = epService.EPAdministrator.CreateEPL(stmtTxtOne); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; EPAssertionUtil.AssertEqualsAnyOrder(new [] { new EventPropertyDescriptor("a", typeof(SupportBean_A[]), typeof(SupportBean_A), false, false, true, false, true), new EventPropertyDescriptor("b", typeof(SupportBean_B), null, false, false, false, false, true) }, stmt.EventType.PropertyDescriptors); epService.EPRuntime.SendEvent(new SupportBean_A("A1")); epService.EPRuntime.SendEvent(new SupportBean_A("A2")); epService.EPRuntime.SendEvent(new SupportBean_B("B1")); var theEvent = listener.AssertOneGetNewAndReset(); Assert.IsTrue(theEvent.Underlying is IDictionary <string, object>); // test fragment B type and theEvent var typeFragB = theEvent.EventType.GetFragmentType("b"); Assert.IsFalse(typeFragB.IsIndexed); Assert.AreEqual("B", typeFragB.FragmentType.Name); Assert.AreEqual(typeof(string), typeFragB.FragmentType.GetPropertyType("id")); var eventFragB = (EventBean)theEvent.GetFragment("b"); Assert.AreEqual("B", eventFragB.EventType.Name); // test fragment A type and event var typeFragA = theEvent.EventType.GetFragmentType("a"); Assert.IsTrue(typeFragA.IsIndexed); Assert.AreEqual("A", typeFragA.FragmentType.Name); Assert.AreEqual(typeof(string), typeFragA.FragmentType.GetPropertyType("id")); Assert.IsTrue(theEvent.GetFragment("a") is EventBean[]); var eventFragA1 = (EventBean)theEvent.GetFragment("a[0]"); Assert.AreEqual("A", eventFragA1.EventType.Name); Assert.AreEqual("A1", eventFragA1.Get("id")); var eventFragA2 = (EventBean)theEvent.GetFragment("a[1]"); Assert.AreEqual("A", eventFragA2.EventType.Name); Assert.AreEqual("A2", eventFragA2.Get("id")); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }