use of com.hazelcast.client.cache.impl.HazelcastClientCachingProvider in project hazelcast by hazelcast.
the class CacheClientListenerTest method testEntryListenerUsingMemberConfig.
@Test
public void testEntryListenerUsingMemberConfig() {
System.setProperty("hazelcast.config", "classpath:hazelcast-cache-entrylistener-test.xml");
Hazelcast.newHazelcastInstance();
ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().addAddress("127.0.0.1");
HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
HazelcastClientCachingProvider cachingProvider = createClientCachingProvider(client);
CacheManager cacheManager = cachingProvider.getCacheManager();
Cache<String, String> cache = cacheManager.getCache("entrylistenertestcache");
cache.put("foo", "bar");
HazelcastInstance client2 = HazelcastClient.newHazelcastClient(clientConfig);
HazelcastClientCachingProvider cachingProvider2 = createClientCachingProvider(client2);
CacheManager cacheManager2 = cachingProvider2.getCacheManager();
Cache<String, String> cache2 = cacheManager2.getCache("entrylistenertestcache");
client.shutdown();
// sleep enough so that the put entry is expired
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Trigger expiry event
cache2.get("foo");
final CountDownLatch expiredLatch = ClientCacheEntryExpiredLatchCountdownListener.getExpiredLatch();
assertCountEventually("The expired event should only be received one time", 1, expiredLatch, 3);
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals("Expired event is received more than once", 1, expiredLatch.getCount());
}
}, 3);
}
use of com.hazelcast.client.cache.impl.HazelcastClientCachingProvider in project hazelcast by hazelcast.
the class ClientCacheCreationTest method createSingleCache_whenMemberDown_throwsOperationTimeoutException.
@Test(expected = OperationTimeoutException.class)
public void createSingleCache_whenMemberDown_throwsOperationTimeoutException() {
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
ClientConfig clientConfig = new ClientConfig();
clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
clientConfig.setProperty(ClientProperty.INVOCATION_TIMEOUT_SECONDS.getName(), "2");
HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
HazelcastClientCachingProvider cachingProvider = createClientCachingProvider(client);
CacheManager cacheManager = cachingProvider.getCacheManager();
hazelcastInstance.shutdown();
MutableConfiguration configuration = new MutableConfiguration();
cacheManager.createCache("xmlCache", configuration);
}
use of com.hazelcast.client.cache.impl.HazelcastClientCachingProvider in project hazelcast by hazelcast.
the class ClientCacheCreationTest method createSingleCache_whenMemberBounce.
@Test
public void createSingleCache_whenMemberBounce() throws InterruptedException {
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
ClientConfig clientConfig = new ClientConfig();
clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
HazelcastClientCachingProvider cachingProvider = createClientCachingProvider(client);
final CacheManager cacheManager = cachingProvider.getCacheManager();
hazelcastInstance.shutdown();
final CountDownLatch cacheCreated = new CountDownLatch(1);
new Thread(new Runnable() {
@Override
public void run() {
MutableConfiguration configuration = new MutableConfiguration();
cacheManager.createCache("xmlCache", configuration);
cacheCreated.countDown();
}
}).start();
// leave some gap to let create cache to start and retry
Thread.sleep(2000);
Hazelcast.newHazelcastInstance();
assertOpenEventually(cacheCreated);
}
use of com.hazelcast.client.cache.impl.HazelcastClientCachingProvider in project hazelcast by hazelcast.
the class ClientCacheNearCacheCacheOnUpdateTest method newNearCachedCache.
private ICache<Integer, Integer> newNearCachedCache(NearCacheConfig.LocalUpdatePolicy localUpdatePolicy) {
NearCacheConfig nearCacheConfig = getNearCacheConfig(localUpdatePolicy);
ClientConfig clientConfig = getClientConfig().addNearCacheConfig(nearCacheConfig);
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
CachingProvider provider = new HazelcastClientCachingProvider(client);
HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
return cacheManager.createCache(DEFAULT_CACHE_NAME, newCacheConfig(InMemoryFormat.BINARY));
}
use of com.hazelcast.client.cache.impl.HazelcastClientCachingProvider in project hazelcast by hazelcast.
the class ClientCacheCreationTest method recreateCacheOnRestartedCluster_whenMaxConcurrentInvocationLow.
@Test
public void recreateCacheOnRestartedCluster_whenMaxConcurrentInvocationLow() {
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
ClientConfig clientConfig = new ClientConfig();
clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
clientConfig.setProperty(ClientProperty.MAX_CONCURRENT_INVOCATIONS.getName(), "1");
// disable metrics collection (the periodic send statistics task may interfere with the test)
clientConfig.getMetricsConfig().setEnabled(false);
// disable backup acknowledgements (the backup listener registration may interfere with the test)
clientConfig.setBackupAckToClientEnabled(false);
HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
HazelcastClientCachingProvider cachingProvider = createClientCachingProvider(client);
final CacheManager cacheManager = cachingProvider.getCacheManager();
MutableConfiguration configuration = new MutableConfiguration();
// ensure cache is created despite the low concurrent invocation limit
assertTrueEventually(() -> {
try {
cacheManager.createCache("xmlCache", configuration);
} catch (HazelcastOverloadException e) {
throw new AssertionError("Could not create cache due to " + "low concurrent invocation count.");
}
});
IExecutorService executorService = client.getExecutorService("exec");
// keep the slot for one invocation to test if client can reconnect even if all slots are kept
CountDownLatch testFinished = new CountDownLatch(1);
executorService.submit(new ExecutorServiceTestSupport.SleepingTask(0), new ExecutionCallback<Boolean>() {
@Override
public void onResponse(Boolean response) {
try {
testFinished.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(Throwable t) {
try {
testFinished.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
hazelcastInstance.shutdown();
HazelcastInstance instance = Hazelcast.newHazelcastInstance();
assertTrueEventually(new AssertTask() {
@Override
public void run() {
try {
instance.getCacheManager().getCache("xmlCache");
} catch (Exception e) {
fail();
}
}
});
testFinished.countDown();
}
Aggregations