public void Smallest_mailbox_pool_must_deliver_messages_to_idle_actor()
        {
            var usedActors = new ConcurrentDictionary<int, string>();
            var router = Sys.ActorOf(new SmallestMailboxPool(3).Props(Props.Create(() => new SmallestMailboxActor(usedActors))));

            var busy = new TestLatch(1);
            var received0 = new TestLatch(1);
            router.Tell(Tuple.Create(busy, received0));
            received0.Ready(TestKitSettings.DefaultTimeout);

            var received1 = new TestLatch(1);
            router.Tell(Tuple.Create(1, received1));
            received1.Ready(TestKitSettings.DefaultTimeout);

            var received2 = new TestLatch(1);
            router.Tell(Tuple.Create(2, received2));
            received2.Ready(TestKitSettings.DefaultTimeout);

            var received3 = new TestLatch(1);
            router.Tell(Tuple.Create(3, received3));
            received3.Ready(TestKitSettings.DefaultTimeout);

            busy.CountDown();

            var busyPath = usedActors[0];
            busyPath.Should().NotBeNull();

            var path1 = usedActors[1];
            var path2 = usedActors[2];
            var path3 = usedActors[3];

            path1.Should().NotBeNull(busyPath);
            path2.Should().NotBeNull(busyPath);
            path3.Should().NotBeNull(busyPath);
        }
Exemple #2
0
            public RoundRobinPoolBroadcastActor(TestLatch helloLatch, TestLatch stopLatch)
            {
                _helloLatch = helloLatch;
                _stopLatch = stopLatch;

                Receive<string>(s => s == "hello", c => _helloLatch.CountDown());
            }
            public Watcher(TestLatch exitingLatch, TestLatch removedLatch, Address secondAddress)
            {
                _exitingLatch = exitingLatch;
                _removedLatch = removedLatch;
                _secondAddress = secondAddress;

                Receive<ClusterEvent.CurrentClusterState>(state =>
                {
                    if (state.Members.Any(m => m.Address == _secondAddress && m.Status == MemberStatus.Exiting))
                        _exitingLatch.CountDown();
                });
                Receive<ClusterEvent.MemberExited>(m =>
                {
                    if (m.Member.Address == secondAddress)
                    {
                        exitingLatch.CountDown();
                    }
                });
                Receive<ClusterEvent.MemberRemoved>(m =>
                {
                    if (m.Member.Address == secondAddress)
                    {
                        _removedLatch.CountDown();
                    }
                });
            }
            public BroadcastTarget(TestLatch doneLatch, AtomicCounter counter)
            {
                _doneLatch = doneLatch;
                _counter = counter;

                Receive<string>(s => s == "end", c => _doneLatch.CountDown());
                Receive<int>(msg => _counter.AddAndGet(msg));
            }
Exemple #5
0
            public RoundRobinPoolActor(TestLatch doneLatch, AtomicCounter counter)
            {
                _doneLatch = doneLatch;
                _counter = counter;

                Receive<string>(s => s == "hit", c => Sender.Tell(id.Value));
                Receive<string>(s => s == "end", c => _doneLatch.CountDown());
            }
            public Listener(TestLatch latch, ImmutableList<Address> expectedAddresses)
            {
                _latch = latch;
                _expectedAddresses = expectedAddresses;

                Receive<ClusterEvent.CurrentClusterState>(state =>
                {
                    _members = state.Members;
                });

                Receive<ClusterEvent.MemberUp>(m =>
                {
                    _members = _members.Remove(m.Member).Add(m.Member);

                    if (!_members.Select(c => c.Address).Except(_expectedAddresses).Any())
                        _latch.CountDown();
                });
            }
        public void Smallest_mailbox_router_must_deliver_messages_to_idle_actor()
        {
            var usedActors = new ConcurrentDictionary<int, string>();
            var router = Sys.ActorOf(new SmallestMailboxPool(3).Props(Props.Create(() => new SmallestMailboxActor(usedActors))));

            var busy = new TestLatch(1);
            var received0 = new TestLatch(1);
            router.Tell(Tuple.Create(busy, received0));
            received0.Ready(TestLatch.DefaultTimeout);

            var received1 = new TestLatch(1);
            router.Tell(Tuple.Create(1, received1));
            received1.Ready(TestLatch.DefaultTimeout);

            var received2 = new TestLatch(1);
            router.Tell(Tuple.Create(2, received2));
            received2.Ready(TestLatch.DefaultTimeout);

            var received3 = new TestLatch(1);
            router.Tell(Tuple.Create(3, received3));
            received3.Ready(TestLatch.DefaultTimeout);

            busy.CountDown();

            var busyPath = usedActors[0];
            Assert.NotEqual(busyPath, null);

            Assert.Equal(usedActors.Count, 4);
            var path1 = usedActors[1];
            var path2 = usedActors[2];
            var path3 = usedActors[3];

            Assert.NotEqual(path1, busyPath);
            Assert.NotEqual(path2, busyPath);
            Assert.NotEqual(path3, busyPath);
        }
