public void TestFilter() { var fields = new[] { "Symbol", "vol" }; String stmtText = "select Symbol, Volume * 10 as vol from " + typeof(SupportMarketDataBean).FullName + "#length(5)" + " where Volume < 0"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText); Assert.IsFalse(stmt.HasFirst()); SendEvent("SYM", 100); Assert.IsFalse(stmt.HasFirst()); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, null); SendEvent("SYM", -1); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "SYM", -10L } }); SendEvent("SYM", -6); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "SYM", -10L }, new Object[] { "SYM", -60L } }); SendEvent("SYM", 1); SendEvent("SYM", 16); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "SYM", -10L }, new Object[] { "SYM", -60L } }); SendEvent("SYM", -9); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "SYM", -10L }, new Object[] { "SYM", -60L }, new Object[] { "SYM", -90L } }); SendEvent("SYM", 2); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "SYM", -60L }, new Object[] { "SYM", -90L } }); SendEvent("SYM", 3); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "SYM", -90L } }); SendEvent("SYM", 4); SendEvent("SYM", 5); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "SYM", -90L } }); SendEvent("SYM", 6); Assert.IsFalse(stmt.HasFirst()); }
private void RunAssertionPartitionBy2FieldsKeepall(EPServiceProvider epService) { string[] fields = "a_string,a_cat,a_value,b_value".Split(','); string text = "select * from MyEvent#keepall " + "match_recognize (" + " partition by TheString, cat" + " measures A.TheString as a_string, A.cat as a_cat, A.value as a_value, B.value as b_value " + " all matches pattern (A B) " + " define " + " A as (A.value > PREV(A.value))," + " B as (B.value > PREV(B.value))" + ") order by a_string, a_cat"; EPStatement stmt = epService.EPAdministrator.CreateEPL(text); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportRecogBean("S1", "T1", 5)); epService.EPRuntime.SendEvent(new SupportRecogBean("S2", "T1", 110)); epService.EPRuntime.SendEvent(new SupportRecogBean("S1", "T2", 21)); epService.EPRuntime.SendEvent(new SupportRecogBean("S1", "T1", 7)); epService.EPRuntime.SendEvent(new SupportRecogBean("S2", "T1", 111)); epService.EPRuntime.SendEvent(new SupportRecogBean("S1", "T2", 20)); epService.EPRuntime.SendEvent(new SupportRecogBean("S2", "T1", 110)); epService.EPRuntime.SendEvent(new SupportRecogBean("S2", "T2", 1000)); epService.EPRuntime.SendEvent(new SupportRecogBean("S2", "T2", 1001)); epService.EPRuntime.SendEvent(new SupportRecogBean("S1", null, 9)); Assert.IsFalse(listener.IsInvoked); Assert.IsFalse(stmt.HasFirst()); epService.EPRuntime.SendEvent(new SupportRecogBean("S1", "T1", 9)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "S1", "T1", 7, 9 } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "S1", "T1", 7, 9 } }); epService.EPRuntime.SendEvent(new SupportRecogBean("S2", "T2", 1001)); epService.EPRuntime.SendEvent(new SupportRecogBean("S2", "T1", 109)); epService.EPRuntime.SendEvent(new SupportRecogBean("S1", "T2", 25)); Assert.IsFalse(listener.IsInvoked); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "S1", "T1", 7, 9 } }); epService.EPRuntime.SendEvent(new SupportRecogBean("S2", "T2", 1002)); epService.EPRuntime.SendEvent(new SupportRecogBean("S2", "T2", 1003)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "S2", "T2", 1002, 1003 } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "S1", "T1", 7, 9 }, new object[] { "S2", "T2", 1002, 1003 } }); epService.EPRuntime.SendEvent(new SupportRecogBean("S1", "T2", 28)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "S1", "T2", 25, 28 } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "S1", "T1", 7, 9 }, new object[] { "S1", "T2", 25, 28 }, new object[] { "S2", "T2", 1002, 1003 } }); stmt.Dispose(); }
public void TestGroupByRowPerEventOrdered() { var fields = new[] { "Symbol", "Price", "sumVol" }; String stmtText = "select Symbol, Price, sum(Volume) as sumVol " + "from " + typeof(SupportMarketDataBean).FullName + "#length(5) " + "group by Symbol " + "order by Symbol"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText); Assert.IsFalse(stmt.HasFirst()); SendEvent("SYM", -1, 100); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { "SYM", -1d, 100L } }); SendEvent("TAC", -2, 12); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { "SYM", -1d, 100L }, new object[] { "TAC", -2d, 12L } }); SendEvent("TAC", -3, 13); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { "SYM", -1d, 100L }, new object[] { "TAC", -2d, 25L }, new object[] { "TAC", -3d, 25L } }); SendEvent("SYM", -4, 1); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { "SYM", -1d, 101L }, new object[] { "SYM", -4d, 101L }, new object[] { "TAC", -2d, 25L }, new object[] { "TAC", -3d, 25L } }); SendEvent("OCC", -5, 99); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { "OCC", -5d, 99L }, new object[] { "SYM", -1d, 101L }, new object[] { "SYM", -4d, 101L }, new object[] { "TAC", -2d, 25L }, new object[] { "TAC", -3d, 25L } }); SendEvent("TAC", -6, 2); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { "OCC", -5d, 99L }, new object[] { "SYM", -4d, 1L }, new object[] { "TAC", -2d, 27L }, new object[] { "TAC", -3d, 27L }, new object[] { "TAC", -6d, 27L } }); }
public void TestNamedWindowInSequenceDelete() { Configuration config = SupportConfigFactory.GetConfiguration(); config.AddEventType("SupportRecogBean", typeof(SupportRecogBean)); config.AddEventType <SupportBean>(); EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(config); epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName); } epService.EPAdministrator.CreateEPL("create window MyWindow#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,b".Split(','); String text = "select * from MyWindow " + "match_recognize (" + " measures A[0].TheString as a0, A[1].TheString as a1, B.TheString as b" + " pattern ( A* B ) " + " 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", 1)); epService.EPRuntime.SendEvent(new SupportRecogBean("E2", 1)); epService.EPRuntime.SendEvent(new SupportBean("E1", 0)); // deletes E1 epService.EPRuntime.SendEvent(new SupportBean("E2", 0)); // deletes E2 epService.EPRuntime.SendEvent(new SupportRecogBean("E3", 3)); Assert.IsFalse(listener.IsInvoked); Assert.IsFalse(stmt.HasFirst()); 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", 1)); epService.EPRuntime.SendEvent(new SupportRecogBean("E7", 2)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new[] { new Object[] { "E5", "E6", "E7" } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "E5", "E6", "E7" } }); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
private void RunAssertionUnboundStreamNoIterator(EPServiceProvider epService) { string[] fields = "string,value".Split(','); string text = "select * from MyEvent " + "match_recognize (" + " measures A.TheString as string, A.value as value" + " all matches pattern (A) " + " define " + " A as PREV(A.TheString, 1) = TheString" + ")"; EPStatement stmt = epService.EPAdministrator.CreateEPL(text); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportRecogBean("s1", 1)); epService.EPRuntime.SendEvent(new SupportRecogBean("s2", 2)); epService.EPRuntime.SendEvent(new SupportRecogBean("s1", 3)); epService.EPRuntime.SendEvent(new SupportRecogBean("s3", 4)); epService.EPRuntime.SendEvent(new SupportRecogBean("s2", 5)); epService.EPRuntime.SendEvent(new SupportRecogBean("s1", 6)); Assert.IsFalse(stmt.HasFirst()); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportRecogBean("s1", 7)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "s1", 7 } }); Assert.IsFalse(stmt.HasFirst()); stmt.Dispose(); /* * Optionally send some more events. * * for (int i = 0; i < 100000; i++) * { * epService.EPRuntime.SendEvent(new SupportRecogBean("P2", 1)); * } * epService.EPRuntime.SendEvent(new SupportRecogBean("P2", 1)); */ }
private void RunAssertionSkipToNextRow(EPServiceProvider epService) { string[] fields = "a_string,b_string".Split(','); string text = "select * from MyEvent#keepall " + "match_recognize (" + " measures A.TheString as a_string, B.TheString as b_string " + " all matches " + " after match skip to next 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)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "E5", "E6" } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E2", "E3" }, new object[] { "E4", "E5" }, new object[] { "E5", "E6" } }); 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" }, new object[] { "E5", "E6" } }); stmt.Stop(); }
public void TestGroupByComplex() { var fields = new[] { "Symbol", "msg" }; String stmtText = "insert into Cutoff " + "select Symbol, (System.Convert.ToString(count(*)) || 'x1000.0') as msg " + "from " + typeof(SupportMarketDataBean).FullName + "#groupwin(Symbol)#length(1) " + "where Price - Volume >= 1000.0 group by Symbol having count(*) = 1"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText); Assert.IsFalse(stmt.HasFirst()); _epService.EPRuntime.SendEvent(new SupportMarketDataBean("SYM", -1, -1L, null)); Assert.IsFalse(stmt.HasFirst()); _epService.EPRuntime.SendEvent(new SupportMarketDataBean("SYM", 100000d, 0L, null)); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { "SYM", "1x1000.0" } }); _epService.EPRuntime.SendEvent(new SupportMarketDataBean("SYM", 1d, 1L, null)); Assert.IsFalse(stmt.HasFirst()); }
public void TestGroupByRowPerGroup() { var fields = new[] { "Symbol", "sumVol" }; String stmtText = "select Symbol, sum(Volume) as sumVol " + "from " + typeof(SupportMarketDataBean).FullName + "#length(5) " + "group by Symbol"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText); Assert.IsFalse(stmt.HasFirst()); SendEvent("SYM", 100); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { "SYM", 100L } }); SendEvent("SYM", 10); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { "SYM", 110L } }); SendEvent("TAC", 1); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { "SYM", 110L }, new object[] { "TAC", 1L } }); SendEvent("SYM", 11); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { "SYM", 121L }, new object[] { "TAC", 1L } }); SendEvent("TAC", 2); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { "SYM", 121L }, new object[] { "TAC", 3L } }); SendEvent("OCC", 55); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { "SYM", 21L }, new object[] { "TAC", 3L }, new object[] { "OCC", 55L } }); SendEvent("OCC", 4); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { "TAC", 3L }, new object[] { "SYM", 11L }, new object[] { "OCC", 59L } }); SendEvent("OCC", 3); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { "SYM", 11L }, new object[] { "TAC", 2L }, new object[] { "OCC", 62L } }); }
private void RunAssertionFilter(EPServiceProvider epService) { var fields = new string[] { "symbol", "vol" }; string stmtText = "select symbol, volume * 10 as vol from " + typeof(SupportMarketDataBean).FullName + "#length(5)" + " where volume < 0"; EPStatement stmt = epService.EPAdministrator.CreateEPL(stmtText); Assert.IsFalse(stmt.HasFirst()); SendEvent(epService, "SYM", 100); Assert.IsFalse(stmt.HasFirst()); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, null); SendEvent(epService, "SYM", -1); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", -10L } }); SendEvent(epService, "SYM", -6); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", -10L }, new object[] { "SYM", -60L } }); SendEvent(epService, "SYM", 1); SendEvent(epService, "SYM", 16); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", -10L }, new object[] { "SYM", -60L } }); SendEvent(epService, "SYM", -9); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", -10L }, new object[] { "SYM", -60L }, new object[] { "SYM", -90L } }); SendEvent(epService, "SYM", 2); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", -60L }, new object[] { "SYM", -90L } }); SendEvent(epService, "SYM", 3); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", -90L } }); SendEvent(epService, "SYM", 4); SendEvent(epService, "SYM", 5); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", -90L } }); SendEvent(epService, "SYM", 6); Assert.IsFalse(stmt.HasFirst()); stmt.Dispose(); }
private void RunAssertionGroupByComplex(EPServiceProvider epService) { var fields = new string[] { "symbol", "msg" }; string stmtText = "insert into Cutoff " + "select symbol, (Convert.ToString(count(*)) || 'x1000.0') as msg " + "from " + typeof(SupportMarketDataBean).FullName + "#groupwin(symbol)#length(1) " + "where price - volume >= 1000.0 group by symbol having count(*) = 1"; EPStatement stmt = epService.EPAdministrator.CreateEPL(stmtText); Assert.IsFalse(stmt.HasFirst()); epService.EPRuntime.SendEvent(new SupportMarketDataBean("SYM", -1, -1L, null)); Assert.IsFalse(stmt.HasFirst()); epService.EPRuntime.SendEvent(new SupportMarketDataBean("SYM", 100000d, 0L, null)); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", "1x1000.0" } }); epService.EPRuntime.SendEvent(new SupportMarketDataBean("SYM", 1d, 1L, null)); Assert.IsFalse(stmt.HasFirst()); stmt.Dispose(); }
public void TestRowForAllHaving() { var fields = new[] { "sumVol" }; String stmtText = "select sum(Volume) as sumVol " + "from " + typeof(SupportMarketDataBean).FullName + "#length(3) having sum(Volume) > 100"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText); Assert.IsFalse(stmt.HasFirst()); SendEvent(100); Assert.IsFalse(stmt.HasFirst()); SendEvent(50); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { 150L } }); SendEvent(25); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { 175L } }); SendEvent(10); Assert.IsFalse(stmt.HasFirst()); }
private void RunAssertionOneToMany(EPServiceProvider epService) { string[] fields = "a_string,b0_string,b1_string,b2_string,c_string".Split(','); string text = "select * from MyEvent#keepall " + "match_recognize (" + " measures A.TheString as a_string, " + " B[0].TheString as b0_string, " + " B[1].TheString as b1_string, " + " B[2].TheString as b2_string, " + " C.TheString as c_string" + " all matches " + " pattern (A B+ C) " + " define \n" + " A as (A.value = 10),\n" + " B as (B.value > 10),\n" + " C as (C.value < 10)\n" + ") " + "order by a_string, c_string"; EPStatement stmt = epService.EPAdministrator.CreateEPL(text); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportRecogBean("E1", 12)); epService.EPRuntime.SendEvent(new SupportRecogBean("E2", 10)); epService.EPRuntime.SendEvent(new SupportRecogBean("E3", 8)); epService.EPRuntime.SendEvent(new SupportRecogBean("E4", 10)); epService.EPRuntime.SendEvent(new SupportRecogBean("E5", 12)); Assert.IsFalse(listener.IsInvoked); Assert.IsFalse(stmt.HasFirst()); epService.EPRuntime.SendEvent(new SupportRecogBean("E6", 8)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "E4", "E5", null, null, "E6" } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E4", "E5", null, null, "E6" } }); epService.EPRuntime.SendEvent(new SupportRecogBean("E7", 10)); epService.EPRuntime.SendEvent(new SupportRecogBean("E8", 12)); epService.EPRuntime.SendEvent(new SupportRecogBean("E9", 12)); epService.EPRuntime.SendEvent(new SupportRecogBean("E10", 12)); epService.EPRuntime.SendEvent(new SupportRecogBean("E11", 9)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "E7", "E8", "E9", "E10", "E11" } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E4", "E5", null, null, "E6" }, new object[] { "E7", "E8", "E9", "E10", "E11" } }); stmt.Stop(); }
private void RunAssertionVariable(EPServiceProvider epService) { epService.EPRuntime.SendEvent(new CurrentTimeEvent(0)); epService.EPAdministrator.CreateEPL("create variable bool KEEP = true"); var fields = new[] { "TheString" }; EPStatement stmt = epService.EPAdministrator.CreateEPL("select irstream * from SupportBean#expr(KEEP)"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new CurrentTimeEvent(1000)); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { "E1" } }); epService.EPRuntime.SetVariableValue("KEEP", false); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { "E1" } }); listener.Reset(); epService.EPRuntime.SendEvent(new CurrentTimeEvent(1001)); EPAssertionUtil.AssertProps(listener.AssertOneGetOldAndReset(), fields, new object[] { "E1" }); Assert.IsFalse(stmt.HasFirst()); epService.EPRuntime.SendEvent(new SupportBean("E2", 2)); EPAssertionUtil.AssertProps(listener.LastNewData[0], fields, new object[] { "E2" }); EPAssertionUtil.AssertProps(listener.LastOldData[0], fields, new object[] { "E2" }); listener.Reset(); Assert.IsFalse(stmt.HasFirst()); epService.EPRuntime.SetVariableValue("KEEP", true); epService.EPRuntime.SendEvent(new SupportBean("E3", 3)); EPAssertionUtil.AssertProps(listener.AssertOneGetNewAndReset(), fields, new object[] { "E3" }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new object[] { "E3" } }); stmt.Stop(); }
public void TestPrevPartitioned() { Configuration config = SupportConfigFactory.GetConfiguration(); config.AddEventType <SupportRecogBean>("MyEvent"); EPServiceProvider epService = EPServiceProviderManager.GetDefaultProvider(config); epService.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(epService, GetType(), GetType().FullName); } String[] fields = "a,Cat".Split(','); String text = "@Hint('iterate_only') select * from MyEvent.std:lastevent() " + "match_recognize (" + " partition by Cat" + " measures A.TheString as a, A.Cat as Cat" + " all matches " + " pattern (A) " + " define A as prev(A.Value, 2) = Value" + ")"; EPStatement stmt = epService.EPAdministrator.CreateEPL(text); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportRecogBean("E1", "A", 1)); epService.EPRuntime.SendEvent(new SupportRecogBean("E2", "B", 1)); epService.EPRuntime.SendEvent(new SupportRecogBean("E3", "B", 3)); epService.EPRuntime.SendEvent(new SupportRecogBean("E4", "A", 4)); epService.EPRuntime.SendEvent(new SupportRecogBean("E5", "B", 2)); Assert.IsFalse(stmt.HasFirst()); epService.EPRuntime.SendEvent(new SupportRecogBean("E6", "A", 1)); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "E6", "A" } }); epService.EPRuntime.SendEvent(new SupportRecogBean("E7", "B", 3)); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "E7", "B" } }); Assert.IsFalse(listener.IsInvoked); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }
private void RunAssertionRowForAllHaving(EPServiceProvider epService) { var fields = new string[] { "sumVol" }; string stmtText = "select sum(volume) as sumVol " + "from " + typeof(SupportMarketDataBean).FullName + "#length(3) having sum(volume) > 100"; EPStatement stmt = epService.EPAdministrator.CreateEPL(stmtText); Assert.IsFalse(stmt.HasFirst()); SendEvent(epService, 100); Assert.IsFalse(stmt.HasFirst()); SendEvent(epService, 50); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { 150L } }); SendEvent(epService, 25); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { 175L } }); SendEvent(epService, 10); Assert.IsFalse(stmt.HasFirst()); stmt.Dispose(); }
public void TestVariable() { _epService.EPRuntime.SendEvent(new CurrentTimeEvent(0)); _epService.EPAdministrator.CreateEPL("create variable bool KEEP = true"); String[] fields = { "TheString" }; EPStatement stmt = _epService.EPAdministrator.CreateEPL("select irstream * from SupportBean.win:expr(KEEP)"); stmt.Events += _listener.Update; _epService.EPRuntime.SendEvent(new CurrentTimeEvent(1000)); _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "E1" } }); _epService.EPRuntime.SetVariableValue("KEEP", false); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "E1" } }); _listener.Reset(); _epService.EPRuntime.SendEvent(new CurrentTimeEvent(1001)); EPAssertionUtil.AssertProps(_listener.AssertOneGetOldAndReset(), fields, new Object[] { "E1" }); Assert.IsFalse(stmt.HasFirst()); _epService.EPRuntime.SendEvent(new SupportBean("E2", 2)); EPAssertionUtil.AssertProps(_listener.LastNewData[0], fields, new Object[] { "E2" }); EPAssertionUtil.AssertProps(_listener.LastOldData[0], fields, new Object[] { "E2" }); _listener.Reset(); Assert.IsFalse(stmt.HasFirst()); _epService.EPRuntime.SetVariableValue("KEEP", true); _epService.EPRuntime.SendEvent(new SupportBean("E3", 3)); EPAssertionUtil.AssertProps(_listener.AssertOneGetNewAndReset(), fields, new Object[] { "E3" }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "E3" } }); stmt.Stop(); }
private void RunAssertionVariableMoreThenOnce(EPServiceProvider epService) { string[] fields = "a0,b,a1".Split(','); string text = "select * from MyEvent#keepall " + "match_recognize (" + " measures A[0].TheString as a0, B.TheString as b, A[1].TheString as a1 " + " all matches 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)); Assert.IsFalse(listener.IsInvoked); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E5", "E6", "E7" } }); epService.EPRuntime.SendEvent(new SupportRecogBean("E10", 2)); epService.EPRuntime.SendEvent(new SupportRecogBean("E11", 1)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "E9", "E10", "E11" } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E5", "E6", "E7" }, new object[] { "E9", "E10", "E11" } }); stmt.Dispose(); }
public void TestGroupByRowPerGroupOrdered() { var fields = new[] { "Symbol", "sumVol" }; String stmtText = "select Symbol, sum(Volume) as sumVol " + "from " + typeof(SupportMarketDataBean).FullName + ".win:length(5) " + "group by Symbol " + "order by Symbol"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText); Assert.IsFalse(stmt.HasFirst()); SendEvent("SYM", 100); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "SYM", 100L } }); SendEvent("OCC", 5); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "OCC", 5L }, new Object[] { "SYM", 100L } }); SendEvent("SYM", 10); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "OCC", 5L }, new Object[] { "SYM", 110L } }); SendEvent("OCC", 6); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "OCC", 11L }, new Object[] { "SYM", 110L } }); SendEvent("ATB", 8); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "ATB", 8L }, new Object[] { "OCC", 11L }, new Object[] { "SYM", 110L } }); SendEvent("ATB", 7); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new[] { new Object[] { "ATB", 15L }, new Object[] { "OCC", 11L }, new Object[] { "SYM", 10L } }); }
private void RunAssertionAlterWithinConcat(EPServiceProvider epService) { string[] fields = "a_string,b_string,c_string,d_string".Split(','); string text = "select * from MyEvent#keepall " + "match_recognize (" + " measures A.TheString as a_string, B.TheString as b_string, C.TheString as c_string, D.TheString as d_string " + " all matches pattern ( (A | B) (C | D) ) " + " define " + " A as (A.value = 1)," + " B as (B.value = 2)," + " C as (C.value = 3)," + " D as (D.value = 4)" + ")"; 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)); Assert.IsFalse(listener.IsInvoked); Assert.IsFalse(stmt.HasFirst()); epService.EPRuntime.SendEvent(new SupportRecogBean("E6", 3)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "E5", null, "E6", null } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E5", null, "E6", null } }); epService.EPRuntime.SendEvent(new SupportRecogBean("E7", 2)); epService.EPRuntime.SendEvent(new SupportRecogBean("E8", 3)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { null, "E7", "E8", null } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "E5", null, "E6", null }, new object[] { null, "E7", "E8", null } }); stmt.Dispose(); }
private void RunAssertionNamedWindowInSequenceDelete(EPServiceProvider epService) { epService.EPAdministrator.CreateEPL("create window MyWindow#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,b".Split(','); string text = "select * from MyWindow " + "match_recognize (" + " measures A[0].TheString as a0, A[1].TheString as a1, B.TheString as b" + " pattern ( A* B ) " + " 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", 1)); epService.EPRuntime.SendEvent(new SupportRecogBean("E2", 1)); epService.EPRuntime.SendEvent(new SupportBean("E1", 0)); // deletes E1 epService.EPRuntime.SendEvent(new SupportBean("E2", 0)); // deletes E2 epService.EPRuntime.SendEvent(new SupportRecogBean("E3", 3)); Assert.IsFalse(listener.IsInvoked); Assert.IsFalse(stmt.HasFirst()); 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", 1)); epService.EPRuntime.SendEvent(new SupportRecogBean("E7", 2)); 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.EPAdministrator.DestroyAllStatements(); }
private void RunAssertionOrderByProps(EPServiceProvider epService) { var fields = new string[] { "symbol", "volume" }; string stmtText = "select symbol, volume from " + typeof(SupportMarketDataBean).FullName + "#length(3) order by symbol, volume"; EPStatement stmt = epService.EPAdministrator.CreateEPL(stmtText); Assert.IsFalse(stmt.HasFirst()); SendEvent(epService, "SYM", 1); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", 1L } }); SendEvent(epService, "OCC", 2); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "OCC", 2L }, new object[] { "SYM", 1L } }); SendEvent(epService, "SYM", 0); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "OCC", 2L }, new object[] { "SYM", 0L }, new object[] { "SYM", 1L } }); SendEvent(epService, "OCC", 3); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "OCC", 2L }, new object[] { "OCC", 3L }, new object[] { "SYM", 0L } }); stmt.Dispose(); }
public void TestOrderByWildcard() { String stmtText = "select * from " + typeof(SupportMarketDataBean).FullName + "#length(5) order by Symbol, Volume"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText); Assert.IsFalse(stmt.HasFirst()); Object eventOne = SendEvent("SYM", 1); ArrayAssertionUtil.AreEqualExactOrderUnderlying(stmt.GetEnumerator(), new[] { eventOne }); Object eventTwo = SendEvent("OCC", 2); ArrayAssertionUtil.AreEqualExactOrderUnderlying(stmt.GetEnumerator(), new[] { eventTwo, eventOne }); Object eventThree = SendEvent("TOC", 3); ArrayAssertionUtil.AreEqualExactOrderUnderlying(stmt.GetEnumerator(), new[] { eventTwo, eventOne, eventThree }); Object eventFour = SendEvent("SYM", 0); ArrayAssertionUtil.AreEqualExactOrderUnderlying(stmt.GetEnumerator(), new[] { eventTwo, eventFour, eventOne, eventThree }); Object eventFive = SendEvent("SYM", 10); ArrayAssertionUtil.AreEqualExactOrderUnderlying(stmt.GetEnumerator(), new[] { eventTwo, eventFour, eventOne, eventFive, eventThree }); Object eventSix = SendEvent("SYM", 4); ArrayAssertionUtil.AreEqualExactOrderUnderlying(stmt.GetEnumerator(), new[] { eventTwo, eventFour, eventSix, eventFive, eventThree }); }
private void RunAssertionLimitation(EPServiceProvider epService) { EPStatement stmtWindow = epService.EPAdministrator.CreateEPL("create window MyVDW.test:vdw() as SupportBean"); SupportVirtualDW window = (SupportVirtualDW)GetFromContext(epService, "/virtualdw/MyVDW"); var supportBean = new SupportBean("S1", 100); window.Data = Collections.SingletonList <object>(supportBean); epService.EPAdministrator.CreateEPL("insert into MyVDW select * from SupportBean"); // cannot iterate named window Assert.IsFalse(stmtWindow.HasFirst()); // test data window aggregation (rows not included in aggregation) EPStatement stmtAggregate = epService.EPAdministrator.CreateEPL("select window(TheString) as val0 from MyVDW"); var listener = new SupportUpdateListener(); stmtAggregate.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean("E1", 100)); EPAssertionUtil.AssertEqualsExactOrder(new object[] { "E1" }, (string[])listener.AssertOneGetNewAndReset().Get("val0")); DestroyStmtsRemoveTypes(epService); }
private void RunAssertionGroupByRowPerGroupHaving(EPServiceProvider epService) { var fields = new string[] { "symbol", "sumVol" }; string stmtText = "select symbol, sum(volume) as sumVol " + "from " + typeof(SupportMarketDataBean).FullName + "#length(5) " + "group by symbol having sum(volume) > 10"; EPStatement stmt = epService.EPAdministrator.CreateEPL(stmtText); Assert.IsFalse(stmt.HasFirst()); SendEvent(epService, "SYM", 100); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", 100L } }); SendEvent(epService, "SYM", 5); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", 105L } }); SendEvent(epService, "TAC", 1); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", 105L } }); SendEvent(epService, "SYM", 3); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", 108L } }); SendEvent(epService, "TAC", 12); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", 108L }, new object[] { "TAC", 13L } }); SendEvent(epService, "OCC", 55); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "TAC", 13L }, new object[] { "OCC", 55L } }); SendEvent(epService, "OCC", 4); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "TAC", 13L }, new object[] { "OCC", 59L } }); SendEvent(epService, "OCC", 3); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "TAC", 12L }, new object[] { "OCC", 62L } }); stmt.Dispose(); }
private void RunAssertionGroupByRowPerEventOrdered(EPServiceProvider epService) { var fields = new string[] { "symbol", "price", "sumVol" }; string stmtText = "select symbol, price, sum(volume) as sumVol " + "from " + typeof(SupportMarketDataBean).FullName + "#length(5) " + "group by symbol " + "order by symbol"; EPStatement stmt = epService.EPAdministrator.CreateEPL(stmtText); Assert.IsFalse(stmt.HasFirst()); SendEvent(epService, "SYM", -1, 100); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", -1d, 100L } }); SendEvent(epService, "TAC", -2, 12); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", -1d, 100L }, new object[] { "TAC", -2d, 12L } }); SendEvent(epService, "TAC", -3, 13); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", -1d, 100L }, new object[] { "TAC", -2d, 25L }, new object[] { "TAC", -3d, 25L } }); SendEvent(epService, "SYM", -4, 1); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", -1d, 101L }, new object[] { "SYM", -4d, 101L }, new object[] { "TAC", -2d, 25L }, new object[] { "TAC", -3d, 25L } }); SendEvent(epService, "OCC", -5, 99); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "OCC", -5d, 99L }, new object[] { "SYM", -1d, 101L }, new object[] { "SYM", -4d, 101L }, new object[] { "TAC", -2d, 25L }, new object[] { "TAC", -3d, 25L } }); SendEvent(epService, "TAC", -6, 2); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "OCC", -5d, 99L }, new object[] { "SYM", -4d, 1L }, new object[] { "TAC", -2d, 27L }, new object[] { "TAC", -3d, 27L }, new object[] { "TAC", -6d, 27L } }); stmt.Dispose(); }
private void RunAssertionAggregateAll(EPServiceProvider epService) { var fields = new string[] { "symbol", "sumVol" }; string stmtText = "select symbol, sum(volume) as sumVol " + "from " + typeof(SupportMarketDataBean).FullName + "#length(3) "; EPStatement stmt = epService.EPAdministrator.CreateEPL(stmtText); Assert.IsFalse(stmt.HasFirst()); SendEvent(epService, "SYM", 100); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", 100L } }); SendEvent(epService, "TAC", 1); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", 101L }, new object[] { "TAC", 101L } }); SendEvent(epService, "MOV", 3); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "SYM", 104L }, new object[] { "TAC", 104L }, new object[] { "MOV", 104L } }); SendEvent(epService, "SYM", 10); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { "TAC", 14L }, new object[] { "MOV", 14L }, new object[] { "SYM", 14L } }); stmt.Dispose(); }
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#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 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 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 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(); } }