Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var pong = ProcessId.Top["redis-watcher-b"]["user"]["pong"];

            // Let Language Ext know that Redis exists
            RedisCluster.register();

            // Connect to the Redis cluster
            ProcessConfig.initialise("sys", "global", "redis-watcher-a", "localhost", "0");

            var ping = spawn <string>(
                Name: "ping",
                Inbox: msg =>
            {
                Console.WriteLine(msg);
                tell(pong, "pong", 1000 * ms);
            },
                Terminated: pid => Console.WriteLine(pid + " is pushing up the daisies"),
                Flags: ProcessFlags.PersistInbox
                );

            Console.WriteLine("Now run RedisWatcherB and press enter");
            Console.ReadKey();

            watch(ping, pong);
            tell(ping, "running");
            Console.ReadKey();
        }
Exemplo n.º 2
0
        public void PubSubTest()
        {
            lock (sync)
            {
                shutdownAll();
                Assert.True(Systems.Count == 0);

                ProcessConfig.initialise();
                // Spawn a process
                var pid = spawn <string>("pubsub", msg =>
                {
                    // Publish anything we're sent
                    publish(msg);
                });

                string value = null;

                // Subscribe to the 'string' publications
                var sub = subscribe(pid, (string v) => value = v);

                // Send string message to the process
                tell(pid, "hello");

                Thread.Sleep(50);

                Assert.True(value == "hello");
            }
        }
Exemplo n.º 3
0
        public static void ProcessStartupInvalidTypeError()
        {
            lock (sync)
            {
                shutdownAll();
                Assert.True(Systems.Count == 0);

                ProcessConfig.initialise();

                try
                {
                    var pid = spawn <Unit, string>("world",
                                                   () => failwith <Unit>("Failed!"),
                                                   (_, __) => _, ProcessFlags.PersistInbox
                                                   );

                    ask <Unit>(pid, unit);

                    throw new Exception("Shouldn't get here");
                }
                catch (ProcessException e)
                {
                    Assert.True(e.Message == "Process issue: Invalid message type for ask (expected System.String)");
                }
            }
        }
Exemplo n.º 4
0
        public void ScheduledMsgTest()
        {
            lock (sync)
            {
                shutdownAll();
                Assert.True(Systems.Count == 0);

                ProcessConfig.initialise();

                string v = "";

                var p = spawn <string>("test-sch", x => v = x);

                var future = DateTime.UtcNow.AddSeconds(3);

                tell(p, "hello", future);

                while (DateTime.UtcNow < future)
                {
                    Assert.True(v == "");
                    Thread.Sleep(10);
                }

                while (DateTime.UtcNow < future.AddMilliseconds(1000))
                {
                    Thread.Sleep(10);
                }
                Assert.True(v == "hello");
            }
        }
Exemplo n.º 5
0
        public void SpawnAndKillProcess()
        {
            lock (sync)
            {
                shutdownAll();
                Assert.True(Systems.Count == 0);

                ProcessConfig.initialise();

                string value = null;
                var    pid   = spawn <string>("SpawnAndKillProcess", msg => value = msg);
                tell(pid, "1");

                Thread.Sleep(10);

                kill(pid);

                Thread.Sleep(10);

                Assert.Throws <ProcessException>(() =>
                {
                    tell(pid, "2");
                });

                Thread.Sleep(10);

                Assert.True(value == "1");
                Assert.True(children(User()).Length == 0);
            }
        }
Exemplo n.º 6
0
        //
        //  Launch a process that adds the int sent in a message to its state
        //  Then calls itself after a second to do the same again.  The state value gradually
        //  increases.
        //
        //  If you stop the sample and restart you'll notice the state has been persisted
        //
        static void Main(string[] args)
        {
            // Log what's going on
            ProcessSystemLog.Subscribe(Console.WriteLine);

            // Let Language Ext know that Redis exists
            RedisCluster.register();

            // Connect to the Redis cluster
            ProcessConfig.initialise("sys", "global", "redis-test", "localhost", "0");

            // Spawn the process
            var pid = spawn <string>("redis-inbox-sample", Inbox, ProcessFlags.PersistInbox);

            Console.WriteLine("Press a key to add 100 messages to the process queue");
            Console.WriteLine(" - The process queue has a Thread.Sleep(200) in it");
            Console.WriteLine(" - So it takes 20 seconds to get through all of the messages");
            Console.WriteLine(" - If you quit the sample and restart, you should see the ");
            Console.WriteLine(" - inbox has persisted.");
            Console.WriteLine("");
            Console.WriteLine("Press a key");
            Console.ReadKey();

            var rnd = new Random();

            for (var i = 0; i < 100; i++)
            {
                tell(pid, "Message sent: " + DateTime.Now + " " + DateTime.Now.Ticks + " " + rnd.Next());
            }

            Console.ReadKey();
        }