Exemple #8
0
 public void PersistentActor_should_preserve_order_of_incoming_messages()
 {
     var pref = ActorOf(Props.Create(() => new StressOrdering(Name)));
     pref.Tell(new Cmd("a"));
     var latch = new TestLatch(1);
     pref.Tell(new LatchCmd(latch, "b"));
     pref.Tell("c");
     ExpectMsg("a");
     ExpectMsg("b");
     pref.Tell("d");
     latch.CountDown();
     ExpectMsg("c");
     ExpectMsg("d");
 }
        public void A_Flow_with_SelectAsyncUnordered_must_signal_error_from_SelectAsyncUnordered()
        {
            this.AssertAllStagesStopped(() =>
            {
                var latch = new TestLatch(1);
                var c = this.CreateManualSubscriberProbe<int>();
                Source.From(Enumerable.Range(1, 5))
                    .SelectAsyncUnordered(4, n =>
                    {
                        if (n == 3)
                            throw new TestException("err2");

                        return Task.Run(() =>
                        {
                            latch.Ready(TimeSpan.FromSeconds(10));
                            return n;
                        });
                    })
                    .RunWith(Sink.FromSubscriber(c), Materializer);
                var sub = c.ExpectSubscription();
                sub.Request(10);
                c.ExpectError().Message.Should().Be("err2");
                latch.CountDown();
            }, Materializer);
        }
Exemple #10
0
            public RoundRobinGroupActor(TestLatch doneLatch)
            {
                _doneLatch = doneLatch;

                Receive<string>(s => s == "hit", c => Sender.Tell(Self.Path.Name));
                Receive<string>(s => s == "end", c => _doneLatch.CountDown());
            }
        public void InputStreamSource_must_emit_as_soon_as_read()
        {
            this.AssertAllStagesStopped(() =>
            {
                var latch = new TestLatch(1);
                var probe = StreamConverters.FromInputStream(() => new EmittedInputStream(latch), chunkSize: 1)
                    .RunWith(this.SinkProbe<ByteString>(), _materializer);

                probe.Request(4);
                probe.ExpectNext(ByteString.FromString("M"));
                latch.CountDown();
                probe.ExpectComplete();
            }, _materializer);
        }
        public void A_Flow_with_SelectAsync_must_signal_task_failure()
        {
            this.AssertAllStagesStopped(() =>
            {
                var latch = new TestLatch(1);
                var c = TestSubscriber.CreateManualProbe<int>(this);
                Source.From(Enumerable.Range(1, 5))
                    .SelectAsync(4, n => Task.Run(() =>
                    {
                        if (n == 3)
                            throw new TestException("err1");

                        latch.Ready(TimeSpan.FromSeconds(10));
                        return n;
                    }))
                    .To(Sink.FromSubscriber(c)).Run(Materializer);
                var sub = c.ExpectSubscription();
                sub.Request(10);
                c.ExpectError().InnerException.Message.Should().Be("err1");
                latch.CountDown();
            }, Materializer);
        }
        public void A_FlattenMerge_must_cancel_substreams_when_failing_map_function()
        {
            var settings = ActorMaterializerSettings.Create(Sys).WithSyncProcessingLimit(1);
            var materializer = ActorMaterializer.Create(Sys, settings);
            var p = TestPublisher.CreateProbe<int>(this);
            var ex = new TestException("buh");
            var latch = new TestLatch();

            Source.From(Enumerable.Range(1, 3)).MergeMany(10, i =>
            {
                if (i == 1)
                    return Source.FromPublisher(p);

                latch.Ready(TimeSpan.FromSeconds(3));
                throw ex;
            }).RunWith(Sink.First<int>(), materializer);
            p.ExpectRequest();
            latch.CountDown();
            p.ExpectCancellation();
        }
        public void A_ForeachParallel_must_resume_after_function_failure()
        {
            this.AssertAllStagesStopped(() =>
            {
                var probe = CreateTestProbe();
                var latch = new TestLatch(1);

                var p = Source.From(Enumerable.Range(1, 5)).RunWith(Sink.ForEachParallel<int>(4, n =>
                {
                    if (n == 3)
                        throw new TestException("err1");

                    probe.Ref.Tell(n);
                    latch.Ready(TimeSpan.FromSeconds(10));
                }).WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.ResumingDecider)), Materializer);

                latch.CountDown();
                probe.ExpectMsgAllOf(1, 2, 4, 5);

                p.Wait(TimeSpan.FromSeconds(5)).Should().BeTrue();
            }, Materializer);
        }
        public void A_ForeachParallel_must_finish_after_function_thrown_exception()
        {
            this.AssertAllStagesStopped(() =>
            {
                var probe = CreateTestProbe();
                var latch = new TestLatch(1);

                var p = Source.From(Enumerable.Range(1, 5)).RunWith(Sink.ForEachParallel<int>(3, n =>
                {
                    if (n == 3)
                        throw new TestException("err2");

                    probe.Ref.Tell(n);
                    latch.Ready(TimeSpan.FromSeconds(10));
                }).WithAttributes(ActorAttributes.CreateSupervisionStrategy(Deciders.StoppingDecider)), Materializer);
                
                // make sure the stream is up and running, otherwise the latch is maybe ready before the third message arrives
                Thread.Sleep(500);
                latch.CountDown();
                probe.ExpectMsgAllOf(1, 2);

                var ex = p.Invoking(t => t.Wait(TimeSpan.FromSeconds(1))).ShouldThrow<AggregateException>().Which;
                ex.Flatten().InnerException.Should().BeOfType<TestException>();
                ex.Flatten().InnerException.Message.Should().Be("err2");

                p.IsCompleted.Should().BeTrue();
            }, Materializer);
        }
            public Observer(ActorPath path2, ActorPath path3, TestLatch watchEstablished, IActorRef testActorRef)
            {
                _watchEstablished = watchEstablished;
                _testActorRef = testActorRef;

                Receive<ActorIdentity>(identity => identity.MessageId.Equals(path2), identity =>
                {
                    Context.Watch(identity.Subject);
                    _watchEstablished.CountDown();
                });

                Receive<ActorIdentity>(identity => identity.MessageId.Equals(path3), identity =>
                {
                    Context.Watch(identity.Subject);
                    _watchEstablished.CountDown();
                });

                Receive<Terminated>(terminated =>
                {
                    _testActorRef.Tell(terminated.ActorRef.Path);
                });

                Context.ActorSelection(path2).Tell(new Identify(path2));
                Context.ActorSelection(path3).Tell(new Identify(path3));

            }
