Example #1
0
        public void LazyMessenger_DeliverTo_Cluster_Exception()
        {
            MsgRouter     router    = null;
            BasicTopology cluster   = null;
            LazyMessenger messenger = null;
            DateTime      start     = DateTime.UtcNow;
            PropertyMsg   query;

            try
            {
                router = CreateLeaf("detached", "hub", group);
                router.Dispatcher.AddTarget(this);

                cluster = new BasicTopology();
                cluster.OpenClient(router, "logical://foo", null);

                messenger = new LazyMessenger();
                messenger.OpenClient(router, "logical://confirm", null, new DeliveryConfirmCallback(OnDeliveryConfirmation));

                Thread.Sleep(wait);

                query = new PropertyMsg();
                query["operation"] = "exception";
                query["data"]      = "Hello World!";
                query["query"]     = "yes";

                confirmation = null;

                try
                {
                    messenger.Deliver(cluster, null, query, true);
                    Assert.Fail("Exception expected");
                }
                catch (Exception e)
                {
                    Assert.AreEqual("Test Exception", e.Message);
                }
            }
            finally
            {
                if (messenger != null)
                {
                    messenger.Close();
                }

                if (cluster != null)
                {
                    cluster.Close();
                }

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

                Config.SetConfig(null);
            }
        }
Example #2
0
        public void LazyMessenger_DeliverTo_Cluster_NoConfirm2()
        {
            MsgRouter     router    = null;
            BasicTopology cluster   = null;
            LazyMessenger messenger = null;
            DateTime      start     = DateTime.UtcNow;
            PropertyMsg   query;

            try
            {
                router = CreateLeaf("detached", "hub", group);
                router.Dispatcher.AddTarget(this);

                cluster = new BasicTopology();
                cluster.OpenClient(router, "logical://foo", null);

                messenger = new LazyMessenger();
                messenger.OpenClient(router, "logical://confirm", null, null);

                Thread.Sleep(wait);

                query          = new PropertyMsg();
                query["data"]  = "Hello World!";
                query["query"] = "yes";

                confirmation = null;
                messenger.Deliver(cluster, null, query, true);
                Thread.Sleep(wait);

                Assert.IsNull(confirmation);
            }
            finally
            {
                if (messenger != null)
                {
                    messenger.Close();
                }

                if (cluster != null)
                {
                    cluster.Close();
                }

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

                Config.SetConfig(null);
            }
        }
Example #3
0
        public void LazyMessenger_DeliverTo_Endpoint_Timeout()
        {
            MsgRouter     router    = null;
            LazyMessenger messenger = null;
            DateTime      start     = DateTime.UtcNow;
            PropertyMsg   query;

            try
            {
                router    = CreateLeaf("detached", "hub", group);
                messenger = new LazyMessenger();
                messenger.OpenClient(router, "logical://confirm", null, new DeliveryConfirmCallback(OnDeliveryConfirmation));
                router.Dispatcher.AddTarget(this);
                Thread.Sleep(wait);

                query = new PropertyMsg();
                query["operation"] = "timeout";
                query["data"]      = "Hello World!";
                query["query"]     = "yes";

                confirmation = null;
                try
                {
                    messenger.Deliver("logical://foo", query, true);
                    Assert.Fail("TimeoutException expected.");
                }
                catch (Exception e)
                {
                    Assert.IsInstanceOfType(e, typeof(TimeoutException));
                }
            }
            finally
            {
                if (messenger != null)
                {
                    messenger.Close();
                }

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

                Config.SetConfig(null);
            }
        }
Example #4
0
        public void LazyMessenger_DeliverTo_Endpoint()
        {
            MsgRouter     router    = null;
            LazyMessenger messenger = null;
            DateTime      start     = DateTime.UtcNow;
            PropertyMsg   query;

            try
            {
                router    = CreateLeaf("detached", "hub", group);
                messenger = new LazyMessenger();
                messenger.OpenClient(router, "logical://confirm", null, new DeliveryConfirmCallback(OnDeliveryConfirmation));
                router.Dispatcher.AddTarget(this);
                Thread.Sleep(wait);

                query          = new PropertyMsg();
                query["data"]  = "Hello World!";
                query["query"] = "yes";

                confirmation = null;
                messenger.Deliver("logical://foo", query, true);
                Thread.Sleep(wait);

                Assert.IsNotNull(confirmation);
                Assert.IsTrue(confirmation.Timestamp >= start);
                Assert.IsTrue(confirmation.Timestamp <= DateTime.UtcNow);
                Assert.AreEqual(MsgEP.Parse("logical://foo"), confirmation.TargetEP);
                Assert.IsInstanceOfType(confirmation.Query, typeof(PropertyMsg));
                Assert.AreEqual("yes", ((PropertyMsg)confirmation.Query)["query"]);
                Assert.IsInstanceOfType(confirmation.Response, typeof(PropertyMsg));
                Assert.AreEqual(query["data"], ((PropertyMsg)confirmation.Response)["data"]);
                Assert.IsNull(confirmation.Exception);
            }
            finally
            {
                if (messenger != null)
                {
                    messenger.Close();
                }

                router.Stop();

                Config.SetConfig(null);
            }
        }
Example #5
0
 private void OnDeliveryConfirmation(DeliveryConfirmation confirmation)
 {
     this.confirmation = confirmation;
 }