Exemplo n.º 7
0
        public void SpawnErrorSurviveProcess()
        {
            lock (sync)
            {
                shutdownAll();
                Assert.True(Systems.Count == 0);

                ProcessConfig.initialise();

                int value = 0;
                int count = 0;

                var pid = spawn <string>("SpawnAnErrorProcess", _ =>
                {
                    if (count++ == 0)
                    {
                        throw new Exception("fail");
                    }
                    else
                    {
                        value = count;
                    }
                });

                tell(pid, "msg");
                tell(pid, "msg");
                tell(pid, "msg");

                Thread.Sleep(400);
                Assert.True(value == 3);

                kill(pid);
            }
        }
Exemplo n.º 8
0
        public static void MassiveSpawnAndKillHierarchy2()
        {
            Func <Unit> setup = null;
            int         depth = 6;
            int         nodes = 5;
            int         max   = DepthMax(depth);

            shutdownAll();
            ProcessConfig.initialise();

            var actor = fun((Unit s, string msg) =>
            {
                iter(Children.Values, child => tell(child, msg));
            });

            setup = fun(() =>
            {
                int level = Int32.Parse(Self.Name.Value.Split('_').First()) + 1;
                if (level <= depth)
                {
                    iter(Range(0, nodes), i => spawn(level + "_" + i, setup, actor));
                }
            });

            var zero = spawn("0", setup, actor);

            tell(zero, "Hello");
            kill(zero);

            Debug.Assert(children(User()).Count() == 0);
        }
Exemplo n.º 9
0
        public static void AskReplyError()
        {
            lock (sync)
            {
                shutdownAll();
                Assert.True(Systems.Count == 0);

                // Let Language Ext know that Redis exists
                RedisCluster.register();

                // Connect to the Redis cluster
                ProcessConfig.initialise("sys", "global", "redis-ask-reply-test", "localhost", "0");

                var world = spawn <ProcessId, string>("world",
                                                      () => spawn <string>("hello", msg => failwith <Unit>("Failed!"), ProcessFlags.PersistInbox),
                                                      (pid, msg) =>
                {
                    Assert.Throws <ProcessException>(() =>
                    {
                        ask <string>(pid, msg);
                    });
                    return(pid);
                },
                                                      ProcessFlags.PersistInbox
                                                      );

                tell(world, "error throwing test");

                Thread.Sleep(100);
            }
        }
Exemplo n.º 10
0
        public static void AskReplyError()
        {
            shutdownAll();

            // Let Language Ext know that Redis exists
            RedisCluster.register();

            // Connect to the Redis cluster
            ProcessConfig.initialise("sys", "global", "redis-test", "localhost", "0");

            try
            {
                var world = spawn <ProcessId, string>("world",
                                                      () => spawn <string>("hello", msg => failwith <Unit>("Failed!"), ProcessFlags.PersistInbox),
                                                      (pid, msg) =>
                {
                    ask <string>(pid, msg);
                    return(pid);
                },
                                                      ProcessFlags.PersistInbox
                                                      );
                tell(world, "error throwing test");
            }
            catch (Exception e)
            {
                Debug.Assert(e.Message == "Process issue: Failed!");
            }

            Thread.Sleep(1000);
        }
Exemplo n.º 11
0
        public static void SpawnProcess()
        {
            shutdownAll();
            ProcessConfig.initialise();

            Console.WriteLine("*** ABOUT TO SHUTDOWN ***");

            shutdownAll();

            Console.WriteLine("*** SHUTDOWN COMPLETE ***");
            ProcessConfig.initialise();

            var pid = spawn <string, string>("SpawnProcess", () => "", (_, msg) => msg);

            string value = null;

            observeState <string>(pid).Subscribe(x => value = x);

            tell(pid, "hello, world");

            Thread.Sleep(100);

            if (value != "hello, world")
            {
                Console.WriteLine(" Value actually is: " + value);
            }

            Debug.Assert(value == "hello, world");

            kill(pid);

            Debug.Assert(children(User()).Count == 0);

            Console.WriteLine("*** END OF TEST ***");
        }
