Esempio n. 1
0
        public void RouterService_HubMode()
        {
            // Verify that the router service actually deploys a hub router
            // by starting an instance of the application and a couple of
            // non-P2P leaf routers and making sure that the service is
            // routing messages between the two leaves.

            Process        svcProcess = null;
            LeafRouter     leaf1      = null;
            LeafRouter     leaf2      = null;
            ConfigRewriter rewriter;
            Assembly       assembly;
            string         iniPath;

            assembly = typeof(LillTek.Datacenter.RouterService.Program).Assembly;
            iniPath  = Config.GetConfigPath(assembly);
            rewriter = new ConfigRewriter(iniPath);

            try
            {
                // Rewrite the config file to have it start in hub mode
                // and then start the router service as a form application.

                rewriter.Rewrite(new ConfigRewriteTag[] { new ConfigRewriteTag("Mode", "#define HUBMODE\r\n#undef ROOTMODE\r\n#define HUBNAME hub\r\n") });
                svcProcess = Helper.StartProcess(assembly, "-mode:form -start");
                Thread.Sleep(10000);    // Give the process a chance to spin up

                // Crank up a couple of leaf routers and send a message from
                // one to the other.

                leaf1 = CreateLeaf("detached", Const.DCDefHubName, "leaf1", Const.DCCloudEP.ToString(), false);
                leaf2 = CreateLeaf("detached", Const.DCDefHubName, "leaf2", Const.DCCloudEP.ToString(), false);
                Thread.Sleep(2000);

                recvMsg = null;
                leaf1.SendTo("logical://leaf2", new PropertyMsg());
                Thread.Sleep(1000);

                Assert.IsNotNull(recvMsg);
            }
            finally
            {
                rewriter.Restore();

                if (svcProcess != null)
                {
                    svcProcess.Kill();
                    svcProcess.Close();
                }

                if (leaf1 != null)
                {
                    leaf1.Stop();
                }

                if (leaf2 != null)
                {
                    leaf2.Stop();
                }
            }
        }