public void TestHeartBeatStoppedOnOwnerNode() { var map = Client.GetMap <string, string>(TestSupport.RandomString()); var key = TestSupport.RandomString(); var key2 = TestSupport.RandomString(); var value = TestSupport.RandomString(); var value2 = TestSupport.RandomString(); map.Put(key, value); int eventCount = 0; var regId = map.AddEntryListener(new EntryListener <string, string> { EntryAddedAction = e => Interlocked.Increment(ref eventCount) }, key2, false); var nodeId = Cluster.NodeIds.First(); Cluster.SuspendNode(nodeId); Thread.Sleep(2000); Cluster.ResumeNode(nodeId); Assert.That(map.Get(key), Is.EqualTo(value)); TestSupport.AssertTrueEventually(() => { map.Put(key2, value2); Assert.IsTrue(eventCount > 0); }); }
public void TestListenerEventOrder() { const int maxSize = 10000; var map2 = Client.GetMap <int, int>(TestSupport.RandomString()); map2.Put(1, 0); var eventDataReceived = new Queue <int>(); var listener = new EntryAdapter <int, int>( e => { }, e => { }, e => eventDataReceived.Enqueue(e.GetValue()), e => { }); map2.AddEntryListener(listener, true); for (var i = 1; i < maxSize; i++) { map2.Put(1, i); } TestSupport.AssertTrueEventually(() => Assert.AreEqual(maxSize - 1, eventDataReceived.Count)); var oldEventData = -1; foreach (var eventData in eventDataReceived) { Assert.Less(oldEventData, eventData); oldEventData = eventData; } }
public void TestNearCacheLruEviction() { var lruMap = Client.GetMap <object, object>("nearCacheMapLru-" + TestSupport.RandomString()); var keys = new List <object>(); for (var i = 0; i < MaxSize; i++) { lruMap.Put(i, i); keys.Add(i); } // make sure all keys are cached lruMap.GetAll(keys); // make keys in sublist accessed again var subList = keys.Take(MaxSize / 2).ToList(); lruMap.GetAll(subList); // add another item, triggering eviction lruMap.Put(MaxSize, MaxSize); lruMap.Get(MaxSize); var cache = GetNearCache(lruMap); TestSupport.AssertTrueEventually(() => { Assert.IsTrue(cache.Cache.Count <= MaxSize, cache.Cache.Count + " should be less than " + MaxSize); foreach (var key in subList) { var keyData = ((HazelcastClientProxy)Client).GetClient().GetSerializationService().ToData(key); Assert.IsTrue(cache.Cache.ContainsKey(keyData), "key " + key + " not found in cache"); } }); }
public void TestNearCacheIdleEviction() { var map = Client.GetMap <int, int>("nearCacheIdle-" + TestSupport.RandomString()); var keys = Enumerable.Range(0, 10).ToList(); foreach (var k in keys) { map.Put(k, k); } var nonIdleKey = 100; map.Put(nonIdleKey, nonIdleKey); map.GetAll(keys); var cache = GetNearCache(map); Assert.AreEqual(keys.Count, cache.Cache.Count); TestSupport.AssertTrueEventually(() => { map.Get(nonIdleKey); //force ttl check foreach (var k in keys) { var keyData = ToKeyData(k); Assert.IsFalse(cache.Cache.ContainsKey(keyData), "key " + k + " should have expired."); } var nonIdleKeyData = ToKeyData(nonIdleKey); Assert.IsTrue(cache.Cache.ContainsKey(nonIdleKeyData), "key 100 should not have expired."); }); }
public void TestHeartStoppedOnNonOwnerNode() { var id = AddNodeAndWait(); var map = Client.GetMap <int, string>(TestSupport.RandomString()); var count = 50; // make sure we have a connection open to the second node for (var i = 0; i < count / 2; i++) { map.Put(i, TestSupport.RandomString()); } Cluster.SuspendNode(id); for (var i = count / 2; i < count; i++) { try { map.PutAsync(i, TestSupport.RandomString()); } catch (Exception e) { Assert.Fail(e.Message); } } Thread.Sleep(5000); Cluster.ResumeNode(id); TestSupport.AssertTrueEventually(() => { Assert.AreEqual(count, map.Size()); }); RemoveNodeAndWait(id); }
public void TestConsoleLoggingLevel() { Environment.SetEnvironmentVariable("hazelcast.logging.level", "info"); var logger = new ConsoleLogFactory().GetLogger("logger"); var original = Console.Out; try { var memoryStream = new MemoryStream(); var streamWriter = new StreamWriter(memoryStream); Console.SetOut(streamWriter); var message1 = TestSupport.RandomString(); var message2 = TestSupport.RandomString(); logger.Info(message1); logger.Finest(message2); streamWriter.Flush(); memoryStream.Seek(0, SeekOrigin.Begin); var log = new StreamReader(memoryStream).ReadToEnd(); Assert.IsFalse(logger.IsFinestEnabled()); Assert.That(logger.GetLevel(), Is.EqualTo(LogLevel.Info)); Assert.That(log, Is.StringContaining(message1)); Assert.That(log, Is.Not.StringContaining(message2)); } finally { Console.SetOut(original); Environment.SetEnvironmentVariable("hazelcast.logging.level", null); } }
public void TestRetryTimeout() { Environment.SetEnvironmentVariable("hazelcast.client.invocation.timeout.seconds", "2"); var client = new HazelcastClientFactory().CreateClient(c => c.GetNetworkConfig().AddAddress("127.0.0.1:5701")); try { var map = client.GetMap <string, string>(TestSupport.RandomString()); Cluster.RemoveNode(); var resetEvent = new ManualResetEventSlim(); Task.Factory.StartNew(() => { Logging.Logger.GetLogger("ClientRetryTest").Info("Calling map.Put"); map.Put("key", "value"); }).ContinueWith(t => { if (t.IsFaulted) { resetEvent.Set(); } else { Assert.Fail("Method invocation did not fail as expected"); } }); Assert.IsTrue(resetEvent.Wait(4000), "Did not get an exception within seconds"); } finally { Environment.SetEnvironmentVariable("hazelcast.client.invocation.timeout.seconds", null); client.Shutdown(); } }
public void TestAsyncOperationDuringClientShutdown() { 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(); Client = null; }); try { reset.Wait(); Assert.IsFalse(Task.WaitAll(tasks.ToArray(), 30 * 1000)); } catch (AggregateException e) { throw e.InnerExceptions.First(); } }
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); }); }
public void TestRetryRequestsWhenInstanceIsShutdown() { var member = _remoteController.startMember(_cluster.Id); var client = CreateClient(); var member2 = StartMemberAndWait(client, _remoteController, _cluster, 2); var map = client.GetMap <int, string>(TestSupport.RandomString()); for (var i = 0; i < Count; i++) { map.Put(i, TestSupport.RandomString()); if (i == Count / 2) { StopMember(_remoteController, _cluster, member2); } } TestSupport.AssertTrueEventually(() => { var keys = map.KeySet(); for (var i = 0; i < Count; i++) { Assert.IsTrue(keys.Contains(i), "Key " + i + " was not found"); } Assert.AreEqual(Count, map.Size()); }, 60); }
public virtual void TestListenerExtreme() { var qX = Client.GetQueue <object>(TestSupport.RandomString()); const int TestItemCount = 1 * 100; Assert.AreEqual(0, qX.Count); for (var i = 0; i < TestItemCount; i++) { qX.Offer("ali"); } Assert.AreEqual(TestItemCount, qX.Count); var latch = new CountdownEvent(TestItemCount * TestItemCount); for (var j = 0; j < TestItemCount; j++) { var listener = new ItemListener <object>(null, latch); var id = qX.AddItemListener(listener, true); Assert.NotNull(id); } qX.Clear(); Assert.AreEqual(0, qX.Count); Assert.IsTrue(latch.Wait(TimeSpan.FromSeconds(100))); }
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(); }
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 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(); } }
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()); }
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(); }
public void TestAsyncOperationDuringClientShutdown() { Assert.Throws <HazelcastException>(() => { 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(); } }); }
[Test, Ignore] // https://github.com/hazelcast/hazelcast-csharp-client/issues/28 public void TestRetryAsyncRequest() { var member = _remoteController.startMember(_cluster.Id); var client = CreateClient(); var count = 100; var member2 = StartMemberAndWait(client, _remoteController, _cluster, 2); var map = client.GetMap <int, string>(TestSupport.RandomString()); for (var i = 0; i < count; i++) { map.PutAsync(i, TestSupport.RandomString()).IgnoreExceptions(); } _remoteController.shutdownMember(_cluster.Id, member2.Uuid); TestSupport.AssertTrueEventually(() => { var keys = map.KeySet(); for (var i = 0; i < count; i++) { Assert.IsTrue(keys.Contains(i), "Key " + i + " was not found"); } Assert.AreEqual(count, map.Size()); }, 60); }
public void TestInitNeg() { var semInit = Client.GetSemaphore(TestSupport.RandomString()); semInit.Init(-2); semInit.Destroy(); }
public void TestHeartStoppedOnNonOwnerNode() { var member1 = _remoteController.startMember(_cluster.Id); var client = CreateClient(); var member2 = StartMemberAndWait(client, _remoteController, _cluster, 2); var map = client.GetMap <int, string>(TestSupport.RandomString()); var count = 50; // make sure we have a connection open to the second node for (var i = 0; i < count / 2; i++) { map.Put(i, TestSupport.RandomString()); } SuspendMember(_remoteController, _cluster, member2); for (var i = count / 2; i < count; i++) { try { map.PutAsync(i, TestSupport.RandomString()); } catch (Exception e) { Assert.Fail(e.Message); } } Thread.Sleep(10000); ResumeMember(_remoteController, _cluster, member2); TestSupport.AssertTrueEventually(() => { Assert.AreEqual(count, map.Size()); }); }
public void TestListenerWithNonSmartRouting() { var map = _client.GetMap <string, string>(TestSupport.RandomString()); var keys = TestSupport.RandomArray(TestSupport.RandomString, 10); var registrations = new List <string>(); var tasks = new List <Task>(); foreach (var key in keys) { var tcs = new TaskCompletionSource <bool>(); var id = map.AddEntryListener(new EntryAdapter <string, string> { Added = e => tcs.SetResult(true) }, key, false); registrations.Add(id); tasks.Add(tcs.Task); } foreach (var key in keys) { map.Put(key, TestSupport.RandomString()); } Assert.IsTrue(Task.WaitAll(tasks.ToArray(), 500), "Did not get all entry added events within 500ms"); foreach (var id in registrations) { Assert.IsTrue(map.RemoveEntryListener(id)); } }
public void TestInit() { var semInit = Client.GetSemaphore(TestSupport.RandomString()); semInit.Init(2); Assert.AreEqual(2, semInit.AvailablePermits()); semInit.Destroy(); }
public void Init() { s = Client.GetSemaphore(TestSupport.RandomString()); s.ReducePermits(100); s.Release(9); s.Release(); }
public void Init() { //CAUTION TEST SERVER SHOULD CONFIGURE A QUEUE WITH NAME starts with queueName //which is configured as; //QueueConfig queueConfig = config.getQueueConfig(queueName); //queueConfig.setMaxSize(6); // q = Client.GetQueue <object>(queueName + TestSupport.RandomString()); }
public void TestOperationAfterShutdown() { var map = Client.GetMap <int, string>(TestSupport.RandomString()); for (int i = 0; i < 100; i++) { map.Put(i, TestSupport.RandomString()); } Client.Shutdown(); Client = null; map.Get(0); }
public void TestPutWithNonSmartRouting() { var cm = ((HazelcastClientProxy)_client).GetClient().GetConnectionManager(); var map = _client.GetMap <int, int>(TestSupport.RandomString()); var n = 1000; for (var i = 0; i < n; i++) { map.Put(i, i); Assert.AreEqual(1, cm.ActiveConnections.Count); } }
protected object GenerateKeyForPartition(IHazelcastInstance client, int partitionId) { var partitionService = ((HazelcastClientProxy)client).GetClient().GetClientPartitionService(); while (true) { var randomKey = TestSupport.RandomString(); if (partitionService.GetPartitionId(randomKey) == partitionId) { return(randomKey); } } }
public void TestGetDistributedObjects() { var map = Client.GetMap <int, int>(TestSupport.RandomString()); var topic = Client.GetTopic <int>(TestSupport.RandomString()); var semaphore = Client.GetSemaphore(TestSupport.RandomString()); Assert.AreEqual(3, Client.GetDistributedObjects().Count); map.Destroy(); topic.Destroy(); semaphore.Destroy(); Assert.AreEqual(0, Client.GetDistributedObjects().Count); }
public void TestOperationAfterShutdown() { var member = _remoteController.startMember(_cluster.Id); var client = CreateClient(); var map = client.GetMap <int, string>(TestSupport.RandomString()); for (var i = 0; i < 100; i++) { map.Put(i, TestSupport.RandomString()); } client.Shutdown(); map.Get(0); }
public void TestCreds() { // do a normal IMap operation // expect it to work with Kerberos authentication / authorization var user = new User { Name = "qsdf" }; var map = Client.GetMap <string, User>(TestSupport.RandomString()); map.Put("x", user); var mapUser = map.Get("x"); Assert.AreEqual(user.Name, mapUser.Name); }