Exemplo n.º 12
0
        public MainWindow()
        {
            InitializeComponent();

            ProcessConfig.initialise();

            SpawnUpdate();
            SpawnResolver();
        }
Exemplo n.º 13
0
        public void ProxyTest3()
        {
            lock (ProcessTests.sync)
            {
                shutdownAll();
                ProcessConfig.initialise();

                var proxy = spawn <IMyProcess>("proxy-test3", () => new MyProcess());

                Assert.True(proxy.MsgLength("Hello") == 5);
            }
        }
Exemplo n.º 14
0
        public void ProxyOptionTest1()
        {
            lock (ProcessTests.sync)
            {
                shutdownAll();
                ProcessConfig.initialise();

                var proxy = spawn <IMyProcess>("proxy-test4", () => new MyProcess());

                Assert.True(proxy.TestOption(123) == 123);
            }
        }
Exemplo n.º 15
0
        public void RedisRegisterTest()
        {
            lock (sync)
            {
                shutdownAll();
                Assert.True(Systems.Count == 0);

                // Let Language Ext know that Redis exists
                RedisCluster.register();

                // Connect to the Redis cluster
                ProcessConfig.initialise("sys", "global", "redis-test", "localhost", "0");

                string value = null;
                var    pid   = spawn <string>("reg-proc", msg => value = msg);

                var regid = register("woooo amazing", pid);

                Assert.True(regid == "/disp/reg/global-woooo amazing");

                Thread.Sleep(200);

                tell(regid, "hello");

                Thread.Sleep(200);

                Assert.True(value == "hello");

                tell(find("woooo amazing"), "world");

                Thread.Sleep(200);

                Assert.True(value == "world");

                deregisterById(pid);

                Thread.Sleep(200);

                try
                {
                    tell(find("woooo amazing"), "noooo");
                }
                catch (Exception e)
                {
                    Assert.True(e.Message.Contains("No processes in group"));
                }

                Thread.Sleep(200);

                Assert.True(value != "noooo");
            }
        }
Exemplo n.º 16
0
        public static void MassiveSpawnAndKillHierarchy()
        {
            shutdownAll();
            ProcessConfig.initialise();

            Func <Unit> setup = null;
            int         count = 0;
            int         depth = 6;
            int         nodes = 5;
            int         max   = DepthMax(depth);

            var actor = fun((Unit s, string msg) =>
            {
                Console.WriteLine(msg);
                Interlocked.Increment(ref count);
                iter(Children.Values, child => tell(child, msg));
            });

            setup = fun(() =>
            {
                Interlocked.Increment(ref count);

                int level = Int32.Parse(Self.Name.Value.Split('_').First()) + 1;
                if (level <= depth)
                {
                    iter(Range(0, nodes), i => {
                        Console.WriteLine("Spawning: " + level + "_" + i);
                        spawn(level + "_" + i, setup, actor);
                        Console.WriteLine("Done spawning: " + level + "_" + i);
                    });
                }
            });

            var zero = spawn("0", setup, actor);

            tell(zero, "Hello");

            // crude, but whatever
            while (count < max)
            {
                Thread.Sleep(50);
            }
            count = 0;

            kill(zero);

            Thread.Sleep(3000);

            Debug.Assert(children(User()).Count() == 0);
        }
Exemplo n.º 17
0
        public void TestRegistered()
        {
            lock (ProcessTests.sync)
            {
                Process.shutdownAll();
                ProcessConfig.initialise();

                ProcessId test1 = "@registered";
                Assert.True(test1.Path == "/disp/reg/local-registered");

                ProcessId test2 = "@another:registered";
                Assert.True(test2.Path == "/disp/reg/another-registered");
            }
        }
Exemplo n.º 18
0
        public void ProxyTest2()
        {
            lock (ProcessTests.sync)
            {
                shutdownAll();
                ProcessConfig.initialise();

                var proxy = spawn <IMyProcess>("proxy-test2", () => new MyProcess());

                proxy.Hello("Hello");
                int res = proxy.World("World");

                Assert.True(res == 2);
            }
        }
