Esempio n. 1
0
        public void TellTest()
        {
            Debug.WriteLine($"Start of {nameof(TellTest)}");

            var         cfg       = GetLocaSysConfig();
            ActorSystem sysLocal  = new AkkaSb.Net.ActorSystem($"{nameof(TellTest)}/local", cfg);
            ActorSystem sysRemote = new ActorSystem($"{nameof(TellTest)}/remote", GetRemoteSysConfig());

            CancellationTokenSource src = new CancellationTokenSource();

            var task = Task.Run(() =>
            {
                sysRemote.Start(src.Token);
            });

            ActorReference actorRef1 = sysLocal.CreateActor <MyActor>(1);

            actorRef1.Tell("message 1").Wait();

            actorRef1.Tell(new TestClass()).Wait();

            ActorReference actorRef2 = sysLocal.CreateActor <MyActor>(2);

            actorRef2.Tell("message 2").Wait();

            while (true)
            {
                if (receivedMessages.Count == 3)
                {
                    Assert.IsTrue(receivedMessages.Values.Contains("message 1"));
                    Assert.IsTrue(receivedMessages.Values.Contains("message 2"));
                    Assert.IsTrue(receivedMessages.Values.Contains("UnitTestsProject.SbAkkaTest+TestClass"));
                    src.Cancel();
                    break;
                }
                Thread.Sleep(250);
            }

            task.Wait();

            Debug.WriteLine($"End of {nameof(TellTest)}");
        }