use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class CacheHazelcastInstanceAwareTest method test_inject_hazelcastInstance_to_entryProcessor_if_itIs_hazelcastInstanceAware.
@Test
public void test_inject_hazelcastInstance_to_entryProcessor_if_itIs_hazelcastInstanceAware() {
long id = generateUniqueHazelcastInjectionId();
CacheConfig<Integer, Integer> cacheConfig = createCacheConfig(CACHE_NAME);
HazelcastInstance hazelcastInstance = createInstance();
CacheManager cacheManager = createCachingProvider(hazelcastInstance).getCacheManager();
Cache<Integer, Integer> cache = cacheManager.createCache(CACHE_NAME, cacheConfig);
cache.invoke(1, new HazelcastInstanceAwareEntryProcessor(id));
assertEquals("Hazelcast instance has not been injected into entry processor!", Boolean.TRUE, HAZELCAST_INSTANCE_INJECTION_RESULT_MAP.get(id));
}
use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class CacheHazelcastInstanceAwareTest method test_inject_hazelcastInstance_to_completionListener_if_itIs_hazelcastInstanceAware.
@Test
public void test_inject_hazelcastInstance_to_completionListener_if_itIs_hazelcastInstanceAware() {
final long id = generateUniqueHazelcastInjectionId();
CacheConfig<Integer, Integer> cacheConfig = createCacheConfig(CACHE_NAME);
HazelcastInstance hazelcastInstance = createInstance();
CacheManager cacheManager = createCachingProvider(hazelcastInstance).getCacheManager();
Cache<Integer, Integer> cache = cacheManager.createCache(CACHE_NAME, cacheConfig);
cache.loadAll(new HashSet<Integer>(), false, new HazelcastInstanceAwareCompletionListener(id));
assertEqualsEventually(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return HAZELCAST_INSTANCE_INJECTION_RESULT_MAP.get(id);
}
}, Boolean.TRUE);
}
use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class CacheHazelcastInstanceAwareTest method test_inject_hazelcastInstance_to_entryListener_if_itIs_hazelcastInstanceAware.
@Test
public void test_inject_hazelcastInstance_to_entryListener_if_itIs_hazelcastInstanceAware() {
long id1 = generateUniqueHazelcastInjectionId();
long id2 = generateUniqueHazelcastInjectionId();
CacheConfig<Integer, Integer> cacheConfig = createCacheConfig(CACHE_NAME);
cacheConfig.addCacheEntryListenerConfiguration(new HazelcastInstanceAwareCacheEntryListenerConfiguration(id1, id2));
HazelcastInstance hazelcastInstance = createInstance();
CacheManager cacheManager = createCachingProvider(hazelcastInstance).getCacheManager();
cacheManager.createCache(CACHE_NAME, cacheConfig);
assertEquals("Hazelcast instance has not been injected into entry listener factory!", Boolean.TRUE, HAZELCAST_INSTANCE_INJECTION_RESULT_MAP.get(id1));
assertEquals("Hazelcast instance has not been injected into entry listener!", Boolean.TRUE, HAZELCAST_INSTANCE_INJECTION_RESULT_MAP.get(id2));
}
use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class CacheSplitBrainTest method createCache.
private static Cache createCache(HazelcastInstance hazelcastInstance, CacheConfig cacheConfig) {
CachingProvider cachingProvider1 = HazelcastServerCachingProvider.createCachingProvider(hazelcastInstance);
CacheManager cacheManager1 = cachingProvider1.getCacheManager();
return cacheManager1.createCache(cacheConfig.getName(), cacheConfig);
}
use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class ClientCacheRecordStateStressTest method all_records_are_readable_state_in_the_end.
@Test
public void all_records_are_readable_state_in_the_end() throws Exception {
HazelcastInstance member = factory.newHazelcastInstance();
CachingProvider provider = HazelcastServerCachingProvider.createCachingProvider(member);
final CacheManager serverCacheManager = provider.getCacheManager();
factory.newHazelcastInstance();
factory.newHazelcastInstance();
// populated from member.
CacheConfig cacheConfig = new CacheConfig();
cacheConfig.getEvictionConfig().setMaximumSizePolicy(ENTRY_COUNT).setSize(MAX_VALUE);
final Cache memberCache = serverCacheManager.createCache(cacheName, cacheConfig);
for (int i = 0; i < KEY_SPACE; i++) {
memberCache.put(i, i);
}
ClientConfig clientConfig = new ClientConfig();
NearCacheConfig nearCacheConfig = new NearCacheConfig();
nearCacheConfig.setInvalidateOnChange(true).setLocalUpdatePolicy(localUpdatePolicy).getEvictionConfig().setMaximumSizePolicy(ENTRY_COUNT).setSize(MAX_VALUE);
clientConfig.addNearCacheConfig(nearCacheConfig);
List<Thread> threads = new ArrayList<Thread>();
// member
for (int i = 0; i < PUT_THREAD_COUNT; i++) {
Put put = new Put(memberCache);
threads.add(put);
}
// client
HazelcastClientProxy client = (HazelcastClientProxy) factory.newHazelcastClient(clientConfig);
CachingProvider clientCachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
CacheManager cacheManager = clientCachingProvider.getCacheManager();
final Cache clientCache = cacheManager.createCache(cacheName, cacheConfig);
for (int i = 0; i < GET_ALL_THREAD_COUNT; i++) {
GetAll getAll = new GetAll(clientCache);
threads.add(getAll);
}
for (int i = 0; i < PUT_ALL_THREAD_COUNT; i++) {
PutAll putAll = new PutAll(clientCache);
threads.add(putAll);
}
for (int i = 0; i < PUT_IF_ABSENT_THREAD_COUNT; i++) {
PutIfAbsent putIfAbsent = new PutIfAbsent(clientCache);
threads.add(putIfAbsent);
}
for (int i = 0; i < GET_THREAD_COUNT; i++) {
Get get = new Get(clientCache);
threads.add(get);
}
for (int i = 0; i < REMOVE_THREAD_COUNT; i++) {
Remove remove = new Remove(clientCache);
threads.add(remove);
}
for (int i = 0; i < CLEAR_THREAD_COUNT; i++) {
Clear clear = new Clear(clientCache);
threads.add(clear);
}
// start threads
for (Thread thread : threads) {
thread.start();
}
// stress for a while
sleepSeconds(TEST_RUN_SECONDS);
// stop threads
stop.set(true);
for (Thread thread : threads) {
thread.join();
}
assertFinalRecordStateIsReadPermitted(clientCache, member);
}
Aggregations