@Test
  public void testAddManager() throws Exception {
    LOG.info("START TEST");

    cacheName = "sampleCacheSyncBootstrap";
    if (manager1.getStatus() != Status.STATUS_SHUTDOWN) {
      manager1.shutdown();
    }

    manager1 = new CacheManager(CacheTestUtilities.ASYNC_CONFIG_URL1);
    CacheTestUtilities.waitForBootstrap(manager1, MAX_WAIT_TIME);

    final Ehcache cache1 = manager1.getEhcache(cacheName);
    final Ehcache cache2 = manager2.getEhcache(cacheName);
    final Ehcache cache3 = manager3.getEhcache(cacheName);
    final Ehcache cache4 = manager4.getEhcache(cacheName);

    // Wait up to 2 seconds for the caches to become coherent
    CacheTestUtilities.waitForReplication(0, MAX_WAIT_TIME, cache1, cache2, cache3, cache4);

    cache1.put(new Element(1, new Date()));
    cache2.put(new Element(2, new Date()));

    // Wait up to 2 seconds for the caches to become coherent
    CacheTestUtilities.waitForReplication(2, MAX_WAIT_TIME, cache1, cache2, cache3, cache4);

    assertEquals(2, cache1.getKeys().size());
    assertEquals(2, cache2.getKeys().size());
    assertEquals(2, cache3.getKeys().size());
    assertEquals(2, cache4.getKeys().size());

    LOG.info("END TEST");
  }
  public void testAddManager() throws Exception {
    cacheName = SAMPLE_CACHE1;
    if (manager1.getStatus() != Status.STATUS_SHUTDOWN) manager1.shutdown();

    Thread.currentThread().sleep(1000);
    manager1 =
        new CacheManager(
            AbstractCacheTest.TEST_CONFIG_DIR
                + "distribution/jgroups/ehcache-distributed-jgroups.xml");
    Thread.currentThread().sleep(3000);
    manager2.clearAll();

    Thread.currentThread().sleep(1000);

    manager2.getEhcache(cacheName).put(new Element(new Integer(2), new Date()));
    manager1.getEhcache(cacheName).put(new Element(new Integer(3), new Date()));
    Thread.currentThread().sleep(2000);

    assertTrue(
        manager1.getEhcache(cacheName).getKeys().size()
                == manager2.getEhcache(cacheName).getKeys().size()
            && manager1.getEhcache(cacheName).getKeys().size()
                == manager3.getEhcache(cacheName).getKeys().size()
            && manager1.getEhcache(cacheName).getKeys().size()
                == manager4.getEhcache(cacheName).getKeys().size()
            && manager1.getEhcache(cacheName).getKeys().size() == 2);
  }
 @Bean
 public net.sf.ehcache.CacheManager customEhCacheCacheManager() {
   net.sf.ehcache.CacheManager cacheManager = mock(net.sf.ehcache.CacheManager.class);
   given(cacheManager.getStatus()).willReturn(Status.STATUS_ALIVE);
   given(cacheManager.getCacheNames()).willReturn(new String[0]);
   return cacheManager;
 }
 protected Cache getCache() {
   if (manager == null
       || Status.STATUS_SHUTDOWN.equals(manager.getStatus())
       || cache == null
       || !Status.STATUS_ALIVE.equals(cache.getStatus())) {
     cache = createCache();
   } else {
     cache = getManager().getCache(cacheId);
   }
   return cache;
 }
 public void dispose() {
   if (cacheManager.getStatus().equals(Status.STATUS_ALIVE)) {
     log.info("Disposing cache: " + ehcache);
     if (this.ehcache != null) {
       cacheManager.removeCache(this.ehcache.getName());
       ehcache = null;
     }
   } else {
     log.debug("Not disposing cache, because cacheManager is not alive: " + ehcache);
   }
 }
示例#6
0
 /** Service INIT */
 public void init() {
   if (cacheManager == null) {
     throw new IllegalStateException("init(): Ehcache CacheManager is null!");
   }
   log.info(
       "INIT: "
           + cacheManager.getStatus()
           + ", caches: "
           + Arrays.asList(cacheManager.getCacheNames()));
   if (serverConfigurationService.getBoolean("memory.ehcache.jmx", true)) {
     EhCacheJmxRegistration registration = new EhCacheJmxRegistration();
     registration.register(cacheManager);
   }
 }
示例#7
0
 public CacheFactory() {
   log.info(
       String.format(
           "Cache manager is %s: %s", manager.getStatus(), manager.getActiveConfigurationText()));
 }
 public CacheManager getManager() {
   if (manager == null || Status.STATUS_SHUTDOWN.equals(manager.getStatus())) {
     manager = CacheManager.create();
   }
   return manager;
 }
 public void shutdown() {
   if (cacheManager.getStatus() == Status.STATUS_ALIVE) cacheManager.shutdown();
 }