コード例 #1
0
            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));
            }
コード例 #2
0
 protected override void OnReceive(object message)
 {
     if (message.Equals("hello"))
     {
         _helloLatch.CountDown();
     }
 }
コード例 #3
0
            public RoundRobinPoolBroadcastActor(TestLatch helloLatch, TestLatch stopLatch)
            {
                _helloLatch = helloLatch;
                _stopLatch  = stopLatch;

                Receive <string>(s => s == "hello", c => _helloLatch.CountDown());
            }
コード例 #4
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());
            }
コード例 #5
0
ファイル: BTActorSpec.cs プロジェクト: dagmatic/akka.net
 public SequenceReceive(List<string> pipe, TestLatch latch)
 {
     StartWith(AllSucceed(
         Execute(ctx => ctx.GlobalData.Add("1")),
         ReceiveAny(Execute(ctx => ctx.GlobalData.Add(ctx.CurrentMessage as string))),
         Execute(ctx => latch.CountDown())), pipe);
 }
コード例 #6
0
        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))).Should().Throw <AggregateException>().Which;
                ex.Flatten().InnerException.Should().BeOfType <TestException>();
                ex.Flatten().InnerException.Message.Should().Be("err2");

                p.IsCompleted.Should().BeTrue();
            }, Materializer);
        }
コード例 #7
0
            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();
                    }
                });
            }
コード例 #8
0
                public Logic(CompletionLatch stage, TestLatch latch) : base(stage.Shape)
                {
                    _stage = stage;

                    var sum = 0;

                    SetHandler(stage.In, onPush: () =>
                    {
                        sum += Grab(stage.In).Value;
                        Pull(stage.In);
                    }, onUpstreamFinish: () =>
                    {
                        // Do not ignore work along the chain
                        // on the jvm:
                        // org.openjdk.jmh.infra.Blackhole.consume(sum)
                        var i = 0;
                        while (i != sum)
                        {
                            sum--;
                        }

                        latch.CountDown();
                        CompleteStage();
                    });
                }
コード例 #9
0
        public void A_Flow_with_SelectAsyncUnordered_must_signal_error_from_SelectAsyncUnordered()
        {
            this.AssertAllStagesStopped(() =>
            {
                var latch = new TestLatch(1);
                var c     = TestSubscriber.CreateManualProbe <int>(this);
                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);
        }
コード例 #10
0
ファイル: ActorSystemSpec.cs プロジェクト: supadmins/akka.net
        public void Run_termination_callbacks_in_order()
        {
            var actorSystem = ActorSystem.Create(Guid.NewGuid().ToString());
            var result      = new List <int>();
            var expected    = new List <int>();
            var count       = 10;
            var latch       = new TestLatch(count);

            for (int i = 0; i < count; i++)
            {
                expected.Add(i);

                var value = i;
                actorSystem.RegisterOnTermination(() =>
                {
                    Task.Delay(Dilated(TimeSpan.FromMilliseconds(value % 3))).Wait();
                    result.Add(value);
                    latch.CountDown();
                });
            }

            actorSystem.Terminate();
            latch.Ready();

            expected.Reverse();

            Assert.Equal(expected, result);
        }
コード例 #11
0
        public void Many_persistent_actors_must_be_able_to_recover_without_overloading()
        {
            Enumerable.Range(1, 100).ForEach(n =>
            {
                Sys.ActorOf(TestPersistentActor.Props($"a{n}", null)).Tell(new Cmd("A"));
                ExpectMsg($"a{n}-A-1");
            });

            // This would starve (block) all threads without max-concurrent-recoveries
            var latch = new TestLatch();

            Enumerable.Range(1, 100).ForEach(n =>
            {
                Sys.ActorOf(TestPersistentActor.Props($"a{n}", latch)).Tell(new Cmd("B"));
            });

            // This should be able to progress even though above is blocking, 2 remaining non-blocked threads
            Enumerable.Range(1, 10).ForEach(n =>
            {
                Sys.ActorOf(EchoActor.Props(this)).Tell(n);
                ExpectMsg(n);
            });

            latch.CountDown();
            ReceiveN(100).ShouldAllBeEquivalentTo(Enumerable.Range(1, 100).Select(n => $"a{n}-B-2"));
        }
コード例 #12
0
ファイル: BTActorSpec.cs プロジェクト: dagmatic/akka.net
            public SequenceTwo(List<string> pipe, TestLatch latch)
            {
                StartWith(AllSucceed(
                    Execute(ctx => ctx.GlobalData.Add("1")),
                    Execute(ctx => ctx.GlobalData.Add("2"))), pipe);

                latch.CountDown();
            }
コード例 #13
0
ファイル: BTActorSpec.cs プロジェクト: dagmatic/akka.net
 public TimeoutAllSucceed(TestLatch latch)
 {
     StartWith(
         Timeout(30.Seconds(),
             AllSucceed(
                 Execute(ctx => latch.CountDown())),
             Execute(ctx => { throw new TimeoutException(); })), null);
 }
コード例 #14
0
ファイル: BTActorSpec.cs プロジェクト: dagmatic/akka.net
 public SequenceParallelReceive(AtomicCounter counter, TestLatch latch)
 {
     StartWith(AllSucceed(
         Parallel(ss => ss.AllSucceed(),
             ReceiveAny(Execute(ctx => ctx.GlobalData.GetAndAdd(1))),
             ReceiveAny(Execute(ctx => ctx.GlobalData.GetAndAdd(4)))),
         Execute(ctx => latch.CountDown())), counter);
 }
コード例 #15
0
            public BroadcastTarget(TestLatch doneLatch, AtomicCounter counter)
            {
                _doneLatch = doneLatch;
                _counter   = counter;

                Receive <string>(s => s == "end", c => _doneLatch.CountDown());
                Receive <int>(msg => _counter.AddAndGet(msg));
            }
コード例 #16
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());
            }
