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 BroadcastTarget(TestLatch doneLatch, AtomicCounter counter) { _doneLatch = doneLatch; _counter = counter; Receive<string>(s => s == "end", c => _doneLatch.CountDown()); Receive<int>(msg => _counter.AddAndGet(msg)); }
public SimpleBroadcastActor(AtomicCounter counter) { _counter = counter; Receive <int>(i => i == 1, c => { lock (_lock) Counter++; throw new InvalidOperationException($"I'm dead. #{Counter}"); }); Receive <int>(i => i == 2, c => { _counter.AddAndGet(1); Sender.Tell(2); }); }
public void When_multiple_concurrent_writing_clients_Should_not_lose_messages() { const int clientsCount = 50; new TestSetup(this).Run(x => { // Setup multiple clients var actors = x.EstablishNewClientConnection(); // Each client sends his index to server var clients = Enumerable.Range(0, clientsCount).Select(i => (Index: i, Probe: CreateTestProbe($"test-client-{i}"))).ToArray(); var counter = new AtomicCounter(0); Parallel.ForEach(clients, client => { var msg = ByteString.FromString(client.Index.ToString()); counter.AddAndGet(msg.Count); client.Probe.Send(actors.ClientConnection, Tcp.Write.Create(msg)); }); // All messages data should be received var received = actors.ServerHandler.ReceiveWhile(o => o as Tcp.Received, TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(1.5)); received.Sum(r => r.Data.Count).ShouldBe(counter.Current); }); }
public ParentActor(AtomicCounter counter) { _counter = counter; for (var i = 0; i < 10; ++i) { var child = Context.ActorOf(Props.Create <SimpleActor>(), $"child-{i}"); _children.Add(child); } ReceiveAsync <string>(str => str.Equals("spam-fails"), async m => { foreach (var child in _children) { child.Tell(1); } await Task.Delay(1000); }); ReceiveAsync <string>(str => str.Equals("run-test"), async m => { for (var i = 0; i < 2; ++i) { foreach (var child in _children) { try { await child.Ask <int>(1, TimeSpan.FromSeconds(0.08)); } catch { _counter.AddAndGet(1); } } } }); }