public void TestHeartBeatStoppedOnOwnerNode()
        {
            var member = _remoteController.startMember(_cluster.Id);
            var client = CreateClient();

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

            var key = TestSupport.RandomString();

            var value  = TestSupport.RandomString();
            var value2 = TestSupport.RandomString();

            map.Put(key, value);

            var eventCount = 0;
            var regId      = map.AddEntryListener(new EntryAdapter <string, string>
            {
                Added = e => Interlocked.Increment(ref eventCount)
            }, false);

            SuspendMember(_remoteController, _cluster, member);
            Thread.Sleep(10000);
            ResumeMember(_remoteController, _cluster, member);

            Assert.That(map.Get(key), Is.EqualTo(value));

            TestSupport.AssertTrueEventually(() =>
            {
                map.Put(TestSupport.RandomString(), value2);
                Assert.IsTrue(eventCount > 0);
            });
        }
Example #2
0
        public void ClientTransactionRetry()
        {
            var member = _remoteController.startMember(_cluster.Id);
            var client = CreateClient();

            var context = client.NewTransactionContext();

            context.BeginTransaction();

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

            Task.Factory.StartNew(() =>
            {
                _remoteController.shutdownMember(_cluster.Id, member.Uuid);
                _remoteController.startMember(_cluster.Id);
            });
            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();
            }
        }
        public void TestAsyncOperationDuringClientShutdown()
        {
            var member = _remoteController.startMember(_cluster.Id);
            var client = CreateClient();

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

            var count = 100;
            var tasks = new List <Task>();
            var reset = new ManualResetEventSlim();

            Task.Factory.StartNew(() =>
            {
                for (var i = 0; i < count; i++)
                {
                    tasks.Add(map.PutAsync(i, TestSupport.RandomString()));
                }
                reset.Set();
            });
            Task.Factory.StartNew(() =>
            {
                client.Shutdown();
            });
            try
            {
                reset.Wait();
                Assert.IsFalse(Task.WaitAll(tasks.ToArray(), 30 * 1000));
            }
            catch (AggregateException e)
            {
                throw e.InnerExceptions.First();
            }
        }
Example #4
0
        public void Setup(bool ssl, bool validateCertificateChain, bool validateCertificateName, string certificateName)
        {
            RemoteController = CreateRemoteController();
            var cluster = CreateCluster(RemoteController, ssl?Resources.hazelcast_ssl:Resources.hazelcast);

            RemoteController.startMember(cluster.Id);
            Client = HazelcastClient.NewHazelcastClient(ConfigureClient(ssl, validateCertificateChain, validateCertificateName, certificateName));
        }
Example #5
0
        public void SetupCluster()
        {
            RemoteController = CreateRemoteController();
            var cluster = CreateCluster(RemoteController);

            RemoteController.startMember(cluster.Id);
            Client = CreateClient();
        }
        private void Setup(bool ssl, bool validateCertificateChain, bool validateCertificateName, string certificateName)
        {
            RemoteController = CreateRemoteController();
            var cluster = CreateCluster(RemoteController, ssl?Resources.hazelcast_ssl:Resources.hazelcast);

            RemoteController.startMember(cluster.Id);
            var clientConfig = ConfigureClient(ssl, validateCertificateChain, validateCertificateName, certificateName);

            clientConfig.GetGroupConfig().SetName(cluster.Id).SetPassword(cluster.Id);
            Client = HazelcastClient.NewHazelcastClient(clientConfig);
        }
Example #7
0
        public void TestListenerReconnect()
        {
            var member = StartMember(_remoteController, _cluster);
            var client = CreateClient();

            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);
                _remoteController.shutdownMember(_cluster.Id, member.Uuid);
                TestSupport.AssertCompletedEventually(clientDisconnected, taskName: "clientDisconnected");
                Interlocked.Exchange(ref eventCount, 0);
                var clientConnected = TestSupport.WaitForClientState(client,
                                                                     LifecycleEvent.LifecycleState.ClientConnected);
                member = _remoteController.startMember(_cluster.Id);
                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();
        }
Example #8
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");
        }
Example #9
0
        protected void Setup(string serverXml, bool isSslEnabled, bool?validateCertificateChain,
                             bool?validateCertificateName, bool?checkCertificateRevocation, string certSubjectName, byte[] clientCertificate,
                             string certPassword)
        {
            RemoteController = CreateRemoteController();
            var cluster = CreateCluster(RemoteController, serverXml);

            RemoteController.startMember(cluster.Id);
            var clientConfig = new ClientConfig();

            clientConfig.GetNetworkConfig().AddAddress("localhost:5701");
            clientConfig.GetNetworkConfig().SetSSLConfig(CreateSslConfig(isSslEnabled, validateCertificateChain,
                                                                         validateCertificateName, checkCertificateRevocation, certSubjectName, clientCertificate, certPassword));
            clientConfig.GetGroupConfig().SetName(cluster.Id).SetPassword(cluster.Id);
            Client = HazelcastClient.NewHazelcastClient(clientConfig);
        }
Example #10
0
 protected virtual Member StartMember(RemoteController.Client remoteController, Cluster cluster)
 {
     _logger.Info("Starting new member");
     return(remoteController.startMember(cluster.Id));
 }