예제 #1
0
        public void CanSerializeScatterGatherFirstCompletedPool()
        {
            var decider = Decider.From(
                Directive.Restart,
                Directive.Stop.When <ArgumentException>(),
                Directive.Stop.When <NullReferenceException>());

            var supervisor = new OneForOneStrategy(decider);

            var message = new ScatterGatherFirstCompletedPool(10, null, supervisor, "abc", TimeSpan.MaxValue);

            AssertEqual(message);
        }
예제 #2
0
        public void CanSerializeConsistentHashPool()
        {
            var decider = Decider.From(
                Directive.Restart,
                Directive.Stop.When <ArgumentException>(),
                Directive.Stop.When <NullReferenceException>());

            var supervisor = new OneForOneStrategy(decider);

            var message = new ConsistentHashingPool(10, null, supervisor, "abc");

            AssertEqual(message);
        }
예제 #3
0
        public void CanSerializeTailChoppingPool()
        {
            var decider = Decider.From(
                Directive.Restart,
                Directive.Stop.When <ArgumentException>(),
                Directive.Stop.When <NullReferenceException>());

            var supervisor = new OneForOneStrategy(decider);

            var message = new TailChoppingPool(10, null, supervisor, "abc", TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(2));

            AssertEqual(message);
        }
예제 #4
0
        public void CanSerializeRandomPool()
        {
            var decider = Decider.From(
                Directive.Restart,
                Directive.Stop.When <ArgumentException>(),
                Directive.Stop.When <NullReferenceException>());

            var supervisor = new OneForOneStrategy(decider);

            var message = new RandomPool(10, new DefaultResizer(0, 1), supervisor, "abc");

            AssertEqual(message);
        }
예제 #5
0
        /// <summary>
        ///     Get the supervisor strategy for the Docker management actor's children.
        /// </summary>
        /// <returns>
        ///     The configured supervisor strategy.
        /// </returns>
        protected override SupervisorStrategy SupervisorStrategy()
        {
            return(new AllForOneStrategy(
                       maxNrOfRetries: 5,
                       withinTimeRange: TimeSpan.FromSeconds(5),
                       decider: Decider.From(exception =>
            {
                // If any of our children encounter an unhandled error, we should restart all of them.
                //
                // AF: This lacks nuance; let's come back to it once we have more tests in place.

                return Directive.Restart;
            })
                       ));
        }
        public void CanSerializeEmptyDecider()
        {
            var decider = Decider.From(
                Directive.Restart,
                Directive.Stop.When <NullReferenceException>(),
                Directive.Escalate.When <Exception>()
                );

            var serializer = Sys.Serialization.FindSerializerFor(decider);
            var bytes      = serializer.ToBinary(decider);
            var sref       = (DeployableDecider)serializer.FromBinary(bytes, typeof(DeployableDecider));

            Assert.NotNull(sref);
            Assert.Equal(decider.DefaultDirective, sref.DefaultDirective);
        }
예제 #7
0
        protected override SupervisorStrategy SupervisorStrategy()
        {
            return(new AllForOneStrategy(Decider.From(ex =>
            {
                switch (ex)
                {
                //case _: IllegalArgumentException     ⇒ SupervisorStrategy.Resume
                //case _: ActorInitializationException ⇒ SupervisorStrategy.Stop
                //case _: DeathPactException           ⇒ SupervisorStrategy.Stop
                //case _: Exception                    ⇒ SupervisorStrategy.Restart

                default:
                    return Directive.Restart;
                }
            })));
        }
예제 #8
0
        public async Task Supervisor_with_Random_Group_router_should_handle_multiple_child_failure()
        {
            const int connectionCount = 10;
            var       doneLatch       = new TestLatch(connectionCount);

            var replies = new Dictionary <string, int>();

            for (int i = 1; i <= connectionCount; i++)
            {
                replies["target-" + i] = 0;
            }

            var paths = Enumerable.Range(1, connectionCount).Select(n =>
            {
                var routee = Sys.ActorOf(Props.Create(() => new SimpleActor()), "target-" + n);
                return(routee.Path.ToStringWithoutAddress());
            });

            var groupProps = Props.Empty
                             .WithRouter(new RandomGroup(paths))
                             .WithSupervisorStrategy(new OneForOneStrategy(Decider.From(Directive.Escalate)));
            var groupActorRef = Sys.ActorOf(groupProps, "random-group1");

            // rapidly fail children. the router should handle children failing
            // while itself is still being recreated
            for (var i = 0; i < 20; i++)
            {
                groupActorRef.Tell(1);
            }

            var failCount = 0;

            for (var i = 0; i < 20; i++)
            {
                try
                {
                    await groupActorRef.Ask <int>(2, _delay);
                }
                catch
                {
                    failCount++;
                }
            }
            failCount.Should().Be(0);
        }
        protected override SupervisorStrategy SupervisorStrategy()
        {
            //return new OneForOneStrategy(
            //    maxNrOfRetries: 10,
            //    withinTimeRange: TimeSpan.FromSeconds(30),
            //    localOnlyDecider: x =>
            //    {
            //        // Error that we have no idea what to do with
            //        //else if (x is InsanelyBadException) return Directive.Escalate;

            //        // Error that we can't recover from, stop the failing child
            //        if (x is NotSupportedException) return Directive.Stop;

            //        // otherwise restart the failing child
            //        else return Directive.Restart;
            //    });
            return(new OneForOneStrategy(Decider.From(Directive.Resume)));
        }
