use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class CacheConfigTest method createCache_WhenCacheConfigIsNull.
@Test
public void createCache_WhenCacheConfigIsNull() {
String cacheName = "cacheNull";
CacheManager cacheManager = Caching.getCachingProvider().getCacheManager();
try {
cacheManager.createCache(cacheName, (Configuration<Object, Object>) null);
fail("NullPointerException expected");
} catch (NullPointerException expected) {
EmptyStatement.ignore(expected);
}
}
use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class CacheConfigTest method cacheManagerByLocationFileTest.
@Test
public void cacheManagerByLocationFileTest() throws URISyntaxException {
URI uri = new URI("MY-SCOPE");
String urlStr = configUrl1.toString();
assertEquals("file", urlStr.substring(0, 4));
Properties properties = new Properties();
properties.setProperty(HazelcastCachingProvider.HAZELCAST_CONFIG_LOCATION, urlStr);
CacheManager cacheManager = Caching.getCachingProvider().getCacheManager(uri, null, properties);
assertNotNull(cacheManager);
URI uri2 = new URI("MY-SCOPE-OTHER");
String urlStr2 = configUrl2.toString();
assertEquals("file", urlStr2.substring(0, 4));
Properties properties2 = new Properties();
properties2.setProperty(HazelcastCachingProvider.HAZELCAST_CONFIG_LOCATION, urlStr2);
CacheManager cacheManager2 = Caching.getCachingProvider().getCacheManager(uri2, null, properties2);
assertNotNull(cacheManager2);
assertEquals(2, Hazelcast.getAllHazelcastInstances().size());
}
use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class CacheReadWriteThroughTest method do_putAsAdd_writeThrough.
private void do_putAsAdd_writeThrough(boolean acceptAll) {
final int ENTRY_COUNT = 100;
final String cacheName = randomName();
CacheManager cacheManager = cachingProvider.getCacheManager();
assertNotNull(cacheManager);
assertNull(cacheManager.getCache(cacheName));
PutCacheWriter putCacheWriter;
if (acceptAll) {
putCacheWriter = new PutCacheWriter();
} else {
putCacheWriter = new PutCacheWriter(new ModValueChecker(ENTRY_COUNT / 10));
}
CacheConfig<Integer, Integer> config = createCacheConfig();
config.setWriteThrough(true);
config.setCacheWriterFactory(FactoryBuilder.factoryOf(putCacheWriter));
ICache<Integer, Integer> cache = cacheManager.createCache(cacheName, config).unwrap(ICache.class);
assertNotNull(cache);
List<Integer> bannedKeys = new ArrayList<Integer>();
for (int i = 0; i < ENTRY_COUNT; i++) {
try {
cache.put(i, i);
} catch (CacheWriterException e) {
bannedKeys.add(i);
}
}
assertEquals(ENTRY_COUNT - bannedKeys.size(), cache.size());
for (Integer bannedKey : bannedKeys) {
assertNull(cache.get(bannedKey));
}
}
use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class CacheReadWriteThroughTest method loadAll_readThrough.
private void loadAll_readThrough(boolean throwError) throws Exception {
final String cacheName = randomName();
CacheManager cacheManager = cachingProvider.getCacheManager();
assertNotNull(cacheManager);
assertNull(cacheManager.getCache(cacheName));
CacheConfig<Integer, Integer> config = createCacheConfig();
config.setReadThrough(true);
config.setCacheLoaderFactory(FactoryBuilder.factoryOf(new GetAllAsyncCacheLoader(throwError)));
Cache<Integer, Integer> cache = cacheManager.createCache(cacheName, config);
assertNotNull(cache);
Set<Integer> keys = new HashSet<Integer>();
for (int i = 0; i < 150; i++) {
keys.add(i);
}
final CountDownLatch latch = new CountDownLatch(1);
cache.loadAll(keys, false, new CompletionListener() {
@Override
public void onCompletion() {
latch.countDown();
}
@Override
public void onException(Exception e) {
e.printStackTrace();
latch.countDown();
}
});
assertOpenEventually(latch);
if (!throwError) {
assertEquals(100, cache.unwrap(ICache.class).size());
}
}
use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class CacheReadWriteThroughTest method test_getAll_readThrough.
@Test
public void test_getAll_readThrough() throws Exception {
final String cacheName = randomName();
CacheManager cacheManager = cachingProvider.getCacheManager();
assertNotNull(cacheManager);
assertNull(cacheManager.getCache(cacheName));
CacheConfig<Integer, Integer> config = createCacheConfig();
config.setReadThrough(true);
config.setCacheLoaderFactory(FactoryBuilder.factoryOf(new GetAllAsyncCacheLoader(false)));
Cache<Integer, Integer> cache = cacheManager.createCache(cacheName, config);
assertNotNull(cache);
Set<Integer> keys = new HashSet<Integer>();
for (int i = 0; i < 150; i++) {
keys.add(i);
}
Map<Integer, Integer> loaded = cache.getAll(keys);
assertEquals(100, loaded.size());
}
Aggregations