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

            ActorSystem sysRemote = new ActorSystem($"{nameof(AskTest)}/remote", GetRemoteSysConfig());

            CancellationTokenSource src = new CancellationTokenSource();

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

            var cfg = GetLocaSysConfig();

            ActorSystem sysLocal = new ActorSystem($"{nameof(AskTest)}/local", cfg);

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

            var response = actorRef1.Ask <long>((long)42).Result;

            Assert.IsTrue(response == 43);

            response = actorRef1.Ask <long>((long)7).Result;

            Assert.IsTrue(response == 8);

            Debug.WriteLine($"End of {nameof(AskTest)}");
        }
Esempio n. 2
0
        private void RunStatePersistenceTest1(string instanceName)
        {
            Debug.WriteLine($"Start of {nameof(RunStatePersistenceTest1)}");

            BlobStoragePersistenceProvider prov = new BlobStoragePersistenceProvider();
            //prov.InitializeAsync(instanceName, new Dictionary<string, object>() { { "StorageConnectionString", storageConnStr } }, purgeOnStart: false).Wait();

            var         cfg      = DotNetActorsTests.GetLocaSysConfig();
            ActorSystem sysLocal = new ActorSystem($"{nameof(BlobStatePersistenceTest)}/local", cfg);

            // TODO: Passing persistence provider null until connection string is not fixed
            ActorSystem sysRemote = new ActorSystem($"{nameof(BlobStatePersistenceTest)}/remote", DotNetActorsTests.GetRemoteSysConfig(), null);

            CancellationTokenSource src = new CancellationTokenSource();

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

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

            var response = actorRef1.Ask <long>((long)42).Result;

            Assert.IsTrue(response == 42);

            response = actorRef1.Ask <long>((long)7).Result;

            Assert.IsTrue(response == 49);

            src.Cancel();

            Debug.WriteLine($"End of {nameof(RunStatePersistenceTest1)}");
        }
Esempio n. 3
0
        public async Task AskClientTest()
        {
            Debug.WriteLine($"Start of {nameof(AskClientTest)}");

            CancellationTokenSource src = new CancellationTokenSource();

            var cfg = GetLocaSysConfig();

            ActorSystem sysLocal = new ActorSystem($"{nameof(AskClientTest)}/local", cfg);

            ActorReference actorRef1 = sysLocal.CreateActor <HtmActor>(new ActorId(1));

            var response = await actorRef1.Ask <string>(new PingNodeMsg()
            {
                Msg = "hello"
            });

            Assert.IsTrue(response.Contains("hello"));

            Assert.IsTrue((await actorRef1.Ask <string>(new PingNodeMsg()
            {
                Msg = "hello again"
            })).Contains("hello again"));

            Debug.WriteLine($"End of {nameof(AskClientTest)}");
        }
        private void RunStatePersistenceTest2(string instanceName)
        {
            Debug.WriteLine($"Start of {nameof(RunStatePersistenceTest2)}");

            TableStoragePersistenceProvider prov = new TableStoragePersistenceProvider();

            prov.InitializeAsync(instanceName, new Dictionary <string, object>()
            {
                { "StorageConnectionString", storageConnStr }
            }, purgeOnStart: false).Wait();

            var         cfg       = DotNetActorsTests.GetLocaSysConfig();
            ActorSystem sysLocal  = new ActorSystem($"{nameof(TblStatePersistenceTest)}/local", cfg);
            ActorSystem sysRemote = new ActorSystem($"{nameof(TblStatePersistenceTest)}/remote", DotNetActorsTests.GetRemoteSysConfig(), persistenceProvider: prov);

            CancellationTokenSource src = new CancellationTokenSource();

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

                prov.Purge().Wait();
            });

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

            var response = actorRef1.Ask <long>((long)1).Result;

            Assert.IsTrue(response == 50);

            src.Cancel();

            Debug.WriteLine($"End of {nameof(RunStatePersistenceTest2)}");
        }
Esempio n. 5
0
        public void AskTestDeviceState()
        {
            Debug.WriteLine($"Start of {nameof(AskTestDeviceState)}");

            ActorSystem sysRemote = new ActorSystem($"{nameof(AskTest)}/remote", GetRemoteSysConfig());

            CancellationTokenSource src = new CancellationTokenSource();

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

            var cfg = GetLocaSysConfig();

            ActorSystem sysLocal = new ActorSystem($"{nameof(AskTest)}/local", cfg);

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

            var response = actorRef1.Ask <DeviceState>(new DeviceState()
            {
                Color = "green", State = true
            }).Result;

            Assert.AreEqual(response.Color, "braun");
            Assert.IsTrue(response.State);
            Debug.WriteLine($"End of {nameof(AskTestDeviceState)}");
        }
