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); } }
public new void Stop() { if (cluster != null) { cluster.Close(); cluster = null; } base.Stop(); }
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); } }
public void LazyMessenger_DeliverTo_Cluster() { 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["data"] = "Hello World!"; query["query"] = "yes"; confirmation = null; messenger.Deliver(cluster, null, 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.AreEqual(cluster.InstanceID, confirmation.TopologyID); Assert.IsNotNull(confirmation.TopologyInfo); Assert.IsNull(confirmation.TopologyParam); Assert.IsInstanceOfType(confirmation.Response, typeof(PropertyMsg)); Assert.AreEqual(query["data"], ((PropertyMsg)confirmation.Response)["data"]); Assert.IsNull(confirmation.Exception); } finally { if (messenger != null) { messenger.Close(); } if (cluster != null) { cluster.Close(); } if (router != null) { router.Stop(); } Config.SetConfig(null); } }
public void BasicTopology_ParallelQuery() { LeafRouter router = null; LeafRouterA[] serverA = null; LeafRouterB[] serverB = null; BasicTopology clusterA = null; BasicTopology clusterB = null; ParallelQuery parallelQuery; try { // Crank up the service instances serverA = new LeafRouterA[3]; serverA[0] = CreateLeafA("detached", "hub", Helper.NewGuid().ToString(), group, dynACounts, 0); serverA[1] = CreateLeafA("detached", "hub", Helper.NewGuid().ToString(), group, dynACounts, 1); serverA[2] = CreateLeafA("detached", "hub", Helper.NewGuid().ToString(), group, dynACounts, 2); serverB = new LeafRouterB[3]; serverB[0] = CreateLeafB("detached", "hub", Helper.NewGuid().ToString(), group, dynBCounts, 0); serverB[1] = CreateLeafB("detached", "hub", Helper.NewGuid().ToString(), group, dynBCounts, 1); serverB[2] = CreateLeafB("detached", "hub", Helper.NewGuid().ToString(), group, dynBCounts, 2); // Create the client and its cluster instances router = CreateLeaf("detached", "hub", Helper.NewGuid().ToString(), group); // Initialize the client clusters clusterA = new BasicTopology(); clusterA.OpenClient(router, "logical://A", null); clusterB = new BasicTopology(); clusterB.OpenClient(router, "logical://B", null); // Delay a bit to allow for endpoint discovery Thread.Sleep(InitDelay); // Make sure that the message handler endpoints were dynamically modified Clear(); parallelQuery = new ParallelQuery(); parallelQuery.Operations.Add(new ParallelOperation(new BlobPropertyMsg())); parallelQuery.Operations.Add(new ParallelOperation(new BlobPropertyMsg())); parallelQuery = clusterA.ParallelQuery(null, parallelQuery); foreach (var operation in parallelQuery.Operations) { Assert.AreEqual("A", ((PropertyMsg)operation.ReplyMsg)["value"]); } Assert.AreEqual(2, dynACounts[0] + dynACounts[1] + dynACounts[2]); Assert.AreEqual(0, dynBCounts[0] + dynBCounts[1] + dynBCounts[2]); Clear(); parallelQuery = new ParallelQuery(); parallelQuery.Operations.Add(new ParallelOperation(new BlobPropertyMsg())); parallelQuery.Operations.Add(new ParallelOperation(new BlobPropertyMsg())); parallelQuery = clusterB.ParallelQuery(null, parallelQuery); foreach (var operation in parallelQuery.Operations) { Assert.AreEqual("B", ((PropertyMsg)operation.ReplyMsg)["value"]); } Assert.AreEqual(0, dynACounts[0] + dynACounts[1] + dynACounts[2]); Assert.AreEqual(2, dynBCounts[0] + dynBCounts[1] + dynBCounts[2]); } finally { if (serverA != null) { for (int i = 0; i < serverA.Length; i++) { if (serverA[i] != null) { serverA[i].Stop(); } } } if (serverB != null) { for (int i = 0; i < serverB.Length; i++) { if (serverB[i] != null) { serverB[i].Stop(); } } } if (clusterA != null) { clusterA.Close(); } if (clusterB != null) { clusterB.Close(); } if (router != null) { router.Stop(); } Config.SetConfig(null); } }
public void BasicTopology_Query() { LeafRouter router = null; LeafRouterA[] serverA = null; LeafRouterB[] serverB = null; BasicTopology clusterA = null; BasicTopology clusterB = null; PropertyMsg reply; try { // Crank up the service instances serverA = new LeafRouterA[3]; serverA[0] = CreateLeafA("detached", "hub", Helper.NewGuid().ToString(), group, dynACounts, 0); serverA[1] = CreateLeafA("detached", "hub", Helper.NewGuid().ToString(), group, dynACounts, 1); serverA[2] = CreateLeafA("detached", "hub", Helper.NewGuid().ToString(), group, dynACounts, 2); serverB = new LeafRouterB[3]; serverB[0] = CreateLeafB("detached", "hub", Helper.NewGuid().ToString(), group, dynBCounts, 0); serverB[1] = CreateLeafB("detached", "hub", Helper.NewGuid().ToString(), group, dynBCounts, 1); serverB[2] = CreateLeafB("detached", "hub", Helper.NewGuid().ToString(), group, dynBCounts, 2); // Create the client and its cluster instances router = CreateLeaf("detached", "hub", Helper.NewGuid().ToString(), group); // Initialize the client clusters clusterA = new BasicTopology(); clusterA.OpenClient(router, "logical://A", null); clusterB = new BasicTopology(); clusterB.OpenClient(router, "logical://B", null); // Delay a bit to allow for endpoint discovery Thread.Sleep(InitDelay); // Make sure that the message handler endpoints were dynamically modified Clear(); reply = (PropertyMsg)clusterA.Query(null, new BlobPropertyMsg()); Assert.AreEqual("A", reply["value"]); Assert.AreEqual(1, dynACounts[0] + dynACounts[1] + dynACounts[2]); Assert.AreEqual(0, dynBCounts[0] + dynBCounts[1] + dynBCounts[2]); Clear(); reply = (PropertyMsg)clusterB.Query(null, new BlobPropertyMsg()); Assert.AreEqual("B", reply["value"]); Assert.AreEqual(0, dynACounts[0] + dynACounts[1] + dynACounts[2]); Assert.AreEqual(1, dynBCounts[0] + dynBCounts[1] + dynBCounts[2]); // Verify that load balancing works Clear(); for (int i = 0; i < 100; i++) { reply = (PropertyMsg)clusterA.Query(null, new BlobPropertyMsg()); Assert.AreEqual("A", reply["value"]); } Thread.Sleep(2000); Assert.AreEqual(0, dynBCounts[0] + dynBCounts[1] + dynBCounts[2]); Assert.AreEqual(100, dynACounts[0] + dynACounts[1] + dynACounts[2]); Assert.IsTrue(dynACounts[0] > 0); Assert.IsTrue(dynACounts[1] > 0); Assert.IsTrue(dynACounts[2] > 0); } finally { if (serverA != null) { for (int i = 0; i < serverA.Length; i++) { if (serverA[i] != null) { serverA[i].Stop(); } } } if (serverB != null) { for (int i = 0; i < serverB.Length; i++) { if (serverB[i] != null) { serverB[i].Stop(); } } } if (clusterA != null) { clusterA.Close(); } if (clusterB != null) { clusterB.Close(); } if (router != null) { router.Stop(); } Config.SetConfig(null); } }
public void BasicTopology_Broadcast() { LeafRouter router = null; LeafRouterA[] serverA = null; LeafRouterB[] serverB = null; BasicTopology clusterA = null; BasicTopology clusterB = null; try { // Crank up the service instances serverA = new LeafRouterA[3]; serverA[0] = CreateLeafA("detached", "hub", Helper.NewGuid().ToString(), group, dynACounts, 0); serverA[1] = CreateLeafA("detached", "hub", Helper.NewGuid().ToString(), group, dynACounts, 1); serverA[2] = CreateLeafA("detached", "hub", Helper.NewGuid().ToString(), group, dynACounts, 2); serverB = new LeafRouterB[3]; serverB[0] = CreateLeafB("detached", "hub", Helper.NewGuid().ToString(), group, dynBCounts, 0); serverB[1] = CreateLeafB("detached", "hub", Helper.NewGuid().ToString(), group, dynBCounts, 1); serverB[2] = CreateLeafB("detached", "hub", Helper.NewGuid().ToString(), group, dynBCounts, 2); // Create the client and its cluster instances router = CreateLeaf("detached", "hub", Helper.NewGuid().ToString(), group); // Initialize the client clusters clusterA = new BasicTopology(); clusterA.OpenClient(router, "logical://A", null); clusterB = new BasicTopology(); clusterB.OpenClient(router, "logical://B", null); // Delay a bit to allow for endpoint discovery Thread.Sleep(InitDelay); // Verify that broadcasting works Clear(); clusterA.Broadcast(null, new PropertyMsg()); Thread.Sleep(1000); Assert.AreEqual(3, dynACounts[0] + dynACounts[1] + dynACounts[2]); Assert.AreEqual(0, dynBCounts[0] + dynBCounts[1] + dynBCounts[2]); Clear(); clusterB.Broadcast(null, new PropertyMsg()); Thread.Sleep(1000); Assert.AreEqual(0, dynACounts[0] + dynACounts[1] + dynACounts[2]); Assert.AreEqual(3, dynBCounts[0] + dynBCounts[1] + dynBCounts[2]); } finally { if (serverA != null) { for (int i = 0; i < serverA.Length; i++) { if (serverA[i] != null) { serverA[i].Stop(); } } } if (serverB != null) { for (int i = 0; i < serverB.Length; i++) { if (serverB[i] != null) { serverB[i].Stop(); } } } if (clusterA != null) { clusterA.Close(); } if (clusterB != null) { clusterB.Close(); } if (router != null) { router.Stop(); } Config.SetConfig(null); } }