コード例 #17
0
ファイル: ActorSystemSpec.cs プロジェクト: supadmins/akka.net
        public FastActor(TestLatch testLatch, IActorRef testActor)
        {
            var ref1 = Context.ActorOf(Props.Empty);
            var ref2 = Context.Child(ref1.Path.Name);

            testActor.Tell(ref2.GetType());
            testLatch.CountDown();
        }
コード例 #18
0
            protected override void OnReceive(object message)
            {
                var state = message as ClusterEvent.CurrentClusterState;

                if (state != null)
                {
                    if (state.Members.Any(m => m.Address == _oldLeaderAddress && m.Status == MemberStatus.Exiting))
                    {
                        _latch.CountDown();
                    }
                }
                var memberExited = message as ClusterEvent.MemberExited;

                if (memberExited != null && memberExited.Member.Address == _oldLeaderAddress)
                {
                    _latch.CountDown();
                }
            }
コード例 #19
0
ファイル: BTActorSpec.cs プロジェクト: dagmatic/akka.net
            public ExecuteIncrement(AtomicCounter counter, TestLatch latch)
            {
                StartWith(Execute(cxt =>
                {
                    cxt.GlobalData.IncrementAndGet();
                }), counter);

                latch.CountDown();
            }
コード例 #20
0
        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");
        }
コード例 #21
0
            protected override bool Receive(object message)
            {
                var msg = message.ToString();

                switch (msg)
                {
                case "complex": _replyTo.Tell("complexRequest"); break;

                case "complex2": _replyTo.Tell("complexRequest2"); break;

                case "simple": _replyTo.Tell("simpleRequest"); break;

                case "complexReply": _latch.CountDown(); break;

                case "simpleReply": _latch.CountDown(); break;
                }

                return(true);
            }
コード例 #22
0
ファイル: BTActorSpec.cs プロジェクト: dagmatic/akka.net
 public FailAfterSuccess(TestLatch latch, AtomicCounter counter)
 {
     StartWith(
         AllSucceed(
             AnySucceed(
                 After(
                     Execute(_ => counter.GetAndIncrement()),
                     Fail()),
                 Execute(_ => counter.GetAndIncrement())),
             Execute(_ => latch.CountDown())), null);
 }
コード例 #23
0
ファイル: BTActorSpec.cs プロジェクト: dagmatic/akka.net
 public SuccessAfterFailure(TestLatch latch, AtomicCounter counter)
 {
     StartWith(
         AllSucceed(
             AllComplete(
                 After(
                     AllSucceed(
                         Execute(_ => counter.GetAndIncrement()),
                         Fail()),
                     Not(Fail())),
                 Execute(_ => counter.GetAndIncrement())),
             Execute(_ => latch.CountDown())), null);
 }
コード例 #24
0
 protected override void OnReceive(object message)
 {
     message.Match()
     .With <ClusterEvent.CurrentClusterState>(state =>
     {
         if (state.Members.Any(c => c.Address.Equals(_secondAddress) && c.Status == MemberStatus.Exiting))
         {
             _exitingLatch.CountDown();
         }
     })
     .With <ClusterEvent.MemberExited>(m =>
     {
         if (m.Member.Address.Equals(_secondAddress))
         {
             _exitingLatch.CountDown();
         }
     })
     .With <ClusterEvent.MemberRemoved>(_ =>
     {
         // not tested here
     });
 }
コード例 #25
0
        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);
        }
コード例 #26
0
ファイル: BTActorSpec.cs プロジェクト: dagmatic/akka.net
 public ShortTimeoutLongTask(TestLatch latch, AtomicCounter counter)
 {
     StartWith(
         Loop(
             ReceiveAny(s => s.Equals("RUN"),
                 After(
                     Timeout(TimeSpan.FromMilliseconds(100),
                         Delay(5.Seconds(), Execute(_ => counter.GetAndIncrement())),
                         Execute(_ =>
                         {
                             counter.GetAndDecrement();
                             Sender.Tell("TIMEOUT");
                         })),
                     Execute(_ => latch.CountDown())))), null);
 }
コード例 #27
0
        public void A_UnfoldResourceAsyncSource_must_close_resource_when_stream_is_abruptly_termianted()
        {
            var closeLatch   = new TestLatch(1);
            var materializer = ActorMaterializer.Create(Sys);
            var p            = Source.UnfoldResourceAsync(_open, Read, reader =>
            {
                closeLatch.CountDown();
                return(Task.FromResult(0));
            }).RunWith(Sink.AsPublisher <string>(false), materializer);
            var c = this.CreateManualSubscriberProbe <string>();

            p.Subscribe(c);
            materializer.Shutdown();
            closeLatch.Ready(TimeSpan.FromSeconds(10));
        }
コード例 #28
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");
        }
コード例 #29
0
ファイル: BroadcastSpec.cs プロジェクト: ststeiger/akka.net
 protected override void OnReceive(object message)
 {
     if (message is string)
     {
         var s = (string)message;
         if (s == "end")
         {
             _latch.CountDown();
         }
     }
     if (message is int)
     {
         var i = (int)message;
         _counter.GetAndAdd(i);
     }
 }
コード例 #30
0
ファイル: ListenerSpec.cs プロジェクト: yildizoglu/akka.net
            protected override void OnReceive(object message)
            {
                PatternMatch.Match(message)
                .With <string>(str =>
                {
                    if (str.Equals("bar"))
                    {
                        _barCount.GetAndIncrement();
                        _barLatch.CountDown();
                    }

                    if (str.Equals("foo"))
                    {
                        _fooLatch.CountDown();
                    }
                });
            }