Esempio n. 6
0
        public override async Task ProcessMessage()
        {
            Log("Ping Received");
            Log("Asking to Pong");
            var tsk1 = pong.Ask(null, Self);
            var tsk2 = pong.Ask(null, Self);

            Log("Waiting Pong's reply");

            //Task.WaitAll (tsk1, tsk2);
            //Task.WaitAll (tsk1);

            await Task.WhenAll(tsk1, tsk2);

            Log("Got Pong's first reply: " + await tsk1);
            Log("Got Pong's second reply: " + await tsk2);

            Log("Waiting two seconds to reschedule a self ping ...");
            Thread.Sleep(2000);
            //Self.Tell (null);
        }
Esempio n. 7
0
        public async Task AskClientTest()
        {
            Debug.WriteLine($"Start of {nameof(AskClientTest)}");

            CancellationTokenSource src = new CancellationTokenSource();

            var cfg = GetLocaSysConfig();

            ActorSystem sysLocal = new ActorSystem($"{nameof(AskClientTest)}/local", cfg);

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

            var response = await actorRef1.Ask <long>((long)42);

            Assert.IsTrue(response == 43);

            response = actorRef1.Ask <long>((long)7).Result;

            Assert.IsTrue(response == 8);

            Debug.WriteLine($"End of {nameof(AskClientTest)}");
        }
Esempio n. 8
0
        public void AskManyNodesManyMessagesTest()
        {
            var         cfg        = GetLocaSysConfig();
            ActorSystem sysLocal   = new ActorSystem("local", cfg);
            ActorSystem sysRemote1 = new ActorSystem("remote1", GetRemoteSysConfig());
            ActorSystem sysRemote2 = new ActorSystem("remote2", GetRemoteSysConfig());

            CancellationTokenSource src = new CancellationTokenSource();

            var task1 = Task.Run(() =>
            {
                sysRemote1.Start(src.Token);
            });

            var task2 = Task.Run(() =>
            {
                sysRemote2.Start(src.Token);
            });

            //Thread.Sleep(int.MaxValue);

            Parallel.For(0, 20, (i) =>
            {
                ActorReference actorRef = sysLocal.CreateActor <MyActor>(i);

                for (int k = 0; k < 5; k++)
                {
                    var response = actorRef.Ask <long>((long)k).Result;
                    Assert.IsTrue(response == k + 1);

                    DateTime dtRes = actorRef.Ask <DateTime>(new DateTime(2019, 1, 1 + i % 17)).Result;

                    Assert.IsTrue(dtRes.Day == 2 + i % 17);
                    Assert.IsTrue(dtRes.Year == 2019);
                    Assert.IsTrue(dtRes.Month == 1);
                }
            });
        }
Esempio n. 9
0
        public void AskManyNodesTest()
        {
            var         cfg        = GetLocaSysConfig();
            ActorSystem sysLocal   = new ActorSystem("local", cfg);
            ActorSystem sysRemote1 = new ActorSystem("node1", GetRemoteSysConfig());
            ActorSystem sysRemote2 = new ActorSystem("node2", GetRemoteSysConfig());

            CancellationTokenSource src = new CancellationTokenSource();

            var task1 = Task.Run(() =>
            {
                sysRemote1.Start(src.Token);
            });

            var task2 = Task.Run(() =>
            {
                sysRemote2.Start(src.Token);
            });

            ActorReference actorRef1 = sysLocal.CreateActor <MyActor>(1);
            var            response  = actorRef1.Ask <long>((long)42).Result;

            Assert.IsTrue(response == 43);

            response = actorRef1.Ask <long>((long)7).Result;
            Assert.IsTrue(response == 8);

            ActorReference actorRef2 = sysLocal.CreateActor <MyActor>(7);
            var            response2 = actorRef2.Ask <long>((long)10).Result;

            Assert.IsTrue(response2 == 11);

            DateTime dtRes = actorRef2.Ask <DateTime>(new DateTime(2019, 1, 1)).Result;

            Assert.IsTrue(dtRes.Day == 2);
            Assert.IsTrue(dtRes.Year == 2019);
            Assert.IsTrue(dtRes.Month == 1);
        }
