public void Run(RegressionEnvironment env) { var stmtTextOne = "@Name('s1') select OrderId, Items.Item[0].ItemId from MediaOrder"; env.CompileDeploy(stmtTextOne).AddListener("s1"); var stmtTextTwo = "@Name('s2') select * from MediaOrder[Books.Book]"; env.CompileDeploy(stmtTextTwo).AddListener("s2"); var stmtTextThree = "@Name('s3') select * from MediaOrder(OrderId='PO200901')[Books.Book]"; env.CompileDeploy(stmtTextThree).AddListener("s3"); var stmtTextFour = "@Name('s4') select count(*) from MediaOrder[Books.Book]#unique(BookId)"; env.CompileDeploy(stmtTextFour).AddListener("s4"); var stmtTextFive = "@Name('s5') select * from MediaOrder[Books.Book][Review]"; env.CompileDeploy(stmtTextFive).AddListener("s5"); var stmtTextSix = "@Name('s6') select * from pattern [c=Cancel -> o=MediaOrder(OrderId = c.OrderId)[Books.Book]]"; env.CompileDeploy(stmtTextSix).AddListener("s6"); var stmtTextSeven = "@Name('s7') select * from MediaOrder[select OrderId, BookId from Books.Book][select * from Review]"; env.CompileDeploy(stmtTextSeven).AddListener("s7"); var stmtTextEight = "@Name('s8') select * from MediaOrder[select * from Books.Book][select ReviewId, Comment from Review]"; env.CompileDeploy(stmtTextEight).AddListener("s8"); var stmtTextNine = "@Name('s9') select * from MediaOrder[Books.Book as Book][select Book.*, ReviewId, Comment from Review]"; env.CompileDeploy(stmtTextNine).AddListener("s9"); var stmtTextTen = "@Name('s10') select * from MediaOrder[Books.Book as Book][select MediaOrder.*, BookId, ReviewId from Review] as MediaOrder"; env.CompileDeploy(stmtTextTen).AddListener("s10"); var path = new RegressionPath(); var stmtTextElevenZero = "@Name('s11_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"; env.CompileDeploy(stmtTextElevenZero, path); var stmtTextElevenOne = "@Name('s11') select MediaOrder.OrderId, Book.BookId, Review.ReviewId from ReviewStream"; env.CompileDeploy(stmtTextElevenOne, path).AddListener("s11"); var stmtTextTwelve = "@Name('s12') select * from MediaOrder[Books.Book where Author = 'Orson Scott Card'][Review]"; env.CompileDeploy(stmtTextTwelve).AddListener("s12"); env.SendEventXMLDOM(eventDocOne, "MediaOrder"); EPAssertionUtil.AssertProps( env.Listener("s1").AssertOneGetNewAndReset(), new [] { "OrderId","Items.Item[0].ItemId" }, new object[] {"PO200901", "100001"}); EPAssertionUtil.AssertPropsPerRow( env.Listener("s2").LastNewData, new [] { "BookId" }, new[] {new object[] {"B001"}, new object[] {"B002"}}); EPAssertionUtil.AssertPropsPerRow( env.Listener("s3").LastNewData, new [] { "BookId" }, new[] {new object[] {"B001"}, new object[] {"B002"}}); EPAssertionUtil.AssertPropsPerRow( env.Listener("s4").LastNewData, new [] { "count(*)" }, new[] {new object[] {2L}}); EPAssertionUtil.AssertPropsPerRow( env.Listener("s5").LastNewData, new [] { "ReviewId" }, new[] {new object[] {"1"}}); Assert.IsFalse(env.Listener("s6").IsInvoked); EPAssertionUtil.AssertPropsPerRow( env.Listener("s7").LastNewData, new [] { "OrderId","BookId","ReviewId" }, new[] {new object[] {"PO200901", "B001", "1"}}); EPAssertionUtil.AssertPropsPerRow( env.Listener("s8").LastNewData, new [] { "ReviewId","BookId" }, new[] {new object[] {"1", "B001"}}); EPAssertionUtil.AssertPropsPerRow( env.Listener("s9").LastNewData, new [] { "ReviewId","BookId" }, new[] {new object[] {"1", "B001"}}); EPAssertionUtil.AssertPropsPerRow( env.Listener("s10").LastNewData, new [] { "ReviewId","BookId" }, new[] {new object[] {"1", "B001"}}); EPAssertionUtil.AssertPropsPerRow( env.Listener("s11").LastNewData, new [] { "MediaOrder.OrderId","Book.BookId","Review.ReviewId" }, new[] {new object[] {"PO200901", "B001", "1"}}); EPAssertionUtil.AssertPropsPerRow( env.Listener("s12").LastNewData, new [] { "ReviewId" }, new[] {new object[] {"1"}}); env.UndeployAll(); }
public void TestSkipToNextRowPartitioned() { Configuration config = SupportConfigFactory.GetConfiguration(); config.AddEventType("MyEvent", typeof(SupportRecogBean)); EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider( config); epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName); } String[] fields = "a_string,a_value,b_value".Split(','); String text = "select * from MyEvent.win:keepall() " + "match_recognize (" + " partition by TheString" + " measures A.TheString as a_string, A.value as a_value, B.value as b_value " + " all matches " + " after match skip to next row " + " pattern (A B) " + " define B as (B.value > A.value)" + ")" + " order by a_string"; EPStatement stmt = epService.EPAdministrator.CreateEPL(text); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportRecogBean("S1", 5)); epService.EPRuntime.SendEvent(new SupportRecogBean("S2", 6)); epService.EPRuntime.SendEvent(new SupportRecogBean("S3", 3)); epService.EPRuntime.SendEvent(new SupportRecogBean("S4", 4)); epService.EPRuntime.SendEvent(new SupportRecogBean("S1", 5)); epService.EPRuntime.SendEvent(new SupportRecogBean("S2", 5)); epService.EPRuntime.SendEvent(new SupportRecogBean("S1", 4)); epService.EPRuntime.SendEvent(new SupportRecogBean("S4", -1)); Assert.IsFalse(listener.IsInvoked); Assert.IsFalse(stmt.HasFirst()); epService.EPRuntime.SendEvent(new SupportRecogBean("S1", 6)); EPAssertionUtil.AssertPropsPerRow( listener.GetAndResetLastNewData(), fields, new Object[][] { new Object[] { "S1", 4, 6 } }); EPAssertionUtil.AssertPropsPerRow( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "S1", 4, 6 } }); epService.EPRuntime.SendEvent(new SupportRecogBean("S4", 10)); EPAssertionUtil.AssertPropsPerRow( listener.GetAndResetLastNewData(), fields, new Object[][] { new Object[] { "S4", -1, 10 } }); EPAssertionUtil.AssertPropsPerRow( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "S1", 4, 6 }, new Object[] { "S4", -1, 10 } }); epService.EPRuntime.SendEvent(new SupportRecogBean("S4", 11)); EPAssertionUtil.AssertPropsPerRow( listener.GetAndResetLastNewData(), fields, new Object[][] { new Object[] { "S4", 10, 11 } }); EPAssertionUtil.AssertPropsPerRow( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "S1", 4, 6 }, new Object[] { "S4", -1, 10 }, new Object[] { "S4", 10, 11 } }); epService.EPRuntime.SendEvent(new SupportRecogBean("S3", 3)); epService.EPRuntime.SendEvent(new SupportRecogBean("S4", -1)); epService.EPRuntime.SendEvent(new SupportRecogBean("S3", 2)); epService.EPRuntime.SendEvent(new SupportRecogBean("S1", 4)); Assert.IsFalse(listener.IsInvoked); EPAssertionUtil.AssertPropsPerRow( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "S1", 4, 6 }, new Object[] { "S4", -1, 10 }, new Object[] { "S4", 10, 11 } }); epService.EPRuntime.SendEvent(new SupportRecogBean("S1", 7)); EPAssertionUtil.AssertPropsPerRow( listener.GetAndResetLastNewData(), fields, new Object[][] { new Object[] { "S1", 4, 7 } }); EPAssertionUtil.AssertPropsPerRow( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "S1", 4, 6 }, new Object[] { "S1", 4, 7 }, new Object[] { "S4", -1, 10 }, new Object[] { "S4", 10, 11 } }); epService.EPRuntime.SendEvent(new SupportRecogBean("S4", 12)); EPAssertionUtil.AssertPropsPerRow( listener.GetAndResetLastNewData(), fields, new Object[][] { new Object[] { "S4", -1, 12 } }); EPAssertionUtil.AssertPropsPerRow( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "S1", 4, 6 }, new Object[] { "S1", 4, 7 }, new Object[] { "S4", -1, 10 }, new Object[] { "S4", 10, 11 }, new Object[] { "S4", -1, 12 } }); epService.EPRuntime.SendEvent(new SupportRecogBean("S4", 12)); epService.EPRuntime.SendEvent(new SupportRecogBean("S1", 7)); epService.EPRuntime.SendEvent(new SupportRecogBean("S2", 4)); epService.EPRuntime.SendEvent(new SupportRecogBean("S1", 5)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportRecogBean("S2", 5)); EPAssertionUtil.AssertPropsPerRow( listener.GetAndResetLastNewData(), fields, new Object[][] { new Object[] { "S2", 4, 5 } }); EPAssertionUtil.AssertPropsPerRow( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "S1", 4, 6 }, new Object[] { "S1", 4, 7 }, new Object[] { "S2", 4, 5 }, new Object[] { "S4", -1, 10 }, new Object[] { "S4", 10, 11 }, new Object[] { "S4", -1, 12 } }); stmt.Dispose(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
public void TestNamedWindowOnDeleteOutOfSeq() { Configuration config = SupportConfigFactory.GetConfiguration(); config.AddEventType <SupportRecogBean>("MyEvent"); config.AddEventType("MyDeleteEvent", typeof(SupportBean)); EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(config); epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName); } epService.EPAdministrator.CreateEPL("create window MyNamedWindow.win:keepall() as MyEvent"); epService.EPAdministrator.CreateEPL("insert into MyNamedWindow select * from MyEvent"); epService.EPAdministrator.CreateEPL( "on MyDeleteEvent as d delete from MyNamedWindow w where d.IntPrimitive = w.Value"); String[] fields = "a_string,b_string".Split(','); String text = "select * from MyNamedWindow " + "match_recognize (" + " measures A.TheString as a_string, B.TheString as b_string" + " all matches pattern (A B) " + " define " + " A as PREV(A.TheString, 3) = 'P3' and PREV(A.TheString, 2) = 'P2' and PREV(A.TheString, 4) = 'P4'," + " B as B.Value in (PREV(B.Value, 4), PREV(B.Value, 2))" + ")"; EPStatement stmt = epService.EPAdministrator.CreateEPL(text); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportRecogBean("P2", 1)); epService.EPRuntime.SendEvent(new SupportRecogBean("P1", 2)); epService.EPRuntime.SendEvent(new SupportRecogBean("P3", 3)); epService.EPRuntime.SendEvent(new SupportRecogBean("P4", 4)); epService.EPRuntime.SendEvent(new SupportRecogBean("P2", 1)); epService.EPRuntime.SendEvent(new SupportRecogBean("E1", 3)); Assert.IsFalse(listener.IsInvoked); Assert.IsFalse(stmt.HasFirst()); epService.EPRuntime.SendEvent(new SupportRecogBean("P4", 11)); epService.EPRuntime.SendEvent(new SupportRecogBean("P3", 12)); epService.EPRuntime.SendEvent(new SupportRecogBean("P2", 13)); epService.EPRuntime.SendEvent(new SupportRecogBean("xx", 4)); epService.EPRuntime.SendEvent(new SupportRecogBean("E2", -4)); epService.EPRuntime.SendEvent(new SupportRecogBean("E3", 12)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new[] { new Object[] { "E2", "E3" } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "E2", "E3" } }); epService.EPRuntime.SendEvent(new SupportRecogBean("P4", 21)); epService.EPRuntime.SendEvent(new SupportRecogBean("P3", 22)); epService.EPRuntime.SendEvent(new SupportRecogBean("P2", 23)); epService.EPRuntime.SendEvent(new SupportRecogBean("xx", -2)); epService.EPRuntime.SendEvent(new SupportRecogBean("E5", -1)); epService.EPRuntime.SendEvent(new SupportRecogBean("E6", -2)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new[] { new Object[] { "E5", "E6" } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "E2", "E3" }, new[] { "E5", "E6" } }); // delete an PREV-referenced event: no effect as PREV is an order-of-arrival operator epService.EPRuntime.SendEvent(new SupportBean("D1", 21)); // delete P4 of second batch EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "E2", "E3" }, new[] { "E5", "E6" } }); // delete an partial-match event epService.EPRuntime.SendEvent(new SupportBean("D2", -1)); // delete E5 of second batch EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "E2", "E3" } }); epService.EPRuntime.SendEvent(new SupportBean("D3", 12)); // delete P3 and E3 of first batch Assert.IsFalse(stmt.HasFirst()); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
public void Run(RegressionEnvironment env) { env.AdvanceTime(0); var fields = new [] { "a_string","b_string","c_string" }; var text = "@Name('s0') select * from SupportRecogBean#time_batch(5 sec) " + "match_recognize (" + " partition by Cat " + " measures A.TheString as a_string, B.TheString as b_string, C.TheString as c_string" + " all matches pattern ( (A | B) C ) " + " define " + " A as A.TheString like 'A%'," + " B as B.TheString like 'B%'," + " C as C.TheString like 'C%' and C.Value in (A.Value, B.Value)" + ") order by a_string"; env.CompileDeploy(text).AddListener("s0"); env.AdvanceTime(50); env.SendEventBean(new SupportRecogBean("A1", "001", 1)); env.SendEventBean(new SupportRecogBean("B1", "002", 1)); env.SendEventBean(new SupportRecogBean("B2", "002", 4)); Assert.IsFalse(env.Listener("s0").IsInvoked); Assert.IsFalse(env.GetEnumerator("s0").MoveNext()); env.Milestone(0); env.AdvanceTime(4000); env.SendEventBean(new SupportRecogBean("C1", "002", 4)); env.SendEventBean(new SupportRecogBean("C2", "002", 5)); env.SendEventBean(new SupportRecogBean("B3", "003", -1)); Assert.IsFalse(env.Listener("s0").IsInvoked); EPAssertionUtil.AssertPropsPerRow( env.GetEnumerator("s0"), fields, new[] {new object[] {null, "B2", "C1"}}); env.Milestone(1); env.AdvanceTime(5050); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new[] {new object[] {null, "B2", "C1"}}); Assert.IsFalse(env.GetEnumerator("s0").MoveNext()); env.Milestone(2); env.AdvanceTime(6000); env.SendEventBean(new SupportRecogBean("C3", "003", -1)); env.SendEventBean(new SupportRecogBean("C4", "001", 1)); Assert.IsFalse(env.Listener("s0").IsInvoked); Assert.IsFalse(env.GetEnumerator("s0").MoveNext()); env.Milestone(3); env.AdvanceTime(10050); Assert.IsFalse(env.Listener("s0").IsInvoked); Assert.IsFalse(env.GetEnumerator("s0").MoveNext()); env.Milestone(4); env.AdvanceTime(14000); env.SendEventBean(new SupportRecogBean("A2", "002", 0)); env.SendEventBean(new SupportRecogBean("B4", "003", 10)); env.SendEventBean(new SupportRecogBean("C5", "002", 0)); env.SendEventBean(new SupportRecogBean("C6", "003", 10)); Assert.IsFalse(env.Listener("s0").IsInvoked); EPAssertionUtil.AssertPropsPerRow( env.GetEnumerator("s0"), fields, new[] {new object[] {null, "B4", "C6"}, new object[] {"A2", null, "C5"}}); env.Milestone(5); env.AdvanceTime(15050); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new[] {new object[] {null, "B4", "C6"}, new object[] {"A2", null, "C5"}}); Assert.IsFalse(env.GetEnumerator("s0").MoveNext()); env.UndeployAll(); }
public void TestAfterNextRow() { Configuration config = SupportConfigFactory.GetConfiguration(); config.AddEventType("MyEvent", typeof(SupportRecogBean)); EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider( config); epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName); } String[] fields = "a,b0,b1".Split(','); String text = "select * from MyEvent.win:keepall() " + "match_recognize (" + " measures A.TheString as a, B[0].TheString as b0, B[1].TheString as b1" + " AFTER MATCH SKIP TO NEXT ROW " + " pattern (A B*) " + " define " + " A as A.TheString like 'A%'," + " B as B.TheString like 'B%'" + ")"; EPStatement stmt = epService.EPAdministrator.CreateEPL(text); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportRecogBean("A1", 1)); EPAssertionUtil.AssertPropsPerRow( listener.GetAndResetLastNewData(), fields, new Object[][] { new Object[] { "A1", null, null } }); EPAssertionUtil.AssertPropsPerRow( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "A1", null, null } }); // since the first match skipped past A, we do not match again epService.EPRuntime.SendEvent(new SupportRecogBean("B1", 2)); Assert.IsFalse(listener.IsInvoked); // incremental skips to next EPAssertionUtil.AssertPropsPerRow( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "A1", "B1", null } }); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
public void TestStartStopCreator() { // create window string stmtTextCreate = "create window MyWindow.win:keepall() as select TheString as a, IntPrimitive as b from " + typeof(SupportBean).FullName; EPStatement stmtCreate = _epService.EPAdministrator.CreateEPL(stmtTextCreate, "stmtCreateFirst"); stmtCreate.AddListener(_listenerWindow); // create delete stmt string stmtTextDelete = "on " + typeof(SupportBean_A).FullName + " delete from MyWindow"; EPStatement stmtDelete = _epService.EPAdministrator.CreateEPL(stmtTextDelete, "stmtDelete"); // create insert into string stmtTextInsertOne = "insert into MyWindow select TheString as a, IntPrimitive as b from " + typeof(SupportBean).FullName; EPStatement stmtInsert = _epService.EPAdministrator.CreateEPL(stmtTextInsertOne, "stmtInsert"); // create consumer string[] fields = new string[] { "a", "b" }; string stmtTextSelect = "select a, b from MyWindow as s1"; EPStatement stmtSelect = _epService.EPAdministrator.CreateEPL(stmtTextSelect, "stmtSelect"); stmtSelect.AddListener(_listenerSelect); // send 1 event SendSupportBean("E1", 1); EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E1", 1 }); EPAssertionUtil.AssertProps(_listenerSelect.AssertOneGetNewAndReset(), fields, new object[] { "E1", 1 }); EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 } }); EPAssertionUtil.AssertPropsPerRow(stmtSelect.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 } }); // stop creator stmtCreate.Stop(); SendSupportBean("E2", 2); Assert.IsFalse(_listenerSelect.IsInvoked); Assert.IsFalse(_listenerWindow.IsInvoked); Assert.That(stmtCreate.GetEnumerator(), Is.Not.Null); Assert.That(stmtCreate.GetEnumerator().MoveNext(), Is.False); EPAssertionUtil.AssertPropsPerRow(stmtSelect.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 } }); // start creator stmtCreate.Start(); SendSupportBean("E3", 3); EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E3", 3 }); Assert.IsFalse(_listenerSelect.IsInvoked); EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E3", 3 } }); EPAssertionUtil.AssertPropsPerRow(stmtSelect.GetEnumerator(), fields, new object[][] { new object[] { "E3", 3 } }); // stop and start consumer: should pick up last event stmtSelect.Stop(); stmtSelect.Start(); EPAssertionUtil.AssertPropsPerRow(stmtSelect.GetEnumerator(), fields, new object[][] { new object[] { "E3", 3 } }); SendSupportBean("E4", 4); EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E4", 4 }); EPAssertionUtil.AssertProps(_listenerSelect.AssertOneGetNewAndReset(), fields, new object[] { "E4", 4 }); EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E3", 3 }, new object[] { "E4", 4 } }); EPAssertionUtil.AssertPropsPerRow(stmtSelect.GetEnumerator(), fields, new object[][] { new object[] { "E3", 3 }, new object[] { "E4", 4 } }); // destroy creator stmtCreate.Dispose(); SendSupportBean("E5", 5); Assert.IsFalse(_listenerSelect.IsInvoked); Assert.IsFalse(_listenerWindow.IsInvoked); Assert.That(stmtCreate.GetEnumerator(), Is.Not.Null); Assert.That(stmtCreate.GetEnumerator().MoveNext(), Is.False); EPAssertionUtil.AssertPropsPerRow(stmtSelect.GetEnumerator(), fields, new object[][] { new object[] { "E3", 3 }, new object[] { "E4", 4 } }); // create window anew stmtTextCreate = "create window MyWindow.win:keepall() as select TheString as a, IntPrimitive as b from " + typeof(SupportBean).FullName; stmtCreate = _epService.EPAdministrator.CreateEPL(stmtTextCreate, "stmtCreate"); stmtCreate.AddListener(_listenerWindow); SendSupportBean("E6", 6); EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E6", 6 }); EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E6", 6 } }); Assert.IsFalse(_listenerSelect.IsInvoked); EPAssertionUtil.AssertPropsPerRow(stmtSelect.GetEnumerator(), fields, new object[][] { new object[] { "E3", 3 }, new object[] { "E4", 4 } }); // create select stmt string stmtTextOnSelect = "on " + typeof(SupportBean_A).FullName + " insert into A select * from MyWindow"; EPStatement stmtOnSelect = _epService.EPAdministrator.CreateEPL(stmtTextOnSelect, "stmtOnSelect"); // assert statement-type reference EPServiceProviderSPI spi = (EPServiceProviderSPI)_epService; Assert.IsTrue(spi.StatementEventTypeRef.IsInUse("MyWindow")); ICollection <string> stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType("MyWindow"); EPAssertionUtil.AssertEqualsAnyOrder(new string[] { "stmtCreate", "stmtSelect", "stmtInsert", "stmtDelete", "stmtOnSelect" }, stmtNames.ToArray()); Assert.IsTrue(spi.StatementEventTypeRef.IsInUse(typeof(SupportBean).FullName)); stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType(typeof(SupportBean).FullName); EPAssertionUtil.AssertEqualsAnyOrder(new string[] { "stmtCreate", "stmtInsert" }, stmtNames.ToArray()); Assert.IsTrue(spi.StatementEventTypeRef.IsInUse(typeof(SupportBean_A).FullName)); stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType(typeof(SupportBean_A).FullName); EPAssertionUtil.AssertEqualsAnyOrder(new string[] { "stmtDelete", "stmtOnSelect" }, stmtNames.ToArray()); stmtInsert.Dispose(); stmtDelete.Dispose(); Assert.IsTrue(spi.StatementEventTypeRef.IsInUse("MyWindow")); stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType("MyWindow"); EPAssertionUtil.AssertEqualsAnyOrder(new string[] { "stmtCreate", "stmtSelect", "stmtOnSelect" }, stmtNames.ToArray()); Assert.IsTrue(spi.StatementEventTypeRef.IsInUse(typeof(SupportBean).FullName)); stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType(typeof(SupportBean).FullName); EPAssertionUtil.AssertEqualsAnyOrder(new string[] { "stmtCreate" }, stmtNames.ToArray()); Assert.IsTrue(spi.StatementEventTypeRef.IsInUse(typeof(SupportBean_A).FullName)); stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType(typeof(SupportBean_A).FullName); EPAssertionUtil.AssertEqualsAnyOrder(new string[] { "stmtOnSelect" }, stmtNames.ToArray()); stmtCreate.Dispose(); Assert.IsTrue(spi.StatementEventTypeRef.IsInUse("MyWindow")); stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType("MyWindow"); EPAssertionUtil.AssertEqualsAnyOrder(new string[] { "stmtSelect", "stmtOnSelect" }, stmtNames.ToArray()); Assert.IsFalse(spi.StatementEventTypeRef.IsInUse(typeof(SupportBean).FullName)); Assert.IsTrue(spi.StatementEventTypeRef.IsInUse(typeof(SupportBean_A).FullName)); stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType(typeof(SupportBean_A).FullName); EPAssertionUtil.AssertEqualsAnyOrder(new string[] { "stmtOnSelect" }, stmtNames.ToArray()); stmtOnSelect.Dispose(); stmtSelect.Dispose(); Assert.IsFalse(spi.StatementEventTypeRef.IsInUse("MyWindow")); Assert.IsFalse(spi.StatementEventTypeRef.IsInUse(typeof(SupportBean).FullName)); Assert.IsFalse(spi.StatementEventTypeRef.IsInUse(typeof(SupportBean_A).FullName)); }
private void RunAssertionInsertWhereTypeAndFilter(EPServiceProvider epService, SupportUpdateListener[] listeners) { var fields = new[] { "TheString" }; // create window string stmtTextCreateOne = "create window MyWindowIWT#keepall as SupportBean"; EPStatement stmtCreateOne = epService.EPAdministrator.CreateEPL(stmtTextCreateOne, "name1"); stmtCreateOne.Events += listeners[0].Update; EventType eventTypeOne = stmtCreateOne.EventType; // create insert into string stmtTextInsertOne = "insert into MyWindowIWT select * from SupportBean(IntPrimitive > 0)"; epService.EPAdministrator.CreateEPL(stmtTextInsertOne); // populate some data Assert.AreEqual(0, GetCount(epService, "MyWindowIWT")); epService.EPRuntime.SendEvent(new SupportBean("A1", 1)); Assert.AreEqual(1, GetCount(epService, "MyWindowIWT")); epService.EPRuntime.SendEvent(new SupportBean("B2", 1)); epService.EPRuntime.SendEvent(new SupportBean("C3", 1)); epService.EPRuntime.SendEvent(new SupportBean("A4", 4)); epService.EPRuntime.SendEvent(new SupportBean("C5", 4)); Assert.AreEqual(5, GetCount(epService, "MyWindowIWT")); Assert.AreEqual("name1", GetStatementName(epService, "MyWindowIWT")); Assert.AreEqual(stmtTextCreateOne, GetEPL(epService, "MyWindowIWT")); listeners[0].Reset(); // create window with keep-all string stmtTextCreateTwo = "create window MyWindowTwo#keepall as MyWindowIWT insert"; EPStatement stmtCreateTwo = epService.EPAdministrator.CreateEPL(stmtTextCreateTwo); stmtCreateTwo.Events += listeners[2].Update; EPAssertionUtil.AssertPropsPerRow(stmtCreateTwo.GetEnumerator(), fields, new[] { new object[] { "A1" }, new object[] { "B2" }, new object[] { "C3" }, new object[] { "A4" }, new object[] { "C5" } }); EventType eventTypeTwo = stmtCreateTwo.First().EventType; Assert.IsFalse(listeners[2].IsInvoked); Assert.AreEqual(5, GetCount(epService, "MyWindowTwo")); Assert.AreEqual(StatementType.CREATE_WINDOW, ((EPStatementSPI)stmtCreateTwo).StatementMetadata.StatementType); // create window with keep-all and filter string stmtTextCreateThree = "create window MyWindowThree#keepall as MyWindowIWT insert where TheString like 'A%'"; EPStatement stmtCreateThree = epService.EPAdministrator.CreateEPL(stmtTextCreateThree); stmtCreateThree.Events += listeners[3].Update; EPAssertionUtil.AssertPropsPerRow(stmtCreateThree.GetEnumerator(), fields, new[] { new object[] { "A1" }, new object[] { "A4" } }); EventType eventTypeThree = stmtCreateThree.First().EventType; Assert.IsFalse(listeners[3].IsInvoked); Assert.AreEqual(2, GetCount(epService, "MyWindowThree")); // create window with last-per-id string stmtTextCreateFour = "create window MyWindowFour#unique(IntPrimitive) as MyWindowIWT insert"; EPStatement stmtCreateFour = epService.EPAdministrator.CreateEPL(stmtTextCreateFour); stmtCreateFour.Events += listeners[4].Update; EPAssertionUtil.AssertPropsPerRow(stmtCreateFour.GetEnumerator(), fields, new[] { new object[] { "C3" }, new object[] { "C5" } }); EventType eventTypeFour = stmtCreateFour.First().EventType; Assert.IsFalse(listeners[4].IsInvoked); Assert.AreEqual(2, GetCount(epService, "MyWindowFour")); epService.EPAdministrator.CreateEPL("insert into MyWindowIWT select * from SupportBean(TheString like 'A%')"); epService.EPAdministrator.CreateEPL("insert into MyWindowTwo select * from SupportBean(TheString like 'B%')"); epService.EPAdministrator.CreateEPL("insert into MyWindowThree select * from SupportBean(TheString like 'C%')"); epService.EPAdministrator.CreateEPL("insert into MyWindowFour select * from SupportBean(TheString like 'D%')"); Assert.IsFalse(listeners[0].IsInvoked || listeners[2].IsInvoked || listeners[3].IsInvoked || listeners[4].IsInvoked); epService.EPRuntime.SendEvent(new SupportBean("B9", -9)); EventBean received = listeners[2].AssertOneGetNewAndReset(); EPAssertionUtil.AssertProps(received, fields, new object[] { "B9" }); Assert.AreSame(eventTypeTwo, received.EventType); Assert.IsFalse(listeners[0].IsInvoked || listeners[3].IsInvoked || listeners[4].IsInvoked); Assert.AreEqual(6, GetCount(epService, "MyWindowTwo")); epService.EPRuntime.SendEvent(new SupportBean("A8", -8)); received = listeners[0].AssertOneGetNewAndReset(); EPAssertionUtil.AssertProps(received, fields, new object[] { "A8" }); Assert.AreSame(eventTypeOne, received.EventType); Assert.IsFalse(listeners[2].IsInvoked || listeners[3].IsInvoked || listeners[4].IsInvoked); epService.EPRuntime.SendEvent(new SupportBean("C7", -7)); received = listeners[3].AssertOneGetNewAndReset(); EPAssertionUtil.AssertProps(received, fields, new object[] { "C7" }); Assert.AreSame(eventTypeThree, received.EventType); Assert.IsFalse(listeners[2].IsInvoked || listeners[0].IsInvoked || listeners[4].IsInvoked); epService.EPRuntime.SendEvent(new SupportBean("D6", -6)); received = listeners[4].AssertOneGetNewAndReset(); EPAssertionUtil.AssertProps(received, fields, new object[] { "D6" }); Assert.AreSame(eventTypeFour, received.EventType); Assert.IsFalse(listeners[2].IsInvoked || listeners[0].IsInvoked || listeners[3].IsInvoked); }
public void Run(RegressionEnvironment env) { var text = "@Name('s0') select irstream Symbol, " + "prev(1, Symbol) as prev1," + "prevtail(Symbol) as prevtail, " + "prevcount(Symbol) as prevCountSym, " + "prevwindow(Symbol) as prevWindowSym " + "from SupportMarketDataBean#sort(3, Symbol)"; env.CompileDeploy(text).AddListener("s0"); string[] fields = {"Symbol", "prev1", "prevtail", "prevCountSym", "prevWindowSym"}; env.SendEventBean(MakeMarketDataEvent("B1")); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").NewDataListFlattened, fields, new[] { new object[] { "B1", null, "B1", 1L, new object[] {"B1"} } }); env.Listener("s0").Reset(); env.Milestone(0); env.SendEventBean(MakeMarketDataEvent("D1")); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").NewDataListFlattened, fields, new[] { new object[] { "D1", "D1", "D1", 2L, new object[] {"B1", "D1"} } }); env.Listener("s0").Reset(); env.SendEventBean(MakeMarketDataEvent("C1")); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").NewDataListFlattened, fields, new[] { new object[] { "C1", "C1", "D1", 3L, new object[] {"B1", "C1", "D1"} } }); env.Listener("s0").Reset(); env.Milestone(1); env.SendEventBean(MakeMarketDataEvent("A1")); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").NewDataListFlattened, fields, new[] { new object[] { "A1", "B1", "C1", 3L, new object[] {"A1", "B1", "C1"} } }); env.Listener("s0").Reset(); env.Milestone(2); env.SendEventBean(MakeMarketDataEvent("F1")); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").NewDataListFlattened, fields, new[] { new object[] { "F1", "B1", "C1", 3L, new object[] {"A1", "B1", "C1"} } }); env.Listener("s0").Reset(); env.Milestone(3); env.UndeployAll(); }
public void TestPatternUnidirectionalOuterJoinNoOn() { // test 2-stream left outer join and SODA // _epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); _epService.EPAdministrator.Configuration.AddEventType <SupportBean_S0>(); _epService.EPAdministrator.Configuration.AddEventType <SupportBean_S1>(); _epService.EPRuntime.SendEvent(new CurrentTimeEvent(1000)); String stmtTextLO = "select sum(IntPrimitive) as c0, count(*) as c1 " + "from pattern [every timer:interval(1 seconds)] unidirectional " + "left outer join " + "SupportBean#keepall"; EPStatement stmtLO = _epService.EPAdministrator.CreateEPL(stmtTextLO); stmtLO.Events += _listener.Update; RunAssertionPatternUniOuterJoinNoOn(0); stmtLO.Dispose(); EPStatementObjectModel model = _epService.EPAdministrator.CompileEPL(stmtTextLO); Assert.AreEqual(stmtTextLO, model.ToEPL()); stmtLO = _epService.EPAdministrator.Create(model); Assert.AreEqual(stmtTextLO, stmtLO.Text); stmtLO.Events += _listener.Update; RunAssertionPatternUniOuterJoinNoOn(100000); stmtLO.Dispose(); // test 2-stream inner join // String[] fieldsIJ = "c0,c1".Split(','); String stmtTextIJ = "select sum(IntPrimitive) as c0, count(*) as c1 " + "from SupportBean_S0 unidirectional " + "inner join " + "SupportBean#keepall"; EPStatement stmtIJ = _epService.EPAdministrator.CreateEPL(stmtTextIJ); stmtIJ.Events += _listener.Update; _epService.EPRuntime.SendEvent(new SupportBean_S0(1, "S0_1")); _epService.EPRuntime.SendEvent(new SupportBean("E1", 100)); Assert.IsFalse(_listener.IsInvoked); _epService.EPRuntime.SendEvent(new SupportBean_S0(2, "S0_2")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsIJ, new Object[] { 100, 1L }); _epService.EPRuntime.SendEvent(new SupportBean("E2", 200)); _epService.EPRuntime.SendEvent(new SupportBean_S0(3, "S0_3")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fieldsIJ, new Object[] { 300, 2L }); stmtIJ.Dispose(); // test 2-stream inner join with group-by RunAssertion2StreamInnerWGroupBy(); // test 3-stream inner join // String[] fields3IJ = "c0,c1".Split(','); String stmtText3IJ = "select sum(IntPrimitive) as c0, count(*) as c1 " + "from " + "SupportBean_S0#keepall " + "inner join " + "SupportBean_S1#keepall " + "inner join " + "SupportBean#keepall"; EPStatement stmt3IJ = _epService.EPAdministrator.CreateEPL(stmtText3IJ); stmt3IJ.Events += _listener.Update; _epService.EPRuntime.SendEvent(new SupportBean_S0(1, "S0_1")); _epService.EPRuntime.SendEvent(new SupportBean("E1", 50)); Assert.IsFalse(_listener.IsInvoked); _epService.EPRuntime.SendEvent(new SupportBean_S1(10, "S1_1")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields3IJ, new Object[] { 50, 1L }); _epService.EPRuntime.SendEvent(new SupportBean("E2", 51)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields3IJ, new Object[] { 101, 2L }); stmt3IJ.Dispose(); // test 3-stream full outer join // String[] fields3FOJ = "P00,P10,TheString".Split(','); String stmtText3FOJ = "select P00, P10, TheString " + "from " + "SupportBean_S0#keepall " + "full outer join " + "SupportBean_S1#keepall " + "full outer join " + "SupportBean#keepall"; EPStatement stmt3FOJ = _epService.EPAdministrator.CreateEPL(stmtText3FOJ); stmt3FOJ.Events += _listener.Update; _epService.EPRuntime.SendEvent(new SupportBean_S0(1, "S0_1")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields3FOJ, new Object[] { "S0_1", null, null }); _epService.EPRuntime.SendEvent(new SupportBean("E10", 0)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields3FOJ, new Object[] { null, null, "E10" }); _epService.EPRuntime.SendEvent(new SupportBean_S0(2, "S0_2")); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetLastNewData(), fields3FOJ, new Object[][] { new Object[] { "S0_2", null, null } }); _epService.EPRuntime.SendEvent(new SupportBean_S1(1, "S1_0")); EPAssertionUtil.AssertPropsPerRowAnyOrder(_listener.GetAndResetLastNewData(), fields3FOJ, new Object[][] { new Object[] { "S0_1", "S1_0", "E10" }, new Object[] { "S0_2", "S1_0", "E10" } }); _epService.EPRuntime.SendEvent(new SupportBean_S0(2, "S0_3")); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetLastNewData(), fields3FOJ, new Object[][] { new Object[] { "S0_3", "S1_0", "E10" } }); _epService.EPRuntime.SendEvent(new SupportBean("E11", 0)); EPAssertionUtil.AssertPropsPerRowAnyOrder(_listener.GetAndResetLastNewData(), fields3FOJ, new Object[][] { new Object[] { "S0_1", "S1_0", "E11" }, new Object[] { "S0_2", "S1_0", "E11" }, new Object[] { "S0_3", "S1_0", "E11" } }); Assert.AreEqual(6, EPAssertionUtil.EnumeratorCount(stmt3FOJ.GetEnumerator())); stmt3FOJ.Dispose(); // test 3-stream full outer join with where-clause // String[] fields3FOJW = "P00,P10,TheString".Split(','); String stmtText3FOJW = "select P00, P10, TheString " + "from " + "SupportBean_S0#keepall as s0 " + "full outer join " + "SupportBean_S1#keepall as s1 " + "full outer join " + "SupportBean#keepall as sb " + "where s0.P00 = s1.P10"; EPStatement stmt3FOJW = _epService.EPAdministrator.CreateEPL(stmtText3FOJW); stmt3FOJW.Events += _listener.Update; _epService.EPRuntime.SendEvent(new SupportBean_S0(1, "X1")); Assert.IsFalse(_listener.IsInvoked); _epService.EPRuntime.SendEvent(new SupportBean_S1(1, "Y1")); Assert.IsFalse(_listener.IsInvoked); _epService.EPRuntime.SendEvent(new SupportBean_S0(1, "Y1")); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields3FOJW, new Object[] { "Y1", "Y1", null }); }
public void Run(RegressionEnvironment env) { var epl = "@Name('s0') select irstream * from SupportBean#sort(3, IntPrimitive desc, LongPrimitive)"; env.CompileDeployAddListenerMileZero(epl, "s0"); var fields = new[] {"TheString", "IntPrimitive", "LongPrimitive"}; env.SendEventBean(MakeEvent("E1", 100, 0L)); EPAssertionUtil.AssertProps( env.Listener("s0").AssertOneGetNewAndReset(), fields, new object[] {"E1", 100, 0L}); EPAssertionUtil.AssertPropsPerRow( env.Statement("s0").GetEnumerator(), fields, new[] {new object[] {"E1", 100, 0L}}); env.SendEventBean(MakeEvent("E2", 99, 5L)); EPAssertionUtil.AssertProps( env.Listener("s0").AssertOneGetNewAndReset(), fields, new object[] {"E2", 99, 5L}); EPAssertionUtil.AssertPropsPerRow( env.Statement("s0").GetEnumerator(), fields, new[] {new object[] {"E1", 100, 0L}, new object[] {"E2", 99, 5L}}); env.SendEventBean(MakeEvent("E3", 100, -1L)); EPAssertionUtil.AssertProps( env.Listener("s0").AssertOneGetNewAndReset(), fields, new object[] {"E3", 100, -1L}); EPAssertionUtil.AssertPropsPerRow( env.Statement("s0").GetEnumerator(), fields, new[] {new object[] {"E3", 100, -1L}, new object[] {"E1", 100, 0L}, new object[] {"E2", 99, 5L}}); env.SendEventBean(MakeEvent("E4", 100, 1L)); EPAssertionUtil.AssertProps( env.Listener("s0").AssertPairGetIRAndReset(), fields, new object[] {"E4", 100, 1L}, new object[] {"E2", 99, 5L}); EPAssertionUtil.AssertPropsPerRow( env.Statement("s0").GetEnumerator(), fields, new[] {new object[] {"E3", 100, -1L}, new object[] {"E1", 100, 0L}, new object[] {"E4", 100, 1L}}); env.SendEventBean(MakeEvent("E5", 101, 10L)); EPAssertionUtil.AssertProps( env.Listener("s0").AssertPairGetIRAndReset(), fields, new object[] {"E5", 101, 10L}, new object[] {"E4", 100, 1L}); EPAssertionUtil.AssertPropsPerRow( env.Statement("s0").GetEnumerator(), fields, new[] {new object[] {"E5", 101, 10L}, new object[] {"E3", 100, -1L}, new object[] {"E1", 100, 0L}}); env.SendEventBean(MakeEvent("E6", 101, 11L)); EPAssertionUtil.AssertProps( env.Listener("s0").AssertPairGetIRAndReset(), fields, new object[] {"E6", 101, 11L}, new object[] {"E1", 100, 0L}); EPAssertionUtil.AssertPropsPerRow( env.Statement("s0").GetEnumerator(), fields, new[] { new object[] {"E5", 101, 10L}, new object[] {"E6", 101, 11L}, new object[] {"E3", 100, -1L} }); env.SendEventBean(MakeEvent("E6", 100, 0L)); EPAssertionUtil.AssertProps( env.Listener("s0").AssertPairGetIRAndReset(), fields, new object[] {"E6", 100, 0L}, new object[] {"E6", 100, 0L}); EPAssertionUtil.AssertPropsPerRow( env.Statement("s0").GetEnumerator(), fields, new[] { new object[] {"E5", 101, 10L}, new object[] {"E6", 101, 11L}, new object[] {"E3", 100, -1L} }); env.UndeployAll(); }
public void Run(RegressionEnvironment env) { var fields = new[] {"TheString", "IntPrimitive"}; var epl = "@Name('s0') select irstream * from SupportBean#sort(3, TheString)"; env.CompileDeployAddListenerMileZero(epl, "s0"); EPAssertionUtil.AssertPropsPerRow(env.GetEnumerator("s0"), fields, null); SendSupportBean(env, "G", 1); EPAssertionUtil.AssertProps( env.Listener("s0").AssertOneGetNewAndReset(), fields, new object[] {"G", 1}); env.Milestone(1); EPAssertionUtil.AssertPropsPerRow( env.GetEnumerator("s0"), fields, new[] {new object[] {"G", 1}}); SendSupportBean(env, "E", 2); EPAssertionUtil.AssertProps( env.Listener("s0").AssertOneGetNewAndReset(), fields, new object[] {"E", 2}); env.Milestone(2); EPAssertionUtil.AssertPropsPerRow( env.GetEnumerator("s0"), fields, new[] {new object[] {"E", 2}, new object[] {"G", 1}}); SendSupportBean(env, "H", 3); EPAssertionUtil.AssertProps( env.Listener("s0").AssertOneGetNewAndReset(), fields, new object[] {"H", 3}); env.Milestone(3); EPAssertionUtil.AssertPropsPerRow( env.GetEnumerator("s0"), fields, new[] {new object[] {"E", 2}, new object[] {"G", 1}, new object[] {"H", 3}}); SendSupportBean(env, "I", 4); EPAssertionUtil.AssertProps( env.Listener("s0").AssertGetAndResetIRPair(), fields, new object[] {"I", 4}, new object[] {"I", 4}); env.Milestone(4); EPAssertionUtil.AssertPropsPerRow( env.GetEnumerator("s0"), fields, new[] {new object[] {"E", 2}, new object[] {"G", 1}, new object[] {"H", 3}}); SendSupportBean(env, "A", 5); EPAssertionUtil.AssertProps( env.Listener("s0").AssertGetAndResetIRPair(), fields, new object[] {"A", 5}, new object[] {"H", 3}); env.Milestone(5); EPAssertionUtil.AssertPropsPerRow( env.GetEnumerator("s0"), fields, new[] {new object[] {"A", 5}, new object[] {"E", 2}, new object[] {"G", 1}}); SendSupportBean(env, "C", 6); EPAssertionUtil.AssertProps( env.Listener("s0").AssertGetAndResetIRPair(), fields, new object[] {"C", 6}, new object[] {"G", 1}); env.Milestone(6); EPAssertionUtil.AssertPropsPerRow( env.GetEnumerator("s0"), fields, new[] {new object[] {"A", 5}, new object[] {"C", 6}, new object[] {"E", 2}}); SendSupportBean(env, "C", 7); EPAssertionUtil.AssertProps( env.Listener("s0").AssertGetAndResetIRPair(), fields, new object[] {"C", 7}, new object[] {"E", 2}); env.Milestone(7); EPAssertionUtil.AssertPropsPerRow( env.GetEnumerator("s0"), fields, new[] {new object[] {"A", 5}, new object[] {"C", 7}, new object[] {"C", 6}}); SendSupportBean(env, "C", 8); EPAssertionUtil.AssertProps( env.Listener("s0").AssertGetAndResetIRPair(), fields, new object[] {"C", 8}, new object[] {"C", 6}); EPAssertionUtil.AssertPropsPerRow( env.GetEnumerator("s0"), fields, new[] {new object[] {"A", 5}, new object[] {"C", 8}, new object[] {"C", 7}}); env.UndeployAll(); }
public void TestAggregation() { String[] fields = new String[] { "TheString" }; // Test un-grouped EPStatement stmtUngrouped = _epService.EPAdministrator.CreateEPL("select irstream TheString from SupportBean.win:expr_batch(sum(IntPrimitive) > 100)"); stmtUngrouped.Events += _listener.Update; _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); _epService.EPRuntime.SendEvent(new SupportBean("E2", 90)); Assert.IsFalse(_listener.IsInvoked); _epService.EPRuntime.SendEvent(new SupportBean("E3", 10)); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E1" }, new Object[] { "E2" }, new Object[] { "E3" } }, null); _epService.EPRuntime.SendEvent(new SupportBean("E4", 101)); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E4" } }, new Object[][] { new Object[] { "E1" }, new Object[] { "E2" }, new Object[] { "E3" } }); _epService.EPRuntime.SendEvent(new SupportBean("E5", 1)); _epService.EPRuntime.SendEvent(new SupportBean("E6", 99)); Assert.IsFalse(_listener.IsInvoked); _epService.EPRuntime.SendEvent(new SupportBean("E7", 1)); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E5" }, new Object[] { "E6" }, new Object[] { "E7" } }, new Object[][] { new Object[] { "E4" } }); stmtUngrouped.Dispose(); // Test grouped EPStatement stmtGrouped = _epService.EPAdministrator.CreateEPL("select irstream TheString from SupportBean.std:groupwin(IntPrimitive).win:expr_batch(sum(LongPrimitive) > 100)"); stmtGrouped.Events += _listener.Update; SendEvent("E1", 1, 10); SendEvent("E2", 2, 10); SendEvent("E3", 1, 90); SendEvent("E4", 2, 80); SendEvent("E5", 2, 10); Assert.IsFalse(_listener.IsInvoked); SendEvent("E6", 2, 1); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E2" }, new Object[] { "E4" }, new Object[] { "E5" }, new Object[] { "E6" } }, null); SendEvent("E7", 2, 50); Assert.IsFalse(_listener.IsInvoked); SendEvent("E8", 1, 2); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E1" }, new Object[] { "E3" }, new Object[] { "E8" } }, null); SendEvent("E9", 2, 50); SendEvent("E10", 1, 101); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E10" } }, new Object[][] { new Object[] { "E1" }, new Object[] { "E3" }, new Object[] { "E8" } }); SendEvent("E11", 2, 1); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E7" }, new Object[] { "E9" }, new Object[] { "E11" } }, new Object[][] { new Object[] { "E2" }, new Object[] { "E4" }, new Object[] { "E5" }, new Object[] { "E6" } }); SendEvent("E12", 1, 102); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E12" } }, new Object[][] { new Object[] { "E10" } }); stmtGrouped.Dispose(); // Test on-delete _epService.EPAdministrator.Configuration.AddEventType <SupportBean_A>(); EPStatement stmt = _epService.EPAdministrator.CreateEPL("create window NW.win:expr_batch(sum(IntPrimitive) >= 10) as SupportBean"); stmt.Events += _listener.Update; _epService.EPAdministrator.CreateEPL("insert into NW select * from SupportBean"); _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); _epService.EPRuntime.SendEvent(new SupportBean("E2", 8)); _epService.EPAdministrator.CreateEPL("on SupportBean_A delete from NW where TheString = id"); _epService.EPRuntime.SendEvent(new SupportBean_A("E2")); _epService.EPRuntime.SendEvent(new SupportBean("E3", 8)); Assert.IsFalse(_listener.IsInvoked); _epService.EPRuntime.SendEvent(new SupportBean("E4", 1)); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E1" }, new Object[] { "E3" }, new Object[] { "E4" } }, null); }
public void Run(RegressionEnvironment env) { // Could have also used a mapping event however here we uses fire-and-forget to load the mapping instead: // @public @buseventtype create schema MappingEvent(foreignSymbol string, localSymbol string); // on MappingEvent merge Mapping insert select foreignSymbol, localSymbol; // The events are: // MappingEvent={foreignSymbol="ABC", localSymbol="123"} // MappingEvent={foreignSymbol="DEF", localSymbol="456"} // MappingEvent={foreignSymbol="GHI", localSymbol="789"} // MappingEvent={foreignSymbol="JKL", localSymbol="666"} // ForeignSymbols={companies={{symbol='ABC', value=500}, {symbol='DEF', value=300}, {symbol='JKL', value=400}}} // LocalSymbols={companies={{symbol='123', value=600}, {symbol='456', value=100}, {symbol='789', value=200}}} var path = new RegressionPath(); var epl = "create schema Symbol(symbol string, value double);\n" + "@public @buseventtype create schema ForeignSymbols(companies Symbol[]);\n" + "@public @buseventtype create schema LocalSymbols(companies Symbol[]);\n" + "\n" + "create table Mapping(foreignSymbol string primary key, localSymbol string primary key);\n" + "create index MappingIndexForeignSymbol on Mapping(foreignSymbol);\n" + "create index MappingIndexLocalSymbol on Mapping(localSymbol);\n" + "\n" + "insert into SymbolsPair select * from ForeignSymbols#lastevent as foreign, LocalSymbols#lastevent as local;\n" + "on SymbolsPair\n" + " insert into SymbolsPairBeginEvent select null\n" + " insert into ForeignSymbolRow select * from [foreign.companies]\n" + " insert into LocalSymbolRow select * from [local.companies]\n" + " insert into SymbolsPairOutputEvent select null" + " insert into SymbolsPairEndEvent select null" + " output all;\n" + "\n" + "create context SymbolsPairContext start SymbolsPairBeginEvent end SymbolsPairEndEvent;\n" + "context SymbolsPairContext create table Result(foreignSymbol string primary key, localSymbol string primary key, value double);\n" + "\n" + "context SymbolsPairContext on ForeignSymbolRow as fsr merge Result as result where result.foreignSymbol = fsr.symbol\n" + " when not matched then insert select fsr.symbol as foreignSymbol,\n" + " (select localSymbol from Mapping as mapping where mapping.foreignSymbol = fsr.symbol) as localSymbol, fsr.value as value\n" + " when matched and fsr.value > result.value then update set value = fsr.value;\n" + "\n" + "context SymbolsPairContext on LocalSymbolRow as lsr merge Result as result where result.localSymbol = lsr.symbol\n" + " when not matched then insert select (select foreignSymbol from Mapping as mapping where mapping.localSymbol = lsr.symbol) as foreignSymbol," + " lsr.symbol as localSymbol, lsr.value as value\n" + " when matched and lsr.value > result.value then update set value = lsr.value;\n" + "\n" + "@Name('out') context SymbolsPairContext on SymbolsPairOutputEvent select foreignSymbol, localSymbol, value from Result order by foreignSymbol asc;\n"; env.CompileDeploy(epl, path).AddListener("out"); // load mapping table var compiledFAF = env.CompileFAF("insert into Mapping select ?::string as foreignSymbol, ?::string as localSymbol", path); var preparedFAF = env.Runtime.FireAndForgetService.PrepareQueryWithParameters(compiledFAF); LoadMapping(env, preparedFAF, "ABC", "123"); LoadMapping(env, preparedFAF, "DEF", "456"); LoadMapping(env, preparedFAF, "GHI", "789"); LoadMapping(env, preparedFAF, "JKL", "666"); SendForeignSymbols(env, "ABC=500,DEF=300,JKL=400"); SendLocalSymbols(env, "123=600,456=100,789=200"); var results = env.Listener("out").GetAndResetLastNewData(); EPAssertionUtil.AssertPropsPerRow( results, "foreignSymbol,localSymbol,value".SplitCsv(), new object[][] { new object[] {"ABC", "123", 600d}, new object[] {"DEF", "456", 300d}, new object[] {"GHI", "789", 200d}, new object[] {"JKL", "666", 400d} }); env.UndeployAll(); }
public void Run(RegressionEnvironment env) { var stmtText = "@Name('s0') select OrderId, Book.BookId,Item.ItemId from MediaOrder[Books.Book] as Book" + " full outer join MediaOrder[select OrderId, * from Items.Item] as Item on ProductId = BookId" + " order by BookId, Item.ItemId asc"; env.CompileDeploy(stmtText).AddListener("s0"); var fields = new [] { "Book.BookId","Item.ItemId" }; env.SendEventXMLDOM(eventDocTwo, "MediaOrder"); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new[] { new object[] {null, "200003"}, new object[] {"B005", "200002"}, new object[] {"B005", "200004"}, new object[] {"B006", "200001"}, new object[] {"B008", null} }); env.SendEventXMLDOM(eventDocOne, "MediaOrder"); PrintRows(env, env.Listener("s0").LastNewData); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new[] {new object[] {"B001", "100001"}, new object[] {"B002", null}}); // count env.UndeployAll(); fields = new [] { "count(*)" }; stmtText = "@Name('s0') select count(*) from MediaOrder[Books.Book] as Book" + " full outer join MediaOrder[Items.Item] as Item on ProductId = BookId"; env.CompileDeploy(stmtText).AddListener("s0"); env.SendEventXMLDOM(eventDocTwo, "MediaOrder"); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new[] {new object[] {5L}}); env.SendEventXMLDOM(eventDocOne, "MediaOrder"); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new[] {new object[] {7L}}); // unidirectional count env.UndeployAll(); stmtText = "@Name('s0') select count(*) from MediaOrder[Books.Book] as Book unidirectional" + " full outer join MediaOrder[Items.Item] as Item on ProductId = BookId"; env.CompileDeploy(stmtText).AddListener("s0"); env.SendEventXMLDOM(eventDocTwo, "MediaOrder"); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new[] {new object[] {4L}}); env.SendEventXMLDOM(eventDocOne, "MediaOrder"); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new[] {new object[] {2L}}); env.UndeployAll(); }
private void RunAssertionSingleRowSplitAndType(EventRepresentationEnum eventRepresentationEnum) { if (eventRepresentationEnum.IsObjectArrayEvent()) { _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("splitSentence", GetType().FullName, "SplitSentenceMethodReturnObjectArray"); _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("splitSentenceBean", GetType().FullName, "SplitSentenceBeanMethodReturnObjectArray"); _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("splitWord", GetType().FullName, "SplitWordMethodReturnObjectArray"); } else { _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("splitSentence", GetType().FullName, "SplitSentenceMethodReturnMap"); _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("splitSentenceBean", GetType().FullName, "SplitSentenceBeanMethodReturnMap"); _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("splitWord", GetType().FullName, "SplitWordMethodReturnMap"); } _epService.EPAdministrator.Configuration.AddPlugInSingleRowFunction("invalidSentence", GetType().FullName, "InvalidSentenceMethod"); _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema SentenceEvent(sentence String)"); _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema WordEvent(word String)"); _epService.EPAdministrator.CreateEPL(eventRepresentationEnum.GetAnnotationText() + " create schema CharacterEvent(char String)"); string stmtText; EPStatement stmt; var fields = "word".Split(','); // test single-row method stmtText = "select * from SentenceEvent[splitSentence(sentence)@type(WordEvent)]"; stmt = _epService.EPAdministrator.CreateEPL(stmtText); stmt.AddListener(_listener); Assert.AreEqual("WordEvent", stmt.EventType.Name); Assert.AreEqual(eventRepresentationEnum.GetOutputClass(), stmt.EventType.UnderlyingType); SendSentenceEvent(eventRepresentationEnum, "I am testing this code"); EPAssertionUtil.AssertPropsPerRow( _listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "I" }, new object[] { "am" }, new object[] { "testing" }, new object[] { "this" }, new object[] { "code" } }); SendSentenceEvent(eventRepresentationEnum, "the second event"); EPAssertionUtil.AssertPropsPerRow( _listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "the" }, new object[] { "second" }, new object[] { "event" } }); stmt.Dispose(); // test SODA var model = _epService.EPAdministrator.CompileEPL(stmtText); Assert.AreEqual(stmtText, model.ToEPL()); stmt = _epService.EPAdministrator.Create(model); Assert.AreEqual(stmtText, stmt.Text); stmt.AddListener(_listener); SendSentenceEvent(eventRepresentationEnum, "the third event"); EPAssertionUtil.AssertPropsPerRow( _listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "the" }, new object[] { "third" }, new object[] { "event" } }); stmt.Dispose(); // test script if (!eventRepresentationEnum.IsObjectArrayEvent()) { stmtText = "expression com.espertech.esper.support.collections.ISupportDataMapCollection js:splitSentenceJS(sentence) [" + " var words = clr.New('com.espertech.esper.support.collections.SupportDataMapList',[]);" + " var factory = clr.New('com.espertech.esper.support.collections.SupportDataMapFactory',[]);" + " words.Add(factory.Create('word', 'wordOne'));" + " words.Add(factory.Create('word', 'wordTwo'));" + " words;" + "]" + "select * from SentenceEvent[splitSentenceJS(sentence)@type(WordEvent)]"; stmt = _epService.EPAdministrator.CreateEPL(stmtText).AddListener(_listener); Assert.AreEqual("WordEvent", stmt.EventType.Name); _epService.EPRuntime.SendEvent(Collections.EmptyDataMap, "SentenceEvent"); EPAssertionUtil.AssertPropsPerRowAnyOrder( _listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "wordOne" }, new object[] { "wordTwo" } }); stmt.Dispose(); } // test multiple splitters stmtText = "select * from SentenceEvent[splitSentence(sentence)@type(WordEvent)][splitWord(word)@type(CharacterEvent)]"; stmt = _epService.EPAdministrator.CreateEPL(stmtText); stmt.AddListener(_listener); Assert.AreEqual("CharacterEvent", stmt.EventType.Name); SendSentenceEvent(eventRepresentationEnum, "I am"); EPAssertionUtil.AssertPropsPerRowAnyOrder( _listener.GetAndResetLastNewData(), "char".Split(','), new object[][] { new object[] { "I" }, new object[] { "a" }, new object[] { "m" } }); stmt.Dispose(); // test wildcard parameter stmtText = "select * from SentenceEvent[splitSentenceBean(*)@type(WordEvent)]"; stmt = _epService.EPAdministrator.CreateEPL(stmtText); stmt.AddListener(_listener); Assert.AreEqual("WordEvent", stmt.EventType.Name); SendSentenceEvent(eventRepresentationEnum, "another test sentence"); EPAssertionUtil.AssertPropsPerRowAnyOrder( _listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "another" }, new object[] { "test" }, new object[] { "sentence" } }); stmt.Dispose(); // test property returning untyped collection if (eventRepresentationEnum.IsObjectArrayEvent()) { _epService.EPAdministrator.Configuration.AddEventType(typeof(ObjectArrayEvent)); stmtText = eventRepresentationEnum.GetAnnotationText() + " select * from ObjectArrayEvent[someObjectArray@type(WordEvent)]"; stmt = _epService.EPAdministrator.CreateEPL(stmtText); stmt.AddListener(_listener); Assert.AreEqual("WordEvent", stmt.EventType.Name); var rows = new object[][] { new object[] { "this" }, new object[] { "is" }, new object[] { "collection" } }; _epService.EPRuntime.SendEvent(new ObjectArrayEvent(rows)); EPAssertionUtil.AssertPropsPerRow( _listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "this" }, new object[] { "is" }, new object[] { "collection" } }); } else { _epService.EPAdministrator.Configuration.AddEventType <CollectionEvent <IDictionary <string, object> > >("CollectionEvent"); stmtText = eventRepresentationEnum.GetAnnotationText() + " select * from CollectionEvent[someCollection@type(WordEvent)]"; stmt = _epService.EPAdministrator.CreateEPL(stmtText); stmt.AddListener(_listener); Assert.AreEqual("WordEvent", stmt.EventType.Name); var coll = new List <IDictionary <string, object> >(); coll.Add(Collections.SingletonDataMap("word", "this")); coll.Add(Collections.SingletonDataMap("word", "is")); coll.Add(Collections.SingletonDataMap("word", "collection")); _epService.EPRuntime.SendEvent(new CollectionEvent <IDictionary <string, object> >(coll)); EPAssertionUtil.AssertPropsPerRowAnyOrder( _listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "this" }, new object[] { "is" }, new object[] { "collection" } }); } // invalid: event type not found TryInvalid("select * from SentenceEvent[splitSentence(sentence)@type(XYZ)]", "Event type by name 'XYZ' could not be found [select * from SentenceEvent[splitSentence(sentence)@type(XYZ)]]"); // invalid lib-function annotation TryInvalid("select * from SentenceEvent[splitSentence(sentence)@dummy(WordEvent)]", "Invalid annotation for property selection, expected 'type' but found 'dummy' in text '[splitSentence(sentence)@dummy(WordEvent)]' [select * from SentenceEvent[splitSentence(sentence)@dummy(WordEvent)]]"); // invalid type assignment to event type if (eventRepresentationEnum.IsObjectArrayEvent()) { TryInvalid("select * from SentenceEvent[invalidSentence(sentence)@type(WordEvent)]", "Event type 'WordEvent' underlying type System.Object[] cannot be assigned a value of type"); } else { TryInvalid("select * from SentenceEvent[invalidSentence(sentence)@type(WordEvent)]", "Event type 'WordEvent' underlying type " + Name.Of <IDictionary <string, object> >() + " cannot be assigned a value of type"); } // invalid subquery TryInvalid("select * from SentenceEvent[splitSentence((select * from SupportBean.win:keepall()))@type(WordEvent)]", "Invalid contained-event expression 'splitSentence(subselect_0)': Aggregation, sub-select, previous or prior functions are not supported in this context [select * from SentenceEvent[splitSentence((select * from SupportBean.win:keepall()))@type(WordEvent)]]"); _epService.Initialize(); }
private void RunAssertion(bool useDefault, bool?preserve, ConfigurationEngineDefaults.Threading.Locking?locking) { var config = SupportConfigFactory.GetConfiguration(); if (!useDefault) { config.EngineDefaults.ThreadingConfig.IsNamedWindowConsumerDispatchPreserveOrder = preserve.GetValueOrDefault(); config.EngineDefaults.ThreadingConfig.NamedWindowConsumerDispatchLocking = locking.GetValueOrDefault(); } var epService = EPServiceProviderManager.GetDefaultProvider(config); epService.Initialize(); var listener = new SupportUpdateListener(); var fields = "company,value,total".Split(','); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(epService, this.GetType(), this.GetType().FullName); } // ESPER-568 epService.EPAdministrator.CreateEPL("create schema S2 ( company string, value double, total double)"); var stmtWin = epService.EPAdministrator.CreateEPL("create window S2Win.win:time(25 hour).std:firstunique(company) as S2"); epService.EPAdministrator.CreateEPL("insert into S2Win select * from S2.std:firstunique(company)"); epService.EPAdministrator.CreateEPL("on S2 as a update S2Win as b set total = b.value + a.value"); var stmt = epService.EPAdministrator.CreateEPL("select count(*) as cnt from S2Win"); stmt.AddListener(listener); CreateSendEvent(epService, "S2", "AComp", 3.0, 0.0); Assert.AreEqual(1L, listener.AssertOneGetNewAndReset().Get("cnt")); EPAssertionUtil.AssertPropsPerRow(stmtWin.GetEnumerator(), fields, new object[][] { new object[] { "AComp", 3.0, 0.0 } }); CreateSendEvent(epService, "S2", "AComp", 6.0, 0.0); Assert.AreEqual(1L, listener.AssertOneGetNewAndReset().Get("cnt")); EPAssertionUtil.AssertPropsPerRow(stmtWin.GetEnumerator(), fields, new object[][] { new object[] { "AComp", 3.0, 9.0 } }); CreateSendEvent(epService, "S2", "AComp", 5.0, 0.0); Assert.AreEqual(1L, listener.AssertOneGetNewAndReset().Get("cnt")); EPAssertionUtil.AssertPropsPerRow(stmtWin.GetEnumerator(), fields, new object[][] { new object[] { "AComp", 3.0, 8.0 } }); CreateSendEvent(epService, "S2", "BComp", 4.0, 0.0); // this example does not have @priority thereby it is undefined whether there are two counts delivered or one if (listener.LastNewData.Length == 2) { Assert.AreEqual(1L, listener.LastNewData[0].Get("cnt")); Assert.AreEqual(2L, listener.LastNewData[1].Get("cnt")); } else { Assert.AreEqual(2L, listener.AssertOneGetNewAndReset().Get("cnt")); } EPAssertionUtil.AssertPropsPerRow(stmtWin.GetEnumerator(), fields, new object[][] { new object[] { "AComp", 3.0, 7.0 }, new object[] { "BComp", 4.0, 0.0 } }); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
private void RunAssertionSelectIndexChoice(bool namedWindow) { var preloadedEventsOne = new object[] { new SupportSimpleBeanOne("E1", 10, 11, 12), new SupportSimpleBeanOne("E2", 20, 21, 22) }; IndexAssertionFAF fafAssertion = (result) => { var fields = "s1,i1".Split(','); EPAssertionUtil.AssertPropsPerRow(result.Array, fields, new object[][] { new object[] { "E2", 20 } }); }; // single index one field (plus declared unique) var noindexes = new string[0]; AssertIndexChoice(namedWindow, noindexes, preloadedEventsOne, "std:unique(s1)", new IndexAssertion[] { new IndexAssertion(null, "s1 = 'E2'", null, null, fafAssertion), new IndexAssertion(null, "s1 = 'E2' and l1 = 22", null, null, fafAssertion), new IndexAssertion("@Hint('index(One)')", "s1 = 'E2' and l1 = 22", null, null, fafAssertion), new IndexAssertion("@Hint('index(Two,bust)')", "s1 = 'E2' and l1 = 22"), // should bust }); // single index one field (plus declared unique) var indexOneField = new string[] { "create unique index One on MyInfra (s1)" }; AssertIndexChoice(namedWindow, indexOneField, preloadedEventsOne, "std:unique(s1)", new IndexAssertion[] { new IndexAssertion(null, "s1 = 'E2'", "One", BACKING_SINGLE_UNIQUE, fafAssertion), new IndexAssertion(null, "s1 in ('E2')", "One", BACKING_SINGLE_UNIQUE, fafAssertion), new IndexAssertion(null, "s1 = 'E2' and l1 = 22", "One", BACKING_SINGLE_UNIQUE, fafAssertion), new IndexAssertion("@Hint('index(One)')", "s1 = 'E2' and l1 = 22", "One", BACKING_SINGLE_UNIQUE, fafAssertion), new IndexAssertion("@Hint('index(Two,bust)')", "s1 = 'E2' and l1 = 22"), // should bust }); // single index two field (plus declared unique) var indexTwoField = new string[] { "create unique index One on MyInfra (s1, l1)" }; AssertIndexChoice(namedWindow, indexTwoField, preloadedEventsOne, "std:unique(s1)", new IndexAssertion[] { new IndexAssertion(null, "s1 = 'E2'", null, null, fafAssertion), new IndexAssertion(null, "s1 = 'E2' and l1 = 22", "One", BACKING_MULTI_UNIQUE, fafAssertion), }); // two index one unique (plus declared unique) var indexSetTwo = new string[] { "create index One on MyInfra (s1)", "create unique index Two on MyInfra (s1, d1)" }; AssertIndexChoice(namedWindow, indexSetTwo, preloadedEventsOne, "std:unique(s1)", new IndexAssertion[] { new IndexAssertion(null, "s1 = 'E2'", "One", BACKING_SINGLE_DUPS, fafAssertion), new IndexAssertion(null, "s1 = 'E2' and l1 = 22", "One", BACKING_SINGLE_DUPS, fafAssertion), new IndexAssertion("@Hint('index(One)')", "s1 = 'E2' and l1 = 22", "One", BACKING_SINGLE_DUPS, fafAssertion), new IndexAssertion("@Hint('index(Two,One)')", "s1 = 'E2' and l1 = 22", "One", BACKING_SINGLE_DUPS, fafAssertion), new IndexAssertion("@Hint('index(Two,bust)')", "s1 = 'E2' and l1 = 22"), // busted new IndexAssertion("@Hint('index(explicit,bust)')", "s1 = 'E2' and l1 = 22", "One", BACKING_SINGLE_DUPS, fafAssertion), new IndexAssertion(null, "s1 = 'E2' and d1 = 21 and l1 = 22", "Two", BACKING_MULTI_UNIQUE, fafAssertion), new IndexAssertion("@Hint('index(explicit,bust)')", "d1 = 22 and l1 = 22"), // busted }); // range (unique) var indexSetThree = new string[] { "create index One on MyInfra (l1 btree)", "create index Two on MyInfra (d1 btree)" }; AssertIndexChoice(namedWindow, indexSetThree, preloadedEventsOne, "std:unique(s1)", new IndexAssertion[] { new IndexAssertion(null, "l1 between 22 and 23", "One", BACKING_SORTED_COERCED, fafAssertion), new IndexAssertion(null, "d1 between 21 and 22", "Two", BACKING_SORTED_COERCED, fafAssertion), new IndexAssertion("@Hint('index(One, bust)')", "d1 between 21 and 22"), // busted }); }
public void Run(RegressionEnvironment env) { var text = "@Name('s0') select * from SupportRecogBean#keepall " + "match_recognize (" + " partition by Cat" + " measures A.Cat as Cat, A.TheString as a_string, " + " D.TheString as d_string, " + " sum(C.Value) as sumc, " + " sum(B.Value) as sumb, " + " sum(B.Value + A.Value) as sumaplusb, " + " sum(C.Value + A.Value) as sumaplusc " + " all matches pattern (A B B C C D) " + " define " + " A as (A.Value >= 10)," + " B as (B.Value > 1)," + " C as (C.Value < -1)," + " D as (D.Value = 999)" + ") order by Cat"; env.CompileDeploy(text).AddListener("s0"); var fields = new [] { "a_string","d_string","sumb","sumc","sumaplusb","sumaplusc" }; env.SendEventBean(new SupportRecogBean("E1", "x", 10)); env.SendEventBean(new SupportRecogBean("E2", "y", 20)); env.Milestone(0); env.SendEventBean(new SupportRecogBean("E3", "x", 7)); // B env.SendEventBean(new SupportRecogBean("E4", "y", 5)); env.SendEventBean(new SupportRecogBean("E5", "x", 8)); env.SendEventBean(new SupportRecogBean("E6", "y", 2)); env.Milestone(1); env.SendEventBean(new SupportRecogBean("E7", "x", -2)); // C env.SendEventBean(new SupportRecogBean("E8", "y", -7)); env.SendEventBean(new SupportRecogBean("E9", "x", -5)); env.SendEventBean(new SupportRecogBean("E10", "y", -4)); env.Milestone(2); env.SendEventBean(new SupportRecogBean("E11", "y", 999)); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new[] {new object[] {"E2", "E11", 7, -11, 47, 29}}); EPAssertionUtil.AssertPropsPerRow( env.Statement("s0").GetEnumerator(), fields, new[] {new object[] {"E2", "E11", 7, -11, 47, 29}}); env.Milestone(3); env.SendEventBean(new SupportRecogBean("E12", "x", 999)); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new[] {new object[] {"E1", "E12", 15, -7, 35, 13}}); EPAssertionUtil.AssertPropsPerRow( env.Statement("s0").GetEnumerator(), fields, new[] {new object[] {"E1", "E12", 15, -7, 35, 13}, new object[] {"E2", "E11", 7, -11, 47, 29}}); env.UndeployAll(); }
private void RunAssertionSubquerySelfCheck(EPServiceProvider epService, bool namedWindow) { var fields = new string[] { "key", "value" }; // create window string stmtTextCreate = namedWindow ? "create window MyInfraSSS#keepall as select TheString as key, IntBoxed as value from " + typeof(SupportBean).FullName : "create table MyInfraSSS (key string primary key, value int)"; EPStatement stmtCreate = epService.EPAdministrator.CreateEPL(stmtTextCreate); var listenerWindow = new SupportUpdateListener(); stmtCreate.Events += listenerWindow.Update; // create insert into (not does insert if key already exists) string stmtTextInsertOne = "insert into MyInfraSSS select TheString as key, IntBoxed as value from " + typeof(SupportBean).FullName + " as s0" + " where not exists (select * from MyInfraSSS as win where win.key = s0.TheString)"; epService.EPAdministrator.CreateEPL(stmtTextInsertOne); SendSupportBean(epService, "E1", 1); if (namedWindow) { EPAssertionUtil.AssertProps(listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E1", 1 }); } else { Assert.IsFalse(listenerWindow.IsInvoked); } EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 } }); SendSupportBean(epService, "E2", 2); if (namedWindow) { EPAssertionUtil.AssertProps(listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E2", 2 }); } EPAssertionUtil.AssertPropsPerRowAnyOrder(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E2", 2 } }); SendSupportBean(epService, "E1", 3); Assert.IsFalse(listenerWindow.IsInvoked); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E2", 2 } }); SendSupportBean(epService, "E3", 4); if (namedWindow) { EPAssertionUtil.AssertProps(listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E3", 4 }); EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E2", 2 }, new object[] { "E3", 4 } }); } else { EPAssertionUtil.AssertPropsPerRowAnyOrder(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E2", 2 }, new object[] { "E3", 4 } }); } // Add delete string stmtTextDelete = "on " + typeof(SupportBean_A).FullName + " delete from MyInfraSSS where key = id"; EPStatement stmtDelete = epService.EPAdministrator.CreateEPL(stmtTextDelete); var listenerStmtDelete = new SupportUpdateListener(); stmtDelete.Events += listenerStmtDelete.Update; // delete E2 epService.EPRuntime.SendEvent(new SupportBean_A("E2")); if (namedWindow) { EPAssertionUtil.AssertProps(listenerWindow.AssertOneGetOldAndReset(), fields, new object[] { "E2", 2 }); } EPAssertionUtil.AssertPropsPerRowAnyOrder(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E3", 4 } }); SendSupportBean(epService, "E2", 5); if (namedWindow) { EPAssertionUtil.AssertProps(listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E2", 5 }); } EPAssertionUtil.AssertPropsPerRowAnyOrder(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E3", 4 }, new object[] { "E2", 5 } }); epService.EPAdministrator.DestroyAllStatements(); epService.EPAdministrator.Configuration.RemoveEventType("MyInfraSSS", false); }
public void Run(RegressionEnvironment env) { var text = "@Name('s0') select * from SupportRecogBean#keepall " + "match_recognize (" + " measures A.TheString as a_string, " + " C.TheString as c_string, " + " max(B.Value) as maxb, " + " min(B.Value) as minb, " + " 2*min(B.Value) as minb2x, " + " last(B.Value) as lastb, " + " first(B.Value) as firstb," + " count(B.Value) as countb " + " all matches pattern (A B* C) " + " define " + " A as (A.Value = 0)," + " B as (B.Value != 1)," + " C as (C.Value = 1)" + ") " + "order by a_string"; env.CompileDeploy(text).AddListener("s0"); var fields = new [] { "a_string","c_string","maxb","minb","minb2x","firstb","lastb","countb" }; env.SendEventBean(new SupportRecogBean("E1", 0)); env.SendEventBean(new SupportRecogBean("E2", 1)); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new[] {new object[] {"E1", "E2", null, null, null, null, null, 0L}}); EPAssertionUtil.AssertPropsPerRow( env.Statement("s0").GetEnumerator(), fields, new[] {new object[] {"E1", "E2", null, null, null, null, null, 0L}}); env.Milestone(0); env.SendEventBean(new SupportRecogBean("E3", 0)); env.SendEventBean(new SupportRecogBean("E4", 5)); env.Milestone(1); env.SendEventBean(new SupportRecogBean("E5", 3)); env.SendEventBean(new SupportRecogBean("E6", 1)); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new[] {new object[] {"E3", "E6", 5, 3, 6, 5, 3, 2L}}); EPAssertionUtil.AssertPropsPerRow( env.Statement("s0").GetEnumerator(), fields, new[] { new object[] {"E1", "E2", null, null, null, null, null, 0L}, new object[] {"E3", "E6", 5, 3, 6, 5, 3, 2L} }); env.Milestone(2); env.SendEventBean(new SupportRecogBean("E7", 0)); env.SendEventBean(new SupportRecogBean("E8", 4)); env.SendEventBean(new SupportRecogBean("E9", -1)); env.Milestone(3); env.SendEventBean(new SupportRecogBean("E10", 7)); env.SendEventBean(new SupportRecogBean("E11", 2)); env.SendEventBean(new SupportRecogBean("E12", 1)); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new[] {new object[] {"E7", "E12", 7, -1, -2, 4, 2, 4L}}); EPAssertionUtil.AssertPropsPerRow( env.Statement("s0").GetEnumerator(), fields, new[] { new object[] {"E1", "E2", null, null, null, null, null, 0L}, new object[] {"E3", "E6", 5, 3, 6, 5, 3, 2L}, new object[] {"E7", "E12", 7, -1, -2, 4, 2, 4L} }); env.UndeployAll(); }
private void RunAssertionLimitSnapshotJoin(EPServiceProvider epService) { var listener = new SupportUpdateListener(); SendTimer(epService, 0); string selectStmt = "select count(*) as cnt from " + typeof(SupportBean).FullName + "#time(10 seconds) as s, " + typeof(SupportMarketDataBean).FullName + "#keepall as m where m.symbol = s.TheString and IntPrimitive > 0 output snapshot every 1 seconds"; EPStatement stmt = epService.EPAdministrator.CreateEPL(selectStmt); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportMarketDataBean("s0", 0, 0L, "")); epService.EPRuntime.SendEvent(new SupportMarketDataBean("s1", 0, 0L, "")); epService.EPRuntime.SendEvent(new SupportMarketDataBean("s2", 0, 0L, "")); epService.EPRuntime.SendEvent(new SupportMarketDataBean("s4", 0, 0L, "")); epService.EPRuntime.SendEvent(new SupportMarketDataBean("s5", 0, 0L, "")); SendEvent(epService, "s0", 1); SendTimer(epService, 500); SendEvent(epService, "s1", 1); SendEvent(epService, "s2", -1); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendTimer(epService, 1000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new[] { "cnt" }, new[] { new object[] { 2L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); SendTimer(epService, 1500); SendEvent(epService, "s4", 2); SendEvent(epService, "s5", 3); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendTimer(epService, 2000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new[] { "cnt" }, new[] { new object[] { 4L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); SendEvent(epService, "s5", 4); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendTimer(epService, 9000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new[] { "cnt" }, new[] { new object[] { 5L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); // The execution of the join is after the snapshot, as joins are internal dispatch SendTimer(epService, 10000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new[] { "cnt" }, new[] { new object[] { 5L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); SendTimer(epService, 10999); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendTimer(epService, 11000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new[] { "cnt" }, new[] { new object[] { 3L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); stmt.Dispose(); }
public void Run(RegressionEnvironment env) { var fields = new[] {"Symbol"}; var text = "@Name('s0') select irstream * from SupportMarketDataBean#ext_timed(Volume, 1 sec)"; env.CompileDeployAddListenerMileZero(text, "s0"); env.SendEventBean(MakeMarketDataEvent("E1", 500)); env.Listener("s0").AssertNewOldData(new[] {new object[] {"Symbol", "E1"}}, null); env.Milestone(1); env.SendEventBean(MakeMarketDataEvent("E2", 600)); env.Listener("s0").AssertNewOldData(new[] {new object[] {"Symbol", "E2"}}, null); env.Milestone(2); env.SendEventBean(MakeMarketDataEvent("E3", 1500)); env.Listener("s0") .AssertNewOldData( new[] {new object[] {"Symbol", "E3"}}, new[] {new object[] {"Symbol", "E1"}}); env.Milestone(3); env.SendEventBean(MakeMarketDataEvent("E4", 1600)); env.Listener("s0") .AssertNewOldData( new[] {new object[] {"Symbol", "E4"}}, new[] {new object[] {"Symbol", "E2"}}); env.Milestone(4); env.SendEventBean(MakeMarketDataEvent("E5", 1700)); env.Listener("s0").AssertNewOldData(new[] {new object[] {"Symbol", "E5"}}, null); env.Milestone(5); env.SendEventBean(MakeMarketDataEvent("E6", 1800)); env.Listener("s0").AssertNewOldData(new[] {new object[] {"Symbol", "E6"}}, null); env.Milestone(6); env.SendEventBean(MakeMarketDataEvent("E7", 1900)); env.Listener("s0").AssertNewOldData(new[] {new object[] {"Symbol", "E7"}}, null); env.Milestone(7); // test iterator var events = EPAssertionUtil.EnumeratorToArray(env.GetEnumerator("s0")); EPAssertionUtil.AssertPropsPerRow( events, fields, new[] { new object[] {"E3"}, new object[] {"E4"}, new object[] {"E5"}, new object[] {"E6"}, new object[] {"E7"} }); env.SendEventBean(MakeMarketDataEvent("E8", 2700)); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").OldDataListFlattened, fields, new[] {new object[] {"E3"}, new object[] {"E4"}, new object[] {"E5"}}); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").NewDataListFlattened, fields, new[] {new object[] {"E8"}}); env.Listener("s0").Reset(); env.Milestone(8); env.SendEventBean(MakeMarketDataEvent("E9", 3700)); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").OldDataListFlattened, fields, new[] {new object[] {"E6"}, new object[] {"E7"}, new object[] {"E8"}}); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").NewDataListFlattened, fields, new[] {new object[] {"E9"}}); env.Listener("s0").Reset(); env.Milestone(9); env.UndeployAll(); }
public void Run(RegressionEnvironment env) { SendTimer(0, env); var fields = new [] { "a_string","b_string","c_string" }; var text = "@Name('s0') select * from SupportRecogBean#time(5 sec) " + "match_recognize (" + " measures A.TheString as a_string, B.TheString as b_string, C.TheString as c_string" + " all matches pattern ( A B C ) " + " define " + " A as (A.Value = 1)," + " B as (B.Value = 2)," + " C as (C.Value = 3)" + ")"; env.CompileDeploy(text).AddListener("s0"); env.Milestone(0); SendTimer(50, env); env.SendEventBean(new SupportRecogBean("E1", 1)); env.Milestone(1); SendTimer(1000, env); env.SendEventBean(new SupportRecogBean("E2", 2)); Assert.IsFalse(env.Statement("s0").GetEnumerator().MoveNext()); Assert.IsFalse(env.Listener("s0").IsInvoked); env.Milestone(2); SendTimer(6000, env); env.SendEventBean(new SupportRecogBean("E3", 3)); Assert.IsFalse(env.Statement("s0").GetEnumerator().MoveNext()); Assert.IsFalse(env.Listener("s0").IsInvoked); env.Milestone(3); SendTimer(7000, env); env.SendEventBean(new SupportRecogBean("E4", 1)); env.Milestone(4); SendTimer(8000, env); env.SendEventBean(new SupportRecogBean("E5", 2)); env.Milestone(5); SendTimer(11500, env); env.SendEventBean(new SupportRecogBean("E6", 3)); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastNewData(), fields, new[] {new object[] {"E4", "E5", "E6"}}); EPAssertionUtil.AssertPropsPerRow( env.Statement("s0").GetEnumerator(), fields, new[] {new object[] {"E4", "E5", "E6"}}); env.Milestone(6); SendTimer(11999, env); Assert.IsTrue(env.Statement("s0").GetEnumerator().MoveNext()); env.Milestone(7); SendTimer(12000, env); Assert.IsFalse(env.Statement("s0").GetEnumerator().MoveNext()); Assert.IsFalse(env.Listener("s0").IsInvoked); env.UndeployAll(); }
public void Run(RegressionEnvironment env) { var fields = new[] {"c0"}; var epl = "@Name('s0') select irstream TheString as c0 from SupportBean#ext_timed(LongPrimitive, 10 sec)"; env.CompileDeployAddListenerMileZero(epl, "s0"); EPAssertionUtil.AssertPropsPerRow(env.GetEnumerator("s0"), fields, new object[0][]); SendSupportBeanWLong(env, "E1", 1000); EPAssertionUtil.AssertProps( env.Listener("s0").AssertOneGetNewAndReset(), fields, new object[] {"E1"}); env.Milestone(1); EPAssertionUtil.AssertPropsPerRowAnyOrder( env.GetEnumerator("s0"), fields, new[] {new object[] {"E1"}}); SendSupportBeanWLong(env, "E2", 5000); EPAssertionUtil.AssertProps( env.Listener("s0").AssertOneGetNewAndReset(), fields, new object[] {"E2"}); env.Milestone(2); EPAssertionUtil.AssertPropsPerRowAnyOrder( env.GetEnumerator("s0"), fields, new[] {new object[] {"E1"}, new object[] {"E2"}}); SendSupportBeanWLong(env, "E3", 11000); EPAssertionUtil.AssertProps( env.Listener("s0").AssertGetAndResetIRPair(), fields, new object[] {"E3"}, new object[] {"E1"}); env.Milestone(3); EPAssertionUtil.AssertPropsPerRowAnyOrder( env.GetEnumerator("s0"), fields, new[] {new object[] {"E2"}, new object[] {"E3"}}); SendSupportBeanWLong(env, "E4", 14000); EPAssertionUtil.AssertProps( env.Listener("s0").AssertOneGetNewAndReset(), fields, new object[] {"E4"}); env.Milestone(4); env.Milestone(5); EPAssertionUtil.AssertPropsPerRowAnyOrder( env.GetEnumerator("s0"), fields, new[] {new object[] {"E2"}, new object[] {"E3"}, new object[] {"E4"}}); SendSupportBeanWLong(env, "E5", 21000); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").LastNewData, fields, new[] {new object[] {"E5"}}); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastOldData(), fields, new[] {new object[] {"E2"}, new object[] {"E3"}}); SendSupportBeanWLong(env, "E6", 24000); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").LastNewData, fields, new[] {new object[] {"E6"}}); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").GetAndResetLastOldData(), fields, new[] {new object[] {"E4"}}); env.UndeployAll(); }
public void TestAfterSkipPastLast() { Configuration config = SupportConfigFactory.GetConfiguration(); config.AddEventType("MyEvent", typeof(SupportRecogBean)); EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(config); epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName); } String[] fields = "a_string,b_string".Split(','); String text = "select * from MyEvent.win:keepall() " + "match_recognize (" + " measures A.TheString as a_string, B.TheString as b_string " + " all matches " + " after match skip past last row" + " pattern (A B) " + " define B as B.value > A.value" + ") " + "order by a_string, b_string"; EPStatement stmt = epService.EPAdministrator.CreateEPL(text); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportRecogBean("E1", 5)); epService.EPRuntime.SendEvent(new SupportRecogBean("E2", 3)); Assert.IsFalse(listener.IsInvoked); Assert.IsFalse(stmt.HasFirst()); epService.EPRuntime.SendEvent(new SupportRecogBean("E3", 6)); EPAssertionUtil.AssertPropsPerRow( listener.GetAndResetLastNewData(), fields, new Object[][] { new Object[] { "E2", "E3" } }); EPAssertionUtil.AssertPropsPerRow( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "E2", "E3" } }); epService.EPRuntime.SendEvent(new SupportRecogBean("E4", 4)); Assert.IsFalse(listener.IsInvoked); EPAssertionUtil.AssertPropsPerRow( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "E2", "E3" } }); epService.EPRuntime.SendEvent(new SupportRecogBean("E5", 6)); EPAssertionUtil.AssertPropsPerRow( listener.GetAndResetLastNewData(), fields, new Object[][] { new Object[] { "E4", "E5" } }); EPAssertionUtil.AssertPropsPerRow( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "E2", "E3" } , new Object[] { "E4", "E5" } }); epService.EPRuntime.SendEvent(new SupportRecogBean("E6", 10)); Assert.IsFalse(listener.IsInvoked); // E5-E6 not a match since "skip past last row" EPAssertionUtil.AssertPropsPerRow( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "E2", "E3" }, new Object[] { "E4", "E5" } }); epService.EPRuntime.SendEvent(new SupportRecogBean("E7", 9)); epService.EPRuntime.SendEvent(new SupportRecogBean("E8", 4)); Assert.IsFalse(listener.IsInvoked); EPAssertionUtil.AssertPropsPerRow( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "E2", "E3" }, new Object[] { "E4", "E5" } }); stmt.Stop(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
public void Run(RegressionEnvironment env) { var text = "@Name('s0') select irstream Symbol," + "prev(1, Symbol) as prev1, " + "prevtail(0, Symbol) as prevTail0, " + "prevtail(1, Symbol) as prevTail1, " + "prevcount(Symbol) as prevCountSym, " + "prevwindow(Symbol) as prevWindowSym " + "from SupportMarketDataBean#ext_timed(Volume, 1 sec)"; env.CompileDeployAddListenerMileZero(text, "s0"); string[] fields = {"Symbol", "prev1", "prevTail0", "prevTail1", "prevCountSym", "prevWindowSym"}; env.SendEventBean(MakeMarketDataEvent("E1", 500)); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").NewDataListFlattened, fields, new[] { new object[] { "E1", null, "E1", null, 1L, new object[] {"E1"} } }); Assert.IsNull(env.Listener("s0").LastOldData); env.Listener("s0").Reset(); env.Milestone(1); env.SendEventBean(MakeMarketDataEvent("E2", 600)); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").NewDataListFlattened, fields, new[] { new object[] { "E2", "E1", "E1", "E2", 2L, new object[] {"E2", "E1"} } }); Assert.IsNull(env.Listener("s0").LastOldData); env.Listener("s0").Reset(); env.Milestone(2); env.SendEventBean(MakeMarketDataEvent("E3", 1500)); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").NewDataListFlattened, fields, new[] { new object[] { "E3", "E2", "E2", "E3", 2L, new object[] {"E3", "E2"} } }); env.Listener("s0").Reset(); env.Milestone(3); env.SendEventBean(MakeMarketDataEvent("E4", 1600)); EPAssertionUtil.AssertPropsPerRow( env.Listener("s0").NewDataListFlattened, fields, new[] { new object[] { "E4", "E3", "E3", "E4", 2L, new object[] {"E4", "E3"} } }); env.Listener("s0").Reset(); env.Milestone(4); env.UndeployAll(); }
public void TestVariableMoreThenOnce() { Configuration config = SupportConfigFactory.GetConfiguration(); config.AddEventType("MyEvent", typeof(SupportRecogBean)); EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider( config); epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName); } String[] fields = "a0,b,a1".Split(','); String text = "select * from MyEvent.win:keepall() " + "match_recognize (" + " measures A[0].TheString as a0, B.TheString as b, A[1].TheString as a1 " + " all matches " + " after match skip to next row " + " pattern ( A B A ) " + " define " + " A as (A.value = 1)," + " B as (B.value = 2)" + ")"; EPStatement stmt = epService.EPAdministrator.CreateEPL(text); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportRecogBean("E1", 3)); epService.EPRuntime.SendEvent(new SupportRecogBean("E2", 1)); epService.EPRuntime.SendEvent(new SupportRecogBean("E3", 2)); epService.EPRuntime.SendEvent(new SupportRecogBean("E4", 5)); epService.EPRuntime.SendEvent(new SupportRecogBean("E5", 1)); epService.EPRuntime.SendEvent(new SupportRecogBean("E6", 2)); Assert.IsFalse(listener.IsInvoked); Assert.IsFalse(stmt.HasFirst()); epService.EPRuntime.SendEvent(new SupportRecogBean("E7", 1)); EPAssertionUtil.AssertPropsPerRow( listener.GetAndResetLastNewData(), fields, new Object[][] { new Object[] { "E5", "E6", "E7" } }); EPAssertionUtil.AssertPropsPerRow( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "E5", "E6", "E7" } }); epService.EPRuntime.SendEvent(new SupportRecogBean("E8", 2)); epService.EPRuntime.SendEvent(new SupportRecogBean("E9", 1)); EPAssertionUtil.AssertPropsPerRow( listener.GetAndResetLastNewData(), fields, new Object[][] { new Object[] { "E7", "E8", "E9" } }); EPAssertionUtil.AssertPropsPerRow( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "E5", "E6", "E7" }, new Object[] { "E7", "E8", "E9" } }); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
public void TestAggregation() { // Test ungrouped String[] fields = { "TheString" }; EPStatement stmtUngrouped = _epService.EPAdministrator.CreateEPL("select irstream TheString from SupportBean#expr(sum(IntPrimitive) < 10)"); stmtUngrouped.Events += _listener.Update; _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); EPAssertionUtil.AssertPropsPerRow(stmtUngrouped.GetEnumerator(), fields, new Object[][] { new Object[] { "E1" } }); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "E1" }); _epService.EPRuntime.SendEvent(new SupportBean("E2", 9)); EPAssertionUtil.AssertPropsPerRow(stmtUngrouped.GetEnumerator(), fields, new Object[][] { new Object[] { "E2" } }); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E2" } }, new Object[][] { new Object[] { "E1" } }); _epService.EPRuntime.SendEvent(new SupportBean("E3", 11)); EPAssertionUtil.AssertPropsPerRow(stmtUngrouped.GetEnumerator(), fields, null); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E3" } }, new Object[][] { new Object[] { "E2" }, new Object[] { "E3" } }); _epService.EPRuntime.SendEvent(new SupportBean("E4", 12)); EPAssertionUtil.AssertPropsPerRow(stmtUngrouped.GetEnumerator(), fields, null); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E4" } }, new Object[][] { new Object[] { "E4" } }); _epService.EPRuntime.SendEvent(new SupportBean("E5", 1)); EPAssertionUtil.AssertPropsPerRow(stmtUngrouped.GetEnumerator(), fields, new Object[][] { new Object[] { "E5" } }); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E5" } }, null); _epService.EPRuntime.SendEvent(new SupportBean("E6", 2)); EPAssertionUtil.AssertPropsPerRow(stmtUngrouped.GetEnumerator(), fields, new Object[][] { new Object[] { "E5" }, new Object[] { "E6" } }); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E6" } }, null); _epService.EPRuntime.SendEvent(new SupportBean("E7", 3)); EPAssertionUtil.AssertPropsPerRow(stmtUngrouped.GetEnumerator(), fields, new Object[][] { new Object[] { "E5" }, new Object[] { "E6" }, new Object[] { "E7" } }); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E7" } }, null); _epService.EPRuntime.SendEvent(new SupportBean("E8", 6)); EPAssertionUtil.AssertPropsPerRow(stmtUngrouped.GetEnumerator(), fields, new Object[][] { new Object[] { "E7" }, new Object[] { "E8" } }); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E8" } }, new Object[][] { new Object[] { "E5" }, new Object[] { "E6" } }); _epService.EPRuntime.SendEvent(new SupportBean("E9", 9)); EPAssertionUtil.AssertPropsPerRow(stmtUngrouped.GetEnumerator(), fields, new Object[][] { new Object[] { "E9" } }); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E9" } }, new Object[][] { new Object[] { "E7" }, new Object[] { "E8" } }); stmtUngrouped.Dispose(); // Test grouped EPStatement stmtGrouped = _epService.EPAdministrator.CreateEPL("select irstream TheString from SupportBean#groupwin(IntPrimitive)#expr(sum(LongPrimitive) < 10)"); stmtGrouped.Events += _listener.Update; SendEvent("E1", 1, 5); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E1" } }, null); SendEvent("E2", 2, 2); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E2" } }, null); SendEvent("E3", 1, 3); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E3" } }, null); SendEvent("E4", 2, 4); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E4" } }, null); SendEvent("E5", 2, 6); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E5" } }, new Object[][] { new Object[] { "E2" }, new Object[] { "E4" } }); SendEvent("E6", 1, 2); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E6" } }, new Object[][] { new Object[] { "E1" } }); stmtGrouped.Dispose(); // Test on-delete _epService.EPAdministrator.Configuration.AddEventType <SupportBean_A>(); EPStatement stmt = _epService.EPAdministrator.CreateEPL("create window NW#expr(sum(IntPrimitive) < 10) as SupportBean"); stmt.Events += _listener.Update; _epService.EPAdministrator.CreateEPL("insert into NW select * from SupportBean"); _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E1" } }, null); _epService.EPRuntime.SendEvent(new SupportBean("E2", 8)); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E2" } }, null); _epService.EPAdministrator.CreateEPL("on SupportBean_A delete from NW where TheString = id"); _epService.EPRuntime.SendEvent(new SupportBean_A("E2")); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, null, new Object[][] { new Object[] { "E2" } }); _epService.EPRuntime.SendEvent(new SupportBean("E3", 7)); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E3" } }, null); _epService.EPRuntime.SendEvent(new SupportBean("E4", 2)); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E4" } }, new Object[][] { new Object[] { "E1" } }); }
public void TestNamedWindowOutOfSequenceDelete() { Configuration config = SupportConfigFactory.GetConfiguration(); config.AddEventType("SupportRecogBean", typeof(SupportRecogBean)); config.AddEventType("SupportBean", typeof(SupportBean)); EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(config); epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName); } epService.EPAdministrator.CreateEPL("create window MyWindow.win:keepall() as SupportRecogBean"); epService.EPAdministrator.CreateEPL("insert into MyWindow select * from SupportRecogBean"); epService.EPAdministrator.CreateEPL( "on SupportBean as s delete from MyWindow as w where s.TheString = w.TheString"); String[] fields = "a0,a1,b0,b1,c".Split(','); String text = "select * from MyWindow " + "match_recognize (" + " measures A[0].TheString as a0, A[1].TheString as a1, B[0].TheString as b0, B[1].TheString as b1, C.TheString as c" + " pattern ( A+ B* C ) " + " define " + " A as (A.Value = 1)," + " B as (B.Value = 2)," + " C as (C.Value = 3)" + ")"; EPStatement stmt = epService.EPAdministrator.CreateEPL(text); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportRecogBean("E1", 1)); epService.EPRuntime.SendEvent(new SupportRecogBean("E2", 1)); epService.EPRuntime.SendEvent(new SupportBean("E2", 0)); // deletes E2 epService.EPRuntime.SendEvent(new SupportRecogBean("E3", 3)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new[] { new Object[] { "E1", null, null, null, "E3" } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "E1", null, null, null, "E3" } }); epService.EPRuntime.SendEvent(new SupportBean("E1", 0)); // deletes E1 epService.EPRuntime.SendEvent(new SupportBean("E4", 0)); // deletes E4 epService.EPRuntime.SendEvent(new SupportRecogBean("E4", 1)); epService.EPRuntime.SendEvent(new SupportRecogBean("E5", 1)); epService.EPRuntime.SendEvent(new SupportBean("E4", 0)); // deletes E4 epService.EPRuntime.SendEvent(new SupportRecogBean("E6", 3)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new[] { new Object[] { "E5", null, null, null, "E6" } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "E5", null, null, null, "E6" } }); epService.EPRuntime.SendEvent(new SupportRecogBean("E7", 1)); epService.EPRuntime.SendEvent(new SupportRecogBean("E8", 1)); epService.EPRuntime.SendEvent(new SupportRecogBean("E9", 2)); epService.EPRuntime.SendEvent(new SupportRecogBean("E10", 2)); epService.EPRuntime.SendEvent(new SupportRecogBean("E11", 2)); epService.EPRuntime.SendEvent(new SupportBean("E9", 0)); // deletes E9 epService.EPRuntime.SendEvent(new SupportRecogBean("E12", 3)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new[] { new Object[] { "E7", "E8", "E10", "E11", "E12" } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "E5", null, null, null, "E6" }, new Object[] { "E7", "E8", "E10", "E11", "E12" } }); // note interranking among per-event result epService.EPRuntime.SendEvent(new SupportRecogBean("E13", 1)); epService.EPRuntime.SendEvent(new SupportRecogBean("E14", 1)); epService.EPRuntime.SendEvent(new SupportRecogBean("E15", 2)); epService.EPRuntime.SendEvent(new SupportRecogBean("E16", 2)); epService.EPRuntime.SendEvent(new SupportBean("E14", 0)); // deletes E14 epService.EPRuntime.SendEvent(new SupportBean("E15", 0)); // deletes E15 epService.EPRuntime.SendEvent(new SupportBean("E16", 0)); // deletes E16 epService.EPRuntime.SendEvent(new SupportBean("E13", 0)); // deletes E17 epService.EPRuntime.SendEvent(new SupportRecogBean("E18", 3)); Assert.IsFalse(listener.IsInvoked); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "E5", null, null, null, "E6" }, new Object[] { "E7", "E8", "E10", "E11", "E12" } }); // note interranking among per-event result if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
public void TestLimitSnapshotJoin() { var listener = new SupportUpdateListener(); SendTimer(0); var selectStmt = "select count(*) as cnt from " + typeof(SupportBean).FullName + ".win:time(10 seconds) as s, " + typeof(SupportMarketDataBean).FullName + ".win:keepall() as m where m.Symbol = s.TheString and IntPrimitive > 0 output snapshot every 1 seconds"; var stmt = _epService.EPAdministrator.CreateEPL(selectStmt); stmt.Events += listener.Update; _epService.EPRuntime.SendEvent(new SupportMarketDataBean("s0", 0, 0L, "")); _epService.EPRuntime.SendEvent(new SupportMarketDataBean("s1", 0, 0L, "")); _epService.EPRuntime.SendEvent(new SupportMarketDataBean("s2", 0, 0L, "")); _epService.EPRuntime.SendEvent(new SupportMarketDataBean("s4", 0, 0L, "")); _epService.EPRuntime.SendEvent(new SupportMarketDataBean("s5", 0, 0L, "")); SendEvent("s0", 1); SendTimer(500); SendEvent("s1", 1); SendEvent("s2", -1); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendTimer(1000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new String[] { "cnt" }, new Object[][] { new Object[] { 2L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); SendTimer(1500); SendEvent("s4", 2); SendEvent("s5", 3); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendTimer(2000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new String[] { "cnt" }, new Object[][] { new Object[] { 4L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); SendEvent("s5", 4); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendTimer(9000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new String[] { "cnt" }, new Object[][] { new Object[] { 5L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); // The execution of the join is after the snapshot, as joins are internal dispatch SendTimer(10000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new String[] { "cnt" }, new Object[][] { new Object[] { 5L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); SendTimer(10999); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendTimer(11000); EPAssertionUtil.AssertPropsPerRow(listener.LastNewData, new String[] { "cnt" }, new Object[][] { new Object[] { 3L } }); Assert.IsNull(listener.LastOldData); listener.Reset(); }