public void ThreadLocal_Dispose() { // store the pool in a weak reference since we don't want to force a strong reference ourselves. var poolRef = new WeakReference(_bufferPoolThreadLocal.Get()); // call clear; kills the strong references. _bufferPoolThreadLocal.Dispose(); TestSupport.AssertTrueEventually(() => { GC.Collect(); Assert.Null(poolRef.Target); }); }
public void TestNearCacheLfuEviction() { var lfuMap = Client.GetMap <object, object>("nearCacheMapLfu-" + TestSupport.RandomString()); var keys = new List <object>(); for (var i = 0; i < MaxSize; i++) { lfuMap.Put(i, i); keys.Add(i); } // make sure all keys are cached lfuMap.GetAll(keys); // make keys in sublist accessed again var subList = keys.Take(MaxSize / 2).ToList(); lfuMap.GetAll(subList); // Add another item, triggering eviction lfuMap.Put(MaxSize, MaxSize); lfuMap.Get(MaxSize); var cache = GetNearCache(lfuMap); // var sl = new SortedList<int, int>(); // // foreach (var cacheRecord in cache.Records.Keys) // { // sl.Add(ClientInternal.SerializationService.ToObject<int>(cacheRecord), 0); // } // foreach (var lazy in cache.Records.Values) // { // if (lazy.Value.Hit.Get() > 0) // { // Console.WriteLine($"non zero hit {ClientInternal.SerializationService.ToObject<int>(lazy.Value.Key)}"); // } // } TestSupport.AssertTrueEventually(() => { Assert.IsTrue(cache.Records.Count <= MaxSize, cache.Records.Count + " should be less than " + MaxSize); foreach (var key in subList) { var keyData = ToData(key); Assert.IsTrue(cache.Records.ContainsKey(keyData), "key " + key + " not found in cache"); } }); }
public void TestNearCache_notContainsStaleValue_whenUpdatedByMultipleThreads() { var threads = new List <Thread>(); for (int i = 0; i < NearCacheInvalidatorThreadCount; i++) { var invalidationThread = new Thread(() => { while (!_stop.Get()) { Assert.True(PopulateMapWithRandomValueFromServer(_mapName, EntryCount).Success); } }); threads.Add(invalidationThread); } for (var i = 0; i < NearCachePutterThreadCount; i++) { var putterThread = new Thread(() => { while (!_stop.Get()) { for (int j = 0; j < EntryCount; j++) { _map.Get(j); } } }); threads.Add(putterThread); } foreach (var thread in threads) { thread.Start(); } Thread.Sleep(TimeSpan.FromSeconds(5)); _stop.Set(true); foreach (var thread in threads) { thread.Join(); } TestSupport.AssertTrueEventually(() => { AssertNoStaleDataExistInNearCache(); }); }
public void TestSequenceUpdateIfKeyRemoveAtServer() { const string theKey = "key"; _map.Put(theKey, "value"); var partitionId = ClientInternal.PartitionService.GetPartitionId(theKey); var nc = GetNearCache(_map) as NearCache; var metaDataContainer = nc.RepairingHandler.GetMetaDataContainer(partitionId); var initialSequence = metaDataContainer.Sequence; RemoveKeyAtServer(_map.Name, theKey); TestSupport.AssertTrueEventually(() => { var latestSequence = metaDataContainer.Sequence; Assert.Greater(latestSequence, initialSequence); }); }
public void Get_whenCleared() { // forces the creation of a bufferpool. _bufferPoolThreadLocal.Get(); // we kill all strong references. _bufferPoolThreadLocal.Dispose(); TestSupport.AssertTrueEventually(() => { GC.Collect(); try { _bufferPoolThreadLocal.Get(); Assert.Fail(); } catch (HazelcastInstanceNotActiveException) { } }); }
public void TestNearCacheGetAsync() { _map.Put("key", "value"); var val = _map.GetAsync("key"); var result = val.Result; Assert.AreEqual("value", result); var clientNearCache = GetNearCache(_map); TestSupport.AssertTrueEventually(() => { Assert.AreEqual(1, clientNearCache.Records.Count); }); val = _map.GetAsync("key"); result = val.Result; Assert.AreEqual("value", result); var cacheRecord = clientNearCache.Records.Values.ToArray()[0]; Assert.AreEqual(1, cacheRecord.Value.Hit.Get()); }
private void TestInvalidate(Action <IMap <string, string>, string> invalidatingAction) { var map = Client.GetMap <string, string>("nearCacheMapInvalidate-" + TestSupport.RandomString()); try { map.Put("key", "value"); var val = map.Get("key"); Assert.AreEqual("value", val); var clientNearCache = GetNearCache(map); Assert.AreEqual(1, clientNearCache.Records.Count); var client = CreateClient(); try { invalidatingAction(client.GetMap <string, string>(map.Name), "key"); } finally { client.Shutdown(); } TestSupport.AssertTrueEventually(() => { Assert.IsFalse(clientNearCache.Records.ContainsKey(ToData("key")), "key should have been invalidated"); }); } finally { map.Destroy(); } }
public void TestNearCacheTtlEviction() { var map = Client.GetMap <int, int>("nearCacheTtl-" + TestSupport.RandomString()); var keys = Enumerable.Range(0, 10).ToList(); foreach (var k in keys) { map.Put(k, k); } map.GetAll(keys); var cache = GetNearCache(map); Assert.AreEqual(keys.Count, cache.Records.Count); TestSupport.AssertTrueEventually(() => { map.Get(100); //force ttl check foreach (var k in keys) { var keyData = ToData(k); Assert.IsFalse(cache.Records.ContainsKey(keyData), "key " + k + " should have expired."); } }); }
public void TestInvalidationDistortionSequenceAndGuid() { var mapName = "nearCachedMapDistortion"; var mapSize = 100000; var stopTest = new AtomicBoolean(false); Assert.True(PopulateMapFromServer(mapName, mapSize).Success); var clientMap = Client.GetMap <int, int>(mapName); var populateNearCache = new Thread(() => { while (!stopTest.Get()) { for (int i = 0; i < mapSize; i++) { clientMap.Get(i); } } }); var distortSequence = new Thread(() => { while (!stopTest.Get()) { var response = DistortRandomPartitionSequence(mapName); Assert.True(response.Success, response.Message); Thread.Sleep(TimeSpan.FromSeconds(1)); } }); var distortUuid = new Thread(() => { while (!stopTest.Get()) { var response = DistortRandomPartitionUuid(); Assert.True(response.Success, response.Message); Thread.Sleep(TimeSpan.FromSeconds(5)); } }); var putOnMember = new Thread(() => { var random = new Random(); // change some data while (!stopTest.Get()) { var key = random.Next(mapSize); var value = random.Next(int.MaxValue); Assert.True(PutOnMember(key, value, mapName).Success); Thread.Sleep(100); } }); // start threads putOnMember.Start(); populateNearCache.Start(); distortSequence.Start(); distortUuid.Start(); Thread.Sleep(TimeSpan.FromSeconds(60)); // stop threads stopTest.Set(true); distortUuid.Join(); distortSequence.Join(); populateNearCache.Join(); putOnMember.Join(); TestSupport.AssertTrueEventually(() => { var allValueFromMember = GetAllValueFromMember(mapSize, mapName); for (int i = 0; i < mapSize; i++) { var valueSeenFromMember = allValueFromMember[i] as int?; var valueSeenFromClient = clientMap.Get(i); Assert.AreEqual(valueSeenFromMember, valueSeenFromClient); } }); }