01: package junit;
02:
03: import ri.cache.ReferenceCacheManager;
04: import ri.cache.ReferenceCache;
05:
06: import javax.cache.Cache;
07: import javax.cache.CacheManager;
08: import javax.cache.CacheException;
09: import javax.cache.spi.CacheLoader;
10:
11: import org.apache.commons.logging.Log;
12: import org.apache.commons.logging.LogFactory;
13:
14: /**
15: * The central class to be modified if the expected test is to be run on different implementations. The rest of this
16: * test suite deals only with javax.cache.* and javax.cache.spi.* interfaces.
17: *
18: * @author <a href="mailto:manik@jboss.org">Manik Surtani</a>
19: */
20: public class CacheImplementationHelper {
21: private static final String CACHE_MANAGER_URI = "cachemanager://ri.cache.CacheManager/DefaultCache";
22: private static final String DEFAULT_CACHE_NAME = "DefaultCache";
23: private static final String LOADER_CACHE_NAME = "LoaderCache";
24:
25: private static Log log = LogFactory
26: .getLog(CacheImplementationHelper.class);
27:
28: private static CacheManager cacheManager;
29:
30: static {
31: try {
32: cacheManager = new ReferenceCacheManager(CACHE_MANAGER_URI);
33: } catch (CacheException e) {
34: log.error("Unable to init class", e);
35: }
36: }
37:
38: /**
39: * returns a new cache instance configured to use the specified cache loader.
40: * @param cacheLoader should not be null
41: * @return a running cache
42: */
43: public static Cache getCacheWithLoader(CacheLoader cacheLoader)
44: throws CacheException {
45: // TODO: How do we inject the necessary cache loader?
46: return cacheManager.getCache(LOADER_CACHE_NAME);
47: }
48:
49: public static CacheManager getCacheManager() throws CacheException {
50: if (cacheManager.getState() != CacheManager.State.RUNNING) {
51: // TODO: how do we start the cache manager? :/
52: }
53: return cacheManager;
54: }
55:
56: public static Cache getDefaultCache() throws CacheException {
57: return cacheManager.getCache(DEFAULT_CACHE_NAME);
58: }
59:
60: /**
61: * Create a new, unregistered cache.
62: */
63: public static Cache newCache(String name) {
64: return new ReferenceCache(name);
65: }
66: }
|