@Override public void close(String reason, Throwable optionalCause) { close(reason, optionalCause, false, false); }
@Override public void close() { close(false); }
@Override public void close(String reason, boolean keepAlive, boolean keepDS) { close(reason, null, keepAlive, keepDS); }
@Override public void close(boolean keepAlive) { close("Normal disconnect", null, keepAlive, false); }
@After public void tearDown() { if (this.cache != null) { this.cache.close(); } }
public void closeAnyPollutedCache() { if (GemFireCacheImpl.getInstance() != null) { GemFireCacheImpl.getInstance().close(); } }
private static final void closeCache() { GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); if (cache != null && !cache.isClosed()) { destroyRegions(cache); cache.close(); } }
@After public void tearDown() { if (cache != null) { cache.close(); } }
close("Shut down all members", null, false, true); } finally { this.shutDownAllFinished.countDown();
@Test public void registerPdxMetaDataThrowsIfInstanceIsNotPDX() { InternalDistributedSystem ds = Fakes.distributedSystem(); CacheConfig cc = new CacheConfig(); TypeRegistry typeRegistry = mock(TypeRegistry.class); GemFireCacheImpl gfc = GemFireCacheImpl.createWithAsyncEventListeners(ds, cc, typeRegistry); try { assertThatThrownBy(() -> gfc.registerPdxMetaData("string")) .isInstanceOf(SerializationException.class) .hasMessage("The instance is not PDX serializable"); } finally { gfc.close(); } }
@Test public void registerPdxMetaDataThrowsIfInstanceNotSerializable() { InternalDistributedSystem ds = Fakes.distributedSystem(); CacheConfig cc = new CacheConfig(); TypeRegistry typeRegistry = mock(TypeRegistry.class); GemFireCacheImpl gfc = GemFireCacheImpl.createWithAsyncEventListeners(ds, cc, typeRegistry); try { assertThatThrownBy(() -> gfc.registerPdxMetaData(new Object())) .isInstanceOf(SerializationException.class).hasMessage("Serialization failed") .hasCauseInstanceOf(NotSerializableException.class); } finally { gfc.close(); } }
@Test public void checkEvictorsClosed() { InternalDistributedSystem ds = Fakes.distributedSystem(); CacheConfig cc = new CacheConfig(); TypeRegistry typeRegistry = mock(TypeRegistry.class); SystemTimer ccpTimer = mock(SystemTimer.class); HeapEvictor he = mock(HeapEvictor.class); OffHeapEvictor ohe = mock(OffHeapEvictor.class); GemFireCacheImpl gfc = GemFireCacheImpl.createWithAsyncEventListeners(ds, cc, typeRegistry); try { gfc.setHeapEvictor(he); gfc.setOffHeapEvictor(ohe); } finally { gfc.close(); } verify(he, times(1)).close(); verify(ohe, times(1)).close(); }
@Test public void checkPurgeCCPTimer() { InternalDistributedSystem ds = Fakes.distributedSystem(); CacheConfig cc = new CacheConfig(); TypeRegistry typeRegistry = mock(TypeRegistry.class); SystemTimer ccpTimer = mock(SystemTimer.class); GemFireCacheImpl gfc = GemFireCacheImpl.createWithAsyncEventListeners(ds, cc, typeRegistry); try { gfc.setCCPTimer(ccpTimer); for (int i = 1; i < GemFireCacheImpl.PURGE_INTERVAL; i++) { gfc.purgeCCPTimer(); verify(ccpTimer, times(0)).timerPurge(); } gfc.purgeCCPTimer(); verify(ccpTimer, times(1)).timerPurge(); for (int i = 1; i < GemFireCacheImpl.PURGE_INTERVAL; i++) { gfc.purgeCCPTimer(); verify(ccpTimer, times(1)).timerPurge(); } gfc.purgeCCPTimer(); verify(ccpTimer, times(2)).timerPurge(); } finally { gfc.close(); } }
@Test public void checkThatAsyncEventListenersUseAllThreadsInPool() { InternalDistributedSystem ds = Fakes.distributedSystem(); CacheConfig cc = new CacheConfig(); TypeRegistry typeRegistry = mock(TypeRegistry.class); GemFireCacheImpl gfc = GemFireCacheImpl.createWithAsyncEventListeners(ds, cc, typeRegistry); try { ThreadPoolExecutor executor = (ThreadPoolExecutor) gfc.getEventThreadPool(); assertEquals(0, executor.getCompletedTaskCount()); assertEquals(0, executor.getActiveCount()); int MAX_THREADS = GemFireCacheImpl.EVENT_THREAD_LIMIT; final CountDownLatch cdl = new CountDownLatch(MAX_THREADS); for (int i = 1; i <= MAX_THREADS; i++) { executor.execute(() -> { cdl.countDown(); try { cdl.await(); } catch (InterruptedException e) { } }); } await().timeout(90, TimeUnit.SECONDS) .untilAsserted(() -> assertEquals(MAX_THREADS, executor.getCompletedTaskCount())); } finally { gfc.close(); } }
close(); // fix for bug 34041 } catch (Throwable ignore) {