Exemplo n.º 1
0
            public new void Stop()
            {
                if (cluster != null)
                {
                    cluster.Close();
                    cluster = null;
                }

                base.Stop();
            }
Exemplo n.º 2
0
        public void StaticHashedTopology_ParallelQuery()
        {
            LeafRouter router = null;

            LeafRouterA[]        serverA  = null;
            LeafRouterB[]        serverB  = null;
            StaticHashedTopology clusterA = null;
            StaticHashedTopology clusterB = null;
            ParallelQuery        parallelQuery;

            try
            {
                // Crank up the service instances

                serverA    = new LeafRouterA[3];
                serverA[0] = CreateLeafA("detached", "hub", "a-0", group, dynACounts, 0);
                serverA[1] = CreateLeafA("detached", "hub", "a-1", group, dynACounts, 1);
                serverA[2] = CreateLeafA("detached", "hub", "a-2", group, dynACounts, 2);

                serverB    = new LeafRouterB[3];
                serverB[0] = CreateLeafB("detached", "hub", "b-0", group, dynBCounts, 0);
                serverB[1] = CreateLeafB("detached", "hub", "b-1", group, dynBCounts, 1);
                serverB[2] = CreateLeafB("detached", "hub", "b-2", group, dynBCounts, 2);

                // Create the client and its cluster instances

                router = CreateLeaf("detached", "hub", "client", group);

                // Initialize the client clusters

                clusterA = OpenClient(router, "logical://A");
                clusterB = OpenClient(router, "logical://B");

                // Delay a bit to allow for endpoint discovery

                Thread.Sleep(InitDelay);

                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);
            }
        }
Exemplo n.º 3
0
        public void StaticHashedTopology_Query()
        {
            LeafRouter router = null;

            LeafRouterA[]        serverA  = null;
            LeafRouterB[]        serverB  = null;
            StaticHashedTopology clusterA = null;
            StaticHashedTopology clusterB = null;
            PropertyMsg          reply;

            try
            {
                // Crank up the service instances

                serverA    = new LeafRouterA[3];
                serverA[0] = CreateLeafA("detached", "hub", "a-0", group, dynACounts, 0);
                serverA[1] = CreateLeafA("detached", "hub", "a-1", group, dynACounts, 1);
                serverA[2] = CreateLeafA("detached", "hub", "a-2", group, dynACounts, 2);

                serverB    = new LeafRouterB[3];
                serverB[0] = CreateLeafB("detached", "hub", "b-0", group, dynBCounts, 0);
                serverB[1] = CreateLeafB("detached", "hub", "b-1", group, dynBCounts, 1);
                serverB[2] = CreateLeafB("detached", "hub", "b-2", group, dynBCounts, 2);

                // Create the client and its cluster instances

                router = CreateLeaf("detached", "hub", "client", group);

                // Initialize the client clusters

                clusterA = OpenClient(router, "logical://A");
                clusterB = OpenClient(router, "logical://B");

                // 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);
            }
        }
Exemplo n.º 4
0
        public void StaticHashedTopology_Broadcast()
        {
            LeafRouter router = null;

            LeafRouterA[]        serverA  = null;
            LeafRouterB[]        serverB  = null;
            StaticHashedTopology clusterA = null;
            StaticHashedTopology 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 = OpenClient(router, "logical://A");
                clusterB = OpenClient(router, "logical://B");

                // 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);
            }
        }