示例#1
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();
        }
示例#2
0
        public void TestReconnect()
        {
            var member = _remoteController.startMember(_cluster.Id);
            var client = CreateClient();

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

            _remoteController.shutdownMember(_cluster.Id, member.Uuid);

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

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

            _remoteController.startMember(_cluster.Id);

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

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

            map.Destroy();
        }
示例#3
0
        public void TestPromoteToOwner()
        {
            var member1 = _remoteController.startMember(_cluster.Id);
            var client  = CreateClient();

            var member2 = StartMemberAndWait(client, _remoteController, _cluster, 2);

            var name = TestSupport.RandomString();
            var map  = client.GetMap <int, int>(name);

            for (var i = 0; i < 1000; i++)
            {
                map.Put(i, i);
            }

            var clientDisconnected = TestSupport.WaitForClientState(client,
                                                                    LifecycleEvent.LifecycleState.ClientDisconnected);
            var clientConnected = TestSupport.WaitForClientState(client, LifecycleEvent.LifecycleState.ClientConnected);

            _remoteController.shutdownMember(_cluster.Id, member1.Uuid);

            TestSupport.AssertCompletedEventually(clientDisconnected, taskName: "clientDisconnected");
            TestSupport.AssertCompletedEventually(clientConnected, taskName: "clientConnected");
            Assert.AreEqual(1000, map.Size());
        }
示例#4
0
        public void TestClientShouldPingServerWhenClientOnlyListening()
        {
            var          clientDisconnected     = TestSupport.WaitForClientState(Client, LifecycleEvent.LifecycleState.ClientDisconnected);
            const int    clientHeartbeatSeconds = 8;
            var          publishMessageCount    = 0;
            var          listenedMessageCount   = 0;
            var          client2   = CreateClient();
            const string topicName = "topicName";
            var          topic     = Client.GetTopic <string>(topicName);
            var          id        = topic.AddMessageListener(msg => { listenedMessageCount++; });

            var topic2 = client2.GetTopic <string>(topicName);

            var begin = Clock.CurrentTimeMillis();

            while (Clock.CurrentTimeMillis() - begin < TimeSpan.FromSeconds(clientHeartbeatSeconds * 2).TotalMilliseconds)
            {
                topic2.Publish("message");
                publishMessageCount++;
            }

            topic.RemoveMessageListener(id);
            Assert.False(clientDisconnected.Wait(100), "Client should not be disconnected");
            Assert.AreEqual(publishMessageCount, listenedMessageCount);
        }
示例#5
0
        public void TestIdle()
        {
            _remoteController.startMember(_cluster.Id);
            _remoteController.startMember(_cluster.Id);
            var client             = CreateClient();
            var clientDisconnected = TestSupport.WaitForClientState(client, LifecycleEvent.LifecycleState.ClientDisconnected);

            Thread.Sleep(10000);
            Assert.False(clientDisconnected.Wait(1000), "Client should not be disconnected");
        }
示例#6
0
        public void TestContinuousGet()
        {
            _remoteController.startMember(_cluster.Id);
            _remoteController.startMember(_cluster.Id);
            var client             = CreateClient();
            var clientDisconnected = TestSupport.WaitForClientState(client, LifecycleEvent.LifecycleState.ClientDisconnected);

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

            map.Put("key", "value");

            var sw = new Stopwatch();

            sw.Start();
            while (sw.ElapsedMilliseconds < 10000)
            {
                map.Get("key");
            }
            Assert.False(clientDisconnected.Wait(1000), "Client should not be disconnected");
        }
示例#7
0
        public void TestPromoteToOwner()
        {
            AddNodeAndWait();
            var name = TestSupport.RandomString();
            var map  = Client.GetMap <int, int>(name);

            for (int i = 0; i < 1000; i++)
            {
                map.Put(i, i);
            }

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

            Cluster.RemoveNode(Cluster.NodeIds.First());
            TestSupport.AssertCompletedEventually(clientDisconnected, taskName: "clientDisconnected");
            TestSupport.AssertCompletedEventually(clientConnected, taskName: "clientConnected");
            Assert.AreEqual(1000, map.Size());
        }
        public void TestExtremeReconnect()
        {
            var member = _remoteController.startMember(_cluster.Id);
            var client = CreateClient();

            for (int i = 0; i < 50; i++)
            {
                var clientDisconnected = TestSupport.WaitForClientState(client,
                                                                        LifecycleEvent.LifecycleState.ClientDisconnected);

                _remoteController.shutdownMember(_cluster.Id, member.Uuid);
                TestSupport.AssertCompletedEventually(clientDisconnected, taskName: $"clientDisconnected-{i}");

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

                member = _remoteController.startMember(_cluster.Id);
                TestSupport.AssertCompletedEventually(clientConnected, taskName: $"clientConnected-{i}");
            }
        }
示例#9
0
        public void TestContinuousGC()
        {
            GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
            _remoteController.startMember(_cluster.Id);
            _remoteController.startMember(_cluster.Id);
            var client             = CreateClient();
            var clientDisconnected = TestSupport.WaitForClientState(client, LifecycleEvent.LifecycleState.ClientDisconnected);

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

            map.Put("key", "value");

            var sw = new Stopwatch();

            sw.Start();
            while (sw.ElapsedMilliseconds < 10000)
            {
                GC.Collect(9, GCCollectionMode.Forced, true, true);
                Thread.Sleep(1000);
            }
            Assert.False(clientDisconnected.Wait(10000), "Client should not be disconnected");
        }
示例#10
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();
        }