use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class InvalidationMetadataDistortionTest method ensure_nearCachedClient_and_member_data_sync_eventually.
@Test
public void ensure_nearCachedClient_and_member_data_sync_eventually() throws Exception {
final int cacheSize = 100000;
final AtomicBoolean stopTest = new AtomicBoolean();
final Config config = createConfig();
final HazelcastInstance member = hazelcastFactory.newHazelcastInstance(config);
CachingProvider provider = HazelcastServerCachingProvider.createCachingProvider(serverInstance);
CacheManager serverCacheManager = provider.getCacheManager();
// populated from member.
final Cache<Integer, Integer> memberCache = serverCacheManager.createCache(DEFAULT_CACHE_NAME, createCacheConfig(BINARY));
for (int i = 0; i < cacheSize; i++) {
memberCache.put(i, i);
}
ClientConfig clientConfig = createClientConfig();
clientConfig.addNearCacheConfig(createNearCacheConfig(BINARY));
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
CachingProvider clientCachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
final Cache<Integer, Integer> clientCache = clientCachingProvider.getCacheManager().createCache(DEFAULT_CACHE_NAME, createCacheConfig(BINARY));
Thread populateNearCache = new Thread(new Runnable() {
public void run() {
while (!stopTest.get()) {
for (int i = 0; i < cacheSize; i++) {
clientCache.get(i);
}
}
}
});
Thread distortSequence = new Thread(new Runnable() {
@Override
public void run() {
while (!stopTest.get()) {
distortRandomPartitionSequence(DEFAULT_CACHE_NAME, member);
sleepSeconds(1);
}
}
});
Thread distortUuid = new Thread(new Runnable() {
@Override
public void run() {
while (!stopTest.get()) {
distortRandomPartitionUuid(member);
sleepSeconds(5);
}
}
});
Thread put = new Thread(new Runnable() {
public void run() {
// change some data
while (!stopTest.get()) {
int key = getInt(cacheSize);
int value = getInt(Integer.MAX_VALUE);
memberCache.put(key, value);
sleepAtLeastMillis(100);
}
}
});
// start threads
put.start();
populateNearCache.start();
distortSequence.start();
distortUuid.start();
sleepSeconds(60);
// stop threads
stopTest.set(true);
distortUuid.join();
distortSequence.join();
populateNearCache.join();
put.join();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
for (int i = 0; i < cacheSize; i++) {
Integer valueSeenFromMember = memberCache.get(i);
Integer valueSeenFromClient = clientCache.get(i);
assertEquals(valueSeenFromMember, valueSeenFromClient);
}
}
});
}
use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class ClientCacheConfigTest method cacheManagerByLocationClasspathTest.
@Test
public void cacheManagerByLocationClasspathTest() throws URISyntaxException {
assertEquals(0, HazelcastClient.getAllHazelcastClients().size());
URI uri1 = new URI("MY-SCOPE");
Properties properties = new Properties();
properties.setProperty(HazelcastCachingProvider.HAZELCAST_CONFIG_LOCATION, "classpath:hazelcast-client-c1.xml");
CacheManager cacheManager = Caching.getCachingProvider().getCacheManager(uri1, null, properties);
assertNotNull(cacheManager);
assertEquals(1, HazelcastClient.getAllHazelcastClients().size());
Caching.getCachingProvider().close();
cacheManager.close();
assertEquals(0, HazelcastClient.getAllHazelcastClients().size());
}
use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class ClientCachePartitionLostListenerTest method test_cachePartitionLostListener_registered.
@Test
public void test_cachePartitionLostListener_registered() {
final String cacheName = randomName();
HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
final CachingProvider cachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
final CacheManager cacheManager = cachingProvider.getCacheManager();
final CacheConfig<Integer, String> cacheConfig = new CacheConfig<Integer, String>();
final Cache<Integer, String> cache = cacheManager.createCache(cacheName, cacheConfig);
final ICache iCache = cache.unwrap(ICache.class);
iCache.addPartitionLostListener(new CachePartitionLostListener() {
@Override
public void partitionLost(CachePartitionLostEvent event) {
}
});
assertRegistrationsSizeEventually(instance, cacheName, 1);
}
use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class ClientCachePartitionLostListenerTest method test_cachePartitionLostListener_invoked.
@Test
public void test_cachePartitionLostListener_invoked() {
final String cacheName = randomName();
HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
final HazelcastServerCachingProvider cachingProvider = createCachingProvider(instance);
final CacheManager cacheManager = cachingProvider.getCacheManager();
final CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
config.setBackupCount(0);
cacheManager.createCache(cacheName, config);
final CachingProvider clientCachingProvider = HazelcastClientCachingProvider.createCachingProvider(client);
final CacheManager clientCacheManager = clientCachingProvider.getCacheManager();
final Cache<Integer, String> cache = clientCacheManager.getCache(cacheName);
final ICache iCache = cache.unwrap(ICache.class);
final EventCollectingCachePartitionLostListener listener = new EventCollectingCachePartitionLostListener();
iCache.addPartitionLostListener(listener);
final CacheService cacheService = getNode(instance).getNodeEngine().getService(CacheService.SERVICE_NAME);
final int partitionId = 5;
cacheService.onPartitionLost(new IPartitionLostEvent(partitionId, 0, null));
assertCachePartitionLostEventEventually(listener, partitionId);
}
use of javax.cache.CacheManager in project hazelcast by hazelcast.
the class CacheClusterWideIteratorTest method getCache.
private Cache<Integer, Integer> getCache() {
String cacheName = randomString();
CacheManager cacheManager = cachingProvider.getCacheManager();
CacheConfig<Integer, Integer> config = createCacheConfig();
return cacheManager.createCache(cacheName, config);
}
Aggregations