Esempio n. 1
0
        internal (ActorPath ActorPath, Type Type, TestProbe TestProbe, SupervisorStrategy SupervisorStrategy, string ActorName) CreateChildVariables()
        {
            string            name               = TestHelper.GenerateString();
            ActorPath         path               = TestActor.Path.Child(name);
            Type              type               = TestHelper.Generate <Type>();
            TestProbe         testProbe          = CreateTestProbe();
            AllForOneStrategy supervisorStrategy = new AllForOneStrategy(
                TestHelper.GenerateNumber(),
                TestHelper.GenerateNumber(),
                exception => TestHelper.Generate <Directive>());

            return(path, type, testProbe, supervisorStrategy, name);
        }
        public void TestProbeChildActorWithSupervisorStrategy_PropsSupervisorStrategy__ReturnsSameResultOnEveryCall()
        {
            //arrange
            AllForOneStrategy exptected = new AllForOneStrategy(
                TestHelper.GenerateNumber(),
                TestHelper.GenerateNumber(),
                exception => TestHelper.Generate <Directive>());
            TestProbeChildActor sut = CreateTestProbeChildActorWithSupervisorStrategy(exptected).UnderlyingActor;

            //act
            SupervisorStrategy result = sut.PropsSupervisorStrategy;

            //assert
            result.Should().BeSameAs(exptected);
        }
        public void UnitTestFramework_ResolvedSupervisorStrategiesAreStored()
        {
            //arrange
            SupervisorStrategy parentSupervisorStrategy = new AllForOneStrategy(exception => Directive.Restart);
            SupervisorStrategy childSupervisorStrategy  = new OneForOneStrategy(exception => Directive.Restart);
            UnitTestFramework <ParentActorWithSupervisorStratery> sut = UnitTestFrameworkSettings
                                                                        .Empty
                                                                        .CreateFramework <ParentActorWithSupervisorStratery>(this,
                                                                                                                             Props.Create(() =>
                                                                                                                                          new ParentActorWithSupervisorStratery(parentSupervisorStrategy, childSupervisorStrategy)), 2);

            //act
            SupervisorStrategy result = sut.ResolvedSupervisorStrategy("ChildWithParentSupervisorStrategy");

            //assert
            result.Should().BeSameAs(parentSupervisorStrategy);
        }
        public void AllForOneStrategy_Should_EscalateFailureToParent()
        {
            var parentMailboxStats = new TestMailboxStatistics(msg => msg is Stopped);
            var strategy           = new AllForOneStrategy((pid, reason) => SupervisorDirective.Escalate, 1, null);
            var childProps         = Actor.FromProducer(() => new ChildActor());
            var parentProps        = Actor.FromProducer(() => new ParentActor(childProps, childProps))
                                     .WithChildSupervisorStrategy(strategy)
                                     .WithMailbox(() => UnboundedMailbox.Create(parentMailboxStats));
            var parent = Actor.Spawn(parentProps);

            parent.Tell("hello");

            parentMailboxStats.Reset.Wait(1000);
            var failure = parentMailboxStats.Received.OfType <Failure>().Single();

            Assert.IsType <Exception>(failure.Reason);
        }
        public void UnitTestFramework_ThrownsWhenChildHasNotBeenResolved()
        {
            //arrange
            SupervisorStrategy parentSupervisorStrategy = new AllForOneStrategy(exception => Directive.Restart);
            SupervisorStrategy childSupervisorStrategy  = new OneForOneStrategy(exception => Directive.Restart);

            UnitTestFramework <ParentActorWithSupervisorStratery> sut = UnitTestFrameworkSettings
                                                                        .Empty
                                                                        .CreateFramework <ParentActorWithSupervisorStratery>(this,
                                                                                                                             Props.Create(() =>
                                                                                                                                          new ParentActorWithSupervisorStratery(parentSupervisorStrategy, childSupervisorStrategy)), 2);

            //act
            Action act = () => sut.ResolvedSupervisorStrategy(Guid.NewGuid().ToString());

            //assert
            act.ShouldThrow <ActorNotFoundException>();
        }
        public void UnitTestFramework_TheParentsSupervisorStrategyIsReturnedWhenTheChildDoesNotHaveOneSetInItsProps()
        {
            //arrange
            SupervisorStrategy parentSupervisorStrategy = new AllForOneStrategy(exception => Directive.Restart);
            SupervisorStrategy childSupervisorStrategy  = new OneForOneStrategy(exception => Directive.Restart);

            UnitTestFramework <ParentActorWithSupervisorStratery> sut = UnitTestFrameworkSettings
                                                                        .Empty
                                                                        .CreateFramework <ParentActorWithSupervisorStratery>(
                this,
                Props.Create(() => new ParentActorWithSupervisorStratery(parentSupervisorStrategy, childSupervisorStrategy)),
                2);

            //act
            SupervisorStrategy result = sut.ResolvedSupervisorStrategy("ChildWithChildSupervisorStrategy");

            //assert
            result.Should().BeSameAs(childSupervisorStrategy);
        }
        public void AllForOneStrategy_Should_ResumeChildOnFailure()
        {
            var child1MailboxStats = new TestMailboxStatistics(msg => msg is ResumeMailbox);
            var child2MailboxStats = new TestMailboxStatistics(msg => msg is ResumeMailbox);
            var strategy           = new AllForOneStrategy((pid, reason) => SupervisorDirective.Resume, 1, null);
            var child1Props        = Actor.FromProducer(() => new ChildActor())
                                     .WithMailbox(() => UnboundedMailbox.Create(child1MailboxStats));
            var child2Props = Actor.FromProducer(() => new ChildActor())
                              .WithMailbox(() => UnboundedMailbox.Create(child2MailboxStats));
            var parentProps = Actor.FromProducer(() => new ParentActor(child1Props, child2Props))
                              .WithChildSupervisorStrategy(strategy);
            var parent = Actor.Spawn(parentProps);

            parent.Tell("hello");

            child1MailboxStats.Reset.Wait(1000);
            Assert.Contains(ResumeMailbox.Instance, child1MailboxStats.Posted);
            Assert.Contains(ResumeMailbox.Instance, child1MailboxStats.Received);
            Assert.DoesNotContain(ResumeMailbox.Instance, child2MailboxStats.Posted);
            Assert.DoesNotContain(ResumeMailbox.Instance, child2MailboxStats.Received);
        }
