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)); }
protected override void OnReceive(object message) { if (message.Equals("hello")) { _helloLatch.CountDown(); } }
public RoundRobinPoolBroadcastActor(TestLatch helloLatch, TestLatch stopLatch) { _helloLatch = helloLatch; _stopLatch = stopLatch; Receive <string>(s => s == "hello", c => _helloLatch.CountDown()); }
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 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); }
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); }
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 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(); }); }
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); }
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); }
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")); }
public SequenceTwo(List<string> pipe, TestLatch latch) { StartWith(AllSucceed( Execute(ctx => ctx.GlobalData.Add("1")), Execute(ctx => ctx.GlobalData.Add("2"))), pipe); latch.CountDown(); }
public TimeoutAllSucceed(TestLatch latch) { StartWith( Timeout(30.Seconds(), AllSucceed( Execute(ctx => latch.CountDown())), Execute(ctx => { throw new TimeoutException(); })), null); }
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); }
public BroadcastTarget(TestLatch doneLatch, AtomicCounter counter) { _doneLatch = doneLatch; _counter = counter; Receive <string>(s => s == "end", c => _doneLatch.CountDown()); Receive <int>(msg => _counter.AddAndGet(msg)); }
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 FastActor(TestLatch testLatch, IActorRef testActor) { var ref1 = Context.ActorOf(Props.Empty); var ref2 = Context.Child(ref1.Path.Name); testActor.Tell(ref2.GetType()); testLatch.CountDown(); }
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(); } }
public ExecuteIncrement(AtomicCounter counter, TestLatch latch) { StartWith(Execute(cxt => { cxt.GlobalData.IncrementAndGet(); }), counter); latch.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"); }
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); }
public FailAfterSuccess(TestLatch latch, AtomicCounter counter) { StartWith( AllSucceed( AnySucceed( After( Execute(_ => counter.GetAndIncrement()), Fail()), Execute(_ => counter.GetAndIncrement())), Execute(_ => latch.CountDown())), null); }
public SuccessAfterFailure(TestLatch latch, AtomicCounter counter) { StartWith( AllSucceed( AllComplete( After( AllSucceed( Execute(_ => counter.GetAndIncrement()), Fail()), Not(Fail())), Execute(_ => counter.GetAndIncrement())), Execute(_ => latch.CountDown())), null); }
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 }); }
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 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); }
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)); }
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"); }
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); } }
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(); } }); }