@Test public void testPutGet() throws Exception { ApplicationConfig config = WikittyConfig.getConfig(); WikittyCacheJCS cache = new WikittyCacheJCS(config); Wikitty w = new WikittyImpl(); cache.putWikitty(w); Wikitty w2 = cache.getWikitty(w.getWikittyId()); Assert.assertEquals(w, w2); }
/** * Override to method in sub tests to change wikitty client implementation. * * @return wikitty client implementation to use in current test case instance */ @Override protected WikittyClient getWikittyClient() { wikittyConfig.setOption(WikittyConfigOption .JCS_DEFAULT_CACHEATTRIBUTES_MAXOBJECTS.getKey(), "10"); WikittyService wikittyService = new WikittyServiceInMemory(wikittyConfig); wikittyService = new WikittyServiceCached(wikittyConfig, wikittyService, new WikittyCacheJCS(wikittyConfig)); WikittyClient client = new WikittyClient(wikittyConfig, wikittyService); return client; }
/** * * @param config not used currently but necessary in futur to configure the cache * Create a soft cache. */ public WikittyCacheJCS(ApplicationConfig config) { try { List<String> priorityExtensions = config.getOptionAsList( WikittyConfigOption.WIKITTY_CACHE_PRIORITY_EXTENSIONS.getKey()).getOption(); getPriorityExtensions().addAll(priorityExtensions); CompositeCacheManager cacheMgr = CompositeCacheManager.getUnconfiguredInstance(); cacheMgr.configure(config.getFlatOptions()); priorityCache = new GroupCacheAccess(cacheMgr.getCache("priority")); wikittyCache = new GroupCacheAccess(cacheMgr.getCache("wikitty")); extensionCache = new GroupCacheAccess(cacheMgr.getCache("extension")); // JCS ne permet pas de passer un Properties mais seulement un nom de fichier :( // JCS.setConfigFilename(config.getConfigFileName()); // wikittyCache = JCS.getInstance("wikitty"); } catch (Exception eee) { throw new WikittyException("Can't initialise JCS cache", eee); } }
/** * Override to method in sub tests to change wikitty client implementation. * * @return wikitty client implementation to use in current test case instance */ @Override protected WikittyClient getWikittyClient() { wikittyConfig.setOption( WikittyConfigOption.WIKITTY_CACHE_RESTORE_COPIES.getKey(), "true"); WikittyService wikittyService = new WikittyServiceInMemory(wikittyConfig); wikittyService = new WikittyServiceCached(wikittyConfig, wikittyService, new WikittyCacheJCS(wikittyConfig)); WikittyClient client = new WikittyClient(wikittyConfig, wikittyService); return client; }