private void RunAssertionStartStop(EPServiceProvider epService) { string epl = "select count(*) as size from " + typeof(SupportBean).FullName; EPStatement sizeStmt = epService.EPAdministrator.CreateEPL(epl); // View created is automatically started Assert.AreEqual(0L, sizeStmt.First().Get("size")); sizeStmt.Stop(); // Send an event, view stopped SendEvent(epService); Assert.IsNotNull(sizeStmt.GetEnumerator()); Assert.That(sizeStmt.GetEnumerator().MoveNext(), Is.False); // Start view sizeStmt.Start(); Assert.AreEqual(0L, sizeStmt.First().Get("size")); // Send event SendEvent(epService); Assert.AreEqual(1L, sizeStmt.First().Get("size")); // Stop view sizeStmt.Stop(); Assert.IsNotNull(sizeStmt.GetEnumerator()); Assert.That(sizeStmt.GetEnumerator().MoveNext(), Is.False); // Start again, iterator is zero sizeStmt.Start(); Assert.AreEqual(0L, sizeStmt.First().Get("size")); sizeStmt.Dispose(); }
public void TestStartStop() { String viewExpr = "select count(*) as size from " + typeof(SupportBean).FullName; EPStatement sizeView = _epService.EPAdministrator.CreateEPL(viewExpr); // View created is automatically started Assert.AreEqual(0l, sizeView.FirstOrDefault().Get("size")); sizeView.Stop(); // Send an event, view stopped SendEvent(); var sizeViewEnum = sizeView.GetEnumerator(); Assert.IsNotNull(sizeViewEnum); var sizeViewArray = sizeViewEnum.EnumeratorToArray(); Assert.That(sizeViewArray.Length, Is.EqualTo(0)); // Start view sizeView.Start(); Assert.AreEqual(0l, sizeView.FirstOrDefault().Get("size")); // Send event SendEvent(); Assert.AreEqual(1l, sizeView.FirstOrDefault().Get("size")); // Stop view sizeView.Stop(); Assert.That(sizeView.GetEnumerator(), Is.InstanceOf <NullEnumerator <EventBean> >()); // Start again, iterator is zero sizeView.Start(); Assert.AreEqual(0l, sizeView.FirstOrDefault().Get("size")); }
public void TestStartStop() { String viewExpr = "@IterableUnbound every tag=" + typeof(SupportBean).FullName; EPStatement patternStmt = _epService.EPAdministrator.CreatePattern(viewExpr, "MyPattern"); Assert.AreEqual(StatementType.PATTERN, ((EPStatementSPI)patternStmt).StatementMetadata.StatementType); // Pattern started when created Assert.IsFalse(patternStmt.HasFirst()); using (IEnumerator <EventBean> safe = patternStmt.GetSafeEnumerator()) { Assert.IsFalse(safe.MoveNext()); } // Stop pattern patternStmt.Stop(); SendEvent(); Assert.That(patternStmt.GetEnumerator(), Is.InstanceOf <NullEnumerator <EventBean> >()); // Start pattern patternStmt.Start(); Assert.IsFalse(patternStmt.HasFirst()); // Send event SupportBean theEvent = SendEvent(); Assert.AreSame(theEvent, patternStmt.First().Get("tag")); using (var safe = patternStmt.GetSafeEnumerator()) { Assert.That(safe.MoveNext(), Is.True); Assert.AreSame(theEvent, safe.Current.Get("tag")); } // Stop pattern patternStmt.Stop(); Assert.That(patternStmt.GetEnumerator(), Is.InstanceOf <NullEnumerator <EventBean> >()); // Start again, iterator is zero patternStmt.Start(); Assert.IsFalse(patternStmt.HasFirst()); // assert statement-eventtype reference info EPServiceProviderSPI spi = (EPServiceProviderSPI)_epService; Assert.IsTrue(spi.StatementEventTypeRef.IsInUse(typeof(SupportBean).FullName)); ICollection <String> stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType(typeof(SupportBean).FullName); Assert.IsTrue(stmtNames.Contains("MyPattern")); patternStmt.Dispose(); Assert.IsFalse(spi.StatementEventTypeRef.IsInUse(typeof(SupportBean).FullName)); stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType(typeof(SupportBean).FullName); Assert.IsFalse(stmtNames.Contains("MyPattern")); }
private void RunAssertionStartStop(EPServiceProvider epService) { string epl = "@IterableUnbound every tag=" + typeof(SupportBean).FullName; EPStatement patternStmt = epService.EPAdministrator.CreatePattern(epl, "MyPattern"); Assert.AreEqual(StatementType.PATTERN, ((EPStatementSPI)patternStmt).StatementMetadata.StatementType); // Pattern started when created Assert.IsFalse(patternStmt.HasFirst()); var safe = patternStmt.GetSafeEnumerator(); Assert.IsFalse(safe.MoveNext()); safe.Dispose(); // Stop pattern patternStmt.Stop(); SendEvent(epService); //Assert.IsNull(patternStmt.GetEnumerator()); // Start pattern patternStmt.Start(); Assert.IsFalse(patternStmt.HasFirst()); // Send event SupportBean theEvent = SendEvent(epService); Assert.AreSame(theEvent, patternStmt.First().Get("tag")); safe = patternStmt.GetSafeEnumerator(); Assert.IsTrue(safe.MoveNext()); Assert.AreSame(theEvent, safe.Current.Get("tag")); safe.Dispose(); // Stop pattern patternStmt.Stop(); //Assert.IsNull(patternStmt.GetEnumerator()); // Start again, iterator is zero patternStmt.Start(); Assert.IsFalse(patternStmt.HasFirst()); // assert statement-eventtype reference info EPServiceProviderSPI spi = (EPServiceProviderSPI)epService; Assert.IsTrue(spi.StatementEventTypeRef.IsInUse(typeof(SupportBean).FullName)); var stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType(typeof(SupportBean).FullName); Assert.IsTrue(stmtNames.Contains("MyPattern")); patternStmt.Dispose(); Assert.IsFalse(spi.StatementEventTypeRef.IsInUse(typeof(SupportBean).FullName)); stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType(typeof(SupportBean).FullName); Assert.IsFalse(stmtNames.Contains("MyPattern")); }
private void RunAssertionAddRemoveListener(EPServiceProvider epService) { string epl = "select count(*) as size from " + typeof(SupportBean).FullName; EPStatement sizeStmt = epService.EPAdministrator.CreateEPL(epl); var listener = new SupportUpdateListener(); // View is started when created // Add listener send event sizeStmt.Events += listener.Update; Assert.IsNull(listener.LastNewData); Assert.AreEqual(0L, sizeStmt.First().Get("size")); SendEvent(epService); Assert.AreEqual(1L, listener.GetAndResetLastNewData()[0].Get("size")); Assert.AreEqual(1L, sizeStmt.First().Get("size")); // Stop view, send event, view sizeStmt.Stop(); SendEvent(epService); Assert.That(sizeStmt.GetEnumerator(), Is.Not.Null); Assert.That(sizeStmt.GetEnumerator().MoveNext(), Is.False); Assert.IsNull(listener.LastNewData); // Start again sizeStmt.Events -= listener.Update; sizeStmt.Events += listener.Update; sizeStmt.Start(); SendEvent(epService); Assert.AreEqual(1L, listener.GetAndResetLastNewData()[0].Get("size")); Assert.AreEqual(1L, sizeStmt.First().Get("size")); // Stop again, leave listeners sizeStmt.Stop(); sizeStmt.Start(); SendEvent(epService); Assert.AreEqual(1L, listener.GetAndResetLastNewData()[0].Get("size")); // Remove listener, send event sizeStmt.Events -= listener.Update; SendEvent(epService); Assert.IsNull(listener.LastNewData); // Add listener back, send event sizeStmt.Events += listener.Update; SendEvent(epService); Assert.AreEqual(3L, listener.GetAndResetLastNewData()[0].Get("size")); sizeStmt.Dispose(); }
public void TestJoinUniquePerId() { String joinStatement = "select * from " + typeof(SupportMarketDataBean).FullName + "(Symbol='IBM').win:length(3) s0, " + typeof(SupportMarketDataBean).FullName + "(Symbol='CSCO').win:length(3) s1" + " where s0.Volume=s1.Volume"; EPStatement joinView = _epService.EPAdministrator.CreateEPL(joinStatement, "MyJoin"); joinView.Events += _updateListener.Update; SendEvent(setOne[0]); SendEvent(setTwo[0]); Assert.NotNull(_updateListener.LastNewData); _updateListener.Reset(); joinView.Stop(); SendEvent(setOne[1]); SendEvent(setTwo[1]); Assert.IsFalse(_updateListener.IsInvoked); joinView.Start(); SendEvent(setOne[2]); Assert.IsFalse(_updateListener.IsInvoked); joinView.Stop(); SendEvent(setOne[3]); SendEvent(setOne[4]); SendEvent(setTwo[3]); joinView.Start(); SendEvent(setTwo[4]); Assert.IsFalse(_updateListener.IsInvoked); // assert type-statement reference EPServiceProviderSPI spi = (EPServiceProviderSPI)_epService; Assert.IsTrue(spi.StatementEventTypeRef.IsInUse(typeof(SupportMarketDataBean).FullName)); ICollection <String> stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType(typeof(SupportMarketDataBean).FullName); Assert.IsTrue(stmtNames.Contains("MyJoin")); joinView.Dispose(); Assert.IsFalse(spi.StatementEventTypeRef.IsInUse(typeof(SupportMarketDataBean).FullName)); stmtNames = spi.StatementEventTypeRef.GetStatementNamesForType(typeof(SupportMarketDataBean).FullName); EPAssertionUtil.AssertEqualsAnyOrder(null, stmtNames.ToArray()); Assert.IsFalse(stmtNames.Contains("MyJoin")); }
public override void Run(EPServiceProvider epService) { var fields = new string[] { "sumPrice" }; string statementString = "select sum(price) as sumPrice from " + typeof(SupportMarketDataBean).FullName + "#length(10) as one, " + typeof(SupportBeanString).FullName + "#length(100) as two " + "where one.symbol = two.TheString " + "order by price"; EPStatement statement = epService.EPAdministrator.CreateEPL(statementString); SendJoinEvents(epService); SendEvent(epService, "CAT", 50); SendEvent(epService, "IBM", 49); SendEvent(epService, "CAT", 15); SendEvent(epService, "IBM", 100); EPAssertionUtil.AssertPropsPerRow(statement.GetEnumerator(), fields, new object[][] { new object[] { 214d } }); SendEvent(epService, "KGB", 75); EPAssertionUtil.AssertPropsPerRow(statement.GetEnumerator(), fields, new object[][] { new object[] { 289d } }); // JIRA ESPER-644 Infinite loop when restarting a statement epService.EPAdministrator.Configuration.AddEventType("FB", Collections.SingletonDataMap("timeTaken", typeof(double))); EPStatement stmt = epService.EPAdministrator.CreateEPL("select avg(timeTaken) as timeTaken from FB order by timeTaken desc"); stmt.Stop(); stmt.Start(); }
private void RunAssertionStartStopStatement(EPServiceProvider epService) { string stmtText = "select id from S0 where (select true from S1#length(1000))"; EPStatement stmt = epService.EPAdministrator.CreateEPL(stmtText); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; epService.EPRuntime.SendEvent(new SupportBean_S0(2)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean_S1(10)); epService.EPRuntime.SendEvent(new SupportBean_S0(2)); Assert.AreEqual(2, listener.AssertOneGetNewAndReset().Get("id")); stmt.Stop(); epService.EPRuntime.SendEvent(new SupportBean_S0(2)); Assert.IsFalse(listener.IsInvoked); stmt.Start(); epService.EPRuntime.SendEvent(new SupportBean_S0(2)); Assert.IsFalse(listener.IsInvoked); epService.EPRuntime.SendEvent(new SupportBean_S1(10)); epService.EPRuntime.SendEvent(new SupportBean_S0(3)); Assert.AreEqual(3, listener.AssertOneGetNewAndReset().Get("id")); stmt.Dispose(); }
public void TestAvgMaxStopStart() { String stmtText = "select (select avg(id) + max(id) from S1.win:length(3)) as value from S0"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText); stmt.Events += _listener.Update; SendEventS0(1); Assert.AreEqual(null, _listener.AssertOneGetNewAndReset().Get("value")); SendEventS1(100); SendEventS0(2); Assert.AreEqual(200.0, _listener.AssertOneGetNewAndReset().Get("value")); SendEventS1(200); SendEventS0(3); Assert.AreEqual(350.0, _listener.AssertOneGetNewAndReset().Get("value")); stmt.Stop(); SendEventS1(10000); SendEventS0(4); Assert.IsFalse(_listener.IsInvoked); stmt.Start(); SendEventS1(10); SendEventS0(5); Assert.AreEqual(20.0, _listener.AssertOneGetNewAndReset().Get("value")); }
private void RunAssertionReuseUnique(EPServiceProvider epService) { epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); EPStatement stmt = epService.EPAdministrator.CreateEPL("select irstream * from SupportBean#unique(IntBoxed)"); var testListener = new SupportUpdateListener(); stmt.Events += testListener.Update; var beanOne = new SupportBean("E1", 1); epService.EPRuntime.SendEvent(beanOne); testListener.Reset(); EPStatement stmtTwo = epService.EPAdministrator.CreateEPL("select irstream * from SupportBean#unique(IntBoxed)"); var testListenerTwo = new SupportUpdateListener(); stmtTwo.Events += testListenerTwo.Update; stmt.Start(); // no effect var beanTwo = new SupportBean("E2", 2); epService.EPRuntime.SendEvent(beanTwo); Assert.AreSame(beanTwo, testListener.LastNewData[0].Underlying); Assert.AreSame(beanOne, testListener.LastOldData[0].Underlying); Assert.AreSame(beanTwo, testListenerTwo.LastNewData[0].Underlying); Assert.IsNull(testListenerTwo.LastOldData); stmt.Dispose(); }
private void RunAssertionUngroupedUncorrelatedTwoAggStopStart() { string stmtText = "select (select avg(id) + max(id) from S1#length(3)) as value from S0"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(stmtText); stmt.AddListener(_listener); SendEventS0(1); Assert.AreEqual(null, _listener.AssertOneGetNewAndReset().Get("value")); SendEventS1(100); SendEventS0(2); Assert.AreEqual(200.0, _listener.AssertOneGetNewAndReset().Get("value")); SendEventS1(200); SendEventS0(3); Assert.AreEqual(350.0, _listener.AssertOneGetNewAndReset().Get("value")); stmt.Stop(); SendEventS1(10000); SendEventS0(4); Assert.IsFalse(_listener.IsInvoked); stmt.Start(); SendEventS1(10); SendEventS0(5); Assert.AreEqual(20.0, _listener.AssertOneGetNewAndReset().Get("value")); stmt.Dispose(); }
private void RunAssertionUngroupedUncorrelatedTwoAggStopStart(EPServiceProvider epService) { string stmtText = "select (select avg(id) + max(id) from S1#length(3)) as value from S0"; EPStatement stmt = epService.EPAdministrator.CreateEPL(stmtText); var listener = new SupportUpdateListener(); stmt.Events += listener.Update; SendEventS0(epService, 1); Assert.AreEqual(null, listener.AssertOneGetNewAndReset().Get("value")); SendEventS1(epService, 100); SendEventS0(epService, 2); Assert.AreEqual(200.0, listener.AssertOneGetNewAndReset().Get("value")); SendEventS1(epService, 200); SendEventS0(epService, 3); Assert.AreEqual(350.0, listener.AssertOneGetNewAndReset().Get("value")); stmt.Stop(); SendEventS1(epService, 10000); SendEventS0(epService, 4); Assert.IsFalse(listener.IsInvoked); stmt.Start(); SendEventS1(epService, 10); SendEventS0(epService, 5); Assert.AreEqual(20.0, listener.AssertOneGetNewAndReset().Get("value")); stmt.Dispose(); }
private void RunAssertionRestartStatement(EPServiceProvider epService) { 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); var 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(epService, 1); Assert.IsFalse(listener.IsInvoked); statement.Start(); SendEventS0(epService, 1); Assert.AreEqual("Z", listener.AssertOneGetNewAndReset().Get("mychar")); } statement.Dispose(); }
public void TestIteratorAggregateRowForAll() { String[] fields = new String[] { "sumPrice" }; String statementString = "select sum(Price) as sumPrice from " + typeof(SupportMarketDataBean).FullName + ".win:length(10) as one, " + typeof(SupportBeanString).FullName + ".win:length(100) as two " + "where one.Symbol = two.TheString " + "order by Price"; EPStatement statement = _epService.EPAdministrator.CreateEPL(statementString); SendJoinEvents(); SendEvent("CAT", 50); SendEvent("IBM", 49); SendEvent("CAT", 15); SendEvent("IBM", 100); EPAssertionUtil.AssertPropsPerRow(statement.GetEnumerator(), fields, new Object[][] { new Object[] { 214d } }); SendEvent("KGB", 75); EPAssertionUtil.AssertPropsPerRow(statement.GetEnumerator(), fields, new Object[][] { new Object[] { 289d } }); // JIRA ESPER-644 Infinite loop when restarting a statement _epService.EPAdministrator.Configuration.AddEventType("FB", Collections.SingletonMap <string, object>("timeTaken", typeof(double))); EPStatement stmt = _epService.EPAdministrator.CreateEPL("select avg(timeTaken) as timeTaken from FB order by timeTaken desc"); stmt.Stop(); stmt.Start(); }
public void TestStartStopStatement() { SubscriberInterface subscriber = new SubscriberInterface(); EPStatement stmt = _epService.EPAdministrator.CreateEPL("select * from SupportMarkerInterface"); stmt.Subscriber = subscriber; SupportBean_A a1 = new SupportBean_A("A1"); _epService.EPRuntime.SendEvent(a1); EPAssertionUtil.AssertEqualsExactOrder(new Object[] { a1 }, subscriber.GetAndResetIndicate().ToArray()); SupportBean_B b1 = new SupportBean_B("B1"); _epService.EPRuntime.SendEvent(b1); EPAssertionUtil.AssertEqualsExactOrder(new Object[] { b1 }, subscriber.GetAndResetIndicate().ToArray()); stmt.Stop(); SupportBean_C c1 = new SupportBean_C("C1"); _epService.EPRuntime.SendEvent(c1); Assert.AreEqual(0, subscriber.GetAndResetIndicate().Count); stmt.Start(); SupportBean_D d1 = new SupportBean_D("D1"); _epService.EPRuntime.SendEvent(d1); EPAssertionUtil.AssertEqualsExactOrder(new Object[] { d1 }, subscriber.GetAndResetIndicate().ToArray()); }
private void AssertStmtDestroyed(EPStatement stmt, String text) { Assert.AreEqual(EPStatementState.DESTROYED, stmt.State); Assert.AreEqual(text, stmt.Text); Assert.AreEqual("s1", stmt.Name); Assert.IsNull(_epService.EPAdministrator.GetStatement("s1")); EPAssertionUtil.AssertEqualsAnyOrder(new String[0], _epService.EPAdministrator.StatementNames); try { stmt.Dispose(); Assert.Fail(); } catch (IllegalStateException ex) { // expected Assert.AreEqual("Statement already destroyed", ex.Message); } try { stmt.Start(); Assert.Fail(); } catch (IllegalStateException ex) { // expected Assert.AreEqual("Cannot start statement, statement is in destroyed state", ex.Message); } try { stmt.Stop(); Assert.Fail(); } catch (IllegalStateException ex) { // expected Assert.AreEqual("Cannot stop statement, statement is in destroyed state", ex.Message); } }
public void TestReuseUnique() { _epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); EPStatement stmt = _epService.EPAdministrator.CreateEPL("select irstream * from SupportBean#unique(IntBoxed)"); stmt.Events += _testListener.Update; SupportBean beanOne = new SupportBean("E1", 1); _epService.EPRuntime.SendEvent(beanOne); _testListener.Reset(); EPStatement stmtTwo = _epService.EPAdministrator.CreateEPL("select irstream * from SupportBean#unique(IntBoxed)"); SupportUpdateListener testListenerTwo = new SupportUpdateListener(); stmtTwo.Events += testListenerTwo.Update; stmt.Start(); // no effect SupportBean beanTwo = new SupportBean("E2", 2); _epService.EPRuntime.SendEvent(beanTwo); Assert.AreSame(beanTwo, _testListener.LastNewData[0].Underlying); Assert.AreSame(beanOne, _testListener.LastOldData[0].Underlying); Assert.AreSame(beanTwo, testListenerTwo.LastNewData[0].Underlying); Assert.IsNull(testListenerTwo.LastOldData); }
public void TestCreateStartStop() { String epl = "@Name('Create-A-Flow') create dataflow MyGraph Emitter -> outstream<?> {}"; EPStatement stmt = _epService.EPAdministrator.CreateEPL(epl); EPDataFlowRuntime dfruntime = _epService.EPRuntime.DataFlowRuntime; EPAssertionUtil.AssertEqualsAnyOrder(new String[] { "MyGraph" }, dfruntime.GetDataFlows()); EPDataFlowDescriptor desc = dfruntime.GetDataFlow("MyGraph"); Assert.AreEqual("MyGraph", desc.DataFlowName); Assert.AreEqual(EPStatementState.STARTED, desc.StatementState); Assert.AreEqual("Create-A-Flow", desc.StatementName); dfruntime.Instantiate("MyGraph"); // test duplicate TryInvalidCompile(epl, "Error starting statement: Data flow by name 'MyGraph' has already been declared ["); // stop - can no longer instantiate but still exists stmt.Stop(); // not removed Assert.AreEqual(EPStatementState.STOPPED, dfruntime.GetDataFlow("MyGraph").StatementState); TryInvalidCompile(epl, "Error starting statement: Data flow by name 'MyGraph' has already been declared ["); TryInstantiate("MyGraph", "Data flow by name 'MyGraph' is currently in STOPPED statement state"); TryInstantiate("DUMMY", "Data flow by name 'DUMMY' has not been defined"); // destroy - should be gone stmt.Dispose(); // removed, create again Assert.AreEqual(null, dfruntime.GetDataFlow("MyGraph")); Assert.AreEqual(0, dfruntime.GetDataFlows().Length); TryInstantiate("MyGraph", "Data flow by name 'MyGraph' has not been defined"); try { stmt.Start(); Assert.Fail(); } catch (IllegalStateException ex) { Assert.AreEqual("Cannot start statement, statement is in destroyed state", ex.Message); } // new one, try start-stop-start stmt = _epService.EPAdministrator.CreateEPL(epl); stmt.Stop(); stmt.Start(); dfruntime.Instantiate("MyGraph"); }
private void RunAssertionStartStopInserter(EPServiceProvider epService, bool namedWindow) { // create window string stmtTextCreate = namedWindow ? "create window MyInfra#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); var listenerWindow = new SupportUpdateListener(); stmtCreate.Events += listenerWindow.Update; // create insert into string stmtTextInsertOne = "insert into MyInfra select TheString as a, IntPrimitive as b from " + typeof(SupportBean).FullName; EPStatement stmtInsert = epService.EPAdministrator.CreateEPL(stmtTextInsertOne); // create consumer var fields = new string[] { "a", "b" }; string stmtTextSelect = "select a, b from MyInfra as s1"; EPStatement stmtSelect = epService.EPAdministrator.CreateEPL(stmtTextSelect); var listenerSelect = new SupportUpdateListener(); stmtSelect.Events += listenerSelect.Update; // send 1 event SendSupportBean(epService, "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 inserter stmtInsert.Stop(); SendSupportBean(epService, "E2", 2); Assert.IsFalse(listenerWindow.IsInvoked); Assert.IsFalse(listenerSelect.IsInvoked); // start inserter stmtInsert.Start(); // consumer receives the next event SendSupportBean(epService, "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[] { "E3", 3 } }); } EPAssertionUtil.AssertPropsPerRowAnyOrder(stmtCreate.GetEnumerator(), fields, new object[][] { new object[] { "E1", 1 }, new object[] { "E3", 3 } }); // destroy inserter stmtInsert.Dispose(); SendSupportBean(epService, "E4", 4); Assert.IsFalse(listenerWindow.IsInvoked); Assert.IsFalse(listenerSelect.IsInvoked); epService.EPAdministrator.DestroyAllStatements(); epService.EPAdministrator.Configuration.RemoveEventType("MyInfra", false); }
public void TestAddRemoveListener() { String viewExpr = "select count(*) as size from " + typeof(SupportBean).FullName; EPStatement sizeView = _epService.EPAdministrator.CreateEPL(viewExpr); // View is started when created // Add listener send event sizeView.Events += _testListener.Update; Assert.IsNull(_testListener.LastNewData); Assert.AreEqual(0l, sizeView.FirstOrDefault().Get("size")); SendEvent(); Assert.AreEqual(1l, _testListener.GetAndResetLastNewData()[0].Get("size")); Assert.AreEqual(1l, sizeView.FirstOrDefault().Get("size")); // Stop view, send event, view sizeView.Stop(); SendEvent(); Assert.That(sizeView.GetEnumerator(), Is.InstanceOf <NullEnumerator <EventBean> >()); Assert.IsNull(_testListener.LastNewData); // Start again sizeView.Events -= _testListener.Update; sizeView.Events += _testListener.Update; sizeView.Start(); SendEvent(); Assert.AreEqual(1l, _testListener.GetAndResetLastNewData()[0].Get("size")); Assert.AreEqual(1l, sizeView.FirstOrDefault().Get("size")); // Stop again, leave listeners sizeView.Stop(); sizeView.Start(); SendEvent(); Assert.AreEqual(1l, _testListener.GetAndResetLastNewData()[0].Get("size")); // Remove listener, send event sizeView.Events -= _testListener.Update; SendEvent(); Assert.IsNull(_testListener.LastNewData); // Add listener back, send event sizeView.Events += _testListener.Update; SendEvent(); Assert.AreEqual(3l, _testListener.GetAndResetLastNewData()[0].Get("size")); }
private void RunAssertionStmtNameDynamic(EPServiceProvider epService) { epService.EPAdministrator.Configuration.AddEventType <SupportBean>(); epService.EPAdministrator.CreateEPL("create dataflow MyDataFlowOne " + "create map schema SingleProp (id string), " + "EPStatementSource -> thedata<SingleProp> {" + " statementName : 'MyStatement'," + "} " + "DefaultSupportCaptureOp(thedata) {}"); var captureOp = new DefaultSupportCaptureOp(SupportContainer.Instance.LockManager()); var options = new EPDataFlowInstantiationOptions() .OperatorProvider(new DefaultSupportGraphOpProvider(captureOp)); EPDataFlowInstance df = epService.EPRuntime.DataFlowRuntime.Instantiate("MyDataFlowOne", options); Assert.IsNull(df.UserObject); Assert.IsNull(df.InstanceId); df.Start(); epService.EPRuntime.SendEvent(new SupportBean("E1", 1)); Assert.AreEqual(0, captureOp.Current.Length); EPStatement stmt = epService.EPAdministrator.CreateEPL("@Name('MyStatement') select TheString as id from SupportBean"); epService.EPRuntime.SendEvent(new SupportBean("E2", 2)); captureOp.WaitForInvocation(100, 1); EPAssertionUtil.AssertProps( epService.Container, captureOp.GetCurrentAndReset()[0], "id".Split(','), new object[] { "E2" }); stmt.Stop(); epService.EPRuntime.SendEvent(new SupportBean("E3", 3)); Assert.AreEqual(0, captureOp.Current.Length); stmt.Start(); epService.EPRuntime.SendEvent(new SupportBean("E4", 4)); captureOp.WaitForInvocation(100, 1); EPAssertionUtil.AssertProps( epService.Container, captureOp.GetCurrentAndReset()[0], "id".Split(','), new object[] { "E4" }); stmt.Dispose(); epService.EPRuntime.SendEvent(new SupportBean("E5", 5)); Assert.AreEqual(0, captureOp.Current.Length); epService.EPAdministrator.CreateEPL("@Name('MyStatement') select 'X'||TheString||'X' as id from SupportBean"); epService.EPRuntime.SendEvent(new SupportBean("E6", 6)); captureOp.WaitForInvocation(100, 1); EPAssertionUtil.AssertProps( epService.Container, captureOp.GetCurrentAndReset()[0], "id".Split(','), new object[] { "XE6X" }); df.Cancel(); epService.EPAdministrator.DestroyAllStatements(); }
/// <summary> /// Starting this statement fires an event and the listener starts a new statement (same expression) again, /// causing a loop. This listener limits to 10 - this is a smoke test. /// </summary> public override void Run(EPServiceProvider epService) { string patternExpr = "not " + typeof(SupportBean).FullName; EPStatement patternStmt = epService.EPAdministrator.CreatePattern(patternExpr); patternStmt.Events += new PatternUpdateListener(epService).Update; patternStmt.Stop(); patternStmt.Start(); }
public void TestStartFireLoop() { String patternExpr = "not " + typeof(SupportBean).FullName; EPStatement patternStmt = _epService.EPAdministrator.CreatePattern(patternExpr); patternStmt.Events += (new PatternUpdateListener(_epService)).Update; patternStmt.Stop(); patternStmt.Start(); }
public void TestSubscribeAndIterate() { String stmtCreateTextOne = "create variable long var1 = null"; EPStatement stmtCreateOne = _epService.EPAdministrator.CreateEPL(stmtCreateTextOne); Assert.AreEqual(StatementType.CREATE_VARIABLE, ((EPStatementSPI)stmtCreateOne).StatementMetadata.StatementType); stmtCreateOne.Events += _listenerCreateOne.Update; String[] fieldsVar1 = new String[] { "var1" }; EPAssertionUtil.AssertPropsPerRow(stmtCreateOne.GetEnumerator(), fieldsVar1, new Object[][] { new Object[] { null } }); Assert.IsFalse(_listenerCreateOne.IsInvoked); EventType typeSet = stmtCreateOne.EventType; Assert.AreEqual(typeof(long?), typeSet.GetPropertyType("var1")); Assert.AreEqual(typeof(Map), typeSet.UnderlyingType); Assert.IsTrue(Collections.AreEqual(typeSet.PropertyNames, new String[] { "var1" })); String stmtCreateTextTwo = "create variable long var2 = 20"; EPStatement stmtCreateTwo = _epService.EPAdministrator.CreateEPL(stmtCreateTextTwo); stmtCreateTwo.Events += _listenerCreateTwo.Update; String[] fieldsVar2 = new String[] { "var2" }; EPAssertionUtil.AssertPropsPerRow(stmtCreateTwo.GetEnumerator(), fieldsVar2, new Object[][] { new Object[] { 20L } }); Assert.IsFalse(_listenerCreateTwo.IsInvoked); String stmtTextSet = "on " + typeof(SupportBean).FullName + " set var1 = IntPrimitive * 2, var2 = var1 + 1"; _epService.EPAdministrator.CreateEPL(stmtTextSet); SendSupportBean("E1", 100); EPAssertionUtil.AssertProps(_listenerCreateOne.LastNewData[0], fieldsVar1, new Object[] { 200L }); EPAssertionUtil.AssertProps(_listenerCreateOne.LastOldData[0], fieldsVar1, new Object[] { null }); _listenerCreateOne.Reset(); EPAssertionUtil.AssertProps(_listenerCreateTwo.LastNewData[0], fieldsVar2, new Object[] { 201L }); EPAssertionUtil.AssertProps(_listenerCreateTwo.LastOldData[0], fieldsVar2, new Object[] { 20L }); _listenerCreateOne.Reset(); EPAssertionUtil.AssertPropsPerRow(stmtCreateOne.GetEnumerator(), fieldsVar1, new Object[][] { new Object[] { 200L } }); EPAssertionUtil.AssertPropsPerRow(stmtCreateTwo.GetEnumerator(), fieldsVar2, new Object[][] { new Object[] { 201L } }); SendSupportBean("E2", 200); EPAssertionUtil.AssertProps(_listenerCreateOne.LastNewData[0], fieldsVar1, new Object[] { 400L }); EPAssertionUtil.AssertProps(_listenerCreateOne.LastOldData[0], fieldsVar1, new Object[] { 200L }); _listenerCreateOne.Reset(); EPAssertionUtil.AssertProps(_listenerCreateTwo.LastNewData[0], fieldsVar2, new Object[] { 401L }); EPAssertionUtil.AssertProps(_listenerCreateTwo.LastOldData[0], fieldsVar2, new Object[] { 201L }); _listenerCreateOne.Reset(); EPAssertionUtil.AssertPropsPerRow(stmtCreateOne.GetEnumerator(), fieldsVar1, new Object[][] { new Object[] { 400L } }); EPAssertionUtil.AssertPropsPerRow(stmtCreateTwo.GetEnumerator(), fieldsVar2, new Object[][] { new Object[] { 401L } }); stmtCreateTwo.Stop(); stmtCreateTwo.Start(); EPAssertionUtil.AssertPropsPerRow(stmtCreateOne.GetEnumerator(), fieldsVar1, new Object[][] { new Object[] { 400L } }); EPAssertionUtil.AssertPropsPerRow(stmtCreateTwo.GetEnumerator(), fieldsVar2, new Object[][] { new Object[] { 20L } }); }
private void RunAssertionIntoTable(EPServiceProvider epService) { string eplCreate = "create table abc (total count(*))"; string eplUse = "select abc from SupportBean"; string eplInto = "into table abc select count(*) as total from SupportBean"; // typical select-use-destroy EPStatement stmtCreate = epService.EPAdministrator.CreateEPL(eplCreate); EPStatement stmtSelect = epService.EPAdministrator.CreateEPL(eplUse); EPStatement stmtInto = epService.EPAdministrator.CreateEPL(eplInto); Assert.IsNotNull(epService.EPAdministrator.Configuration.GetEventType("table_abc__public")); Assert.IsNotNull(epService.EPAdministrator.Configuration.GetEventType("table_abc__internal")); stmtCreate.Dispose(); stmtSelect.Dispose(); AssertFailCreate(epService, eplCreate); stmtInto.Dispose(); // destroy-all epService.EPAdministrator.CreateEPL(eplCreate); epService.EPAdministrator.CreateEPL(eplInto); epService.EPAdministrator.CreateEPL(eplUse); epService.EPAdministrator.DestroyAllStatements(); stmtCreate = epService.EPAdministrator.CreateEPL(eplCreate); stmtCreate.Dispose(); // deploy and undeploy as module string module = eplCreate + ";\n" + eplUse + ";\n" + eplInto + ";\n"; DeploymentResult deployed = epService.EPAdministrator.DeploymentAdmin.ParseDeploy(module); Assert.IsNotNull(epService.EPAdministrator.Configuration.GetEventType("table_abc__public")); Assert.IsNotNull(epService.EPAdministrator.Configuration.GetEventType("table_abc__internal")); AssertFailCreate(epService, eplCreate); epService.EPAdministrator.DeploymentAdmin.Undeploy(deployed.DeploymentId); Assert.IsNull(epService.EPAdministrator.Configuration.GetEventType("table_abc__public")); Assert.IsNull(epService.EPAdministrator.Configuration.GetEventType("table_abc__internal")); // stop and start EPStatement stmtCreateTwo = epService.EPAdministrator.CreateEPL(eplCreate); stmtCreateTwo.Stop(); AssertFailCreate(epService, eplCreate); stmtCreateTwo.Start(); AssertFailCreate(epService, eplCreate); epService.EPAdministrator.DestroyAllStatements(); epService.EPAdministrator.CreateEPL(eplCreate); epService.EPAdministrator.DestroyAllStatements(); }
private void RunAssertionStartStop(EPServiceProvider epService) { if (SupportConfigFactory.SkipTest(typeof(ExecClientIsolationUnit))) { return; } var fields = new string[] { "TheString" }; string epl = "select TheString from SupportBean#time(60)"; EPStatement stmt = epService.EPAdministrator.CreateEPL(epl); var listener = new SupportUpdateListener(); 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(); unit.Dispose(); epService.EPAdministrator.DestroyAllStatements(); }
public void Update(Object sender, UpdateEventArgs e) { Log.Warn(".Update"); if (Count < 10) { Count++; String patternExpr = "not " + typeof(SupportBean).FullName; EPStatement patternStmt = _epService.EPAdministrator.CreatePattern(patternExpr); patternStmt.Events += Update; patternStmt.Stop(); patternStmt.Start(); } }
public override void Run(EPServiceProvider epService) { epService.EPAdministrator.CreateEPL("create objectarray schema MyEvent(SubscriberName string, ValueInt float)"); string query = "select SubscriberName, avg(ValueInt) " + "from MyEvent#groupwin(SubscriberName)#length(4)" + "group by SubscriberName output snapshot every 1 events"; string query2 = "select SubscriberName, avedev(ValueInt) " + "from MyEvent#groupwin(SubscriberName)#length(3) " + "group by SubscriberName output snapshot every 1 events"; string[] groups = { "G_A", "G_A", "G_A", "G_A", "G_B", "G_B", "G_B", "G_B", "G_B", "G_B", "G_B", "G_B", "G_B", "G_B", "G_B", "G_B", "G_B", "G_B", "G_B", "G_B", "G_C", "G_C", "G_C", "G_C", "G_D", "G_A", "G_D", "G_D", "G_A", "G_D", "G_D", "G_D", "G_A", "G_A", "G_A", "G_A", "G_C", "G_C", "G_C", "G_C", "G_D", "G_A", "G_D", "G_D", "G_D", "G_A", "G_D", "G_D", "G_D", "G_E" }; EPStatement statement = epService.EPAdministrator.CreateEPL(query, "myquery"); EPStatement statement2 = epService.EPAdministrator.CreateEPL(query2, "myquery2"); var listener = new SupportUpdateListener(); statement.Events += listener.Update; statement2.Events += listener.Update; int i = 0; foreach (string csv in groups) { object[] @event = { csv, 0f }; epService.EPRuntime.SendEvent(@event, "MyEvent"); i++; EPStatement stmt = epService.EPAdministrator.GetStatement("myquery"); if (i % 6 == 0) { stmt.Stop(); } else if (i % 6 == 4) { stmt.Start(); } } }
private void RunAssertionUnmatchedSendEvent(EPServiceProvider epService) { var listener = new MyUnmatchedListener(); epService.EPRuntime.UnmatchedEvent += listener.Update; // no statement, should be unmatched SupportBean theEvent = SendEvent(epService, "E1"); Assert.AreEqual(1, listener.Received.Count); Assert.AreSame(theEvent, listener.Received[0].Underlying); listener.Reset(); // no unmatched listener epService.EPRuntime.RemoveAllUnmatchedEventHandlers(); SendEvent(epService, "E1"); Assert.AreEqual(0, listener.Received.Count); // create statement and re-register unmatched listener EPStatement stmt = epService.EPAdministrator.CreateEPL("select * from " + typeof(SupportBean).FullName); epService.EPRuntime.UnmatchedEvent += listener.Update; SendEvent(epService, "E1"); Assert.AreEqual(0, listener.Received.Count); // stop statement stmt.Stop(); theEvent = SendEvent(epService, "E1"); Assert.AreEqual(1, listener.Received.Count); Assert.AreSame(theEvent, listener.Received[0].Underlying); listener.Reset(); // start statement stmt.Start(); SendEvent(epService, "E1"); Assert.AreEqual(0, listener.Received.Count); // destroy statement stmt.Dispose(); theEvent = SendEvent(epService, "E1"); Assert.AreEqual(1, listener.Received.Count); Assert.AreSame(theEvent, listener.Received[0].Underlying); epService.EPRuntime.RemoveAllUnmatchedEventHandlers(); }
private void RunAssertionSubclassInterface(EPServiceProvider epService) { 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); EPStatement stmtCreateWin = epService.EPAdministrator.CreateEPL ("create window MyInterfaceWindow#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"); var listenerOne = new SupportUpdateListener(); 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" }); }