本文整理汇总了C#中Akka.TestKit.TestLatch.Ready方法的典型用法代码示例。如果您正苦于以下问题:C# TestLatch.Ready方法的具体用法?C# TestLatch.Ready怎么用?C# TestLatch.Ready使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Akka.TestKit.TestLatch
的用法示例。
在下文中一共展示了TestLatch.Ready方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Listener_must_listen_in
public void Listener_must_listen_in()
{
//arrange
var fooLatch = new TestLatch(2);
var barLatch = new TestLatch(2);
var barCount = new AtomicCounter(0);
var broadcast = Sys.ActorOf<BroadcastActor>();
var newListenerProps = Props.Create(() => new ListenerActor(fooLatch, barLatch, barCount));
var a1 = Sys.ActorOf(newListenerProps);
var a2 = Sys.ActorOf(newListenerProps);
var a3 = Sys.ActorOf(newListenerProps);
//act
broadcast.Tell(new Listen(a1));
broadcast.Tell(new Listen(a2));
broadcast.Tell(new Listen(a3));
broadcast.Tell(new Deafen(a3));
broadcast.Tell(new WithListeners(a => a.Tell("foo")));
broadcast.Tell("foo");
//assert
barLatch.Ready(TestLatch.DefaultTimeout);
Assert.Equal(2, barCount.Current);
fooLatch.Ready(TestLatch.DefaultTimeout);
foreach (var actor in new[] {a1, a2, a3, broadcast})
{
Sys.Stop(actor);
}
}
示例2: Smallest_mailbox_pool_must_deliver_messages_to_idle_actor
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);
}
示例3: GetTimeout
public void GetTimeout()
{
var timeoutLatch = new TestLatch();
var timeoutActor = Sys.ActorOf(Props.Create(() => new TimeoutActor(timeoutLatch)));
timeoutLatch.Ready(TestLatch.DefaultTimeout);
Sys.Stop(timeoutActor);
}
示例4: Props_must_create_actor_by_producer
public void Props_must_create_actor_by_producer()
{
TestLatch latchProducer = new TestLatch(Sys);
TestLatch latchActor = new TestLatch(Sys);
var props = Props.CreateBy<TestProducer>(latchProducer, latchActor);
ActorRef actor = Sys.ActorOf(props);
latchActor.Ready(TimeSpan.FromSeconds(1));
}
示例5: RescheduleTimeout
public void RescheduleTimeout()
{
var timeoutLatch = new TestLatch(Sys);
var timeoutActor = Sys.ActorOf(Props.Create(() => new TimeoutActor(timeoutLatch)));
timeoutActor.Tell(Tick);
timeoutLatch.Ready(TestLatch.DefaultTimeout);
Sys.Stop(timeoutActor);
}
示例6: BroadcastGroup_router_must_broadcast_message_using_Tell
public void BroadcastGroup_router_must_broadcast_message_using_Tell()
{
var doneLatch = new TestLatch(2);
var counter1 = new AtomicCounter(0);
var counter2 = new AtomicCounter(0);
var actor1 = Sys.ActorOf(Props.Create(() => new BroadcastTarget(doneLatch, counter1)));
var actor2 = Sys.ActorOf(Props.Create(() => new BroadcastTarget(doneLatch, counter2)));
var routedActor = Sys.ActorOf(Props.Create<TestActor>().WithRouter(new BroadcastGroup(actor1.Path.ToString(), actor2.Path.ToString())));
routedActor.Tell(new Broadcast(1));
routedActor.Tell(new Broadcast("end"));
doneLatch.Ready(TimeSpan.FromSeconds(1));
counter1.Current.ShouldBe(1);
counter2.Current.ShouldBe(1);
}
示例7: Scatter_gather_router_must_deliver_a_broadcast_message_using_tell
public void Scatter_gather_router_must_deliver_a_broadcast_message_using_tell()
{
var doneLatch = new TestLatch(sys, 2);
var counter1 = new AtomicInteger(0);
var counter2 = new AtomicInteger(0);
var actor1 = sys.ActorOf(Props.Create(() => new BroadcastTarget(doneLatch, counter1)));
var actor2 = sys.ActorOf(Props.Create(() => new BroadcastTarget(doneLatch, counter2)));
var routedActor = sys.ActorOf(Props.Create<TestActor>().WithRouter(new ScatterGatherFirstCompletedGroup(TimeSpan.FromSeconds(1), actor1.Path.ToString(), actor2.Path.ToString())));
routedActor.Tell(new Broadcast(1));
routedActor.Tell(new Broadcast("end"));
doneLatch.Ready(TimeSpan.FromSeconds(1));
counter1.Value.ShouldBe(1);
counter2.Value.ShouldBe(1);
}
示例8: BroadcastGroup_router_must_broadcast_message_using_Ask
public void BroadcastGroup_router_must_broadcast_message_using_Ask()
{
var doneLatch = new TestLatch(2);
var counter1 = new AtomicCounter(0);
var actor1 = Sys.ActorOf(Props.Create(() => new BroadcastTarget(doneLatch, counter1)));
var counter2 = new AtomicCounter(0);
var actor2 = Sys.ActorOf(Props.Create(() => new BroadcastTarget(doneLatch, counter2)));
var paths = new List<string> { actor1.Path.ToString(), actor2.Path.ToString() };
var routedActor = Sys.ActorOf(new BroadcastGroup(paths).Props());
routedActor.Ask(new Broadcast(1));
routedActor.Tell(new Broadcast("end"));
doneLatch.Ready(RemainingOrDefault);
counter1.Current.Should().Be(1);
counter2.Current.Should().Be(1);
}
示例9: Random_must_be_able_to_shut_down_its_instance
public void Random_must_be_able_to_shut_down_its_instance()
{
const int routeeCount = 7;
var testLatch = new TestLatch(Sys, routeeCount);
var router = Sys.ActorOf(new RandomPool(routeeCount).Props(Props.Create(() => new HelloWorldActor(testLatch))));
router.Tell("hello", TestActor);
router.Tell("hello", TestActor);
router.Tell("hello", TestActor);
router.Tell("hello", TestActor);
router.Tell("hello", TestActor);
Within(TimeSpan.FromSeconds(2), () => {
ExpectMsg("world");
ExpectMsg("world");
ExpectMsg("world");
ExpectMsg("world");
ExpectMsg("world");
return true;
});
Sys.Stop(router);
testLatch.Ready(TimeSpan.FromSeconds(5));
}
示例10: Smallest_mailbox_router_must_deliver_messages_to_idle_actor
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);
}
示例11: Within
public void An_actor_watching_a_remote_actor_in_the_cluster_must_receive_terminated_when_watched_node_becomes_down_removed()
{
Within(TimeSpan.FromSeconds(30), () =>
{
AwaitClusterUp(_config.First, _config.Second, _config.Third, _config.Fourth);
EnterBarrier("cluster-up");
RunOn(() =>
{
EnterBarrier("subjected-started");
var path2 = new RootActorPath(GetAddress(_config.Second)) / "user" / "subject";
var path3 = new RootActorPath(GetAddress(_config.Third)) / "user" / "subject";
var watchEstablished = new TestLatch(2);
Sys.ActorOf(Props.Create(() => new Observer(path2, path3, watchEstablished, TestActor))
.WithDeploy(Deploy.Local), "observer1");
watchEstablished.Ready();
EnterBarrier("watch-established");
ExpectMsg(path2);
ExpectNoMsg(TimeSpan.FromSeconds(2));
EnterBarrier("second-terminated");
MarkNodeAsUnavailable(GetAddress(_config.Third));
AwaitAssert(() => Assert.True(ClusterView.UnreachableMembers.Select(x => x.Address).Contains(GetAddress(_config.Third))));
Cluster.Down(GetAddress(_config.Third));
//removed
AwaitAssert(() => Assert.False(ClusterView.Members.Select(x => x.Address).Contains(GetAddress(_config.Third))));
AwaitAssert(() => Assert.False(ClusterView.UnreachableMembers.Select(x => x.Address).Contains(GetAddress(_config.Third))));
ExpectMsg(path3);
EnterBarrier("third-terminated");
}, _config.First);
RunOn(() =>
{
Sys.ActorOf(BlackHoleActor.Props, "subject");
EnterBarrier("subjected-started");
EnterBarrier("watch-established");
RunOn(() =>
{
MarkNodeAsUnavailable(GetAddress(_config.Second));
AwaitAssert(() => Assert.True(ClusterView.UnreachableMembers.Select(x => x.Address).Contains(GetAddress(_config.Second))));
Cluster.Down(GetAddress(_config.Second));
//removed
AwaitAssert(() => Assert.False(ClusterView.Members.Select(x => x.Address).Contains(GetAddress(_config.Second))));
AwaitAssert(() => Assert.False(ClusterView.UnreachableMembers.Select(x => x.Address).Contains(GetAddress(_config.Second))));
}, _config.Third);
EnterBarrier("second-terminated");
EnterBarrier("third-terminated");
}, _config.Second, _config.Third, _config.Fourth);
RunOn(() =>
{
EnterBarrier("subjected-started");
EnterBarrier("watch-established");
EnterBarrier("second-terminated");
EnterBarrier("third-terminated");
}, _config.Fifth);
EnterBarrier("after-1");
});
}
示例12: DefaultResizer_must_be_possible_to_define_in_configuration
public void DefaultResizer_must_be_possible_to_define_in_configuration()
{
var latch = new TestLatch(Sys, 3);
var router = Sys.ActorOf(Props.Create<ResizerTestActor>().WithRouter(new FromConfig()), "router1");
router.Tell(latch);
router.Tell(latch);
router.Tell(latch);
latch.Ready(TestKitSettings.DefaultTimeout);
//messagesPerResize is 10 so there is no risk of additional resize
(RouteeSize(router)).ShouldBe(2);
}
示例13: DefaultResizer_must_be_possible_to_define_programmatically
public void DefaultResizer_must_be_possible_to_define_programmatically()
{
var latch = new TestLatch(Sys, 3);
var resizer = new DefaultResizer(2, 3);
var router = Sys.ActorOf(Props.Create<ResizerTestActor>().WithRouter(new RoundRobinPool(0, resizer)));
router.Tell(latch);
router.Tell(latch);
router.Tell(latch);
latch.Ready(TestKitSettings.DefaultTimeout);
//messagesPerResize is 10 so there is no risk of additional resize
(RouteeSize(router)).ShouldBe(2);
}
示例14: AwaitClusterUp
public void Set_of_connected_cluster_systems_must_when_two_nodes_after_cluster_convergence_updates_membership_table_then_all_MembershipChangeListeners_should_be_triggered()
{
AwaitClusterUp(_config.First);
RunOn(() =>
{
var latch = new TestLatch();
var expectedAddresses = ImmutableList.Create(GetAddress(_config.First), GetAddress(_config.Second));
var listener = Sys.ActorOf(Props.Create(() => new Listener(latch, expectedAddresses)).WithDeploy(Deploy.Local));
Cluster.Subscribe(listener, new[] { typeof(ClusterEvent.IMemberEvent) });
EnterBarrier("listener-1-registered");
Cluster.Join(GetAddress(_config.First));
latch.Ready();
}, _config.First, _config.Second);
RunOn(() =>
{
EnterBarrier("listener-1-registered");
}, _config.Third);
EnterBarrier("after-1");
}
示例15: A_Flow_with_SelectAsyncUnordered_must_signal_error_from_SelectAsyncUnordered
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);
}