示例#1
0
        public void PhysicalQuery_Basic_Self_Blast()
        {
            _LeafRouter leaf = null;
            TestAck     ack;
            string      s;

            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            try
            {
                leaf = CreateLeaf("detached", "hub0", "leaf0", group);
                Thread.Sleep(InitDelay);

                for (int i = 0; i < BlastCount; i++)
                {
                    // Verify a q/r between a single router

                    s   = "Hello World: " + i.ToString();
                    ack = (TestAck)leaf.Query(leaf.RouterEP, new NotCachedMsg("Normal", s));
                    Assert.AreEqual(s, ack.Value);
                }
            }
            finally
            {
                if (leaf != null)
                {
                    leaf.Stop();
                }

                Config.SetConfig(null);
            }
        }
示例#2
0
        public void LogicalQueryViaUdpBroadcast_RequestContext()
        {
            // Verify that using MsgRequestContext to process the request on the
            // server side works.

            _LeafRouter leaf = null;
            TestAck     ack;
            string      s;

            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            try
            {
                leaf = CreateLeaf("detached", "hub0", "leaf0", group);
                Thread.Sleep(InitDelay);

                // Verify a q/r between a single router

                s   = "Hello World!";
                ack = (TestAck)leaf.Query("logical://leaf-async", new NotCachedMsg("Normal-RequestContext", s));
                Assert.AreEqual(s, ack.Value);
            }
            finally
            {
                if (leaf != null)
                {
                    leaf.Stop();
                }

                Config.SetConfig(null);
            }
        }
示例#3
0
        private _LeafRouter CreateLeaf(string root, string hub, string name, string cloudEP)
        {
            const string settings =
                @"
MsgRouter.AppName               = Test
MsgRouter.AppDescription        = Test Description
MsgRouter.RouterEP				= physical://{0}/{1}/{2}
MsgRouter.DiscoveryMode         = MULTICAST
MsgRouter.CloudEP               = {3}
MsgRouter.CloudAdapter          = ANY
MsgRouter.UdpEP					= ANY:0
MsgRouter.TcpEP					= ANY:0
MsgRouter.TcpBacklog			= 100
MsgRouter.TcpDelay				= off
MsgRouter.BkInterval			= 1s
MsgRouter.MaxIdle				= 5m
MsgRouter.AdvertiseTime			= 1m
MsgRouter.DefMsgTTL				= 5
MsgRouter.SharedKey             = PLAINTEXT
MsgRouter.SessionCacheTime      = 2m
MsgRouter.SessionRetries        = 3
MsgRouter.SessionTimeout        = 10s
";

            _LeafRouter router;

            Config.SetConfig(string.Format(settings, root, hub, name, cloudEP));
            router = new _LeafRouter();
            router.Start();

            return(router);
        }
示例#4
0
        public void LogicalQueryViaUdpBroadcast_AsyncQuery_Abort()
        {
            _LeafRouter leaf  = null;
            DateTime    start = SysTime.Now;

            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            try
            {
                // This test verifies that the session is killed automatically

                leaf = CreateLeaf("detached", "hub0", "leaf0", group);
                leaf.Dispatcher.AddTarget(this);
                Thread.Sleep(InitDelay);

                leaf.Query("logical://async-abort", new AsyncMsg("Normal", ""));
                Assert.Fail("Expected a TimeoutException");
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(TimeoutException));
            }
            finally
            {
                if (leaf != null)
                {
                    leaf.Stop();
                }

                Config.SetConfig(null);
            }
        }
示例#5
0
        public void LogicalQueryViaUdpBroadcast_Basic_Self()
        {
            _LeafRouter leaf = null;
            TestAck     ack;
            string      s;

            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            try
            {
                leaf = CreateLeaf("detached", "hub0", "leaf0", group);
                Thread.Sleep(InitDelay);

                // Verify a q/r between a single router

                s   = "Hello World!";
                ack = (TestAck)leaf.Query("logical://leaf", new NotCachedMsg("Normal", s));
                Assert.AreEqual(s, ack.Value);
            }
            finally
            {
                if (leaf != null)
                {
                    leaf.Stop();
                }

                Config.SetConfig(null);
            }
        }
