public void testSharedLoader() throws Exception { CacheContainer cm1 = null, cm2 = null; try { sharedCacheLoader.set(true); cm1 = createCacheManager(tmpDirectory1); Cache c1 = cm1.getCache(cacheName); verifyNoDataOnLoader(c1); verifyNoData(c1); writeInitialData(c1); // starting the second cache would initialize an in-memory state transfer but not a persistent // one since the loader is shared cm2 = createCacheManager(tmpDirectory2); Cache c2 = cm2.getCache(cacheName); TestingUtil.blockUntilViewsReceived(60000, c1, c2); verifyInitialDataOnLoader(c1); verifyInitialData(c1); verifyNoDataOnLoader(c2); verifyNoData(c2); } finally { if (cm1 != null) cm1.stop(); if (cm2 != null) cm2.stop(); sharedCacheLoader.set(false); } }
protected CacheContainer createCacheManager(String tmpDirectory) { // increment the DIMCS store id FileCacheStoreConfig cfg = new FileCacheStoreConfig(); cfg.setLocation(tmpDirectory); cfg.setPurgeSynchronously(true); // for more accurate unit testing cfg.setFetchPersistentState(true); CacheLoaderManagerConfig clmc = new CacheLoaderManagerConfig(); clmc.addCacheLoaderConfig(cfg); clmc.setShared(sharedCacheLoader.get()); config.setCacheLoaderManagerConfig(clmc); EmbeddedCacheManager cm = addClusterEnabledCacheManager(); cm.defineConfiguration(cacheName, config.clone()); return cm; }