Esempio n. 10
0
        /// <summary>
        /// Represents Main class that initialise the client and asks a response from the service
        /// </summary>
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            CancellationTokenSource src = new CancellationTokenSource();
            ILogger logger = generateLogger();
            var     cfg    = new ActorSbConfig();

            cfg.SbConnStr                  = Environment.GetEnvironmentVariable("SbConnStr");
            cfg.ReplyMsgQueue              = "actorsystem/rcvlocal";
            cfg.RequestMsgTopic            = "actorsystem/actortopic";
            cfg.TblStoragePersistenConnStr = null;
            cfg.ActorSystemName            = "inst701";
            logger?.LogInformation("Loaded Configuration, Messaging-Queue:" + cfg.ReplyMsgQueue + ", Message-Topic:" + cfg.RequestMsgTopic);
            ActorSystem sysLocal = new ActorSystem($"TestDotNetWorking", cfg);

            logger?.LogInformation("Created ActorSystem");
            ActorReference actorRef1 = sysLocal.CreateActor <MyActor>(1);
            ActorReference actorRef2 = sysLocal.CreateActor <MyActor>(77);

            logger?.LogInformation("Created two Actor references, actorReference1: " + actorRef1 + ", actorReference2: " + actorRef2);
            logger?.LogInformation("Asking 42 long value from actorReference1");
            var response = await actorRef1.Ask <long>((long)42);

            logger?.LogInformation("Received result: " + response);
            logger?.LogInformation("Asking 7 long value from actorReference1");
            response = actorRef1.Ask <long>((long)7).Result;
            logger?.LogInformation("Received result: " + response);
            var resp = await actorRef1.Ask <DeviceState>(new DeviceState()
            {
                Color = "green", State = true
            });

            var stringResponse = await actorRef1.Ask <DateTime>(DateTime.Now);

            logger?.LogInformation("Successfully tested the functionality");
        }
Esempio n. 11
0
        private static async Task CheckPersistence(ILogger logger)
        {
            logger?.LogInformation("Fetching Car attributes started....");
            CancellationTokenSource src = new CancellationTokenSource();
            var cfg = GetLocaSysConfig();

            logger?.LogInformation("Loaded Configuration, Messaging-Queue:" + cfg.ReplyMsgQueue + ", Message-Topic:" + cfg.RequestMsgTopic);
            ActorSystem sysLocal = new ActorSystem($"CarFunctionalityTest", cfg);

            logger?.LogInformation("Created ActorSystem");

            for (int i = 1; i < 100; i++)
            {
                ActorReference actorRef1 = sysLocal.CreateActor <MyActor>(i);
                var            response  = await actorRef1.Ask <long>(i);

                logger?.LogInformation("Car Speed: " + response);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Tests if Ask() works as designed.
        /// </summary>

        //[TestMethod]
        //[TestCategory("SbActorTests")]
        //[TestCategory("SbActorHostRequired")]
        public void AskTestClientOnly()
        {
            //Thread.Sleep(2000);
            Debug.WriteLine($"Start of {nameof(AskTest)}");

            var         cfg      = GetLocaSysConfig();
            ActorSystem sysLocal = new ActorSystem($"{nameof(AskTest)}/local", cfg);

            CancellationTokenSource src = new CancellationTokenSource();

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

            var response = actorRef1.Ask <string>(new PingNodeMsg()
            {
                Msg = ":)"
            }).Result;

            Assert.IsTrue(response == $"Ping back - :)");

            Debug.WriteLine($"End of {nameof(AskTest)}");
        }
Esempio n. 13
0
        public async Task AskClientTest_DeviceState()
        {
            Debug.WriteLine($"Start of {nameof(AskClientTest_DeviceState)}");

            CancellationTokenSource src = new CancellationTokenSource();

            var cfg = GetLocaSysConfig();

            ActorSystem sysLocal = new ActorSystem($"{nameof(AskClientTest)}/local", cfg);

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

            var response = await actorRef1.Ask <DeviceState>(new DeviceState()
            {
                Color = "yellow", State = true
            });

            Assert.IsFalse(response.State);
            Assert.AreEqual(response.Color, "blue");

            Debug.WriteLine($"End of {nameof(AskClientTest_DeviceState)}");
        }
Esempio n. 14
0
        private static async Task LoadCarAttributes(ILogger logger)
        {
            CancellationTokenSource src = new CancellationTokenSource();
            var cfg = GetLocaSysConfig();

            logger?.LogInformation("Car sample started with reply message queue as " + cfg.ReplyMsgQueue);
            logger?.LogInformation("Loaded Configuration, Messaging-Queue:" + cfg.ReplyMsgQueue + ", Message-Topic:" + cfg.RequestMsgTopic);
            ActorSystem sysLocal = new ActorSystem($"CarFunctionalityTest", cfg);

            logger?.LogInformation("Created ActorSystem");

            logger?.LogInformation("Creating multiple Actor references");

            for (int i = 200; i < 300; i++)
            {
                ActorReference actorRef1 = sysLocal.CreateActor <MyActor>(i);
                var            response  = await actorRef1.Ask <CarAttributes>(new CarAttributes()
                {
                    CarColor = "green", CarSpeed = "" + (222 + i), Persisted = false
                });

                logger?.LogInformation("Received result: " + response.Persisted);
            }
        }