示例#6
0
        public void LogicalQueryViaUdpBroadcast_AsyncQuery()
        {
            _LeafRouter leaf = null;
            TestAck     ack;
            DateTime    start;

            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            try
            {
                // This test verifies that SessionKeepAlive messages continue
                // to be send back to the client even after the message handler
                // has returned an 20 seconds has passed.

                leaf = CreateLeaf("detached", "hub0", "leaf0", group);
                leaf.Dispatcher.AddTarget(this);
                Thread.Sleep(InitDelay);

                start = SysTime.Now;
                ack   = (TestAck)leaf.Query("logical://async-infinite", new AsyncMsg("Normal", ""));

                Assert.AreEqual("async-complete", ack.Value);
                Assert.IsTrue(SysTime.Now - start >= TimeSpan.FromSeconds(20));
            }
            finally
            {
                if (leaf != null)
                {
                    leaf.Stop();
                }

                Config.SetConfig(null);
            }
        }
示例#7
0
        public void LogicalQueryViaUdpBroadcast_Broadcast_Query()
        {
            // Verify that a query with the broadcast flag set is actually
            // delivered to multiple service instances and that the response
            // from one of them is received.

            _LeafRouter leaf0 = null;
            _LeafRouter leaf1 = null;
            _LeafRouter leaf2 = null;
            Msg         query;
            TestAck     ack;
            string      s;

            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            try
            {
                leaf0 = CreateLeaf("detached", "hub0", "leaf0", group);
                leaf1 = CreateLeaf("detached", "hub0", "leaf1", group);
                leaf2 = CreateLeaf("detached", "hub0", "leaf2", group);
                Thread.Sleep(InitDelay);

                s             = "Hello World!";
                query         = new NotCachedMsg("Normal", s);
                query._Flags |= MsgFlag.Broadcast;
                ack           = (TestAck)leaf0.Query("logical://leaf", query);
                Assert.AreEqual(s, ack.Value);

                Thread.Sleep(1000);

                Assert.AreEqual(1, leaf0.ReceiveCount);
                Assert.AreEqual(1, leaf1.ReceiveCount);
                Assert.AreEqual(1, leaf2.ReceiveCount);
            }
            finally
            {
                if (leaf0 != null)
                {
                    leaf0.Stop();
                }

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

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

                Config.SetConfig(null);
            }
        }
示例#8
0
        public void PhysicalQuery_Cached_Remote()
        {
            _HubRouter  hub  = null;
            _LeafRouter leaf = null;
            CachedMsg   query;
            TestAck     ack1;
            TestAck     ack2;

            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            try
            {
                hub  = CreateHub("detached", "hub0", group);
                leaf = CreateLeaf("detached", "hub0", "leaf0", group);
                Thread.Sleep(InitDelay);

                // Verify that sessions and replies are cached

                query = new CachedMsg("ActionCount", string.Empty);

                ack1 = (TestAck)leaf.Query(hub.RouterEP, query);
                Assert.AreEqual(1, hub.ReceiveCount);

                // Simulate the resending of the query message and wait
                // for another reply.  The second reply should hold the
                // same value as the first.

                query            = new CachedMsg("ActionCount", string.Empty);
                query._ToEP      = leaf.RouterEP;
                query._SessionID = ack1._SessionID;
                query._Flags    |= MsgFlag.OpenSession | MsgFlag.ServerSession | MsgFlag.KeepSessionID;

                ack2 = (TestAck)leaf.Query(hub.RouterEP, query);
                Assert.AreEqual(1, hub.ReceiveCount);
                Assert.AreEqual(ack1.Value, ack2.Value);
            }
            finally
            {
                if (hub != null)
                {
                    hub.Stop();
                }

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

                Config.SetConfig(null);
            }
        }
示例#9
0
        public void LogicalQueryViaUdpBroadcast_Timeout_Remote()
        {
            _LeafRouter leaf = null;
            _HubRouter  hub  = null;
            TestAck     ack;

            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            try
            {
                hub  = CreateHub("detached", "hub0", group);
                leaf = CreateLeaf("detached", "hub0", "leaf0", group);
                Thread.Sleep(InitDelay);

                // Verify that retries and timeout works

                try
                {
                    ack = (TestAck)leaf.Query("logical://hub", new NotCachedMsg("Ignore", string.Empty));
                    Assert.Fail("Should have seen a TimeoutException");
                }
                catch (TimeoutException)
                {
                    // Verify that since the NotCachedMsg handlers are not tagged with
                    // [MsgHandler[Idempotent=true)] that we should have seen
                    // all of the retry messages as well.

                    Assert.AreEqual(leaf.SessionRetries, hub.ReceiveCount);
                }
            }
            finally
            {
                if (leaf != null)
                {
                    leaf.Stop();
                }

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

                Config.SetConfig(null);
            }
        }
