@Override public boolean isClosed() { return ehCacheManager.getStatus() == Status.UNINITIALIZED; }
assertThat(e.getMessage(), is("Close not supported from UNINITIALIZED")); assertThat(cacheManager.getStatus(), is(Status.UNINITIALIZED));
@Test public void testCloseWhenRuntimeCacheCreationFails() throws Exception { Store.Provider storeProvider = mock(Store.Provider.class); when(storeProvider.rank(any(Set.class), any(Collection.class))).thenReturn(1); doThrow(new Error("Test EhcacheManager close.")).when(storeProvider).createStore(any(Store.Configuration.class), ArgumentMatchers.<ServiceConfiguration>any()); Map<String, CacheConfiguration<?, ?>> caches = newCacheMap(); DefaultConfiguration config = new DefaultConfiguration(caches, null); final CacheManager cacheManager = new EhcacheManager(config, Arrays.asList( storeProvider, mock(CacheLoaderWriterProvider.class), mock(WriteBehindProvider.class), mock(CacheEventDispatcherFactory.class), mock(CacheEventListenerProvider.class), mock(LocalPersistenceService.class), mock(ResilienceStrategyProvider.class) )); cacheManager.init(); CacheConfiguration<Long, String> cacheConfiguration = new BaseCacheConfiguration<>(Long.class, String.class, null, null, null, ResourcePoolsHelper .createHeapOnlyPools()); try { cacheManager.createCache("cache", cacheConfiguration); fail(); } catch (Error err) { assertThat(err.getMessage(), equalTo("Test EhcacheManager close.")); } cacheManager.close(); assertThat(cacheManager.getStatus(), is(Status.UNINITIALIZED)); }
public static void tearDownCacheManagerAndStatsCollector() throws Exception { if (cacheManager != null && cacheManager.getStatus() == Status.AVAILABLE) { if (nmsService != null) { readTopology().getClient(ehcacheClientIdentifier) .ifPresent(client -> { try { nmsService.stopStatisticCollector(client.getContext().with("cacheManagerName", "my-super-cache-manager")).waitForReturn(); } catch (Exception e) { throw new RuntimeException(e); } }); } cacheManager.close(); } if (nmsService != null) { readTopology().getSingleStripe().getActiveServerEntity(tmsServerEntityIdentifier) .ifPresent(client -> { try { nmsService.stopStatisticCollector(client.getContext()); } catch (Exception e) { throw new RuntimeException(e); } }); managementConnection.close(); } }
@Test(timeout = 60_000) public void test_CACHE_MANAGER_CLOSED() throws Exception { createNmsService(CLUSTER); try (CacheManager cacheManager = newCacheManagerBuilder().with(cluster(CLUSTER.getConnectionURI().resolve("/my-server-entity-1")) .autoCreate() .defaultServerResource("primary-server-resource") .resourcePool("resource-pool-a", 10, MemoryUnit.MB, "secondary-server-resource") // <2> .resourcePool("resource-pool-b", 10, MemoryUnit.MB)) // will take from primary-server-resource // management config .using(new DefaultManagementRegistryConfiguration() .addTags("webapp-1", "server-node-1") .setCacheManagerAlias("my-super-cache-manager")) // cache config .withCache("dedicated-cache-1", newCacheConfigurationBuilder( String.class, String.class, newResourcePoolsBuilder() .heap(10, EntryUnit.ENTRIES) .offheap(1, MemoryUnit.MB) .with(clusteredDedicated("primary-server-resource", 4, MemoryUnit.MB))) .build()) .build(true)) { assertThat(cacheManager.getStatus(), equalTo(Status.AVAILABLE)); waitFor("CACHE_MANAGER_AVAILABLE"); } waitFor("CACHE_MANAGER_CLOSED"); }
assertThat(cacheManager.getStatus(), equalTo(Status.AVAILABLE));
assertThat(cacheManager.getStatus(), equalTo(Status.AVAILABLE));
@Override public boolean isClosed() { return ehCacheManager.getStatus() == Status.UNINITIALIZED; }