Exemplo n.º 19
0
        public static void SpawnAndKillProcess()
        {
            shutdownAll();
            ProcessConfig.initialise();

            ProcessId pid = spawn <string, string>("SpawnAndKillProcess", () => "", (_, msg) => msg);

            tell(pid, "1");
            kill(pid);
            tell(pid, "2");

            var kids = children(User());
            var len  = kids.Length;

            Debug.Assert(len == 0);
        }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            ProcessId test = "/disp/broadcast/[/root/user/c,/root/user/b,/root/user/c]";

            //RedisCluster.register();
            //Cluster.connect("redis", "disp-test", "localhost", "0", "dispatch-role");

            ProcessConfig.initialise();

            var pida = spawn <int>("A", x => Console.WriteLine("A" + x));
            var pidb = spawn <int>("B", x => Console.WriteLine("B" + x));
            var pidc = spawn <int>("C", x => Console.WriteLine("C" + x));

            Console.WriteLine("Press the numeric keys 1 to 4 to select the type of dispatch");
            Console.WriteLine("1. Broadcast");
            Console.WriteLine("2. Least busy");
            Console.WriteLine("3. Round robin");
            Console.WriteLine("4. Random");

            int i = 0;

            while (true)
            {
                ProcessId pid = ProcessId.None;

                switch (Console.ReadKey().KeyChar)
                {
                case '1': pid = Dispatch.broadcast(pida, pidb, pidc);  break;

                case '2': pid = Dispatch.leastBusy(pida, pidb, pidc);  break;

                case '3': pid = Dispatch.roundRobin(pida, pidb, pidc); break;

                case '4': pid = Dispatch.random(pida, pidb, pidc);     break;
                }
                Console.WriteLine();

                if (pid.IsValid)
                {
                    tell(pid, i);
                }
                else
                {
                    break;
                }
            }
        }
Exemplo n.º 21
0
        public void LocalRegisterTest()
        {
            lock (sync)
            {
                shutdownAll();
                Assert.True(Systems.Count == 0);

                ProcessConfig.initialise();

                string value = null;
                var    pid   = spawn <string>("reg-proc", msg => value = msg);

                var regid = register("woooo amazing", pid);

                Assert.True(regid == "/disp/reg/local-woooo amazing");

                tell(regid, "hello");

                Thread.Sleep(100);

                Assert.True(value == "hello");

                tell(find("woooo amazing"), "world");

                Thread.Sleep(100);

                Assert.True(value == "world");

                deregisterById(pid);

                Thread.Sleep(100);

                try
                {
                    tell(find("woooo amazing"), "noooo");
                }
                catch (Exception e)
                {
                    Assert.True(e.Message.Contains("No processes in group"));
                }

                Thread.Sleep(100);

                Assert.True(value != "noooo");
            }
        }
Exemplo n.º 22
0
        public void SpawnAndKillHierarchy()
        {
            lock (sync)
            {
                shutdownAll();
                Assert.True(Systems.Count == 0);

                ProcessConfig.initialise();

                string    value = null;
                ProcessId parentId;

                var pid = spawn <Unit, string>("SpawnAndKillHierarchy.TopLevel",
                                               () =>
                {
                    parentId = Parent;

                    spawn <string>("SpawnAndKillHierarchy.ChildLevel", msg => value = msg);
                    return(unit);
                },
                                               (state, msg) =>
                {
                    value = msg;
                    return(state);
                }
                                               );

                tell(pid, "1");

                Thread.Sleep(10);

                kill(pid);

                Thread.Sleep(10);

                Assert.Throws <ProcessException>(() =>
                {
                    tell(pid, "2");
                });

                Thread.Sleep(10);

                Assert.True(value == "1", "Expected 1, actually equals: " + value);
                Assert.True(children(User()).Length == 0);
            }
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            ProcessConfig.initialise();

            Process.DeadLetters()
            .Observe <DeadLetter>()
            .Subscribe(Console.WriteLine);

            Process.ProcessSystemLog
            .Subscribe(Console.WriteLine);

            FuncCaching.Run();

            ClassCaching.Run();

            Console.ReadKey();
        }
Exemplo n.º 24
0
        static void Main(string[] args)
        {
            // Log what's going on
            // ProcessLog.Subscribe(Console.WriteLine);

            // Let Language Ext know that Redis exists
            RedisCluster.register();

            // Connect to the Redis cluster
            ProcessConfig.initialise("sys", "global", "redis-subscribe-test", "localhost", "0");

            var pid = ProcessId.Top["redis-publish-test"]["user"]["redis-pubsub-random-test"];

            // Listen to the published results coming back from the Redis channel
            subscribe <int>(pid, Console.WriteLine);

            Console.ReadKey();
        }
