use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.
the class NearCacheManagerTestSupport method doCreateAndGetNearCache.
void doCreateAndGetNearCache() {
NearCacheManager nearCacheManager = createNearCacheManager();
assertNull(nearCacheManager.getNearCache(DEFAULT_NEAR_CACHE_NAME));
NearCache createdNearCache1 = createNearCache(nearCacheManager, DEFAULT_NEAR_CACHE_NAME);
assertNotNull(createdNearCache1);
NearCache createdNearCache2 = createNearCache(nearCacheManager, DEFAULT_NEAR_CACHE_NAME);
assertNotNull(createdNearCache2);
assertEquals(createdNearCache1, createdNearCache2);
Collection<NearCache> nearCaches = nearCacheManager.listAllNearCaches();
assertEquals(1, nearCaches.size());
assertEquals(createdNearCache1, nearCaches.iterator().next());
}
use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.
the class NearCacheManagerTestSupport method doClearNearCacheAndClearAllNearCaches.
void doClearNearCacheAndClearAllNearCaches() {
NearCacheManager nearCacheManager = createNearCacheManager();
for (int i = 0; i < DEFAULT_NEAR_CACHE_COUNT; i++) {
createNearCache(nearCacheManager, DEFAULT_NEAR_CACHE_NAME + "-" + i);
}
Collection<NearCache> nearCaches1 = nearCacheManager.listAllNearCaches();
assertEquals(DEFAULT_NEAR_CACHE_COUNT, nearCaches1.size());
for (int i = 0; i < DEFAULT_NEAR_CACHE_COUNT; i++) {
assertTrue(nearCacheManager.clearNearCache(DEFAULT_NEAR_CACHE_NAME + "-" + i));
}
Collection<NearCache> nearCaches2 = nearCacheManager.listAllNearCaches();
// clear doesn't remove Near Cache, just clears it
assertEquals(DEFAULT_NEAR_CACHE_COUNT, nearCaches2.size());
nearCacheManager.clearAllNearCaches();
Collection<NearCache> nearCaches3 = nearCacheManager.listAllNearCaches();
// clear all doesn't remove Near Caches, just clears them
assertEquals(DEFAULT_NEAR_CACHE_COUNT, nearCaches3.size());
assertFalse(nearCacheManager.clearNearCache(DEFAULT_NEAR_CACHE_NAME + "-" + DEFAULT_NEAR_CACHE_COUNT));
}
use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.
the class NearCacheManagerTestSupport method doListNearCaches.
void doListNearCaches() {
NearCacheManager nearCacheManager = createNearCacheManager();
Set<String> nearCacheNames = new HashSet<String>();
Collection<NearCache> nearCaches1 = nearCacheManager.listAllNearCaches();
assertEquals(0, nearCaches1.size());
for (int i = 0; i < DEFAULT_NEAR_CACHE_COUNT; i++) {
String nearCacheName = DEFAULT_NEAR_CACHE_NAME + "-" + i;
createNearCache(nearCacheManager, nearCacheName);
nearCacheNames.add(nearCacheName);
}
Collection<NearCache> nearCaches2 = nearCacheManager.listAllNearCaches();
assertEquals(DEFAULT_NEAR_CACHE_COUNT, nearCaches2.size());
for (NearCache nearCache : nearCaches2) {
assertContains(nearCacheNames, nearCache.getName());
}
}
use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.
the class NearCacheTestSupport method assertNearCacheExpiration.
protected void assertNearCacheExpiration(final IMap<Integer, Integer> map, final int size) {
assertTrueEventually(() -> {
NearCache nearCache = getBackingNearCache(map);
NearCacheStats stats = getNearCacheStats(map);
// make assertions over near cache's backing map size.
long nearCacheSize = nearCache.size();
assertEquals(format("Expected zero near cache size but found: %d, [%s] ", nearCacheSize, stats), 0, nearCacheSize);
// make assertions over near cache stats.
long ownedEntryCount = stats.getOwnedEntryCount();
assertEquals(format("Expected no owned entry but found: %d, [%s]", ownedEntryCount, stats), 0, ownedEntryCount);
long ownedEntryMemoryCost = stats.getOwnedEntryMemoryCost();
assertEquals(format("Expected zero memory cost but found: %d, [%s]", ownedEntryMemoryCost, stats), 0, ownedEntryMemoryCost);
long expiredCount = stats.getExpirations();
assertEquals(format("Expected to see all entries as expired but found: %d, [%s]", expiredCount, stats), size, expiredCount);
long evictedCount = stats.getEvictions();
assertEquals(format("Expiration should not trigger eviction stat but found: %d, [%s]", evictedCount, stats), 0, evictedCount);
});
}
use of com.hazelcast.internal.nearcache.NearCache in project hazelcast by hazelcast.
the class NearCacheTest method testBasicUsage.
@Test
public void testBasicUsage() {
int clusterSize = 3;
int mapSize = 5000;
final String mapName = "testBasicUsage";
Config config = getConfig();
config.getMapConfig(mapName).setNearCacheConfig(newNearCacheConfig().setInvalidateOnChange(true));
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(clusterSize);
final HazelcastInstance[] instances = factory.newInstances(config);
IMap<Integer, Integer> map = instances[0].getMap(mapName);
populateMap(map, mapSize);
for (HazelcastInstance instance : instances) {
IMap<Integer, Integer> instanceMap = instance.getMap(mapName);
for (int i = 0; i < mapSize; i++) {
assertNotNull(instanceMap.get(i));
}
}
for (int i = 0; i < mapSize; i++) {
map.put(i, i * 2);
}
for (HazelcastInstance instance : instances) {
IMap<Object, Object> m = instance.getMap(mapName);
for (int i = 0; i < mapSize; i++) {
assertNotNull(m.get(i));
}
}
for (HazelcastInstance instance : instances) {
int nearCacheSize = getNearCache(mapName, instance).size();
assertTrue("Near Cache size should be > 0 but was " + nearCacheSize, nearCacheSize > 0);
}
map.clear();
assertTrueEventually(() -> {
for (HazelcastInstance instance : instances) {
NearCache nearCache = getNearCache(mapName, instance);
int size = nearCache.size();
assertEquals("Near Cache size should be 0 but was " + size, 0, size);
}
});
}
Aggregations