public virtual void TestListenerChain()
        {
            //create and register the listeners
            LoggingStateChangeListener logListener = new LoggingStateChangeListener();

            Register(logListener);
            BreakableStateChangeListener l0 = new BreakableStateChangeListener("l0");

            Register(l0);
            listener.SetFailingState(Service.STATE.Started);
            Register();
            BreakableStateChangeListener l3 = new BreakableStateChangeListener("l3");

            Register(l3);
            //create and init a service.
            BreakableService service = new BreakableService();

            service.Init(new Configuration());
            AssertServiceStateInited(service);
            AssertListenerState(l0, Service.STATE.Inited);
            AssertListenerState(listener, Service.STATE.Inited);
            AssertListenerState(l3, Service.STATE.Inited);
            service.Start();
            //expect that listener l1 and the failing listener are in start, but
            //not the final one
            AssertServiceStateStarted(service);
            AssertListenerState(l0, Service.STATE.Started);
            AssertListenerEventCount(l0, 2);
            AssertListenerState(listener, Service.STATE.Started);
            AssertListenerEventCount(listener, 2);
            //this is the listener that is not expected to have been invoked
            AssertListenerState(l3, Service.STATE.Inited);
            AssertListenerEventCount(l3, 1);
            //stop the service
            service.Stop();
            //listeners are all updated
            AssertListenerEventCount(l0, 3);
            AssertListenerEventCount(listener, 3);
            AssertListenerEventCount(l3, 2);
            //can all be unregistered in any order
            Unregister(logListener);
            Unregister(l0);
            Unregister(l3);
            //check that the listeners are all unregistered, even
            //though they were registered in a different order.
            //rather than do this by doing unregister checks, a new service is created
            service = new BreakableService();
            //this service is initialized
            service.Init(new Configuration());
            //it is asserted that the event count has not changed for the unregistered
            //listeners
            AssertListenerEventCount(l0, 3);
            AssertListenerEventCount(l3, 2);
            //except for the one listener that was not unregistered, which
            //has incremented by one
            AssertListenerEventCount(listener, 4);
        }
Ejemplo n.º 2
0
        public virtual void TestStopInInitService()
        {
            Org.Apache.Hadoop.Service.Service service = new TestServiceLifecycle.StopInInitService
                                                            ();
            BreakableStateChangeListener listener = new BreakableStateChangeListener();

            service.RegisterServiceListener(listener);
            service.Init(new Configuration());
            AssertServiceInState(service, Service.STATE.Stopped);
            AssertEventCount(listener, 1);
        }
Ejemplo n.º 3
0
        public virtual void TestSelfTerminatingService()
        {
            TestServiceLifecycle.SelfTerminatingService service = new TestServiceLifecycle.SelfTerminatingService
                                                                      ();
            BreakableStateChangeListener listener = new BreakableStateChangeListener();

            service.RegisterServiceListener(listener);
            service.Init(new Configuration());
            AssertEventCount(listener, 1);
            //start the service
            service.Start();
            //and expect an event count of exactly two
            AssertEventCount(listener, 2);
        }
Ejemplo n.º 4
0
        public virtual void TestServiceNotificationsStopOnceUnregistered()
        {
            BreakableService             svc      = new BreakableService(false, false, false);
            BreakableStateChangeListener listener = new BreakableStateChangeListener();

            svc.RegisterServiceListener(listener);
            svc.Init(new Configuration());
            AssertEventCount(listener, 1);
            svc.UnregisterServiceListener(listener);
            svc.Start();
            AssertEventCount(listener, 1);
            svc.Stop();
            AssertEventCount(listener, 1);
            svc.Stop();
        }
Ejemplo n.º 5
0
        public virtual void TestServiceFailingNotifications()
        {
            BreakableService             svc      = new BreakableService(false, false, false);
            BreakableStateChangeListener listener = new BreakableStateChangeListener();

            listener.SetFailingState(Service.STATE.Started);
            svc.RegisterServiceListener(listener);
            svc.Init(new Configuration());
            AssertEventCount(listener, 1);
            //start this; the listener failed but this won't show
            svc.Start();
            //counter went up
            AssertEventCount(listener, 2);
            Assert.Equal(1, listener.GetFailureCount());
            //stop the service -this doesn't fail
            svc.Stop();
            AssertEventCount(listener, 3);
            Assert.Equal(1, listener.GetFailureCount());
            svc.Stop();
        }
Ejemplo n.º 6
0
        public virtual void TestServiceNotificationsUnregisterDuringCallback()
        {
            BreakableService             svc      = new BreakableService(false, false, false);
            BreakableStateChangeListener listener = new TestServiceLifecycle.SelfUnregisteringBreakableStateChangeListener
                                                        ();
            BreakableStateChangeListener l2 = new BreakableStateChangeListener();

            svc.RegisterServiceListener(listener);
            svc.RegisterServiceListener(l2);
            svc.Init(new Configuration());
            AssertEventCount(listener, 1);
            AssertEventCount(l2, 1);
            svc.UnregisterServiceListener(listener);
            svc.Start();
            AssertEventCount(listener, 1);
            AssertEventCount(l2, 2);
            svc.Stop();
            AssertEventCount(listener, 1);
            svc.Stop();
        }
        public virtual void TestListenerFailure()
        {
            listener.SetFailingState(Service.STATE.Inited);
            Register();
            BreakableStateChangeListener l2 = new BreakableStateChangeListener();

            Register(l2);
            BreakableService service = new BreakableService();

            service.Init(new Configuration());
            //expected notifications to fail
            //still should record its invocation
            AssertListenerState(listener, Service.STATE.Inited);
            AssertListenerEventCount(listener, 1);
            //and second listener didn't get notified of anything
            AssertListenerEventCount(l2, 0);
            //service should still consider itself started
            AssertServiceStateInited(service);
            service.Start();
            service.Stop();
        }
 /// <summary>Assert that the number of state change notifications matches expectations.
 ///     </summary>
 /// <param name="breakable">the listener</param>
 /// <param name="count">the expected count.</param>
 public virtual void AssertListenerEventCount(BreakableStateChangeListener breakable
                                              , int count)
 {
     Assert.Equal("Wrong event count in " + breakable, count, breakable
                  .GetEventCount());
 }
 /// <summary>Assert that the last state of the listener is that the test expected.</summary>
 /// <param name="breakable">a breakable listener</param>
 /// <param name="state">the expected state</param>
 public virtual void AssertListenerState(BreakableStateChangeListener breakable, Service.STATE
                                         state)
 {
     Assert.Equal("Wrong state in " + breakable, state, breakable.GetLastState
                      ());
 }
Ejemplo n.º 10
0
 private void AssertEventCount(BreakableStateChangeListener listener, int expected
                               )
 {
     Assert.Equal(listener.ToString(), expected, listener.GetEventCount
                      ());
 }