示例#10
0
        public void LogicalQueryViaUdpBroadcast_RequestContext_Orphaned()
        {
            // Verify that an orphaned MsgRequestContext's finalizer handles
            // transaction cancellation properly.

            _LeafRouter  leaf = null;
            IAsyncResult ar;

            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            try
            {
                leaf = CreateLeaf("detached", "hub0", "leaf0", group);
                Thread.Sleep(InitDelay);

                // Verify a q/r between a single router

                ar = leaf.BeginQuery("logical://leaf-async", new NotCachedMsg("Normal-Orphan-RequestContext", "test"), null, null);
                Thread.Sleep(500);  // Give the request a chance to be received

                // The delay above should have allowed the request to have been received
                // and the MsgRequestContext to be created and orphaned.  We'll force
                // a garbage collection now which should cause the context's finalizer
                // to be called when should cause the query to fail with a CancelException.

                GC.Collect();
                GC.WaitForPendingFinalizers();

                leaf.EndQuery(ar);
                Assert.Fail("Expected a CancelException");
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(CancelException));
            }
            finally
            {
                if (leaf != null)
                {
                    leaf.Stop();
                }

                Config.SetConfig(null);
            }
        }
示例#11
0
        public void PhysicalQuery_Timeout_Remote_Cached()
        {
            _LeafRouter leaf = null;
            _HubRouter  hub  = null;
            TestAck     ack;

            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            try
            {
                hub  = CreateHub("detached", "hub0", group);
                leaf = CreateLeaf("detached", "hub0", "leaf0", group);
                Thread.Sleep(InitDelay);

                // Verify that retries and timeout works

                try
                {
                    ack = (TestAck)leaf.Query(hub.RouterEP, new CachedMsg("Ignore", string.Empty));
                    Assert.Fail("Should have seen a TimeoutException");
                }
                catch (TimeoutException)
                {
                    // Verify that since the CachedMsg handlers are tagged with
                    // [MsgHandler[Idempotent=true)] that we have not
                    // seen any retry messages

                    Assert.AreEqual(1, hub.ReceiveCount);
                }
            }
            finally
            {
                if (leaf != null)
                {
                    leaf.Stop();
                }

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

                Config.SetConfig(null);
            }
        }
示例#12
0
        private _LeafRouter CreateLeaf(string root, string hub, string name, string cloudEP)
        {
            const string settings =
                @"
MsgRouter.AppName               = Test
MsgRouter.AppDescription        = Test Description
MsgRouter.RouterEP				= physical://{0}/{1}/{2}
MsgRouter.DiscoveryMode         = UDPBROADCAST
MsgRouter.CloudEP               = {3}
MsgRouter.CloudAdapter          = ANY
MsgRouter.UdpEP					= ANY:0
MsgRouter.TcpEP					= ANY:0
MsgRouter.TcpBacklog			= 100
MsgRouter.TcpDelay				= off
MsgRouter.BkInterval			= 1s
MsgRouter.MaxIdle				= 5m
MsgRouter.AdvertiseTime			= 1m
MsgRouter.DefMsgTTL				= 5
MsgRouter.SharedKey             = PLAINTEXT
MsgRouter.SessionCacheTime      = 2m
MsgRouter.SessionRetries        = 3
MsgRouter.SessionTimeout        = 10s

MsgRouter.BroadcastSettings.NetworkBinding        = ANY
MsgRouter.BroadcastSettings.SocketBufferSize      = 1M
MsgRouter.BroadcastSettings.Server[0]             = localhost:UDP-BROADCAST
MsgRouter.BroadcastSettings.SharedKey             = aes:NtSkj76eyCAsJE4TnTqmPOuKd5hDDWwSS7ccTfeKEL8=:S9Xc6skGFWtxoxBaoTxJlQ==
MsgRouter.BroadcastSettings.MessageTTL            = 15m
MsgRouter.BroadcastSettings.BroadcastGroup        = 0
MsgRouter.BroadcastSettings.BkTaskInterval        = 1s
MsgRouter.BroadcastSettings.KeepAliveInterval     = 30s
MsgRouter.BroadcastSettings.ServerResolveInterval = 5m
";

            _LeafRouter router;

            Config.SetConfig(string.Format(settings, root, hub, name, cloudEP));
            router = new _LeafRouter();
            router.Start();

            return(router);
        }