Exemple #17
0
 public TestProducer(TestLatch lp, TestLatch la)
 {
     latchActor = la;
     lp.Reset();
     lp.CountDown();
 }
        protected void TestWaitMovingMembersToUp()
        {
            var onUpLatch = new TestLatch(1);
            Cluster.RegisterOnMemberUp(() =>
            {
                onUpLatch.CountDown();
            });

            RunOn(() =>
            {
                Cluster.Join(GetAddress(Myself));
                AwaitAssert(() =>
                {
                    ClusterView.RefreshCurrentState();
                    ClusterView.Status.ShouldBe(MemberStatus.Joining);
                });
            }, First);
            EnterBarrier("first-started");

            onUpLatch.IsOpen.ShouldBeFalse();

            RunOn(() =>
            {
                Cluster.Join(GetAddress(First));
            }, Second);

            RunOn(() =>
            {
                var expectedAddresses = new List<Address> { GetAddress(First), GetAddress(Second) };
                AwaitAssert(() =>
                {
                    ClusterView.RefreshCurrentState();
                    ClusterView.Members.Select(c => c.Address).Except(expectedAddresses).Count().ShouldBe(0);
                });
                ClusterView.Members.All(c => c.Status == MemberStatus.Joining).ShouldBeTrue();
                // and it should not change
                foreach (var _ in Enumerable.Range(1, 5))
                {
                    Thread.Sleep(1000);
                    ClusterView.Members.Select(c => c.Address).Except(expectedAddresses).Count().ShouldBe(0);
                    ClusterView.Members.All(c => c.Status == MemberStatus.Joining).ShouldBeTrue();
                }
            }, First, Second);
            EnterBarrier("second-joined");

            RunOn(() =>
            {
                Cluster.Join(GetAddress(First));
            }, Third);
            AwaitClusterUp(First, Second, Third);

            onUpLatch.Ready(TestKitSettings.DefaultTimeout);
            EnterBarrier("after-1");
        }