public virtual void TestStopFailingInitAndStop() { BreakableService svc = new BreakableService(true, false, true); svc.RegisterServiceListener(new LoggingStateChangeListener()); try { svc.Init(new Configuration()); NUnit.Framework.Assert.Fail("Expected a failure, got " + svc); } catch (BreakableService.BrokenLifecycleEvent e) { Assert.Equal(Service.STATE.Inited, e.state); } //the service state is stopped AssertServiceStateStopped(svc); Assert.Equal(Service.STATE.Inited, svc.GetFailureState()); Exception failureCause = svc.GetFailureCause(); NUnit.Framework.Assert.IsNotNull("Null failure cause in " + svc, failureCause); BreakableService.BrokenLifecycleEvent cause = (BreakableService.BrokenLifecycleEvent )failureCause; NUnit.Framework.Assert.IsNotNull("null state in " + cause + " raised by " + svc, cause.state); Assert.Equal(Service.STATE.Inited, cause.state); }
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 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(); }
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(); }