public void TestRestartSupervisor()
        {
            var restartSupervisorTestResults = new RestartSupervisorTestResults();
            var supervisor = TestWorld.ActorFor <ISupervisor>(
                Definition.Has <RestartSupervisorActor>(
                    Definition.Parameters(restartSupervisorTestResults), "restart-supervisor"));
            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = TestWorld.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults), supervisor.ActorInside, "failure-for-restart"));

            var failureAccess = failureControlTestResults.AfterCompleting(6);
            var restartAccess = restartSupervisorTestResults.AfterCompleting(1);

            failure.Actor.FailNow();

            Assert.Equal(1, restartAccess.ReadFrom <int>("informedCount"));
            Assert.Equal(2, failureAccess.ReadFrom <int>("beforeStartCount"));
            Assert.Equal(1, failureAccess.ReadFrom <int>("failNowCount"));
            Assert.Equal(1, failureAccess.ReadFrom <int>("afterRestartCount"));
            Assert.Equal(1, failureAccess.ReadFrom <int>("afterStopCount"));
            Assert.Equal(1, failureAccess.ReadFrom <int>("beforeRestartCount"));

            var afterFailureAccess = failureControlTestResults.AfterCompleting(1);

            failure.Actor.AfterFailure();

            Assert.Equal(1, afterFailureAccess.ReadFrom <int>("afterFailureCount"));
            Assert.Equal(0, afterFailureAccess.ReadFrom <int>("stoppedCount"));
        }
        public void TestOverride()
        {
            var testResults = new FailureControlActor.FailureControlTestResults();
            var failure     = TestWorld.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(testResults), "failure-for-stop"));

            testResults.UntilFailNow   = Until(20);
            testResults.UntilAfterFail = Until(20);
            for (var idx = 0; idx < 20; ++idx)
            {
                testResults.UntilBeforeResume = Until(1);
                failure.Actor.FailNow();
                testResults.UntilBeforeResume.Completes();
                failure.Actor.AfterFailure();
            }
            testResults.UntilFailNow.Completes();
            testResults.UntilAfterFail.Completes();

            testResults.UntilFailNow   = Until(20);
            testResults.UntilAfterFail = Until(20);
            for (var idx = 0; idx < 20; ++idx)
            {
                testResults.UntilBeforeResume = Until(1);
                failure.Actor.FailNow();
                testResults.UntilBeforeResume.Completes();
                failure.Actor.AfterFailure();
            }
            testResults.UntilFailNow.Completes();
            testResults.UntilAfterFail.Completes();

            Assert.False(failure.ActorInside.IsStopped);
            Assert.Equal(40, testResults.FailNowCount.Get());
            Assert.Equal(40, testResults.AfterFailureCount.Get());
        }
