Exemplo n.º 1
0
        public void FiniteStateMachineTest()
        {
            TestLauncherActor.Test(() =>
            {
                var behaviors = new List <FsmBehavior <string, int> >();
                behaviors.Add(new FsmBehavior <string, int>("StartState", "MidState", i => { }, i => i == 1));
                behaviors.Add(new FsmBehavior <string, int>("MidState", "EndState", i => { }, i => i == 2));
                var fsmActor = new FsmActor <string, int>("StartState", behaviors);

                var currentState1 = fsmActor.GetCurrentState();
                Assert.IsTrue(currentState1.Result() == "StartState");

                fsmActor.SendMessage("StartState", 1);

                var currentState2 = fsmActor.GetCurrentState();
                Assert.IsTrue(currentState2.Result() == "MidState");

                fsmActor.SendMessage("MidState", 2);

                var currentState3 = fsmActor.GetCurrentState();
                Assert.IsTrue(currentState3.Result() == "EndState");

                fsmActor.SendMessage("MidState", 3);

                // unchanged shoud be
                var currentState4 = fsmActor.GetCurrentState();
                Assert.IsTrue(currentState4.Result() == "EndState");
            });
        }
Exemplo n.º 2
0
 public void TestActionActor2()
 {
     TestLauncherActor.Test(
         () =>
     {
         ConcurrentDictionary <int, string> dico = new ConcurrentDictionary <int, string>();
         var future = new Future <int, string>();
         var act    = new ActionActor();
         act.SendAction(() =>
         {
             var tst = new ActionActor <int, string>();
             tst.SendAction((i, t) => dico[i] = t, 1, "test1");
             tst.SendAction((i, t) => dico[i] = t, 2, "test2");
             tst.SendAction((i, t) => dico[i] = t, 3, "test3");
             tst.SendAction(() =>
             {
                 var s = string.Concat(dico.Values);
                 future.SendMessage(dico.Count, s);
             });
         });
         var result = future.Result();
         Assert.AreEqual(3, result.Item1);
         Assert.AreEqual("test1test2test3", result.Item2);
     }
         );
 }
Exemplo n.º 3
0
 public void TestActionActor()
 {
     TestLauncherActor.Test(
         () =>
     {
         ConcurrentQueue <string> queue = new ConcurrentQueue <string>();
         var act    = new ActionActor();
         var future = new Future <int>();
         act.SendAction(() =>
         {
             var tst = new ActionActor <string>();
             tst.SendAction((t) =>
             {
                 queue.Enqueue(t);
             }, "test1");
             tst.SendAction((t) =>
             {
                 queue.Enqueue(t);
             }, "test2");
             tst.SendAction((t) =>
             {
                 queue.Enqueue(t);
             }, "test3");
             tst.SendAction(() =>
             {
                 future.SendMessage(queue.Count);
             });
         });
         Assert.AreEqual(3, future.Result());
     }
         );
 }
Exemplo n.º 4
0
        public static void Test(TestContext testContext, Action action, int timeOutMS)
        {
            var launcher = new TestLauncherActor();

            launcher.SendAction(
                () =>
            {
                try
                {
                    action();
                    launcher.Finish();
                }
                catch (Exception e)
                {
                    launcher.fLauncherException = e;
                    launcher.Fail();
                    if (testContext != null)
                    {
                        testContext.WriteLine(e.Message);
                        testContext.WriteLine(e.StackTrace);
                    }
                    throw;
                }
            });

            Task <bool> testResult = launcher.Wait(timeOutMS);

            if (launcher.fLauncherException != null)
            {
                throw new TestLauncherException(launcher.fLauncherException.Message, launcher.fLauncherException);
            }
            Assert.IsTrue(testResult.Result, "Test Time Out");
        }
Exemplo n.º 5
0
        public void Setup()
        {
            fLauncher = new TestLauncherActor();
            var act = new DirectoryActor();

            Assert.IsNotNull(act, "Can't create Directory Actor");
        }
