use of com.hazelcast.internal.nearcache.NearCacheTestContext in project hazelcast by hazelcast.
the class ClientCacheNearCacheBasicTest method createContext.
@Override
protected <K, V> com.hazelcast.internal.nearcache.NearCacheTestContext<K, V, Data, String> createContext() {
ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
CacheConfig<K, V> cacheConfig = createCacheConfig(nearCacheConfig);
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(getConfig());
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
CachingProvider memberProvider = HazelcastServerCachingProvider.createCachingProvider(member);
HazelcastServerCacheManager memberCacheManager = (HazelcastServerCacheManager) memberProvider.getCacheManager();
NearCacheManager nearCacheManager = client.client.getNearCacheManager();
CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(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);
ICache<K, V> memberCache = memberCacheManager.createCache(DEFAULT_NEAR_CACHE_NAME, cacheConfig);
NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheNameWithPrefix);
return new NearCacheTestContext<K, V, Data, String>(client.getSerializationService(), client, member, new ICacheDataStructureAdapter<K, V>(clientCache), new ICacheDataStructureAdapter<K, V>(memberCache), false, nearCache, nearCacheManager, cacheManager, memberCacheManager);
}
use of com.hazelcast.internal.nearcache.NearCacheTestContext in project hazelcast by hazelcast.
the class ClientCacheNearCachePreloaderTest method createClientContext.
private <K, V> NearCacheTestContext<K, V, Data, String> createClientContext(CacheConfig<K, V> cacheConfig) {
ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
NearCacheManager nearCacheManager = client.client.getNearCacheManager();
CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
String cacheNameWithPrefix = cacheManager.getCacheNameWithPrefix(nearCacheConfig.getName());
ICache<K, V> clientCache = cacheManager.createCache(nearCacheConfig.getName(), cacheConfig);
NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheNameWithPrefix);
return new com.hazelcast.internal.nearcache.NearCacheTestContext<K, V, Data, String>(client.getSerializationService(), client, null, new ICacheDataStructureAdapter<K, V>(clientCache), null, false, nearCache, nearCacheManager, cacheManager, null);
}
use of com.hazelcast.internal.nearcache.NearCacheTestContext in project hazelcast by hazelcast.
the class ClientMapNearCacheBasicTest method createContext.
@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext() {
ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(getConfig());
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
IMap<K, V> memberMap = member.getMap(DEFAULT_NEAR_CACHE_NAME);
IMap<K, V> clientMap = client.getMap(DEFAULT_NEAR_CACHE_NAME);
NearCacheManager nearCacheManager = client.client.getNearCacheManager();
NearCache<Data, String> nearCache = nearCacheManager.getNearCache(DEFAULT_NEAR_CACHE_NAME);
return new NearCacheTestContext<K, V, Data, String>(client.getSerializationService(), client, member, new IMapDataStructureAdapter<K, V>(clientMap), new IMapDataStructureAdapter<K, V>(memberMap), false, nearCache, nearCacheManager);
}
use of com.hazelcast.internal.nearcache.NearCacheTestContext in project hazelcast by hazelcast.
the class ClientMapNearCachePreloaderTest method testPreloadNearCacheLock_withSharedMapConfig_concurrently.
@Test(timeout = TEST_TIMEOUT)
public void testPreloadNearCacheLock_withSharedMapConfig_concurrently() throws Exception {
nearCacheConfig.getPreloaderConfig().setDirectory("");
int nThreads = 10;
ThreadPoolExecutor pool = (ThreadPoolExecutor) newFixedThreadPool(nThreads);
final NearCacheTestContext context = createContext(true);
final CountDownLatch startLatch = new CountDownLatch(nThreads);
final CountDownLatch finishLatch = new CountDownLatch(nThreads);
for (int i = 0; i < nThreads; i++) {
pool.execute(new Runnable() {
@Override
public void run() {
startLatch.countDown();
try {
startLatch.await();
} catch (InterruptedException e) {
currentThread().interrupt();
}
IMap<String, String> map = context.nearCacheInstance.getMap(nearCacheConfig.getName() + currentThread());
for (int i = 0; i < 100; i++) {
map.put("key-" + currentThread() + "-" + i, "value-" + currentThread() + "-" + i);
}
finishLatch.countDown();
}
});
}
finishLatch.await();
pool.shutdownNow();
}
use of com.hazelcast.internal.nearcache.NearCacheTestContext in project hazelcast by hazelcast.
the class ClientMapNearCachePreloaderTest method createContext.
@Override
protected <K, V> NearCacheTestContext<K, V, Data, String> createContext(boolean createClient) {
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(getConfig());
IMap<K, V> memberMap = member.getMap(nearCacheConfig.getName());
if (!createClient) {
return new NearCacheTestContext<K, V, Data, String>(getSerializationService(member), member, new IMapDataStructureAdapter<K, V>(memberMap), false, null, null);
}
NearCacheTestContext<K, V, Data, String> clientContext = createClientContext();
return new NearCacheTestContext<K, V, Data, String>(clientContext.serializationService, clientContext.nearCacheInstance, member, clientContext.nearCacheAdapter, new IMapDataStructureAdapter<K, V>(memberMap), false, clientContext.nearCache, clientContext.nearCacheManager);
}
Aggregations