예제 #10
0
 // Redefine Custom SupervisionStrategy (One for One with restarting by Default)
 protected override SupervisorStrategy SupervisorStrategy()
 {
     return(new OneForOneStrategy(
                maxNrOfRetries: 10,
                withinTimeRange: TimeSpan.FromMinutes(1.0),
                decider: Decider.From(exception =>
     {
         if (exception is ArithmeticException)
         {
             return Directive.Restart;     // Reinicia al actor (e hijos) en caso de esta excepción
         }
         else
         {
             return Directive.Resume;     // Para todas las demás excepciones las ignora
         }
     })
                ));
 }
예제 #11
0
        public void Serialization_must_serialize_and_deserialize_DaemonMsgCreate_with_Deploy_and_RouterConfig()
        {
            var decider = Decider.From(
                Directive.Escalate);

            var supervisorStrategy = new OneForOneStrategy(3, TimeSpan.FromSeconds(10), decider);
            var deploy1            = new Deploy("path1",
                                                ConfigurationFactory.ParseString("a=1"),
                                                new RoundRobinPool(5, null, supervisorStrategy, null),
                                                new RemoteScope(new Address("akka", "Test", "host1", 1921)),
                                                "mydispatcher");
            var deploy2 = new Deploy("path2",
                                     ConfigurationFactory.ParseString("a=2"),
                                     FromConfig.Instance,
                                     new RemoteScope(new Address("akka", "Test", "host2", 1922)),
                                     Deploy.NoDispatcherGiven);

            VerifySerialization(new DaemonMsgCreate(Props.Create <MyActor>().WithDispatcher("my-disp").WithDeploy(deploy1), deploy2, "foo", _supervisor));
        }
예제 #12
0
        public void CanSerializeSupervisor()
        {
            var decider = Decider.From(
                Directive.Restart,
                Directive.Stop.When<ArgumentException>(),
                Directive.Stop.When<NullReferenceException>());

            var supervisor = new OneForOneStrategy(decider);

            var serializer = Sys.Serialization.FindSerializerFor(supervisor);
            var bytes = serializer.ToBinary(supervisor);
            var sref = (OneForOneStrategy)serializer.FromBinary(bytes, typeof(OneForOneStrategy));
            Assert.NotNull(sref);
            var sdecider = sref.Decider as DeployableDecider;
            Assert.Equal(decider.Pairs[0], sdecider.Pairs[0]);
            Assert.Equal(decider.Pairs[1], sdecider.Pairs[1]);
            Assert.Equal(supervisor.MaxNumberOfRetries, sref.MaxNumberOfRetries);
            Assert.Equal(supervisor.WithinTimeRangeMilliseconds, sref.WithinTimeRangeMilliseconds);
            Assert.Equal(decider.DefaultDirective, sdecider.DefaultDirective);
        }
예제 #13
0
        protected override SupervisorStrategy SupervisorStrategy()
        {
            return(new OneForOneStrategy( //or AllForOneStrategy
                                          //maxNrOfRetries: 10,
                                          //duration: TimeSpan.FromSeconds(30),
                       decider: Decider.From(x =>
            {
                Console.WriteLine($"Parent Decider -> {x.ToString()}");

                //Maybe we consider ArithmeticException to not be application critical
                //so we just ignore the error and keep going.
                //if (x is ArithmeticException) return Directive.Resume;

                //Error that we cannot recover from, stop the failing actor
                //else if (x is NotSupportedException) return Directive.Stop;

                //In all other cases, just restart the failing actor
                //else
                return Directive.Resume;
            })));
        }
 protected override SupervisorStrategy SupervisorStrategy()
 {
     return(new OneForOneStrategy(
                maxNrOfRetries: 4,
                withinTimeRange: TimeSpan.FromMinutes(1),
                decider: Decider.From(x =>
     {
         if (x is ArithmeticException)
         {
             return Directive.Resume;
         }
         if (x is ArgumentException)
         {
             return Directive.Restart;
         }
         if (x is Exception)
         {
             return Directive.Stop;
         }
         return Directive.Escalate;
     })
                ));
 }
예제 #15
0
        public void A_constructed_AllForOne_supervisor_strategy_with_nullable_timeouts_and_a_decider_has_the_expected_properties(TimeSpan?timeout, int expectedTimeoutMilliseconds)
        {
            var uut = new OneForOneStrategy(-1, timeout, Decider.From(Directive.Restart));

            Assert.Equal(uut.WithinTimeRangeMilliseconds, expectedTimeoutMilliseconds);
        }
예제 #16
0
        public void A_constructed_AllForOne_supervisor_strategy_with_nullable_retries_and_a_decider_has_the_expected_properties(int?retries, int expectedRetries)
        {
            var uut = new OneForOneStrategy(retries, null, Decider.From(Directive.Restart));

            Assert.Equal(uut.MaxNumberOfRetries, expectedRetries);
        }
예제 #17
0
 protected override SupervisorStrategy SupervisorStrategy()
 {
     return(new AllForOneStrategy(Decider.From(x => Directive.Restart)));
 }