public void SendMessageToActor() { int total = 0; EventWaitHandle wait = new AutoResetEvent(false); Actor actor = new LambdaActor(c => { total += (int)c; wait.Set(); }); ActorSystem system = new ActorSystem(); var server = new TcpServer("localhost", 3000, system); var result = system.ActorOf(actor, "myactor"); var path = result.Path.ToString(); server.Start(); var client = new System.Net.Sockets.TcpClient(); client.Connect("localhost", 3000); var channel = new OutputChannel(new System.IO.BinaryWriter(client.GetStream())); channel.Write(path); channel.Write(1); wait.WaitOne(); Assert.AreEqual(1, total); client.Close(); server.Stop(); system.Shutdown(); }
public void SendMessagesToActor() { int total = 0; EventWaitHandle wait = new AutoResetEvent(false); Actor actor = new LambdaActor(c => { total += (int)c; if (total >= 6) { wait.Set(); } }); ActorSystem system = new ActorSystem(); var server = new TcpServer("localhost", 3003, system); var result = system.ActorOf(actor, "myactor"); var path = result.Path.ToString(); server.Start(); var client = new TcpClient("localhost", 3003); client.Start(); client.Tell(path, 1); client.Tell(path, 2); client.Tell(path, 3); wait.WaitOne(); Assert.AreEqual(6, total); client.Stop(); server.Stop(); system.Shutdown(); }
public void SendMessagesToRemoteActor() { int total = 0; EventWaitHandle wait = new AutoResetEvent(false); Actor actor = new LambdaActor(c => { total += (int)c; if (total >= 6) { wait.Set(); } }); ActorSystem remotesystem = new ActorSystem(); var server = new TcpServer("localhost", 3005, remotesystem); var result = remotesystem.ActorOf(actor, "myactor"); var path = result.Path.ToString(); server.Start(); var system = new ActorSystem(); var remoteref = system.ActorSelect("aktores.tcp://sys@localhost:3005/myactor"); remoteref.Tell(1); remoteref.Tell(2); remoteref.Tell(3); wait.WaitOne(); Assert.AreEqual(6, total); system.Shutdown(); server.Stop(); remotesystem.Shutdown(); }
public void SendMessageToActor() { int total = 0; EventWaitHandle wait = new AutoResetEvent(false); Actor actor = new LambdaActor(c => { total += (int)c; wait.Set(); }); ActorSystem system = new ActorSystem(); var client = new InProcessClient(system); var result = system.ActorOf(actor, "myactor"); var path = result.Path.ToString(); client.Tell(path, 1); wait.WaitOne(); Assert.AreEqual(1, total); system.Shutdown(); }
public void CreateRouterAndSendMessageToActor() { ActorSystem system = new ActorSystem(); int total = 0; EventWaitHandle wait = new AutoResetEvent(false); Actor actor = new LambdaActor(c => { total += (int)c; wait.Set(); }); var actorref = system.ActorOf(actor, "myactor"); var router = new RouterActor(); router.Register(actorref); var routerref = system.ActorOf(router, "myrouter"); routerref.Tell(3); Assert.IsTrue(wait.WaitOne(1000)); Assert.AreEqual(3, total); system.Shutdown(); }
public void CreateRouterAndSendMessageToActors() { ActorSystem system = new ActorSystem(); int total = 0; EventWaitHandle wait = new AutoResetEvent(false); var router = new RouterActor(); var routerref = system.ActorOf(router, "myrouter"); for (int k = 0; k < 100; k++) { Actor actor = new LambdaActor(c => { lock (system) { total += (int)c; } if (total >= 10) { wait.Set(); } }); var actorref = system.ActorOf(actor); router.Register(actorref); } routerref.Tell(1); routerref.Tell(2); routerref.Tell(3); routerref.Tell(4); Assert.IsTrue(wait.WaitOne(1000)); Assert.AreEqual(10, total); system.Shutdown(); }