示例#13
0
        public void PhysicalQuery_Exception()
        {
            _LeafRouter leaf = null;
            _HubRouter  hub  = null;
            TestAck     ack;

            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            try
            {
                hub  = CreateHub("detached", "hub0", group);
                leaf = CreateLeaf("detached", "hub0", "leaf0", group);
                Thread.Sleep(InitDelay);

                // Verify that retries and timeout works

                try
                {
                    ack = (TestAck)leaf.Query(hub.RouterEP, new NotCachedMsg("Exception", "Test Exception"));
                    Assert.Fail("Should have seen a TimeoutException");
                }
                catch (SessionException e)
                {
                    Assert.AreEqual("Test Exception", e.Message);
                }
            }
            finally
            {
                if (leaf != null)
                {
                    leaf.Stop();
                }

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

                Config.SetConfig(null);
            }
        }
示例#14
0
        public void LogicalQueryViaUdpBroadcast_Basic_Remote_Blast()
        {
            _LeafRouter leaf = null;
            _HubRouter  hub  = null;
            TestAck     ack;
            string      s;

            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            try
            {
                hub  = CreateHub("detached", "hub0", group);
                leaf = CreateLeaf("detached", "hub0", "leaf0", group);
                Thread.Sleep(InitDelay);

                for (int i = 0; i < BlastCount; i++)
                {
                    // Verify a q/r between two routers

                    s   = "Hello World: " + i.ToString();
                    ack = (TestAck)hub.Query("logical://leaf", new NotCachedMsg("Normal", s));
                    Assert.AreEqual(s, ack.Value);
                }
            }
            finally
            {
                if (leaf != null)
                {
                    leaf.Stop();
                }

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

                Config.SetConfig(null);
            }
        }
示例#15
0
        public void PhysicalQuery_LongQuery_Remote()
        {
            _LeafRouter leaf = null;
            _HubRouter  hub  = null;
            TestAck     ack;
            string      s;

            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            try
            {
                hub  = CreateHub("detached", "hub0", group);
                leaf = CreateLeaf("detached", "hub0", "leaf0", group);
                Thread.Sleep(InitDelay);

                // Verify a long running q/r between two routers,
                // verifying that the query was not sent multiple times.

                s   = "Hello World!";
                ack = (TestAck)hub.Query(leaf.RouterEP, new NotCachedMsg("Sleep", s));
                Assert.AreEqual(s, ack.Value);
                Assert.IsTrue(leaf.ReceiveCount == 1);
            }
            finally
            {
                if (leaf != null)
                {
                    leaf.Stop();
                }

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

                Config.SetConfig(null);
            }
        }
示例#16
0
        public void LogicalQueryViaUdpBroadcast_LongQuery_Remote()
        {
            _LeafRouter leaf = null;
            _HubRouter  hub  = null;
            TestAck     ack;
            string      s;

            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            try
            {
                hub  = CreateHub("detached", "hub0", group);
                leaf = CreateLeaf("detached", "hub0", "leaf0", group);
                Thread.Sleep(InitDelay);

                // Verify a q/r between two routers

                s   = "Hello World!";
                ack = (TestAck)hub.Query("logical://leaf", new NotCachedMsg("Sleep", s));
                Assert.AreEqual(s, ack.Value);
                Assert.IsTrue(leaf.ReceiveCount > 0);
            }
            finally
            {
                if (leaf != null)
                {
                    leaf.Stop();
                }

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

                Config.SetConfig(null);
            }
        }
示例#17
0
        public void PhysicalQuery_Basic_Remote()
        {
            _LeafRouter leaf = null;
            _HubRouter  hub  = null;
            TestAck     ack;
            string      s;

            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            try
            {
                hub  = CreateHub("detached", "hub0", group);
                leaf = CreateLeaf("detached", "hub0", "leaf0", group);
                Thread.Sleep(InitDelay);

                // Verify a q/r between two routers

                s   = "Hello World!";
                ack = (TestAck)hub.Query(leaf.RouterEP, new NotCachedMsg("Normal", s));
                Assert.AreEqual(s, ack.Value);
            }
            finally
            {
                if (leaf != null)
                {
                    leaf.Stop();
                }

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

                Config.SetConfig(null);
            }
        }