Java Code Examples for javax.cache.CacheManager#destroyCache()

The following examples show how to use javax.cache.CacheManager#destroyCache() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CacheMBStatisticsBeanTest.java    From cache2k with Apache License 2.0 6 votes vote down vote up
@Test
public void testExpiryOnCreation() throws Exception {

    // close cache since need to configure cache with ExpireOnCreationPolicy
    CacheManager mgr = cache.getCacheManager();
    mgr.destroyCache(cache.getName());

    MutableConfiguration<Long, String> config = new MutableConfiguration<Long, String>();
    config.setStatisticsEnabled(true);
    config.setTypes(Long.class, String.class);
    config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(ExpireOnCreationPolicy.class));

    cache = mgr.createCache(getTestCacheName(), config);
    cache.put(1L, "hello");
    assertEquals(0L, lookupManagementAttribute(cache, CacheStatistics, "CachePuts"));

    Map<Long, String> map = new HashMap<Long, String>();
    map.put(2L, "goodbye");
    map.put(3L, "world");
    cache.putAll(map);
    assertEquals(0L, lookupManagementAttribute(cache, CacheStatistics, "CachePuts"));
}
 
Example 2
Source File: CacheStopAndDestroySelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 3
Source File: TCKCacheManagerTest.java    From blazingcache with Apache License 2.0 5 votes vote down vote up
@Test(expected = NullPointerException.class)
public void getCacheNullValueClass() {
    String name = "c1";
    CacheManager manager = Caching.getCachingProvider().getCacheManager();
    manager.createCache(name, new MutableConfiguration().setTypes(Long.class, String.class));
    try {
        Caching.getCache(name, Long.class, null);
    } finally {
        manager.destroyCache(name);
    }
}
 
Example 4
Source File: TCKCacheManagerTest.java    From blazingcache with Apache License 2.0 5 votes vote down vote up
@Test
public void removeCache_Null() {
    CacheManager cacheManager = getCacheManager();
    try {
        cacheManager.destroyCache(null);
        fail("should have thrown an exception - cache name null");
    } catch (NullPointerException e) {
        //good
    }
}
 
Example 5
Source File: TCKCacheManagerTest.java    From blazingcache with Apache License 2.0 5 votes vote down vote up
@Test
public void removeCache_There() {
    CacheManager cacheManager = getCacheManager();
    String name1 = "c1";
    cacheManager.createCache(name1, new MutableConfiguration());
    cacheManager.destroyCache(name1);
    assertFalse(cacheManager.getCacheNames().iterator().hasNext());
}
 
Example 6
Source File: TCKCacheManagerTest.java    From blazingcache with Apache License 2.0 5 votes vote down vote up
@Test
public void removeCache_CacheStopped() {
    CacheManager cacheManager = getCacheManager();
    String name1 = "c1";
    cacheManager.createCache(name1, new MutableConfiguration());
    Cache cache1 = cacheManager.getCache(name1);
    cacheManager.destroyCache(name1);
    ensureClosed(cache1);
}
 
Example 7
Source File: TCKCacheManagerTest.java    From blazingcache with Apache License 2.0 5 votes vote down vote up
@Test
public void removeCache_Stopped() {
    CacheManager cacheManager = getCacheManager();
    cacheManager.close();
    try {
        cacheManager.destroyCache("c1");
        fail();
    } catch (IllegalStateException e) {
        //ok
    }
}
 
Example 8
Source File: CacheManagerTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@After
public void teardown() {
  CacheManager cacheManager = getCacheManager();
  for (String cacheName : cacheManager.getCacheNames()) {
    cacheManager.destroyCache(cacheName);
  }
  cacheManager.close();
}
 
Example 9
Source File: CacheManagerTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Test
public void removeCache_Null() {
  CacheManager cacheManager = getCacheManager();
  try {
    cacheManager.destroyCache(null);
    fail("should have thrown an exception - cache name null");
  } catch (NullPointerException e) {
    //good
  }
}
 
Example 10
Source File: CacheManagerTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Test
public void removeCache_There() {
  CacheManager cacheManager = getCacheManager();
  String name1 = "c1";
  cacheManager.createCache(name1, new MutableConfiguration());
  cacheManager.destroyCache(name1);
  assertFalse(cacheManager.getCacheNames().iterator().hasNext());
}
 
Example 11
Source File: CacheManagerTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Test
public void removeCache_CacheStopped() {
  CacheManager cacheManager = getCacheManager();
  String name1 = "c1";
  cacheManager.createCache(name1, new MutableConfiguration());
  Cache cache1 = cacheManager.getCache(name1);
  cacheManager.destroyCache(name1);
  ensureClosed(cache1);
}
 
Example 12
Source File: CacheManagerTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Test
public void removeCache_Stopped() {
  CacheManager cacheManager = getCacheManager();
  cacheManager.close();
  try {
    cacheManager.destroyCache("c1");
    fail();
  } catch (IllegalStateException e) {
    //ok
  }
}
 
Example 13
Source File: CacheManagerManagementTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultipleCacheManagers() throws Exception {
  cacheManager.createCache("new cache", configuration);
  assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(2));

  CacheManager cacheManager2 = getCacheManager();
  cacheManager2.createCache("other cache", configuration);

  assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(4));
  cacheManager.destroyCache("new cache");
  cacheManager2.destroyCache("other cache");
  cacheManager2.close();
}
 
Example 14
Source File: CachingTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@Test(expected = NullPointerException.class)
public void getCacheNullValueClass() {
  String name = "c1";
  CacheManager manager = Caching.getCachingProvider().getCacheManager();
  manager.createCache(name, new MutableConfiguration().setTypes(Long.class, String.class));
  try {
    Caching.getCache(name, Long.class, null);
  } finally {
    manager.destroyCache(name);
  }
}
 
Example 15
Source File: TCKCacheManagerTest.java    From blazingcache with Apache License 2.0 4 votes vote down vote up
@Test
public void removeCache_NotThere() {
    CacheManager cacheManager = getCacheManager();
    cacheManager.destroyCache("c1");
}
 
Example 16
Source File: CacheManagerTest.java    From cache2k with Apache License 2.0 4 votes vote down vote up
@Test
public void removeCache_NotThere() {
  CacheManager cacheManager = getCacheManager();
  cacheManager.destroyCache("c1");
}