Exemple #3
0
        public void Test5Intensity1PeriodRestartStrategy()
        {
            var restartFiveInOneSupervisorTestResults = new RestartFiveInOneSupervisorActor.RestartFiveInOneSupervisorTestResults();
            var supervisor = TestWorld.ActorFor <ISupervisor>(
                Definition.Has <RestartFiveInOneSupervisorActor>(
                    Definition.Parameters(restartFiveInOneSupervisorTestResults), "resuming-5-1-supervisor"));
            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = TestWorld.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults), supervisor.ActorInside, "failure-for-stop"));

            var failureAccess = failureControlTestResults.AfterCompleting(0);
            var restartAccess = restartFiveInOneSupervisorTestResults.AfterCompleting(5);

            for (var idx = 1; idx <= 5; ++idx)
            {
                failureAccess = failureControlTestResults.AfterCompleting(1);
                failure.Actor.FailNow();
                failure.Actor.AfterFailure();
            }

            Assert.Equal(5, failureAccess.ReadFrom <int>("failNowCount"));
            Assert.Equal(5, failureAccess.ReadFrom <int>("afterFailureCount"));

            failureAccess = failureControlTestResults.AfterCompleting(1);
            restartAccess = restartFiveInOneSupervisorTestResults.AfterCompleting(1);

            failure.Actor.FailNow();
            failure.Actor.AfterFailure();

            Assert.True(failure.ActorInside.IsStopped);
            Assert.Equal(6, failureAccess.ReadFrom <int>("failNowCount"));
            Assert.Equal(5, failureAccess.ReadFrom <int>("afterFailureCount"));
            Assert.Equal(6, restartAccess.ReadFrom <int>("informedCount"));
        }
        public void TestRestartSupervisor()
        {
            var restartSupervisorTestResults = new RestartSupervisorTestResults();
            var supervisor = TestWorld.ActorFor <ISupervisor>(
                Definition.Has <RestartSupervisorActor>(
                    Definition.Parameters(restartSupervisorTestResults), "restart-supervisor"));
            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = TestWorld.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults), supervisor.ActorInside, "failure-for-restart"));

            Assert.Equal(0, failureControlTestResults.FailNowCount.Get());
            Assert.Equal(0, restartSupervisorTestResults.InformedCount.Get());
            Assert.Equal(0, failureControlTestResults.AfterRestartCount.Get());
            Assert.Equal(0, failureControlTestResults.AfterStopCount.Get());
            Assert.Equal(0, failureControlTestResults.BeforeRestartCount.Get());
            Assert.Equal(1, failureControlTestResults.BeforeStartCount.Get());

            failure.Actor.FailNow();

            Assert.Equal(1, failureControlTestResults.FailNowCount.Get());
            Assert.Equal(1, restartSupervisorTestResults.InformedCount.Get());
            Assert.Equal(1, failureControlTestResults.AfterRestartCount.Get());
            Assert.Equal(1, failureControlTestResults.AfterStopCount.Get());
            Assert.Equal(1, failureControlTestResults.BeforeRestartCount.Get());
            Assert.Equal(2, failureControlTestResults.BeforeStartCount.Get());

            Assert.Equal(0, failureControlTestResults.AfterFailureCount.Get());
            failure.Actor.AfterFailure();
            Assert.Equal(1, failureControlTestResults.AfterFailureCount.Get());

            Assert.Equal(0, failureControlTestResults.StoppedCount.Get());
        }
        public void TestOverride()
        {
            var testResults = new FailureControlActor.FailureControlTestResults();
            var failure     = TestWorld.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(testResults), "failure-for-stop"));

            var access = testResults.AfterCompleting(40);

            for (var idx = 0; idx < 20; ++idx)
            {
                failure.Actor.FailNow();
                failure.Actor.AfterFailure();
            }

            access.ReadFromExpecting("beforeResume", 20);
            Assert.Equal(20, access.ReadFrom <int>("beforeResume"));
            Assert.Equal(20, access.ReadFrom <int>("failNowCount"));
            Assert.Equal(20, access.ReadFrom <int>("afterFailureCount"));

            access = testResults.AfterCompleting(40);

            for (var idx = 0; idx < 20; ++idx)
            {
                failure.Actor.FailNow();
                failure.Actor.AfterFailure();
            }

            access.ReadFromExpecting("beforeResume", 40);
            Assert.Equal(40, access.ReadFrom <int>("failNowCount"));
            Assert.Equal(40, access.ReadFrom <int>("afterFailureCount"));

            Assert.False(failure.ActorInside.IsStopped);
        }
Exemple #6
0
        public void TestEscalate()
        {
            var escalateSupervisorTestResults = new EscalateSupervisorActor.EscalateSupervisorTestResults();
            var supervisor = TestWorld.ActorFor <ISupervisor>(
                Definition.Has <EscalateSupervisorActor>(
                    Definition.Parameters(escalateSupervisorTestResults), "escalate"));
            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = TestWorld.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults), supervisor.ActorInside, "failure"));

            failureControlTestResults.UntilFailNow   = Until(1);
            failureControlTestResults.UntilAfterFail = Until(1);

            Assert.Equal(0, escalateSupervisorTestResults.InformedCount.Get());
            Assert.Equal(0, failureControlTestResults.StoppedCount.Get());

            failure.Actor.FailNow();

            failureControlTestResults.UntilFailNow.Completes();
            failureControlTestResults.UntilStopped.Completes();

            Assert.Equal(1, escalateSupervisorTestResults.InformedCount.Get());
            Assert.Equal(1, failureControlTestResults.StoppedCount.Get());
        }
