@Override public void release() { underlyingCache.close(); } }
@Override public void destroyCache(String cacheName) { requireNotClosed(); Cache<?, ?> cache = caches.remove(cacheName); if (cache != null) { cache.close(); } }
@Override public void close() { if (isClosed()) { return; } synchronized (cacheFactory) { if (!isClosed()) { cacheProvider.close(uri, classLoaderReference.get()); for (Cache<?, ?> cache : caches.values()) { cache.close(); } closed = true; } } }
@Override public void close() { if (isClosed()) { return; } synchronized (cacheProvider) { if (!isClosed()) { cacheProvider.close(uri, classLoader); for (Cache<?, ?> cache : caches.values()) { try { cache.close(); } catch (Exception e) { // skip } } if (redisson != null) { redisson.shutdown(); } closed = true; } } }
@Override public void close() { if (isClosed()) { return; } synchronized (cacheProvider) { if (!isClosed()) { cacheProvider.close(uri, classLoader); for (Cache<?, ?> cache : caches.values()) { try { cache.close(); } catch (Exception e) { // skip } } if (redisson != null) { redisson.shutdown(); } closed = true; } } }
@Override public void invalidate(Class<?> type) { Cache cache = getCache(type); if (cache != null) { cache.clear(); String cacheName = getCacheName(model.typeOf(type)); cacheManager.destroyCache(cacheName); synchronized (caches) { caches.remove(type); } cache.close(); } }
/** * Tests start -> destroy -> start -> close using CacheManager. */ @Test public void testTckStyleCreateDestroyClose() throws Exception { startGridsMultiThreaded(gridCount()); CacheManager mgr = Caching.getCachingProvider().getCacheManager(); String cacheName = "cache"; mgr.createCache(cacheName, new MutableConfiguration<Integer, String>().setTypes(Integer.class, String.class)); mgr.destroyCache(cacheName); Cache<Integer, String> cache = mgr.createCache(cacheName, new MutableConfiguration<Integer, String>().setTypes(Integer.class, String.class)); cache.close(); // Check second close succeeds without exception. cache.close(); try { cache.get(1); fail(); } catch (IllegalStateException ignored) { // No-op; } }
@Override public void close() { grantCache.close(); super.close(); } }
@Test public void put_Closed() { cache.close(); try { cache.put(null, null); fail("should have thrown an exception - cache closed"); } catch (IllegalStateException e) { //good } }
@Test public void putIfAbsent_Closed() { cache.close(); try { cache.putIfAbsent(null, null); fail("should have thrown an exception - cache closed"); } catch (IllegalStateException e) { //good } }
@Test public void getAndReplace_Closed() { cache.close(); try { cache.getAndReplace(null, null); fail("should have thrown an exception - cache closed"); } catch (IllegalStateException e) { //good } }
@Test public void iterator_Closed() { cache.close(); try { cache.iterator(); fail("should have thrown an exception - cache closed"); } catch (IllegalStateException e) { //good } }
@Test public void removeAll_1arg_Closed() { cache.close(); try { cache.removeAll(null); fail("should have thrown an exception - cache closed"); } catch (IllegalStateException e) { //good } }
@Test public void load_Closed() { cache.close(); try { cache.loadAll(null, true, null); fail("should have thrown an exception - cache closed"); } catch (IllegalStateException e) { //good } }
@Test public void getAll_Closed() { cache.close(); try { cache.getAll(null); fail("should have thrown an exception - cache closed"); } catch (IllegalStateException e) { //good } }
@Test public void getAndPut_Closed() { cache.close(); try { cache.getAndPut(null, null); fail("should have thrown an exception - cache closed"); } catch (IllegalStateException e) { //good } }
@Test public void removeAll_0arg_Closed() { cache.close(); try { cache.removeAll(); fail("should have thrown an exception - cache closed"); } catch (IllegalStateException e) { //good } }
@Test public void containsKey_Closed() { cache.close(); try { cache.containsKey(null); fail("should have thrown an exception - cache closed"); } catch (IllegalStateException e) { //good } }
@Override public void call() throws Exception { AdvancedCache<Integer, String> advCache = cm.<Integer, String>getCache().getAdvancedCache(); Cache<Integer, String> local = FunctionalJCache.create(advCache); assertFalse(local.isClosed()); local.close(); assertTrue(local.isClosed()); } });