Esempio n. 8
0
        public void WhenActorWithChildrenStopped_DisposeIsCalledInEachChild()
        {
            bool child1Disposed     = false;
            bool child2Disposed     = false;
            var  child1MailboxStats = new TestMailboxStatistics(msg => msg is Stopped);
            var  child2MailboxStats = new TestMailboxStatistics(msg => msg is Stopped);
            var  strategy           = new AllForOneStrategy((pid, reason) => SupervisorDirective.Stop, 1, null);
            var  child1Props        = Actor.FromProducer(() => new DisposableActor(() => child1Disposed = true))
                                      .WithMailbox(() => UnboundedMailbox.Create(child1MailboxStats));
            var child2Props = Actor.FromProducer(() => new DisposableActor(() => child2Disposed = true))
                              .WithMailbox(() => UnboundedMailbox.Create(child2MailboxStats));
            var parentProps = Actor.FromProducer(() => new ParentWithMultipleChildrenActor(child1Props, child2Props))
                              .WithChildSupervisorStrategy(strategy);
            var parent = Actor.Spawn(parentProps);

            parent.Tell("crash");

            child1MailboxStats.Reset.Wait(1000);
            child2MailboxStats.Reset.Wait(1000);
            Assert.True(child1Disposed);
            Assert.True(child2Disposed);
        }
        public void AllForOneStrategy_Should_PassExceptionOnRestart()
        {
            var child1MailboxStats = new TestMailboxStatistics(msg => msg is Stopped);
            var child2MailboxStats = new TestMailboxStatistics(msg => msg is Stopped);
            var strategy           = new AllForOneStrategy((pid, reason) => SupervisorDirective.Restart, 1, null);
            var child1Props        = Actor.FromProducer(() => new ChildActor())
                                     .WithMailbox(() => UnboundedMailbox.Create(child1MailboxStats));
            var child2Props = Actor.FromProducer(() => new ChildActor())
                              .WithMailbox(() => UnboundedMailbox.Create(child2MailboxStats));
            var parentProps = Actor.FromProducer(() => new ParentActor(child1Props, child2Props))
                              .WithChildSupervisorStrategy(strategy);
            var parent = Actor.Spawn(parentProps);

            parent.Tell("hello");

            child1MailboxStats.Reset.Wait(1000);
            child2MailboxStats.Reset.Wait(1000);
            Assert.Contains(child1MailboxStats.Posted, msg => (msg is Restart r) && r.Reason == Exception);
            Assert.Contains(child1MailboxStats.Received, msg => (msg is Restart r) && r.Reason == Exception);
            Assert.Contains(child2MailboxStats.Posted, msg => (msg is Restart r) && r.Reason == Exception);
            Assert.Contains(child2MailboxStats.Received, msg => (msg is Restart r) && r.Reason == Exception);
        }
        public void AllForOneStrategy_Should_StopAllChildrenOnFailure()
        {
            var child1MailboxStats = new TestMailboxStatistics(msg => msg is Stopped);
            var child2MailboxStats = new TestMailboxStatistics(msg => msg is Stopped);
            var strategy           = new AllForOneStrategy((pid, reason) => SupervisorDirective.Stop, 1, null);
            var child1Props        = Props.FromProducer(() => new ChildActor())
                                     .WithMailbox(() => UnboundedMailbox.Create(child1MailboxStats));
            var child2Props = Props.FromProducer(() => new ChildActor())
                              .WithMailbox(() => UnboundedMailbox.Create(child2MailboxStats));
            var parentProps = Props.FromProducer(() => new ParentActor(child1Props, child2Props))
                              .WithChildSupervisorStrategy(strategy);
            var parent = Context.Spawn(parentProps);

            Context.Send(parent, "hello");

            child1MailboxStats.Reset.Wait(1000);
            child2MailboxStats.Reset.Wait(1000);
            Assert.Contains(Stop.Instance, child1MailboxStats.Posted);
            Assert.Contains(Stop.Instance, child1MailboxStats.Received);
            Assert.Contains(Stop.Instance, child2MailboxStats.Posted);
            Assert.Contains(Stop.Instance, child2MailboxStats.Received);
        }
Esempio n. 11
0
        public void A_constructed_AllForOne_supervisor_strategy_with_nullable_timeouts_has_the_expected_properties(TimeSpan?timeout, int expectedTimeoutMilliseconds)
        {
            var uut = new AllForOneStrategy(-1, timeout, exn => Directive.Restart);

            Assert.Equal(uut.WithinTimeRangeMilliseconds, expectedTimeoutMilliseconds);
        }
Esempio n. 12
0
        public void A_constructed_AllForOne_supervisor_strategy_with_nullable_retries_has_the_expected_properties(int?retries, int expectedRetries)
        {
            var uut = new AllForOneStrategy(retries, null, exn => Directive.Restart);

            Assert.Equal(uut.MaxNumberOfRetries, expectedRetries);
        }