protected void doDestroyNearCacheAndDestroyAllNearCaches() { 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.destroyNearCache(DEFAULT_NEAR_CACHE_NAME + "-" + i)); } Collection<NearCache> nearCaches2 = nearCacheManager.listAllNearCaches(); // destroy also removes Near Cache assertEquals(0, nearCaches2.size()); assertFalse( nearCacheManager.clearNearCache(DEFAULT_NEAR_CACHE_NAME + "-" + DEFAULT_NEAR_CACHE_COUNT)); for (int i = 0; i < DEFAULT_NEAR_CACHE_COUNT; i++) { createNearCache(nearCacheManager, DEFAULT_NEAR_CACHE_NAME + "-" + i); } Collection<NearCache> nearCaches3 = nearCacheManager.listAllNearCaches(); assertEquals(DEFAULT_NEAR_CACHE_COUNT, nearCaches3.size()); nearCacheManager.destroyAllNearCaches(); Collection<NearCache> nearCaches4 = nearCacheManager.listAllNearCaches(); // destroy all also removes Near Caches assertEquals(0, nearCaches4.size()); }
protected 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()); }
protected 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)); }
@Override public void destroy() { if (nearCache != null) { removeInvalidationListener(); nearCacheManager.destroyNearCache(nearCache.getName()); } if (statisticsEnabled) { statistics.clear(); } super.destroy(); }
protected 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) { assertTrue(nearCacheNames.contains(nearCache.getName())); } }
private void initNearCache() { NearCacheConfig nearCacheConfig = clientContext.getClientConfig().getNearCacheConfig(name); if (nearCacheConfig != null) { cacheOnUpdate = nearCacheConfig.getLocalUpdatePolicy() == NearCacheConfig.LocalUpdatePolicy.CACHE; NearCacheContext nearCacheContext = new NearCacheContext( nearCacheManager, clientContext.getSerializationService(), createNearCacheExecutor(clientContext.getExecutionService())); nearCache = nearCacheManager.getOrCreateNearCache(nameWithPrefix, nearCacheConfig, nearCacheContext); registerInvalidationListener(); } }
protected NearCache createNearCache(NearCacheManager nearCacheManager, String name) { return nearCacheManager.getOrCreateNearCache( name, createNearCacheConfig(DEFAULT_NEAR_CACHE_NAME, NearCacheConfig.DEFAULT_MEMORY_FORMAT), createNearCacheContext()); }