Exemplo n.º 6
0
        public void TestMessageTracer()
        {
            IMessageTracerService mts = new MemoryMessageTracerService();

            TestLauncherActor.Test(() =>
            {
                BaseActor actor1 = new BaseActor()
                {
                    MessageTracerService = mts
                };
                actor1.SendMessage("Test 1");
                actor1.SendMessage("Test 2");
                actor1.SendMessage("Test 3");
            });

            var    query = mts.CopyAllMessages().ToList();
            string s     = string.Empty;

            query.ForEach(item => s += item);
            Assert.AreEqual(3, query.Count, s);
            Assert.IsTrue(query.Contains("Test 2"));
            Assert.IsFalse(query.Contains("Test 4"));
            Assert.AreEqual("Test 1", query.First());
            Assert.AreEqual("Test 3", query.Last());
        }
Exemplo n.º 7
0
 public void PeerNewNodeTest()
 {
     TestLauncherActor.Test(TestContext, () =>
     {
         var node1 = new PeerActor <int, string>();
         var node2 = new PeerActor <int, string>();
         var node3 = new PeerActor <int, string>();
         var node4 = new PeerActor <int, string>();
         node1.NewPeer(node2, node2.GetHashKey().Result());
         node1.NewPeer(node3, node3.GetHashKey().Result());
         node1.NewPeer(node4, node4.GetHashKey().Result());
         node1.StoreNode(10, "10");
         node2.StoreNode(20, "20");
         node3.StoreNode(30, "30");
         var future = new Future <IPeerActor <int, string> >();
         node1.FindPeer(30, future);
         var result = future.Result();
         Assert.IsNotNull(result);
         // Assert.AreEqual(node3.Tag.Key(), result.Tag.Key());
         future = new Future <IPeerActor <int, string> >();
         node1.FindPeer(40, future);
         result = future.Result();
         Assert.IsNotNull(result);
         // Assert.AreEqual(node1.Tag.Key(), result.Tag.Key());
     });
 }
Exemplo n.º 8
0
        public void TestTextWriter()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(TestContext.TestRunDirectory);
            sb.Append(@"\");
            sb.Append("testwritertestfile.txt");
            string fullPath = sb.ToString();

            TestLauncherActor.Test(() =>
            {
                using (var textWriter = new TextWriterActor(fullPath))
                {
                    textWriter.SendMessage("1st line");
                    textWriter.SendMessage("2nd line");
                    textWriter.SendMessage("3rd line");
                    textWriter.Flush();
                }
                using (var stream = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    StreamReader reader = new StreamReader(stream);
                    try
                    {
                        Assert.AreEqual(reader.ReadLine(), "1st line");
                        Assert.AreEqual(reader.ReadLine(), "2nd line");
                        Assert.AreEqual(reader.ReadLine(), "3rd line");
                    }
                    finally
                    {
                        reader.Dispose();
                    }
                }
            });
        }
Exemplo n.º 9
0
        public void BehaviorGraphTest()
        {
            TestLauncherActor.Test(() =>
            {
                var graph = new BehaviorGraph <string, int>();
                var nodeA = new NodeActor <string, int>();
                var nodeB = new NodeActor <string, int>();
                graph.AddNode(nodeA);
                graph.AddNode(nodeB);
                nodeA.AddEdge(nodeB);
                var act = new Receiver <IMessageParam <IActor, bool> >();
                nodeA.Adjacent(nodeB, act);
                Assert.IsTrue(act.Call().Item2);

                var nodeC = new NodeActor <string, int>();
                graph.AddNode(nodeC);
                nodeA.AddEdge(nodeC);

                var act2 = new Receiver <IMessageParam <IActor, IEnumerable <NodeActor <string, int> > > >();
                nodeA.Neighbors(act2);
                var r = act2.Call().Item2;
                Assert.IsNotNull(r);
                Assert.IsFalse(r.Contains(nodeA));
                Assert.IsTrue(r.Contains(nodeB));
                Assert.IsTrue(r.Contains(nodeC));

                // test as future
                var future = nodeA.Neighbors();
                Assert.IsNotNull(future);
                Assert.IsTrue(future.Result().Item2.Count() == 2);
            });
        }
