use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.
the class ClientCacheNearCachePreloaderTest method createNearCacheContextBuilder.
private <K, V> NearCacheTestContextBuilder<K, V, Data, String> createNearCacheContextBuilder(CacheConfig<K, V> cacheConfig) {
ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
CachingProvider provider = createClientCachingProvider(client);
HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
String cacheNameWithPrefix = cacheManager.getCacheNameWithPrefix(nearCacheConfig.getName());
ICache<K, V> clientCache = cacheManager.createCache(nearCacheConfig.getName(), cacheConfig);
NearCacheManager nearCacheManager = ((ClientCacheProxy) clientCache).getContext().getNearCacheManager(clientCache.getServiceName());
NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheNameWithPrefix);
return new NearCacheTestContextBuilder<K, V, Data, String>(nearCacheConfig, client.getSerializationService()).setNearCacheInstance(client).setNearCacheAdapter(new ICacheDataStructureAdapter<>(clientCache)).setNearCache(nearCache).setNearCacheManager(nearCacheManager).setCacheManager(cacheManager);
}
use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.
the class ClientCacheNearCacheSerializationCountTest method createNearCacheContextBuilder.
private <K, V> NearCacheTestContextBuilder<K, V, Data, String> createNearCacheContextBuilder(CacheConfig<K, V> cacheConfig) {
ClientConfig clientConfig = getClientConfig();
if (nearCacheConfig != null) {
clientConfig.addNearCacheConfig(nearCacheConfig);
}
prepareSerializationConfig(clientConfig.getSerializationConfig());
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
CachingProvider provider = createClientCachingProvider(client);
HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
String cacheNameWithPrefix = cacheManager.getCacheNameWithPrefix(DEFAULT_NEAR_CACHE_NAME);
ICache<K, V> clientCache = cacheManager.createCache(DEFAULT_NEAR_CACHE_NAME, cacheConfig);
NearCacheManager nearCacheManager = ((ClientCacheProxy) clientCache).getContext().getNearCacheManager(clientCache.getServiceName());
NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheNameWithPrefix);
return new NearCacheTestContextBuilder<K, V, Data, String>(nearCacheConfig, client.getSerializationService()).setNearCacheInstance(client).setNearCacheAdapter(new ICacheDataStructureAdapter<>(clientCache)).setNearCache(nearCache).setNearCacheManager(nearCacheManager).setCacheManager(cacheManager);
}
use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.
the class ClientCacheNearCacheInvalidationTest method createNearCacheTest.
private <K, V, NK, NV> NearCacheTestContext<K, V, NK, NV> createNearCacheTest(String cacheName, NearCacheConfig nearCacheConfig, CacheConfig<K, V> cacheConfig) {
ClientConfig clientConfig = getClientConfig().setProperty(RECONCILIATION_INTERVAL_SECONDS.getName(), "0").addNearCacheConfig(nearCacheConfig);
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
CachingProvider provider = createClientCachingProvider(client);
HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
ICache<K, V> cache = cacheManager.createCache(cacheName, cacheConfig);
NearCacheManager nearCacheManager = ((ClientCacheProxy) cache).getContext().getNearCacheManager(CacheService.SERVICE_NAME);
NearCache<NK, NV> nearCache = nearCacheManager.getNearCache(cacheManager.getCacheNameWithPrefix(cacheName));
NearCacheTestContextBuilder<K, V, NK, NV> builder = new NearCacheTestContextBuilder<>(nearCacheConfig, client.getSerializationService());
return builder.setNearCacheInstance(client).setNearCacheAdapter(new ICacheDataStructureAdapter<>(cache)).setNearCacheManager(nearCacheManager).setNearCache(nearCache).build();
}
use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.
the class ClientCacheMetaDataGeneratorTest method createCacheFromNewClient.
private ICache<Integer, Integer> createCacheFromNewClient() {
HazelcastClientProxy client = (HazelcastClientProxy) factory.newHazelcastClient(clientConfig);
CachingProvider clientCachingProvider = createClientCachingProvider(client);
CacheManager cacheManager = clientCachingProvider.getCacheManager();
ICache<Integer, Integer> cache = (ICache<Integer, Integer>) cacheManager.createCache(CACHE_NAME, cacheConfig);
assertInstanceOf(NearCachedClientCacheProxy.class, cache);
return cache;
}
use of com.hazelcast.client.impl.clientside.HazelcastClientProxy in project hazelcast by hazelcast.
the class ClientCacheInvalidationMetadataDistortionTest method ensure_nearCachedClient_and_member_data_sync_eventually.
@Test
public void ensure_nearCachedClient_and_member_data_sync_eventually() {
final Config config = createConfig();
final HazelcastInstance member = hazelcastFactory.newHazelcastInstance(config);
CachingProvider provider = createServerCachingProvider(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 < CACHE_SIZE; i++) {
memberCache.put(i, i);
}
ClientConfig clientConfig = createClientConfig();
clientConfig.addNearCacheConfig(createNearCacheConfig(BINARY));
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
CachingProvider clientCachingProvider = createClientCachingProvider(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 < CACHE_SIZE; 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(CACHE_SIZE);
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);
assertJoinable(distortUuid, distortSequence, populateNearCache, put);
assertTrueEventually(new AssertTask() {
@Override
public void run() {
for (int i = 0; i < CACHE_SIZE; i++) {
Integer valueSeenFromMember = memberCache.get(i);
Integer valueSeenFromClient = clientCache.get(i);
assertEquals(valueSeenFromMember, valueSeenFromClient);
}
}
});
}
Aggregations