Exemple #7
0
        public void TestEscalate()
        {
            var escalateSupervisorTestResults = new EscalateSupervisorActor.EscalateSupervisorTestResults();
            var supervisor = TestWorld.ActorFor <ISupervisor>(
                Definition.Has <EscalateSupervisorActor>(
                    Definition.Parameters(escalateSupervisorTestResults), "escalate"));
            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = TestWorld.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults), supervisor.ActorInside, "failure"));

            var escalateAccess = escalateSupervisorTestResults.AfterCompleting(1);
            var failureAccess  = failureControlTestResults.AfterCompleting(1);

            failure.Actor.FailNow();

            Assert.Equal(1, escalateAccess.ReadFrom <int>("informedCount"));
            Assert.Equal(1, failureAccess.ReadFrom <int>("stoppedCount"));
        }
        public void TestStoppingSupervisor()
        {
            var supervisor = TestWorld.ActorFor <ISupervisor>(
                Definition.Has <StoppingSupervisorActor>(Definition.NoParameters, "stopping-supervisor"));
            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = TestWorld.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults), supervisor.ActorInside, "failure-for-stop"));

            Assert.Equal(0, failureControlTestResults.FailNowCount.Get());
            failure.Actor.FailNow();
            Assert.Equal(1, failureControlTestResults.FailNowCount.Get());

            Assert.Equal(0, failureControlTestResults.AfterFailureCount.Get());
            failure.Actor.AfterFailure();
            Assert.Equal(0, failureControlTestResults.AfterFailureCount.Get());

            Assert.Equal(1, failureControlTestResults.AfterStopCount.Get());
        }
Exemple #9
0
        public void Test5Intensity1PeriodRestartStrategy()
        {
            var restartFiveInOneSupervisorTestResults = new RestartFiveInOneSupervisorActor.RestartFiveInOneSupervisorTestResults();
            var supervisor = TestWorld.ActorFor <ISupervisor>(
                Definition.Has <RestartFiveInOneSupervisorActor>(
                    Definition.Parameters(restartFiveInOneSupervisorTestResults), "resuming-5-1-supervisor"));
            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = TestWorld.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults), supervisor.ActorInside, "failure-for-stop"));

            failureControlTestResults.UntilFailNow   = Until(5);
            failureControlTestResults.UntilAfterFail = Until(5);

            for (var idx = 1; idx <= 5; ++idx)
            {
                restartFiveInOneSupervisorTestResults.UntilInform = Until(1);
                failure.Actor.FailNow();
                restartFiveInOneSupervisorTestResults.UntilInform.Completes();
                failure.Actor.AfterFailure();
            }
            failureControlTestResults.UntilFailNow.Completes();
            failureControlTestResults.UntilAfterFail.Completes();

            Assert.Equal(5, failureControlTestResults.FailNowCount.Get());
            Assert.Equal(5, failureControlTestResults.AfterFailureCount.Get());

            failureControlTestResults.UntilFailNow            = Until(1);
            failureControlTestResults.UntilAfterFail          = Until(0);
            restartFiveInOneSupervisorTestResults.UntilInform = Until(1);

            failure.Actor.FailNow();
            failure.Actor.AfterFailure();

            failureControlTestResults.UntilFailNow.Completes();
            restartFiveInOneSupervisorTestResults.UntilInform.Completes();
            failureControlTestResults.UntilAfterFail.Completes();

            Assert.True(failure.ActorInside.IsStopped);
            Assert.Equal(6, failureControlTestResults.FailNowCount.Get());
            Assert.Equal(6, restartFiveInOneSupervisorTestResults.InformedCount.Get());
            Assert.Equal(5, failureControlTestResults.AfterFailureCount.Get());
        }
        public void TestPublicRootDefaultParentSupervisor()
        {
            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = World.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults), World.DefaultParent, "failure-for-default"));

            var access = failureControlTestResults.AfterCompleting(3);

            failure.FailNow();

            Assert.Equal(1, access.ReadFrom <int>("failNowCount"));
            Assert.Equal(1, access.ReadFromExpecting("afterRestartCount", 1));

            access = failureControlTestResults.AfterCompleting(1);

            failure.AfterFailure();

            Assert.Equal(1, access.ReadFromExpecting <int>("afterFailureCount", 1));
        }
        public void TestPublicRootDefaultParentSupervisor()
        {
            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = World.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults), World.DefaultParent, "failure-for-default"));

            failureControlTestResults.UntilFailNow = Until(1);
            Assert.Equal(0, failureControlTestResults.FailNowCount.Get());

            failure.FailNow();
            failureControlTestResults.UntilFailNow.Completes();
            Assert.Equal(1, failureControlTestResults.FailNowCount.Get());

            failureControlTestResults.UntilAfterFail = Until(1);
            Assert.Equal(0, failureControlTestResults.AfterFailureCount.Get());
            failure.AfterFailure();
            failureControlTestResults.UntilAfterFail.Completes();
            Assert.Equal(1, failureControlTestResults.AfterFailureCount.Get());
        }
        public void TestStoppingSupervisor()
        {
            var supervisor = TestWorld.ActorFor <ISupervisor>(
                Definition.Has <StoppingSupervisorActor>(Definition.NoParameters, "stopping-supervisor"));
            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = TestWorld.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults), supervisor.ActorInside, "failure-for-stop"));

            var access = failureControlTestResults.AfterCompleting(2);

            failure.Actor.FailNow();

            Assert.Equal(1, access.ReadFrom <int>("failNowCount"));

            failure.Actor.AfterFailure();

            Assert.Equal(1, access.ReadFrom <int>("stoppedCount"));

            Assert.Equal(0, access.ReadFrom <int>("afterFailureCount"));
        }
