Search in sources :

Example 1 with CacheService

use of org.exoplatform.services.cache.CacheService in project kernel by exoplatform.

the class TestCacheService method testCacheFactory.

public void testCacheFactory() throws Exception {
    InitParams params = new InitParams();
    ObjectParameter param = new ObjectParameter();
    param.setName("NoImpl");
    ExoCacheConfig config = new ExoCacheConfig();
    config.setName(param.getName());
    param.setObject(config);
    params.addParameter(param);
    param = new ObjectParameter();
    param.setName("KnownImpl");
    config = new ExoCacheConfig();
    config.setName(param.getName());
    config.setImplementation("org.exoplatform.services.cache.concurrent.ConcurrentFIFOExoCache");
    param.setObject(config);
    params.addParameter(param);
    param = new ObjectParameter();
    param.setName("UnKnownImpl");
    config = new ExoCacheConfig();
    config.setName(param.getName());
    config.setImplementation("fakeImpl");
    param.setObject(config);
    params.addParameter(param);
    param = new ObjectParameter();
    param.setName("UnKnownImplButCorrectFQN");
    config = new ExoCacheConfig();
    config.setName(param.getName());
    config.setImplementation("java.lang.String");
    param.setObject(config);
    params.addParameter(param);
    param = new ObjectParameter();
    param.setName("NoImpl-MyExoCacheConfig");
    config = new MyExoCacheConfig();
    config.setName(param.getName());
    param.setObject(config);
    params.addParameter(param);
    param = new ObjectParameter();
    param.setName("KnownImpl-MyExoCacheConfig");
    config = new MyExoCacheConfig();
    config.setName(param.getName());
    config.setImplementation("org.exoplatform.services.cache.FIFOExoCache");
    param.setObject(config);
    params.addParameter(param);
    param = new ObjectParameter();
    param.setName("UnKnownImpl-MyExoCacheConfig");
    config = new MyExoCacheConfig();
    config.setName(param.getName());
    config.setImplementation("fakeImpl");
    param.setObject(config);
    params.addParameter(param);
    param = new ObjectParameter();
    param.setName("UnKnownImplButCorrectFQN-MyExoCacheConfig");
    config = new MyExoCacheConfig();
    config.setName(param.getName());
    config.setImplementation("java.lang.String");
    param.setObject(config);
    params.addParameter(param);
    CacheService cs = new CacheServiceImpl(params, new MyExoCacheFactory());
    assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("NoImpl").getClass(), cs.getCacheInstance("NoImpl") instanceof MyExoCache);
    assertTrue("Expected type ConcurrentFIFOExoCache found " + cs.getCacheInstance("KnownImpl").getClass(), cs.getCacheInstance("KnownImpl") instanceof ConcurrentFIFOExoCache);
    assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("UnKnownImpl").getClass(), cs.getCacheInstance("UnKnownImpl") instanceof MyExoCache);
    assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("UnKnownImplButCorrectFQN").getClass(), cs.getCacheInstance("UnKnownImplButCorrectFQN") instanceof MyExoCache);
    assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("NoImpl-MyExoCacheConfig").getClass(), cs.getCacheInstance("NoImpl-MyExoCacheConfig") instanceof MyExoCache);
    assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("KnownImpl-MyExoCacheConfig").getClass(), cs.getCacheInstance("KnownImpl-MyExoCacheConfig") instanceof MyExoCache);
    assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("UnKnownImpl-MyExoCacheConfig").getClass(), cs.getCacheInstance("UnKnownImpl-MyExoCacheConfig") instanceof MyExoCache);
    assertTrue("Expected type MyExoCache found " + cs.getCacheInstance("UnKnownImplButCorrectFQN-MyExoCacheConfig").getClass(), cs.getCacheInstance("UnKnownImplButCorrectFQN-MyExoCacheConfig") instanceof MyExoCache);
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) ObjectParameter(org.exoplatform.container.xml.ObjectParameter) CacheServiceImpl(org.exoplatform.services.cache.impl.CacheServiceImpl) ExoCacheConfig(org.exoplatform.services.cache.ExoCacheConfig) ConcurrentFIFOExoCache(org.exoplatform.services.cache.concurrent.ConcurrentFIFOExoCache) CacheService(org.exoplatform.services.cache.CacheService)

Example 2 with CacheService

use of org.exoplatform.services.cache.CacheService in project kernel by exoplatform.

the class TestExoCacheFactoryImpl method testCacheFactory.

public void testCacheFactory() {
    CacheService service_ = (CacheService) pc.getComponentInstanceOfType(CacheService.class);
    @SuppressWarnings("rawtypes") ExoCache cache = service_.getCacheInstance("myCache");
    assertTrue("expect an instance of MCExoCache but was " + cache, cache instanceof MCExoCache);
}
Also used : ExoCache(org.exoplatform.services.cache.ExoCache) CacheService(org.exoplatform.services.cache.CacheService)

Aggregations

CacheService (org.exoplatform.services.cache.CacheService)2 InitParams (org.exoplatform.container.xml.InitParams)1 ObjectParameter (org.exoplatform.container.xml.ObjectParameter)1 ExoCache (org.exoplatform.services.cache.ExoCache)1 ExoCacheConfig (org.exoplatform.services.cache.ExoCacheConfig)1 ConcurrentFIFOExoCache (org.exoplatform.services.cache.concurrent.ConcurrentFIFOExoCache)1 CacheServiceImpl (org.exoplatform.services.cache.impl.CacheServiceImpl)1