コード例 #1
0
 public void Add(INode node)
 {
     lock (_lock)
     {
         Servers.AddNode(node);
         ServerQueue.Enqueue(node);
     }
 }
コード例 #2
0
        public void TestListenerReconnect()
        {
            var name       = TestSupport.RandomString();
            var map        = Client.GetMap <string, string>(name);
            var eventCount = 0;
            var count      = 2;
            var regId      = map.AddEntryListener(new EntryAdapter <string, string>
            {
                Added = e => { Interlocked.Increment(ref eventCount); }
            }, true);

            // try to start and stop the instance several times
            for (var i = 0; i < count; i++)
            {
                var clientDisconnected = TestSupport.WaitForClientState(Client,
                                                                        LifecycleEvent.LifecycleState.ClientDisconnected);
                Cluster.RemoveNode();
                TestSupport.AssertCompletedEventually(clientDisconnected, taskName: "clientDisconnected");
                Interlocked.Exchange(ref eventCount, 0);
                var clientConnected = TestSupport.WaitForClientState(Client,
                                                                     LifecycleEvent.LifecycleState.ClientConnected);
                Cluster.AddNode();
                TestSupport.AssertCompletedEventually(clientConnected, taskName: "clientConnected");

                TestSupport.AssertTrueEventually(() =>
                {
                    map.Put(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
                    return(eventCount > 0);
                });
            }
            Assert.IsTrue(map.RemoveEntryListener(regId));
            map.Destroy();
        }
コード例 #3
0
        public void MemberRemovedEvent()
        {
            var node = Cluster.AddNode();

            Client.GetCluster().AddMembershipListener(new MembershipListener
            {
                OnMemberAdded = memberAddedEvent => { Cluster.RemoveNode(node); }
            });

            var reset = new ManualResetEventSlim();

            MembershipEvent memberRemovedEvent = null;

            Client.GetCluster().AddMembershipListener(new MembershipListener
            {
                OnMemberRemoved = memberRemoved =>
                {
                    memberRemovedEvent = memberRemoved;
                    reset.Set();
                }
            });
            Assert.IsTrue(reset.Wait(30 * 1000));
            Assert.IsInstanceOf <ICluster>(memberRemovedEvent.Source);
            Assert.IsInstanceOf <ICluster>(memberRemovedEvent.GetCluster());
            Assert.AreEqual(MembershipEvent.MemberRemoved, memberRemovedEvent.GetEventType());
            Assert.IsNotNull(memberRemovedEvent.GetMember());
            Assert.AreEqual(1, memberRemovedEvent.GetMembers().Count);
        }
コード例 #4
0
        public void ClientTransactionRetry()
        {
            var context = Client.NewTransactionContext();

            context.BeginTransaction();

            var map = context.GetMap <int, string>(TestSupport.RandomString());

            Task.Factory.StartNew(() =>
            {
                Cluster.RemoveNode();
                Cluster.AddNode();
            });
            try
            {
                for (var i = 0; i < Count; i++)
                {
                    // put should eventually fail as the node which the transaction is running against
                    // will be shut down
                    map.Put(i, TestSupport.RandomString());
                }
            }
            finally
            {
                context.RollbackTransaction();
            }
        }
コード例 #5
0
        /// <summary>
        /// The method for finding the min span tree
        /// </summary>
        private List <Edge> FindMinSpanTree(NodesWithEdges inputData)
        {
            var result = new List <Edge>();

            // the forest contains all visited nodes
            // List<Node> forest = new List<Node>();

            foreach (var node in inputData.Nodes)
            {
                node.Cluster = new Cluster {
                    Label = node.Label
                };
                node.Cluster.AddNode(node);
            }

            var clusters = inputData.Nodes
                           .Select(p => p.Cluster)
                           .Distinct()
                           .ToList();

            // sort the edges by their length
            inputData.Edges.Sort();

            foreach (Edge currentEdge in inputData.Edges)
            {
                if (clusters.Count == 1)
                {
                    break;
                }

                Cluster cluster1 = currentEdge.FirstNode.Cluster;
                Cluster cluster2 = currentEdge.SecondNode.Cluster;

                if (cluster1.Label != cluster2.Label)
                {
                    result.Add(currentEdge);

                    // add the length to the total cost
                    // totalCost += currentEdge.Length;

                    currentEdge.Visited            = true;
                    currentEdge.FirstNode.Visited  = true;
                    currentEdge.SecondNode.Visited = true;

                    // merge two cluster and make a single one of them
                    List <Node> nodeList = cluster2.GetNodeList();
                    foreach (Node n in nodeList)
                    {
                        cluster1.AddNode(n);
                        n.Cluster = cluster1;
                    }

                    clusters.Remove(cluster2);
                }
            }

            return(result);
            // return totalCost;
        }
コード例 #6
0
 public void ErrorOccurred(INode node, Exception exc = null)
 {
     lock (_lock)
     {
         Blacklisted.AddNode(node);
         RefreshServerQueue();
         exc.InitializeIfNull(new Exception("Unknown exception"));
         ErrorCallback.NotNull(a => a(new HeliosNodeException(exc, node)));
     }
 }
コード例 #7
0
        protected int AddNodeAndWait()
        {
            var resetEvent = new ManualResetEventSlim();
            var regId      = Client.GetCluster().AddMembershipListener(new MembershipListener
            {
                OnMemberAdded = @event => resetEvent.Set()
            });
            var id = Cluster.AddNode();

            Assert.IsTrue(resetEvent.Wait(120 * 1000), "The member did not get added in 120 seconds");
            Assert.IsTrue(Client.GetCluster().RemoveMembershipListener(regId));

            // make sure partitions are updated
            TestSupport.AssertTrueEventually(() => { Assert.AreEqual(Cluster.Size, GetUniquePartitionOwnerCount()); },
                                             60, "The partition list did not contain " + Cluster.Size + " partitions.");

            return(id);
        }
コード例 #8
0
        public void FixtureTearDown()
        {
            if (Client != null)
            {
                Client.Shutdown();
            }
            //try to rebalance the cluster size
            if (Cluster.Size > 1)
            {
                while (Cluster.Size != 1)
                {
                    Cluster.RemoveNode();
                }
            }
            if (Cluster.Size == 0)
            {
                Cluster.AddNode();
            }

            Assert.AreEqual(1, Cluster.Size);
        }
コード例 #9
0
        public void TestReconnect()
        {
            var name = TestSupport.RandomString();
            var map  = Client.GetMap <string, string>(name);

            map.Put("key", "value");
            Assert.AreEqual("value", map.Get("key"));

            var clientDisconnected = TestSupport.WaitForClientState(Client, LifecycleEvent.LifecycleState.ClientDisconnected);

            Cluster.RemoveNode();
            TestSupport.AssertCompletedEventually(clientDisconnected, taskName: "clientDisconnected");

            var clientConnected = TestSupport.WaitForClientState(Client, LifecycleEvent.LifecycleState.ClientConnected);

            Cluster.AddNode();
            TestSupport.AssertCompletedEventually(clientConnected, taskName: "clientConnected");

            map.Put("key", "value2");
            Assert.AreEqual("value2", map.Get("key"));

            map.Destroy();
        }
コード例 #10
0
 public void TearDown()
 {
     Cluster.RemoveNode();
     Cluster.AddNode();
 }