예제 #1
0
        public async Task CollectionActorRemove_ExpectsNewStateWithoutRemovedItems()
        {
            var stateManager = new Mock <IActorStateManager>();
            var list         = new List <string> {
                Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
            };
            var state = new HashSet <string>(list);

            stateManager.Setup(manager => manager.GetStateAsync <HashSet <string> >(_stateName, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(state))
            .Verifiable();
            stateManager.Setup(manager => manager.SetStateAsync(_stateName, state, It.IsAny <CancellationToken>()))
            .Verifiable();
            CollectionActor testDemoActor = await CreateActor(stateManager.Object, "Test Collection");

            await testDemoActor.Remove(list[2]);

            await testDemoActor.Remove(list[0]);

            list.Remove(list[2]);
            list.Remove(list[0]);
            state.Should().HaveCount(3);
            state.Should().Contain(list);

            stateManager.VerifyAll();
        }
예제 #2
0
        public async Task CollectionActorAdd_ExpectsNewStateWithNewItems()
        {
            var stateManager = new Mock <IActorStateManager>();
            var state1       = new HashSet <string> {
                Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
            };
            var state2 = new List <string> {
                Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
            };

            stateManager.Setup(manager => manager.GetStateAsync <HashSet <string> >(_stateName, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(state1))
            .Verifiable();
            stateManager.Setup(manager => manager.SetStateAsync(_stateName, state1, It.IsAny <CancellationToken>()))
            .Verifiable();
            CollectionActor testDemoActor = await CreateActor(stateManager.Object, "Test Collection");

            await testDemoActor.Add(state2[0]);

            await testDemoActor.Add(state2[1]);

            await testDemoActor.Add(state2[2]);

            state1.Should().HaveCount(8);
            state1.Should().Contain(state2);

            stateManager.VerifyAll();
        }
예제 #3
0
        private async Task <CollectionActor> CreateActor(IActorStateManager actorStateManager, string id)
        {
            var actorTypeInformation = ActorTypeInformation.Get(typeof(CollectionActor));

            CollectionActor actorFactory(ActorService service, ActorId id) =>
            new CollectionActor(service, id, actorStateManager);

            var             actorService = new ActorService(actorTypeInformation, actorFactory);
            CollectionActor actor        = actorFactory(actorService, new ActorId(id));
            MethodInfo      OnActivate   = actor.GetType().GetMethod("OnActivateAsync", BindingFlags.NonPublic | BindingFlags.Instance);

            await(Task) OnActivate.Invoke(actor, Array.Empty <object>());
            return(actor);
        }
예제 #4
0
        public async Task CollectionActorExist_ExpectsFalse()
        {
            var stateManager = new Mock <IActorStateManager>();
            var list         = new List <string> {
                Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
            };
            var state = new HashSet <string>(list);

            stateManager.Setup(manager => manager.GetStateAsync <HashSet <string> >(_stateName, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(state))
            .Verifiable();
            CollectionActor testDemoActor = await CreateActor(stateManager.Object, "Test Collection");

            bool result = await testDemoActor.Exist("this value does not exist");

            result.Should().BeFalse();

            stateManager.VerifyAll();
        }
 public void TestActorCollectionEnumerator()
 {
     TestLauncherActor.Test(() =>
     {
         var collect = new CollectionActor <string>();
         for (int i = 0; i < 100; i++)
         {
             collect.Add(string.Format("Test {0}", i));
         }
         Assert.AreEqual(100, collect.Count());
         // try to enum
         var enumerable = collect.ToList();
         Assert.AreEqual(100, enumerable.Count);
         // try a query
         var query = from col in collect
                     where col.Contains('1')
                     select col;
         Assert.AreEqual(query.Count(), 19);
     });
 }
예제 #6
0
 public void TestActorCollection()
 {
     TestLauncherActor.Test(() =>
     {
         CollectionActor <string> collect = new CollectionActor <string>();
         collect.Add("Test1");
         collect.Add("Test2");
         collect.Add("Test3");
         Assert.IsTrue(collect.Any(t => t == "Test1"));
         Assert.IsTrue(collect.Contains("Test2"));
         Assert.IsTrue(collect.First(t => t == "Test3") != null);
         collect.Remove("Test1");
         collect.Remove("Test2");
         collect.Remove("Test3");
         collect.Add("Test4");
         collect.Add("Test5");
         List <string> enumerable = collect.ToList();
         Assert.AreEqual(2, enumerable.Count);
     });
 }
예제 #7
0
        public void TestActorCollectionEnumerator()
        {
            TestLauncherActor.Test(() =>
            {
                CollectionActor <string> collect = new CollectionActor <string>();
                for (int i = 0; i < 100; i++)
                {
                    collect.Add($"Test {i}");
                }

                Assert.AreEqual(100, collect.Count());

                List <string> enumerable = collect.ToList();
                Assert.AreEqual(100, enumerable.Count);

                IEnumerable <string> query = from col in collect
                                             where col.Contains('1')
                                             select col;
                Assert.AreEqual(query.Count(), 19);
            });
        }
예제 #8
0
        public async Task CollectionActorAdd_ExpectGetStateAsync()
        {
            var stateManager = new Mock <IActorStateManager>();
            var state        = new HashSet <string> {
                Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
            };

            stateManager.Setup(manager => manager.GetStateAsync <HashSet <string> >(_stateName, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(state))
            .Verifiable();
            CollectionActor testDemoActor = await CreateActor(stateManager.Object, "Test Collection");

            object result = await testDemoActor.GetStateValue();

            result.Should().NotBeNull();
            result.Should().BeOfType <HashSet <string> >();
            var ids = (HashSet <string>)result;

            ids.Should().HaveCount(state.Count);
            ids.Should().BeEquivalentTo(state);

            stateManager.VerifyAll();
        }
 public void TestActorCollection()
 {
     TestLauncherActor.Test(() =>
     {
         var collect = new CollectionActor <string>();
         collect.Add("Test1");
         collect.Add("Test2");
         collect.Add("Test3");
         Assert.IsTrue(collect.Any(t => t == "Test1"));
         Assert.IsTrue(collect.Contains("Test2"));
         Assert.IsTrue(collect.Where(t => t == "Test3").First() != null);
         collect.Remove("Test1");
         //Assert.IsFalse(collect.Exists("Test1").Result);
         collect.Remove("Test2");
         //Assert.IsFalse(collect.Exists("Test2").Result);
         collect.Remove("Test3");
         //Assert.IsFalse(collect.Exists("Test3").Result);
         collect.Add("Test4");
         collect.Add("Test5");
         var enumerable = collect.ToList();
         Assert.AreEqual(2, enumerable.Count);
     });
 }
예제 #10
0
        private void DoBehavior(string msg)
        {
            Console.WriteLine("Serv Start");
            var start = DateTime.UtcNow.Ticks;

            collect = new CollectionActor <string>();
            var list = new List <string>();

            for (int i = 0; i < 10; i++)
            {
                collect.Add(i.ToString(CultureInfo.InvariantCulture));
                list.Add(i.ToString(CultureInfo.InvariantCulture));
            }

            foreach (var item in collect)
            {
                Console.WriteLine("Collect " + item);
            }

            var actForeach = new BaseActor(new ForEachBehavior <string>());

            actForeach.SendMessage <IEnumerable <string>, Action <String> >(list,
                                                                            t => Console.WriteLine("list " + t));


            Console.WriteLine("Should have work");

            var linkedlist = new LinkedListActor <string>();

            for (int i = 0; i < 100; i++)
            {
                linkedlist.SendMessage(LinkedListOperation.Add, i.ToString());
            }

            new EchoActor <Tuple <LinkedListOperation, string> >(linkedlist, Tuple.Create(LinkedListOperation.First, "5"));

            new RingActor(1000, 1000); // 10 sec

            new LinkedListActor <string>();

            IActor aServer = new EchoServerActor();

            clientList = new List <IActor>();
            for (int i = 0; i < 100; i++)
            {
                EchoClientActor aClient = new EchoClientActor();// new actEchoClient(aServer);
                // DirectoryRequest.SendRegister("client + " + i.ToString(), aClient);
                aClient.Connect("EchoServer");
                aClient.SendMessage("client-" + i.ToString(CultureInfo.InvariantCulture));
                clientList.Add(aClient);
                // aClient.Disconnect();
            }
            var end = DateTime.UtcNow.Ticks;

            Console.WriteLine("All client allocated {0}", (double)(end - start) / 10000.0);

            // basic redirection
            IActor target = new BaseActor(new Behavior <string>(t => { Console.WriteLine(t); }));
            IActor middle = new BaseActor(new Behavior <string>(t => { t = t + " augmenté"; }));

            middle.SendMessage("Bonjour");


            // dynamic use DLR to handle the send / dispatch business ...
            dynamic test = new ExpandoObject();
            dynamic dyn  = new DynamicActor(test);

            test.PrintSomething = (Action <string>)((t) => Console.WriteLine(t));
            dyn.PrintSomething("Got it !");
        }
예제 #11
0
        static void Main(string[] args)
        {
            string lName = "";
            string lPort = "";

            if (args.Length > 0)
            {
                lName = args.FirstOrDefault(t => t.StartsWith("-n:"));
                lPort = args.FirstOrDefault(t => t.StartsWith("-p:"));
            }
            if (!string.IsNullOrEmpty(lName))
            {
                lName = lName.Replace("-n:", "");
            }
            else
            {
                lName = "ARnActorServer";
            }

            if (!String.IsNullOrEmpty(lPort))
            {
                lPort = lPort.Replace("-p:", "");
            }
            else
            {
                lPort = "80";
            }

            ActorServer.Start(lName, int.Parse(lPort), new HostRelayActor());
            IActor fMain = new ActorMain();

            // new actActionReceiver().ConsoleWrite("Welcome in an action world");

            //var Input = new SDRInput("Machine") ;
            //var Region = new HTMRegion(Input);

            string s = string.Empty;

            do
            {
                s = Console.ReadLine();
                if (!string.IsNullOrEmpty(s))
                {
                    switch (s)
                    {
                    case "Many": { fMillion = new actMillion(); break; }

                    case "SendMany": { fMillion.Send(); break; }

                    case "quit": break;

                    case "Col":
                    {
                        var fLauncher = new TestLauncherActor();
                        fLauncher.SendAction(() =>
                            {
                                var collect = new CollectionActor <string>();
                                for (int i = 0; i < 100; i++)
                                {
                                    collect.Add(string.Format("Test {0}", i));
                                }
                                if (collect.Count() != 100)
                                {
                                    throw new Exception("failed");
                                }
                                // try to enum
                                var enumerable = collect.ToList();
                                if (enumerable.Count != 100)
                                {
                                    throw new ActorException("failed");
                                }
                                // try a query
                                var query = from col in collect
                                            where col.Contains('1')
                                            select col;
                                if (query.Count() != 19)
                                {
                                    throw new ActorException("failed");
                                }
                                fLauncher.Finish();
                            });
                        fLauncher.Wait();
                        break;
                    }

                    case "Ring":
                    {
                        new RingActor(10000, 10000);         // 30 sec
                        break;
                    }

                    case "Rings":
                    {
                        Console.Write("Enter ring size : ");
                        var rs = Console.ReadLine();
                        Console.Write("Enter cycle : ");
                        var cy = Console.ReadLine();
                        int.TryParse(rs, out int r);
                        int.TryParse(cy, out int y);
                        new RingActor(y, r);         // 30 sec
                        break;
                    }

                    case "Clients":
                    {
                        var    start   = DateTime.UtcNow.Ticks;
                        IActor aServer = new EchoServerActor();
                        for (int i = 0; i < 1000; i++)
                        {
                            EchoClientActor aClient = new EchoClientActor();        // new actEchoClient(aServer);
                                                                                    // DirectoryRequest.SendRegister("client + " + i.ToString(), aClient);
                            aClient.Connect("EchoServer");
                            aClient.SendMessage("client-" + i.ToString());
                            // aClient.Disconnect();
                        }
                        var end = DateTime.UtcNow.Ticks;
                        Console.WriteLine("All client allocated {0}", (double)(end - start) / 10000.0);
                        break;
                    }

                    case "Download":
                    {
                        Console.WriteLine("trying Download");
                        IActor down = new ActorDownloadTest();
                        break;
                    }

                    //case "Brain":
                    //    {
                    //        Console.Write("Enter word : ");
                    //        var s2 = Console.ReadLine();
                    //        Input.SetData(s2);
                    //        Region.Run();
                    //        Region.Print();
                    //        break;
                    //    }
                    //case "Learn":
                    //    {
                    //        Input.SetData("Hello world ! ") ;
                    //        for (int i = 0; i < 100; i++)
                    //        {
                    //            Region.Run();
                    //            Region.Print();
                    //        }
                    //        break;
                    //    }
                    case "Pricing":
                    {
                        new ActorScheduler();
                        break;
                    }

                    case "ParserTest":
                    {
                        new EchoActor(new ParserTest(), "");
                        break;
                    }

                    default:
                    {
                        new EchoActor(new ActorAdminServer(), s);
                        break;
                    }
                    }
                }
            } while (s != "quit");
        }
예제 #12
0
        private void DoBehavior(string msg)
        {
            Console.WriteLine(ServerStart);
            long start = DateTime.UtcNow.Ticks;

            _collect = new CollectionActor <string>();
            List <string> list = new List <string>();

            for (int i = 0; i < 10; i++)
            {
                _collect.Add(i.ToString(CultureInfo.InvariantCulture));
                list.Add(i.ToString(CultureInfo.InvariantCulture));
            }

            foreach (string item in _collect)
            {
                Console.WriteLine("Collect " + item);
            }

            BaseActor actForeach = new BaseActor(new ForEachBehavior <string>());

            actForeach.SendMessage <IEnumerable <string>, Action <String> >(list,
                                                                            t => Console.WriteLine("list " + t));

            Console.WriteLine("Should have work");

            LinkedListActor <string> linkedlist = new LinkedListActor <string>();

            for (int i = 0; i < 100; i++)
            {
                linkedlist.SendMessage(LinkedListOperation.Add, i.ToString());
            }

            new EchoActor <Tuple <LinkedListOperation, string> >(linkedlist, Tuple.Create(LinkedListOperation.First, "5"));

            new RingActor(1000, 1000); // 10 sec

            new LinkedListActor <string>();

            IActor aServer = new EchoServerActor();

            _clientList = new List <IActor>();
            for (int i = 0; i < 100; i++)
            {
                EchoClientActor aClient = new EchoClientActor();// new actEchoClient(aServer);
                // DirectoryRequest.SendRegister("client + " + i.ToString(), aClient);
                aClient.Connect("EchoServer");
                aClient.SendMessage("client-" + i.ToString(CultureInfo.InvariantCulture));
                _clientList.Add(aClient);
                // aClient.Disconnect();
            }
            long end = DateTime.UtcNow.Ticks;

            Console.WriteLine("All client allocated {0}", (end - start) / 10000.0);

            // basic redirection
            IActor target = new BaseActor(new Behavior <string>(t => Console.WriteLine(t)));
            IActor middle = new BaseActor(new Behavior <string>(t => t += " augmenté"));

            middle.SendMessage("Bonjour");
        }
예제 #13
0
 public DemoWorker(CollectionActor <string> memLogger) : base()
 {
     fMemLogger = memLogger;
 }