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();
        }
예제 #2
0
        public void TestStatementStateChange()
        {
            var spi = (EPServiceProviderSPI)_epService;

            var observer = new SupportStmtLifecycleObserver();

            spi.StatementLifecycleSvc.LifecycleEvent += observer.Observe;
            var listener = new SupportStatementStateListener();

            _epService.StatementCreate      += listener.OnStatementCreate;
            _epService.StatementStateChange += listener.OnStatementStateChange;

            var stmt = _epService.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.NotNull(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());
        }