public void Execute(bool allowAnyOrder) { bool isAssert = Environment.GetEnvironmentVariable("ASSERTION_DISABLED") == null; bool expectRemoveStream = _stmt.Text.ToLower().Contains("select irstream"); Execute(isAssert, !expectRemoveStream, allowAnyOrder); _stmt.Stop(); // Second execution is for IRSTREAM, asserting both the insert and remove stream if (_irTestSelector != ResultAssertExecutionTestSelector.TEST_ONLY_AS_PROVIDED) { String epl = _stmt.Text; String irStreamEPL = epl.Replace("select ", "select irstream "); _stmt = _engine.EPAdministrator.CreateEPL(irStreamEPL); _stmt.AddListener(_listener); Execute(isAssert, false, allowAnyOrder); } }
private void TrySend(int numThreads, int numRepeats) { EPStatement stmt = _engine.EPAdministrator.CreateEPL( "select (select id from S0#length(1000000) where id = s1.id) as value from S1 as s1"); _listener = new SupportMTUpdateListener(); stmt.Events += _listener.Update; var threadPool = Executors.NewFixedThreadPool(numThreads); var future = new Future <bool> [numThreads]; for (int i = 0; i < numThreads; i++) { var callable = new StmtSubqueryCallable(i, _engine, numRepeats); future[i] = threadPool.Submit(callable); } threadPool.Shutdown(); threadPool.AwaitTermination(TimeSpan.FromSeconds(10)); for (int i = 0; i < numThreads; i++) { Assert.IsTrue(future[i].GetValueOrDefault()); } // Assert results int totalExpected = numThreads * numRepeats; // assert new data EventBean[] resultNewData = _listener.GetNewDataListFlattened(); Assert.AreEqual(totalExpected, resultNewData.Length); ICollection <int> values = new HashSet <int>(); foreach (EventBean theEvent in resultNewData) { values.Add(theEvent.Get("value").AsInt()); } Assert.AreEqual(totalExpected, values.Count, "Unexpected duplicates"); _listener.Reset(); stmt.Stop(); }
private void RunAssertionConcatWithinAlter(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", 5)); epService.EPRuntime.SendEvent(new SupportRecogBean("E3", 4)); epService.EPRuntime.SendEvent(new SupportRecogBean("E4", 3)); Assert.IsFalse(listener.IsInvoked); Assert.IsFalse(stmt.HasFirst()); epService.EPRuntime.SendEvent(new SupportRecogBean("E5", 4)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { null, null, "E4", "E5" } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { null, null, "E4", "E5" } }); epService.EPRuntime.SendEvent(new SupportRecogBean("E1", 1)); epService.EPRuntime.SendEvent(new SupportRecogBean("E1", 1)); epService.EPRuntime.SendEvent(new SupportRecogBean("E2", 2)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetLastNewData(), fields, new object[][] { new object[] { "E1", "E2", null, null } }); EPAssertionUtil.AssertPropsPerRow(stmt.GetEnumerator(), fields, new object[][] { new object[] { null, null, "E4", "E5" }, new object[] { "E1", "E2", null, null } }); stmt.Stop(); }
private void RunAssertionStatementStateChange() { EPServiceProvider stateChangeEngine = EPServiceProviderManager.GetProvider( SupportContainer.Instance, this.GetType().Name + "_statechange", SupportConfigFactory.GetConfiguration()); EPServiceProviderSPI spi = (EPServiceProviderSPI)stateChangeEngine; var observer = new SupportStmtLifecycleObserver(); spi.StatementLifecycleSvc.LifecycleEvent += observer.Observe; var listener = new SupportStatementStateListener(); stateChangeEngine.StatementCreate += listener.OnStatementCreate; stateChangeEngine.StatementStateChange += listener.OnStatementStateChange; EPStatement stmt = stateChangeEngine.EPAdministrator.CreateEPL("select * from " + typeof(SupportBean).FullName); Assert.AreEqual("CREATE;STATECHANGE;", observer.EventsAsString); Assert.AreEqual(stmt, listener.AssertOneGetAndResetCreatedEvents()); Assert.AreEqual(stmt, listener.AssertOneGetAndResetStateChangeEvents()); observer.Flush(); stmt.Stop(); Assert.AreEqual("STATECHANGE;", observer.EventsAsString); Assert.AreEqual(stmt.Name, observer.Events[0].Statement.Name); Assert.AreEqual(stmt, listener.AssertOneGetAndResetStateChangeEvents()); observer.Flush(); stmt.Events += (sender, args) => { }; Assert.AreEqual("LISTENER_ADD;", observer.EventsAsString); Assert.IsNotNull(observer.LastContext); Assert.IsTrue(observer.LastContext[0] is UpdateEventHandler); observer.Flush(); stmt.RemoveAllEventHandlers(); Assert.AreEqual(StatementLifecycleEvent.LifecycleEventType.LISTENER_REMOVE_ALL.ToString() + ";", observer.EventsAsString); stmt.Dispose(); Assert.AreEqual(stmt, listener.AssertOneGetAndResetStateChangeEvents()); stateChangeEngine.Dispose(); }
private void RunAssertionManagementEvents(EPServiceProvider epService) { SupportVirtualDW vdw = RegisterTypeSetMapData(epService); // create-index event vdw.Events.Clear(); EPStatement stmtIndex = epService.EPAdministrator.CreateEPL("create index IndexOne on MyVDW (col3, col2 btree)"); VirtualDataWindowEventStartIndex startEvent = (VirtualDataWindowEventStartIndex)vdw.Events[0]; Assert.AreEqual("MyVDW", startEvent.NamedWindowName); Assert.AreEqual("IndexOne", startEvent.IndexName); Assert.AreEqual(2, startEvent.Fields.Count); Assert.AreEqual("col3", ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(startEvent.Fields[0].Expressions[0])); Assert.AreEqual("hash", startEvent.Fields[0].Type); Assert.AreEqual("col2", ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(startEvent.Fields[1].Expressions[0])); Assert.AreEqual("btree", startEvent.Fields[1].Type); Assert.IsFalse(startEvent.IsUnique); // stop-index event vdw.Events.Clear(); stmtIndex.Stop(); VirtualDataWindowEventStopIndex stopEvent = (VirtualDataWindowEventStopIndex)vdw.Events[0]; Assert.AreEqual("MyVDW", stopEvent.NamedWindowName); Assert.AreEqual("IndexOne", stopEvent.IndexName); // stop named window vdw.Events.Clear(); epService.EPAdministrator.GetStatement("create-nw").Stop(); VirtualDataWindowEventStopWindow stopWindow = (VirtualDataWindowEventStopWindow)vdw.Events[0]; Assert.AreEqual("MyVDW", stopWindow.NamedWindowName); // start named window (not an event but a new factory call) SupportVirtualDWFactory.Windows.Clear(); SupportVirtualDWFactory.Initializations.Clear(); epService.EPAdministrator.GetStatement("create-nw").Start(); Assert.AreEqual(1, SupportVirtualDWFactory.Windows.Count); Assert.AreEqual(1, SupportVirtualDWFactory.Initializations.Count); DestroyStmtsRemoveTypes(epService); }
private void RunAssertionQueryFields(EPServiceProvider epService) { string statementText = "select myInt + 2 as intVal, 'x' || myString || 'x' as stringVal from MyObjectArrayEvent#length(5)"; EPStatement statement = epService.EPAdministrator.CreateEPL(statementText); var listener = new SupportUpdateListener(); statement.Events += listener.Update; // send IDictionary<string, Object> event epService.EPRuntime.SendEvent(new object[] { 3, "some string", SupportBeanComplexProps.MakeDefaultBean() }, "MyObjectArrayEvent"); Assert.AreEqual(5, listener.LastNewData[0].Get("intVal")); Assert.AreEqual("xsome stringx", listener.LastNewData[0].Get("stringVal")); // send Map base event epService.EPRuntime.SendEvent(new object[] { 4, "string2", null }, "MyObjectArrayEvent"); Assert.AreEqual(6, listener.LastNewData[0].Get("intVal")); Assert.AreEqual("xstring2x", listener.LastNewData[0].Get("stringVal")); statement.Stop(); }
public void TestSubclassInterface() { _epService.EPAdministrator.Configuration.AddEventType("ISupportRevisionFull", typeof(ISupportRevisionFull)); _epService.EPAdministrator.Configuration.AddEventType("ISupportDeltaFive", typeof(ISupportDeltaFive)); var config = new ConfigurationRevisionEventType(); config.AddNameBaseEventType("ISupportRevisionFull"); config.KeyPropertyNames = (new String[] { "K0" }); config.AddNameDeltaEventType("ISupportDeltaFive"); _epService.EPAdministrator.Configuration.AddRevisionEventType("MyInterface", config); _stmtCreateWin = _epService.EPAdministrator.CreateEPL( "create window MyInterfaceWindow.win:keepall() as select * from MyInterface"); _epService.EPAdministrator.CreateEPL("insert into MyInterfaceWindow select * from ISupportRevisionFull"); _epService.EPAdministrator.CreateEPL("insert into MyInterfaceWindow select * from ISupportDeltaFive"); EPStatement consumerOne = _epService.EPAdministrator.CreateEPL("@Audit select irstream K0,P0,P1 from MyInterfaceWindow"); consumerOne.Events += _listenerOne.Update; String[] fields = "K0,P0,P1".Split(','); EPAssertionUtil.AssertEqualsAnyOrder(consumerOne.EventType.PropertyNames, fields); _epService.EPRuntime.SendEvent(new SupportRevisionFull(null, "00", "10", "20", "30", "40", "50")); EPAssertionUtil.AssertProps(_listenerOne.AssertOneGetNewAndReset(), fields, new Object[] { null, "00", "10" }); _epService.EPRuntime.SendEvent(new SupportDeltaFive(null, "999", null)); EPAssertionUtil.AssertProps(_listenerOne.LastNewData[0], fields, new Object[] { null, "00", "999" }); EPAssertionUtil.AssertProps(_listenerOne.LastOldData[0], fields, new Object[] { null, "00", "10" }); _listenerOne.Reset(); _stmtCreateWin.Stop(); _stmtCreateWin.Start(); consumerOne.Stop(); consumerOne.Start(); _epService.EPRuntime.SendEvent(new SupportRevisionFull("zz", "xx", "yy", "20", "30", "40", "50")); EPAssertionUtil.AssertProps(_listenerOne.AssertOneGetNewAndReset(), fields, new Object[] { "zz", "xx", "yy" }); }
private void TryExpr(String filterExpr, String fieldName, Object[] values, bool[] isInvoked) { String expr = "select * from " + typeof(SupportBean).FullName + filterExpr; EPStatement stmt = _epService.EPAdministrator.CreateEPL(expr); stmt.Events += _testListener.Update; for (int i = 0; i < values.Length; i++) { SendBean(fieldName, values[i]); Assert.AreEqual( isInvoked[i], _testListener.IsInvoked, "Listener invocation unexpected for " + filterExpr + " field " + fieldName + "=" + values[i] ); _testListener.Reset(); } stmt.Stop(); }
public void TestStartStop() { String stmtText = "select * from pattern [every(a=" + typeof(SupportBean).FullName + " or b=" + typeof(SupportBeanComplexProps).FullName + ")]"; EPStatement statement = _epService.EPAdministrator.CreateEPL(stmtText); statement.Events += _updateListener.Update; for (int i = 0; i < 100; i++) { SendAndAssert(); statement.Stop(); _epService.EPRuntime.SendEvent(new SupportBean()); _epService.EPRuntime.SendEvent(SupportBeanComplexProps.MakeDefaultBean()); Assert.IsFalse(_updateListener.IsInvoked); statement.Start(); } }
public DynaLatencySpikeMonitor(LatencyLimit limit) { Log.Debug("New limit, for operation '" + limit.OperationName + "' and customer '" + limit.CustomerId + "'" + " setting threshold " + limit.LatencyThreshold); var filter = "operationName='" + limit.OperationName + "',customerId='" + limit.CustomerId + "'"; // Alert specific to operation and customer _spikeLatencyAlert = _admin.CreatePattern( "every alert=" + typeof(OperationMeasurement).FullName + "(" + filter + ", latency>" + limit.LatencyThreshold + ")"); _spikeLatencyAlert.Events += LogLatencyEvent; // Stop pattern when the threshold changes String eventName = typeof(LatencyLimit).FullName; EPStatement stopPattern = _admin.CreatePattern(eventName + "(" + filter + ")"); stopPattern.Events += ((newEvents, oldEvents) => _spikeLatencyAlert.Stop()); }
private void RunAssertionVariableBatch(EPServiceProvider epService) { epService.EPRuntime.SendEvent(new CurrentTimeEvent(0)); epService.EPAdministrator.CreateEPL("create variable bool POST = false"); var fields = new string[] { "TheString" }; EPStatement stmt = epService.EPAdministrator.CreateEPL("select irstream * from SupportBean#expr_batch(POST)"); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new CurrentTimeEvent(1000)); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SetVariableValue("POST", true); epService.EPRuntime.SendEvent(new CurrentTimeEvent(1001)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new object[][] { new object[] { "E1" } }, null); epService.EPRuntime.SendEvent(new SupportBean("E2", 1)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new object[][] { new object[] { "E2" } }, new object[][] { new object[] { "E1" } }); epService.EPRuntime.SendEvent(new SupportBean("E3", 1)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new object[][] { new object[] { "E3" } }, new object[][] { new object[] { "E2" } }); epService.EPRuntime.SetVariableValue("POST", false); epService.EPRuntime.SendEvent(new SupportBean("E4", 1)); epService.EPRuntime.SendEvent(new SupportBean("E5", 2)); epService.EPRuntime.SendEvent(new CurrentTimeEvent(2000)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SetVariableValue("POST", true); epService.EPRuntime.SendEvent(new CurrentTimeEvent(2001)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new object[][] { new object[] { "E4" }, new object[] { "E5" } }, new object[][] { new object[] { "E3" } }); epService.EPRuntime.SendEvent(new SupportBean("E6", 1)); EPAssertionUtil.AssertPropsPerRow(listener.GetAndResetDataListsFlattened(), fields, new object[][] { new object[] { "E6" } }, new object[][] { new object[] { "E4" }, new object[] { "E5" } }); stmt.Stop(); }
private void TryString(String expression, String[] input, bool?[] result) { String caseExpr = "select " + expression + " as result from " + typeof(SupportBean).FullName; EPStatement selectTestCase = _epService.EPAdministrator.CreateEPL( caseExpr); selectTestCase.Events += _listener.Update; Assert.AreEqual( typeof(bool?), selectTestCase.EventType.GetPropertyType("result")); for (int i = 0; i < input.Length; i++) { SendSupportBeanEvent(input[i]); EventBean theEvent = _listener.AssertOneGetNewAndReset(); Assert.AreEqual(result[i], theEvent.Get("result"), "Wrong result for " + input[i]); } selectTestCase.Stop(); }
public void TestVariableBatch() { _epService.EPRuntime.SendEvent(new CurrentTimeEvent(0)); _epService.EPAdministrator.CreateEPL("create variable bool POST = false"); String[] fields = new String[] { "TheString" }; EPStatement stmt = _epService.EPAdministrator.CreateEPL("select irstream * from SupportBean.win:expr_batch(POST)"); stmt.Events += _listener.Update; _epService.EPRuntime.SendEvent(new CurrentTimeEvent(1000)); _epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); Assert.IsFalse(_listener.IsInvoked); _epService.EPRuntime.SetVariableValue("POST", true); _epService.EPRuntime.SendEvent(new CurrentTimeEvent(1001)); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E1" } }, null); _epService.EPRuntime.SendEvent(new SupportBean("E2", 1)); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E2" } }, new Object[][] { new Object[] { "E1" } }); _epService.EPRuntime.SendEvent(new SupportBean("E3", 1)); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E3" } }, new Object[][] { new Object[] { "E2" } }); _epService.EPRuntime.SetVariableValue("POST", false); _epService.EPRuntime.SendEvent(new SupportBean("E4", 1)); _epService.EPRuntime.SendEvent(new SupportBean("E5", 2)); _epService.EPRuntime.SendEvent(new CurrentTimeEvent(2000)); Assert.IsFalse(_listener.IsInvoked); _epService.EPRuntime.SetVariableValue("POST", true); _epService.EPRuntime.SendEvent(new CurrentTimeEvent(2001)); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E4" }, new Object[] { "E5" } }, new Object[][] { new Object[] { "E3" } }); _epService.EPRuntime.SendEvent(new SupportBean("E6", 1)); EPAssertionUtil.AssertPropsPerRow(_listener.GetAndResetDataListsFlattened(), fields, new Object[][] { new Object[] { "E6" } }, new Object[][] { new Object[] { "E4" }, new Object[] { "E5" } }); stmt.Stop(); }
private void TrySendEvents(EPServiceProvider engine, int numEvents, bool useRandomLookupKey) { Random random = new Random(); String stmtText = "select myint from " + typeof(SupportBean_S0).FullName + " as s0," + " sql:MyDB ['select myint from mytesttable where ${id} = mytesttable.mybigint'] as s1"; EPStatement statement = engine.EPAdministrator.CreateEPL(stmtText); _listener = new SupportUpdateListener(); statement.Events += _listener.Update; Log.Debug(".trySendEvents Sending " + numEvents + " events"); for (int i = 0; i < numEvents; i++) { int id = 0; if (useRandomLookupKey) { id = random.Next(1000); } else { id = i % 10 + 1; } SupportBean_S0 bean = new SupportBean_S0(id); engine.EPRuntime.SendEvent(bean); if ((!useRandomLookupKey) || ((id >= 1) && (id <= 10))) { EventBean received = _listener.AssertOneGetNewAndReset(); Assert.AreEqual(id * 10, received.Get("myint")); } } Log.Debug(".trySendEvents Stopping statement"); statement.Stop(); }
public void TestInDynamic() { String expr = "select * from pattern [a=" + typeof(SupportBeanNumeric).FullName + " -> every b=" + typeof(SupportBean).FullName + "(IntPrimitive in (a.intOne, a.intTwo))]"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(expr); stmt.Events += _testListener.Update; SendBeanNumeric(10, 20); SendBeanInt(10); Assert.IsTrue(_testListener.GetAndClearIsInvoked()); SendBeanInt(11); Assert.IsFalse(_testListener.GetAndClearIsInvoked()); SendBeanInt(20); Assert.IsTrue(_testListener.GetAndClearIsInvoked()); stmt.Stop(); expr = "select * from pattern [a=" + typeof(SupportBean_S0).FullName + " -> every b=" + typeof(SupportBean).FullName + "(TheString in (a.p00, a.p01, a.p02))]"; stmt = _epService.EPAdministrator.CreateEPL(expr); stmt.Events += _testListener.Update; _epService.EPRuntime.SendEvent( new SupportBean_S0(1, "a", "b", "c", "d")); SendBeanString("a"); Assert.IsTrue(_testListener.GetAndClearIsInvoked()); SendBeanString("x"); Assert.IsFalse(_testListener.GetAndClearIsInvoked()); SendBeanString("b"); Assert.IsTrue(_testListener.GetAndClearIsInvoked()); SendBeanString("c"); Assert.IsTrue(_testListener.GetAndClearIsInvoked()); SendBeanString("d"); Assert.IsFalse(_testListener.GetAndClearIsInvoked()); }
private void TrySelectWhereJoined4Coercion(EPServiceProvider epService, string stmtText) { EPStatement stmt = epService.EPAdministrator.CreateEPL(stmtText); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; SendBean(epService, "A", 1, 10, 200, 3000); // IntPrimitive, IntBoxed, LongBoxed, DoubleBoxed SendBean(epService, "B", 1, 10, 200, 3000); SendBean(epService, "C", 1, 10, 200, 3000); Assert.IsNull(listener.AssertOneGetNewAndReset().Get("ids0")); SendBean(epService, "S", -2, 11, 0, 3001); SendBean(epService, "A", 2, 0, 11, 0); // IntPrimitive, IntBoxed, LongBoxed, DoubleBoxed SendBean(epService, "B", 2, 0, 0, 11); SendBean(epService, "C", 2, 3001, 0, 0); Assert.AreEqual(-2, listener.AssertOneGetNewAndReset().Get("ids0")); SendBean(epService, "S", -3, 12, 0, 3002); SendBean(epService, "A", 3, 0, 12, 0); // IntPrimitive, IntBoxed, LongBoxed, DoubleBoxed SendBean(epService, "B", 3, 0, 0, 12); SendBean(epService, "C", 3, 3003, 0, 0); Assert.AreEqual(null, listener.AssertOneGetNewAndReset().Get("ids0")); SendBean(epService, "S", -4, 11, 0, 3003); SendBean(epService, "A", 4, 0, 0, 0); // IntPrimitive, IntBoxed, LongBoxed, DoubleBoxed SendBean(epService, "B", 4, 0, 0, 11); SendBean(epService, "C", 4, 3003, 0, 0); Assert.AreEqual(null, listener.AssertOneGetNewAndReset().Get("ids0")); SendBean(epService, "S", -5, 14, 0, 3004); SendBean(epService, "A", 5, 0, 14, 0); // IntPrimitive, IntBoxed, LongBoxed, DoubleBoxed SendBean(epService, "B", 5, 0, 0, 11); SendBean(epService, "C", 5, 3004, 0, 0); Assert.AreEqual(null, listener.AssertOneGetNewAndReset().Get("ids0")); stmt.Stop(); }
public void TestInNumericCoercionDouble() { String caseExpr = "select IntBoxed in (FloatBoxed, DoublePrimitive, LongBoxed) as result from " + typeof(SupportBean).FullName; EPStatement selectTestCase = _epService.EPAdministrator.CreateEPL( caseExpr); selectTestCase.Events += _listener.Update; Assert.AreEqual( typeof(bool?), selectTestCase.EventType.GetPropertyType("result")); SendAndAssert(1, 2f, 3d, 4L, false); SendAndAssert(1, 1f, 3d, 4L, true); SendAndAssert(1, 1.1f, 1.0d, 4L, true); SendAndAssert(1, 1.1f, 1.2d, 1L, true); SendAndAssert(1, null, 1.2d, 1L, true); SendAndAssert(null, null, 1.2d, 1L, null); SendAndAssert(null, 11f, 1.2d, 1L, null); selectTestCase.Stop(); }
public void TestInNumericCoercionLong() { String caseExpr = "select IntPrimitive in (ShortBoxed, IntBoxed, LongBoxed) as result from " + typeof(SupportBean).FullName; EPStatement selectTestCase = _epService.EPAdministrator.CreateEPL( caseExpr); selectTestCase.Events += _listener.Update; Assert.AreEqual( typeof(bool?), selectTestCase.EventType.GetPropertyType("result")); SendAndAssert(1, 2, 3, 4L, false); SendAndAssert(1, 1, 3, 4L, true); SendAndAssert(1, 3, 1, 4L, true); SendAndAssert(1, 3, 7, 1L, true); SendAndAssert(1, 3, 7, null, null); SendAndAssert(1, 1, null, null, true); SendAndAssert(1, 0, null, 1L, true); selectTestCase.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(); }
private void RunAssertionInDynamic(EPServiceProvider epService) { string expr = "select * from pattern [a=" + typeof(SupportBeanNumeric).FullName + " -> every b=" + typeof(SupportBean).FullName + "(IntPrimitive in (a.intOne, a.intTwo))]"; EPStatement stmt = epService.EPAdministrator.CreateEPL(expr); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; SendBeanNumeric(epService, 10, 20); SendBeanInt(epService, 10); Assert.IsTrue(listener.GetAndClearIsInvoked()); SendBeanInt(epService, 11); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendBeanInt(epService, 20); Assert.IsTrue(listener.GetAndClearIsInvoked()); stmt.Stop(); expr = "select * from pattern [a=" + typeof(SupportBean_S0).FullName + " -> every b=" + typeof(SupportBean).FullName + "(TheString in (a.p00, a.p01, a.p02))]"; stmt = epService.EPAdministrator.CreateEPL(expr); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean_S0(1, "a", "b", "c", "d")); SendBeanString(epService, "a"); Assert.IsTrue(listener.GetAndClearIsInvoked()); SendBeanString(epService, "x"); Assert.IsFalse(listener.GetAndClearIsInvoked()); SendBeanString(epService, "b"); Assert.IsTrue(listener.GetAndClearIsInvoked()); SendBeanString(epService, "c"); Assert.IsTrue(listener.GetAndClearIsInvoked()); SendBeanString(epService, "d"); Assert.IsFalse(listener.GetAndClearIsInvoked()); stmt.Dispose(); }
private void TrySelectWhereJoined4Coercion(String stmtText) { EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText); stmt.Events += _listener.Update; SendBean("A", 1, 10, 200, 3000); // intPrimitive, intBoxed, longBoxed, doubleBoxed SendBean("B", 1, 10, 200, 3000); SendBean("C", 1, 10, 200, 3000); Assert.IsNull(_listener.AssertOneGetNewAndReset().Get("ids0")); SendBean("S", -2, 11, 0, 3001); SendBean("A", 2, 0, 11, 0); // intPrimitive, intBoxed, longBoxed, doubleBoxed SendBean("B", 2, 0, 0, 11); SendBean("C", 2, 3001, 0, 0); Assert.AreEqual(-2, _listener.AssertOneGetNewAndReset().Get("ids0")); SendBean("S", -3, 12, 0, 3002); SendBean("A", 3, 0, 12, 0); // intPrimitive, intBoxed, longBoxed, doubleBoxed SendBean("B", 3, 0, 0, 12); SendBean("C", 3, 3003, 0, 0); Assert.AreEqual(null, _listener.AssertOneGetNewAndReset().Get("ids0")); SendBean("S", -4, 11, 0, 3003); SendBean("A", 4, 0, 0, 0); // intPrimitive, intBoxed, longBoxed, doubleBoxed SendBean("B", 4, 0, 0, 11); SendBean("C", 4, 3003, 0, 0); Assert.AreEqual(null, _listener.AssertOneGetNewAndReset().Get("ids0")); SendBean("S", -5, 14, 0, 3004); SendBean("A", 5, 0, 14, 0); // intPrimitive, intBoxed, longBoxed, doubleBoxed SendBean("B", 5, 0, 0, 11); SendBean("C", 5, 3004, 0, 0); Assert.AreEqual(null, _listener.AssertOneGetNewAndReset().Get("ids0")); stmt.Stop(); }
private void RunAssertionStartStopTwo(EPServiceProvider epService) { string stmtText = "select * from pattern [Every(a=" + typeof(SupportBean).FullName + " or b=" + typeof(SupportBeanComplexProps).FullName + ")]"; EPStatement statement = epService.EPAdministrator.CreateEPL(stmtText); var updateListener = new SupportUpdateListener(); statement.Events += updateListener.Update; for (int i = 0; i < 100; i++) { SendAndAssert(epService, updateListener); statement.Stop(); epService.EPRuntime.SendEvent(new SupportBean()); epService.EPRuntime.SendEvent(SupportBeanComplexProps.MakeDefaultBean()); Assert.IsFalse(updateListener.IsInvoked); statement.Start(); } statement.Dispose(); }
public static void RunAssertion(EPServiceProvider epService) { string statementText = "select nested as a, " + "nested.n1 as b," + "nested.n2 as c," + "nested.n2.n1n1 as d " + "from NestedMap#length(5)"; EPStatement statement = epService.EPAdministrator.CreateEPL(statementText); var listener = new SupportUpdateListener(); statement.Events += listener.Update; IDictionary <string, Object> mapEvent = TestData; epService.EPRuntime.SendEvent(mapEvent, "NestedMap"); EventBean theEvent = listener.AssertOneGetNewAndReset(); Assert.AreSame(mapEvent.Get("nested"), theEvent.Get("a")); Assert.AreSame("abc", theEvent.Get("b")); Assert.AreSame(((IDictionary <string, object>)mapEvent.Get("nested")).Get("n2"), theEvent.Get("c")); Assert.AreSame("def", theEvent.Get("d")); statement.Stop(); }
public void TestBetweenNumericCoercionLong() { String caseExpr = "select IntPrimitive between ShortBoxed and LongBoxed as result from " + typeof(SupportBean).FullName; EPStatement selectTestCase = _epService.EPAdministrator.CreateEPL( caseExpr); selectTestCase.Events += _listener.Update; Assert.AreEqual( typeof(bool?), selectTestCase.EventType.GetPropertyType("result")); SendAndAssert(1, 2, 3L, false); SendAndAssert(2, 2, 3L, true); SendAndAssert(3, 2, 3L, true); SendAndAssert(4, 2, 3L, false); SendAndAssert(5, 10, 1L, true); SendAndAssert(1, 10, 1L, true); SendAndAssert(10, 10, 1L, true); SendAndAssert(11, 10, 1L, false); selectTestCase.Stop(); }
public void TestRestartStatement() { String stmtText = "select mychar from " + typeof(SupportBean_S0).FullName + " as s0," + " sql:MyDB ['select mychar from mytesttable where ${id} = mytesttable.mybigint'] as s1"; EPStatement statement = _epService.EPAdministrator.CreateEPL(stmtText); _listener = new SupportUpdateListener(); statement.Events += _listener.Update; // Too many connections unless the stop actually relieves them for (int i = 0; i < 100; i++) { statement.Stop(); SendEventS0(1); Assert.IsFalse(_listener.IsInvoked); statement.Start(); SendEventS0(1); Assert.AreEqual("Z", _listener.AssertOneGetNewAndReset().Get("mychar")); } }
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 RunAssertionStartStopDeleter(bool namedWindow) { SupportNamedWindowObserver observer = new SupportNamedWindowObserver(); NamedWindowLifecycleEvent theEvent; if (namedWindow) { _epService.NamedWindowMgmtService.AddObserver(observer); } // create window string stmtTextCreate = namedWindow ? "create window MyInfra.win:keepall() as select TheString as a, IntPrimitive as b from " + typeof(SupportBean).FullName : "create table MyInfra(a string primary key, b int primary key)"; EPStatement stmtCreate = _epService.EPAdministrator.CreateEPL(stmtTextCreate); Assert.AreEqual(namedWindow ? StatementType.CREATE_WINDOW : StatementType.CREATE_TABLE, ((EPStatementSPI)stmtCreate).StatementMetadata.StatementType); stmtCreate.AddListener(_listenerWindow); if (namedWindow) { theEvent = observer.GetFirstAndReset(); Assert.AreEqual(NamedWindowLifecycleEvent.LifecycleEventType.CREATE, theEvent.EventType); Assert.AreEqual("MyInfra", theEvent.Name); } // stop and start, no consumers or deleters stmtCreate.Stop(); if (namedWindow) { theEvent = observer.GetFirstAndReset(); Assert.AreEqual(NamedWindowLifecycleEvent.LifecycleEventType.DESTROY, theEvent.EventType); Assert.AreEqual("MyInfra", theEvent.Name); } stmtCreate.Start(); if (namedWindow) { Assert.AreEqual(NamedWindowLifecycleEvent.LifecycleEventType.CREATE, observer.GetFirstAndReset().EventType); } // create delete stmt string stmtTextDelete = "on " + typeof(SupportBean_A).FullName + " delete from MyInfra"; EPStatement stmtDelete = _epService.EPAdministrator.CreateEPL(stmtTextDelete); // create insert into string stmtTextInsertOne = "insert into MyInfra select TheString as a, IntPrimitive as b from " + typeof(SupportBean).FullName; _epService.EPAdministrator.CreateEPL(stmtTextInsertOne); // create consumer string[] fields = new string[] { "a", "b" }; string stmtTextSelect = "select irstream a, b from MyInfra as s1"; EPStatement stmtSelect = _epService.EPAdministrator.CreateEPL(stmtTextSelect); stmtSelect.AddListener(_listenerSelect); // send 1 event SendSupportBean("E1", 1); if (namedWindow) { EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E1", 1 }); EPAssertionUtil.AssertProps(_listenerSelect.AssertOneGetNewAndReset(), fields, new object[] { "E1", 1 }); } else { Assert.IsFalse(_listenerWindow.IsInvoked); Assert.IsFalse(_listenerSelect.IsInvoked); } EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 } }); // Delete all events, 1 row expected SendSupportBean_A("A2"); if (namedWindow) { EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetOldAndReset(), fields, new object[] { "E1", 1 }); EPAssertionUtil.AssertProps(_listenerSelect.AssertOneGetOldAndReset(), fields, new object[] { "E1", 1 }); } EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, null); SendSupportBean("E2", 2); if (namedWindow) { EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E2", 2 }); EPAssertionUtil.AssertProps(_listenerSelect.AssertOneGetNewAndReset(), fields, new object[] { "E2", 2 }); } EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E2", 2 } }); // Stop the deleting statement stmtDelete.Stop(); SendSupportBean_A("A2"); Assert.IsFalse(_listenerWindow.IsInvoked); // Start the deleting statement stmtDelete.Start(); SendSupportBean_A("A3"); if (namedWindow) { EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetOldAndReset(), fields, new object[] { "E2", 2 }); EPAssertionUtil.AssertProps(_listenerSelect.AssertOneGetOldAndReset(), fields, new object[] { "E2", 2 }); } EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, null); SendSupportBean("E3", 3); if (namedWindow) { EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E3", 3 }); EPAssertionUtil.AssertProps(_listenerSelect.AssertOneGetNewAndReset(), fields, new object[] { "E3", 3 }); } EPAssertionUtil.AssertPropsPerRow(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E3", 3 } }); stmtDelete.Dispose(); SendSupportBean_A("A3"); Assert.IsFalse(_listenerWindow.IsInvoked); _epService.EPAdministrator.DestroyAllStatements(); _epService.EPAdministrator.Configuration.RemoveEventType("MyInfra", false); }
private void RunAssertionStartStopConsumer(bool namedWindow) { // create window string stmtTextCreate = namedWindow ? "create window MyInfra.win:keepall() as select TheString as a, IntPrimitive as b from " + typeof(SupportBean).FullName : "create table MyInfra(a string primary key, b int primary key)"; EPStatement stmtCreate = _epService.EPAdministrator.CreateEPL(stmtTextCreate); stmtCreate.AddListener(_listenerWindow); // create insert into string stmtTextInsertOne = "insert into MyInfra select TheString as a, IntPrimitive as b from " + typeof(SupportBean).FullName; _epService.EPAdministrator.CreateEPL(stmtTextInsertOne); // create consumer string[] fields = new string[] { "a", "b" }; string stmtTextSelect = "select a, b from MyInfra as s1"; EPStatement stmtSelect = _epService.EPAdministrator.CreateEPL(stmtTextSelect); stmtSelect.AddListener(_listenerSelect); // send 1 event SendSupportBean("E1", 1); if (namedWindow) { 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 } }); // stop consumer stmtSelect.Stop(); SendSupportBean("E2", 2); if (namedWindow) { EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E2", 2 }); } Assert.IsFalse(_listenerSelect.IsInvoked); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E2", 2 } }); // start consumer: the consumer has the last event even though he missed it stmtSelect.Start(); EPAssertionUtil.AssertPropsPerRowAnyOrder(stmtSelect.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E2", 2 } }); // consumer receives the next event SendSupportBean("E3", 3); if (namedWindow) { EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E3", 3 }); EPAssertionUtil.AssertProps(_listenerSelect.AssertOneGetNewAndReset(), fields, new object[] { "E3", 3 }); EPAssertionUtil.AssertPropsPerRow(stmtSelect.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E2", 2 }, new object[] { "E3", 3 } }); } EPAssertionUtil.AssertPropsPerRowAnyOrder(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E2", 2 }, new object[] { "E3", 3 } }); // destroy consumer stmtSelect.Dispose(); SendSupportBean("E4", 4); if (namedWindow) { EPAssertionUtil.AssertProps(_listenerWindow.AssertOneGetNewAndReset(), fields, new object[] { "E4", 4 }); } Assert.IsFalse(_listenerSelect.IsInvoked); _epService.EPAdministrator.DestroyAllStatements(); _epService.EPAdministrator.Configuration.RemoveEventType("MyInfra", false); }
public void TestStartStop() { var fields = new String[] { "TheString" }; String epl = "select TheString from SupportBean.win:time(60)"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(epl); stmt.Events += _listener.Update; EPServiceProviderIsolated unit = _epService.GetEPServiceIsolated("i1"); unit.EPAdministrator.AddStatement(stmt); _epService.EPRuntime.SendEvent(new SupportBean("E1", 0)); unit.EPRuntime.SendEvent(new SupportBean("E2", 0)); EPAssertionUtil.AssertPropsPerRowAnyOrder( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "E2" } } ); stmt.Stop(); unit.EPAdministrator.RemoveStatement(stmt); stmt.Start(); EPAssertionUtil.AssertPropsPerRowAnyOrder( stmt.GetEnumerator(), fields, null); _epService.EPRuntime.SendEvent(new SupportBean("E3", 0)); unit.EPRuntime.SendEvent(new SupportBean("E4", 0)); EPAssertionUtil.AssertPropsPerRowAnyOrder( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "E3" } } ); unit.EPAdministrator.AddStatement(stmt); _epService.EPRuntime.SendEvent(new SupportBean("E5", 0)); unit.EPRuntime.SendEvent(new SupportBean("E6", 0)); EPAssertionUtil.AssertPropsPerRowAnyOrder( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "E3" }, new Object[] { "E6" } } ); unit.EPAdministrator.RemoveStatement(stmt); _epService.EPRuntime.SendEvent(new SupportBean("E7", 0)); unit.EPRuntime.SendEvent(new SupportBean("E8", 0)); EPAssertionUtil.AssertPropsPerRowAnyOrder( stmt.GetEnumerator(), fields, new Object[][] { new Object[] { "E3" }, new Object[] { "E6" }, new Object[] { "E7" } } ); stmt.Stop(); _epService.EPAdministrator.DestroyAllStatements(); }
private void RunTest(PatternTestStyle testStyle) { Configuration config = SupportConfigFactory.GetConfiguration(); config.AddEventType("A", typeof(SupportBean_A)); config.AddEventType("B", typeof(SupportBean_B)); config.AddEventType("C", typeof(SupportBean_C)); config.AddEventType("D", typeof(SupportBean_D)); config.AddEventType("E", typeof(SupportBean_E)); config.AddEventType("F", typeof(SupportBean_F)); config.AddEventType("G", typeof(SupportBean_G)); EPServiceProvider serviceProvider = EPServiceProviderManager.GetDefaultProvider(config); serviceProvider.Initialize(); if (InstrumentationHelper.ENABLED) { InstrumentationHelper.StartTest(serviceProvider, _testClass, _testMethodName); } EPRuntime runtime = serviceProvider.EPRuntime; // Send the start time to the runtime if (_sendEventCollection.GetTime(EventCollection.ON_START_EVENT_ID) != null) { TimerEvent startTime = new CurrentTimeEvent(_sendEventCollection.GetTime(EventCollection.ON_START_EVENT_ID).Value); runtime.SendEvent(startTime); Log.Debug("RunTest: Start time is " + startTime); } // Set up expression filters and match listeners int index = 0; foreach (EventExpressionCase descriptor in _caseList.Results) { String expressionText = descriptor.ExpressionText; EPStatementObjectModel model = descriptor.ObjectModel; EPStatement statement = null; try { if (model != null) { statement = serviceProvider.EPAdministrator.Create(model, "name--" + expressionText); } else { if (testStyle == PatternTestStyle.USE_PATTERN_LANGUAGE) { statement = serviceProvider.EPAdministrator.CreatePattern(expressionText, "name--" + expressionText); } else if (testStyle == PatternTestStyle.USE_EPL) { String text = "@Audit('pattern') @Audit('pattern-instances') select * from pattern [" + expressionText + "]"; statement = serviceProvider.EPAdministrator.CreateEPL(text); expressionText = text; } else if (testStyle == PatternTestStyle.USE_EPL_AND_CONSUME_NOCHECK) { String text = "select * from pattern @DiscardPartialsOnMatch @SuppressOverlappingMatches [" + expressionText + "]"; statement = serviceProvider.EPAdministrator.CreateEPL(text); expressionText = text; } else if (testStyle == PatternTestStyle.COMPILE_TO_MODEL) { String text = "select * from pattern [" + expressionText + "]"; EPStatementObjectModel mymodel = serviceProvider.EPAdministrator.CompileEPL(text); statement = serviceProvider.EPAdministrator.Create(mymodel); expressionText = text; } else if (testStyle == PatternTestStyle.COMPILE_TO_EPL) { String text = "select * from pattern [" + expressionText + "]"; EPStatementObjectModel mymodel = serviceProvider.EPAdministrator.CompileEPL(text); String reverse = mymodel.ToEPL(); statement = serviceProvider.EPAdministrator.CreateEPL(reverse); expressionText = reverse; } else { throw new ArgumentException("Unknown test style"); } } } catch (Exception ex) { String text = expressionText; if (model != null) { text = "Model: " + model.ToEPL(); } Log.Error(".runTest Failed to create statement for style " + testStyle + " pattern expression=" + text, ex); Assert.Fail(".runTest Failed to create statement for style " + testStyle + " pattern expression=" + text); } // We stop the statement again and start after the first listener was added. // Thus we can handle patterns that fireStatementStopped on startup. statement.Stop(); _expressions[index] = statement; _expressions[index].Events += _listeners[index].Update; // Start the statement again: listeners now got called for on-start events such as for a "not" statement.Start(); index++; } // Some expressions may fireStatementStopped as soon as they are started, such as a "not b()" expression, for example. // Check results for any such listeners/expressions. // NOTE: For EPL statements we do not support calling listeners when a pattern that fires upon start. // Reason is that this should not be a relevant functionality of a pattern, the start pattern // event itself cannot carry any information and is thus ignore. Note subsequent events // generated by the same pattern are fine. int totalEventsReceived = 0; if (testStyle != PatternTestStyle.USE_PATTERN_LANGUAGE) { ClearListenerEvents(); totalEventsReceived += CountExpectedEvents(EventCollection.ON_START_EVENT_ID); } else // Patterns do need to handle event publishing upon pattern expression start (patterns that turn true right away) { CheckResults(testStyle, EventCollection.ON_START_EVENT_ID); totalEventsReceived += CountListenerEvents(); ClearListenerEvents(); } // Send actual test events var entryCollection = _sendEventCollection.ToArray(); for (int ii = 0; ii < entryCollection.Length; ii++) { var entry = entryCollection[ii]; var eventId = entry.Key; // Manipulate the time when this event was send if (_sendEventCollection.GetTime(eventId) != null) { TimerEvent currentTimeEvent = new CurrentTimeEvent(_sendEventCollection.GetTime(eventId).Value); runtime.SendEvent(currentTimeEvent); Log.Debug("RunTest: Sending event {0} = {1} timed {2}", entry.Key, entry.Value, currentTimeEvent); } // Send event itself runtime.SendEvent(entry.Value); // Check expected results for this event if (testStyle != PatternTestStyle.USE_EPL_AND_CONSUME_NOCHECK) { CheckResults(testStyle, eventId); // Count and clear the list of events that each listener has received totalEventsReceived += CountListenerEvents(); } ClearListenerEvents(); } // Count number of expected matches int totalExpected = 0; foreach (EventExpressionCase descriptor in _caseList.Results) { totalExpected += descriptor.ExpectedResults.Values.Sum(events => events.Count); } if (totalExpected != totalEventsReceived && testStyle != PatternTestStyle.USE_EPL_AND_CONSUME_NOCHECK) { Log.Debug(".test Count expected does not match count received, expected=" + totalExpected + " received=" + totalEventsReceived); Assert.Fail(); } // Kill all expressions foreach (EPStatement expression in _expressions) { expression.RemoveAllEventHandlers(); } // Send test events again to also test that all were indeed killed foreach (var entry in _sendEventCollection) { runtime.SendEvent(entry.Value); } // Make sure all listeners are still at zero foreach (SupportUpdateListener listener in _listeners) { if (listener.NewDataList.Count > 0) { Log.Debug(".test A match was received after stopping all expressions"); Assert.Fail(); } } if (InstrumentationHelper.ENABLED) { InstrumentationHelper.EndTest(); } }