Exemplo n.º 10
0
 public void TestTextWriter()
 {
     TestLauncherActor.Test(() =>
     {
         using (var textWriter = new TextWriterActor("textwritertestfile.txt"))
         {
             textWriter.SendMessage("1st line");
             textWriter.SendMessage("2nd line");
             textWriter.SendMessage("3rd line");
             textWriter.Flush();
         }
         using (var stream = new FileStream("textwritertestfile.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
         {
             StreamReader reader = new StreamReader(stream);
             try
             {
                 Assert.AreEqual(reader.ReadLine(), "1st line");
                 Assert.AreEqual(reader.ReadLine(), "2nd line");
                 Assert.AreEqual(reader.ReadLine(), "3rd line");
             }
             finally
             {
                 reader.Dispose();
             }
         }
     }, 20000);
 }
Exemplo n.º 11
0
        public void FSMBehaviorsTest()
        {
            TestLauncherActor.Test(() =>
            {
                var behaviors = new FsmBehaviors <string, int>();
                behaviors
                .AddRule("StartState", i => i == 1, i => { }, "MidState")
                .AddRule("MidState", i => i == 2, i => { }, "EndState");

                var fsmActor = new BaseActor(behaviors);

                var currentState1 = new Future <string>();
                fsmActor.SendMessage(currentState1);
                Assert.IsTrue(currentState1.Result() == "StartState");

                fsmActor.SendMessage(1);

                var currentState2 = new Future <string>();
                fsmActor.SendMessage(currentState2);
                Assert.IsTrue(currentState2.Result() == "MidState");

                fsmActor.SendMessage(2);

                var currentState3 = new Future <string>();
                fsmActor.SendMessage(currentState3);
                Assert.IsTrue(currentState3.Result() == "EndState");

                fsmActor.SendMessage(3);

                // unchanged shoud be
                var currentState4 = new Future <string>();
                fsmActor.SendMessage(currentState4);
                Assert.IsTrue(currentState4.Result() == "EndState");
            });
        }
Exemplo n.º 12
0
 public void ChainTest()
 {
     TestLauncherActor.Test(() =>
     {
         var chain = new Chain();
         chain.SendMessage(4, 4, 4);
     });
 }
Exemplo n.º 13
0
 public void AddElementTest()
 {
     TestLauncherActor.Test(() =>
     {
         var act = new EnumerableActor <string>();
         act.Add("test");
     });
 }
Exemplo n.º 14
0
 public void EnumerableActorTest()
 {
     TestLauncherActor.Test(() =>
     {
         var act = new EnumerableActor <string>();
         Assert.IsNotNull(act);
     });
 }
Exemplo n.º 15
0
 public void TestNullBehavior()
 {
     TestLauncherActor.Test(() =>
     {
         var actor = new BaseActor(new NullBehavior());
         actor.SendMessage("delta");
     });
 }
Exemplo n.º 16
0
 public void TestShardRun()
 {
     TestLauncherActor.Test(() =>
     {
         ActorServer.Start("localhost", 80, new HostRelayActor());
         new ShardDirectoryClientTest();
     });
 }
Exemplo n.º 17
0
 public void FindTest()
 {
     TestLauncherActor.Test(() =>
     {
         var dirtest = new DirectoryTestActor();
         DirectoryActor.GetDirectory().Register(dirtest, dirtest.Tag.Key());
     });
 }
Exemplo n.º 18
0
 public void DictionaryActorTest()
 {
     TestLauncherActor.Test(() =>
     {
         var act = new DictionaryActor <string, int>();
         Assert.IsNotNull(act);
     });
 }
Exemplo n.º 19
0
 public void SubscribeTest()
 {
     TestLauncherActor.Test(() =>
     {
         var rx  = new RxObservable <string>();
         var dsp = rx.Subscribe(new Observer());
         Assert.IsTrue(dsp is IDisposable);
     });
 }
Exemplo n.º 20
0
 public void RegisterTest()
 {
     TestLauncherActor.Test(() =>
     {
         var act = new DirectoryTestActor();
         DirectoryActor.GetDirectory().Register(act, act.Tag.Key());
         act.SendMessage(fLauncher, act, act.Tag.Key());
     });
 }
Exemplo n.º 21
0
 public void ReceiveWaitTimeOut1Test()
 {
     TestLauncherActor.Test(() =>
     {
         var actor     = new ReceiveActor <int, string>();
         var target    = new TargetActor();
         var resultOdd = actor.WaitAsync(target, 1, 10000);
         Assert.IsTrue(resultOdd.Result.Item2 == "odd");
     });
 }
Exemplo n.º 22
0
 public void ObservableActorTest()
 {
     TestLauncherActor.Test(() =>
     {
         ObservableActor <string> act = new ObservableActor <string>();
         Assert.IsNotNull(act);
         Assert.IsTrue(act is ObservableActor <string>);
         Assert.IsTrue(act is IActor);
     });
 }
 public void LinkedListActorTest()
 {
     TestLauncherActor.Test(
         () =>
     {
         var ll = new LinkedListActor <string>();
         Assert.IsNotNull(ll);
     }
         );
 }
Exemplo n.º 24
0
 public void AddKVTest()
 {
     TestLauncherActor.Test(() =>
     {
         var act = new DictionaryActor <string, int>();
         Assert.IsNotNull(act);
         act.AddKeyValue("1", 1);
         act.AddKeyValue("2", 2);
     });
 }
Exemplo n.º 25
0
 public void DiscoTest()
 {
     TestLauncherActor.Test(() =>
     {
         ActorServer.Start("localhost", 80, null);
         var act = new DiscoTestActor(fLauncher);
         DirectoryActor.GetDirectory().Disco(act);
     }
                            );
 }
Exemplo n.º 26
0
 public void SendReplyTest()
 {
     TestLauncherActor.Test(() =>
     {
         var actor  = new SimpleSendReplyActor();
         var future = new Future <IActor, string>();
         actor.SendMessage((IActor)future, "Test 1");
         Assert.AreEqual("Test 1", future.Result().Item2);
     });
 }
Exemplo n.º 27
0
 public void TestADecoratedActor()
 {
     TestLauncherActor.Test(() =>
     {
         var actor  = new TestActor();
         var future = actor.GetAnswer();
         actor.SendMessage("Test Decorated");
         Assert.AreEqual("Test Decorated", future.Result());
     });
 }
Exemplo n.º 28
0
 public void DiscoTest()
 {
     TestLauncherActor.Test(() =>
     {
         ActorServer.Start(ActorConfigManager.CastForTest());
         var act = new DiscoTestActor(fLauncher);
         DirectoryActor.GetDirectory().Disco(act);
     }
                            );
 }
Exemplo n.º 29
0
 public void ReceiveWait4Test()
 {
     TestLauncherActor.Test(() =>
     {
         var actor      = new ReceiveActor <int>();
         var target     = new TargetActor2();
         var resultEven = actor.WaitAsync(target, 2);
         Assert.IsTrue(resultEven.Result.Item2 == 4);
     });
 }
Exemplo n.º 30
0
 public void ReceiveWaitTimeOut2Test()
 {
     TestLauncherActor.Test(() =>
     {
         var actor      = new ReceiveActor <int, string>();
         var target     = new TargetActor();
         var resultEven = actor.WaitAsync((IActor)target, 2, 2000);
         Assert.IsTrue(resultEven.Result.Item2 == "even");
     });
 }