Exemplo n.º 25
0
        static void Test1()
        {
            ProcessId pong = ProcessId.None;
            ProcessId ping = ProcessId.None;

            // Let Language Ext know that Redis exists
            RedisCluster.register();

            // Connect to the Redis cluster
            ProcessConfig.initialise("sys", "global", "redis-test", "localhost", "0");

            ping = spawn <string>(
                Name:      "ping",
                Inbox:     msg =>
            {
                Console.WriteLine(msg);
                tell(pong, "pong", 100 * ms);
            },
                Terminated: pid => Console.WriteLine(pid + " is pushing up the daisies"),
                Flags: ProcessFlags.PersistInbox
                );

            pong = spawn <string>(
                Name:     "pong",
                Inbox:     msg =>
            {
                Console.WriteLine(msg);
                tell(ping, "ping", 100 * ms);
            },
                Terminated: pid => Console.WriteLine(pid + " is pushing up the daisies"),
                Flags: ProcessFlags.PersistInbox
                );

            watch(ping, pong);
            watch(pong, ping);

            tell(pong, "Running");

            Console.WriteLine("Press key to kill ping");
            Console.ReadKey();
            kill(ping);
            Console.WriteLine("Press key to exit");
            Console.ReadKey();
        }
Exemplo n.º 26
0
        public void AskReply()
        {
            lock (sync)
            {
                shutdownAll();
                Assert.True(Systems.Count == 0);
                ProcessConfig.initialise();
                Assert.True(Systems.Count == 1);

                var helloServer = spawn <string>("hello-server", msg =>
                {
                    reply("Hello, " + msg);
                });

                var response = ask <string>(helloServer, "Paul");

                Assert.True(response == "Hello, Paul");
            }
        }
Exemplo n.º 27
0
        public void TestSelectionIds()
        {
            lock (ProcessTests.sync)
            {
                Process.shutdownAll();
                ProcessConfig.initialise();

                ProcessId test = "/disp/broadcast/[/root/user/a,/root/user/b,/root/user/c]";

                Assert.True(test.Take(1).Name == "disp");
                Assert.True(test.Skip(1).Take(1).Name == "broadcast");
                Assert.True(test.Skip(2).Take(1).Name == "[/root/user/a,/root/user/b,/root/user/c]");
                Assert.True(test.Skip(2).Take(1).IsSelection);
                Assert.True(test.Skip(2).Take(1).GetSelection().Count() == 3);
                Assert.True(test.Skip(2).Take(1).GetSelection().First().Path == "/root/user/a");
                Assert.True(test.Skip(2).Take(1).GetSelection().Skip(1).First().Path == "/root/user/b");
                Assert.True(test.Skip(2).Take(1).GetSelection().Skip(2).First().Path == "/root/user/c");
            }
        }
Exemplo n.º 28
0
        public void SpawnProcess()
        {
            lock (sync)
            {
                shutdownAll();
                Assert.True(Systems.Count == 0);

                ProcessConfig.initialise();

                string value = null;
                var    pid   = spawn <string>("SpawnProcess", msg => value = msg);

                tell(pid, "hello, world");

                Thread.Sleep(200);
                Assert.True(value == "hello, world");

                kill(pid);
            }
        }
Exemplo n.º 29
0
        //public static void RegisteredAskReply()
        //{
        //    shutdownAll();
        //    ProcessConfig.initialise();

        //    var helloServer = spawn<string>("hello-server", msg =>
        //    {
        //        reply("Hello, " + msg);
        //    });

        //    var hi = register<string>("hi", helloServer);

        //    var response = ask<string>(find("hi"), "Paul");

        //    Debug.Assert(response == "Hello, Paul");
        //}

        public static void AskReply()
        {
            shutdownAll();

            // Let Language Ext know that Redis exists
            RedisCluster.register();

            // Connect to the Redis cluster
            ProcessConfig.initialise("sys", "global", "redis-test", "localhost", "0");

            var helloServer = spawn <string>("hello-server", msg =>
            {
                reply("Hello, " + msg);
            },
                                             ProcessFlags.PersistInbox);

            var response = ask <string>(helloServer, "Paul");

            Debug.Assert(response == "Hello, Paul");
        }
Exemplo n.º 30
0
        private static void ProxyTesting()
        {
            ProcessConfig.initialise();

            var pid = ProxyTest();

            Console.ReadKey();
            Console.WriteLine("done.  next to kill process... press a key");
            Console.ReadKey();

            kill(pid);

            Console.WriteLine("process is killed.  next to shutdown... press a key");
            Console.ReadKey();

            shutdownAll();

            Console.WriteLine("done.  any key to quit.");
            Console.ReadKey();
        }