Exemple #13
0
        public void TestRestartForeverStrategy()
        {
            var restartForeverSupervisorTestResults = new RestartForeverSupervisorActor.RestartForeverSupervisorTestResults();
            var supervisor = TestWorld.ActorFor <ISupervisor>(
                Definition.Has <RestartForeverSupervisorActor>(
                    Definition.Parameters(restartForeverSupervisorTestResults), "restart-forever-supervisor"));
            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = TestWorld.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults), supervisor.ActorInside, "failure-for-stop"));

            failureControlTestResults.UntilFailNow   = Until(20);
            failureControlTestResults.UntilAfterFail = Until(20);
            for (var idx = 1; idx <= 20; ++idx)
            {
                restartForeverSupervisorTestResults.UntilInform = Until(1);
                failure.Actor.FailNow();
                restartForeverSupervisorTestResults.UntilInform.Completes();
                failure.Actor.AfterFailure();
            }
            failureControlTestResults.UntilFailNow.Completes();
            failureControlTestResults.UntilAfterFail.Completes();

            failureControlTestResults.UntilFailNow   = Until(20);
            failureControlTestResults.UntilAfterFail = Until(20);
            for (var idx = 1; idx <= 20; ++idx)
            {
                restartForeverSupervisorTestResults.UntilInform = Until(1);
                failure.Actor.FailNow();
                restartForeverSupervisorTestResults.UntilInform.Completes();
                failure.Actor.AfterFailure();
            }
            failureControlTestResults.UntilFailNow.Completes();
            failureControlTestResults.UntilAfterFail.Completes();

            Assert.Equal(40, failureControlTestResults.FailNowCount.Get());
            Assert.Equal(40, failureControlTestResults.AfterFailureCount.Get());
            Assert.True(40 <= restartForeverSupervisorTestResults.InformedCount.Get());
        }
Exemple #14
0
        public void TestRestartForeverStrategy()
        {
            var restartForeverSupervisorTestResults = new RestartForeverSupervisorActor.RestartForeverSupervisorTestResults();
            var supervisor = TestWorld.ActorFor <ISupervisor>(
                Definition.Has <RestartForeverSupervisorActor>(
                    Definition.Parameters(restartForeverSupervisorTestResults), "restart-forever-supervisor"));
            var failureControlTestResults = new FailureControlActor.FailureControlTestResults();
            var failure = TestWorld.ActorFor <IFailureControl>(
                Definition.Has <FailureControlActor>(
                    Definition.Parameters(failureControlTestResults), supervisor.ActorInside, "failure-for-stop"));

            var failedAccess  = failureControlTestResults.AfterCompleting(40);
            var restartAccess = restartForeverSupervisorTestResults.AfterCompleting(40);

            for (var idx = 1; idx <= 20; ++idx)
            {
                failure.Actor.FailNow();
                failure.Actor.AfterFailure();
            }

            Assert.Equal(20, failedAccess.ReadFrom <int>("failNowCount"));
            Assert.Equal(20, failedAccess.ReadFrom <int>("afterFailureCount"));

            failedAccess = failureControlTestResults.AfterCompleting(40);

            for (var idx = 1; idx <= 20; ++idx)
            {
                failure.Actor.FailNow();
                failure.Actor.AfterFailure();
            }

            failureControlTestResults.UntilFailNow.Completes();
            failureControlTestResults.UntilAfterFail.Completes();

            Assert.Equal(40, failedAccess.ReadFrom <int>("failNowCount"));
            Assert.Equal(40, failedAccess.ReadFrom <int>("afterFailureCount"));
            Assert.True(40 <= restartAccess.ReadFrom <int>("informedCount"));
        }