use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.
the class ClientReconnectTest method testClientReconnectOnClusterDown.
@Test
public void testClientReconnectOnClusterDown() throws Exception {
final HazelcastInstance h1 = hazelcastFactory.newHazelcastInstance();
ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().setConnectionAttemptLimit(Integer.MAX_VALUE);
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
final CountDownLatch connectedLatch = new CountDownLatch(2);
client.getLifecycleService().addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
connectedLatch.countDown();
}
});
IMap<String, String> m = client.getMap("default");
h1.shutdown();
hazelcastFactory.newHazelcastInstance();
assertOpenEventually(connectedLatch);
assertNull(m.put("test", "test"));
assertEquals("test", m.get("test"));
}
use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.
the class ClientRegressionWithMockNetworkTest method testDeadlock_whenDoingOperationFromLifecycleListener_withNearCache.
@Test
public void testDeadlock_whenDoingOperationFromLifecycleListener_withNearCache() {
String mapName = randomMapName();
EvictionConfig evictionConfig = new EvictionConfig().setMaximumSizePolicy(ENTRY_COUNT).setSize(1);
NearCacheConfig nearCacheConfig = new NearCacheConfig().setName(mapName).setEvictionConfig(evictionConfig);
ClientConfig clientConfig = new ClientConfig().addNearCacheConfig(nearCacheConfig).setExecutorPoolSize(1);
HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
hazelcastFactory.newHazelcastInstance();
final CountDownLatch latch = new CountDownLatch(1);
final IMap<Object, Object> map = client.getMap(mapName);
client.getLifecycleService().addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
if (event.getState() == LifecycleState.CLIENT_DISCONNECTED) {
map.get(1);
map.get(2);
latch.countDown();
}
}
});
instance.shutdown();
assertOpenEventually(latch);
}
use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.
the class ClientCacheNearCacheStaleReadTest method setUp.
@Before
public void setUp() throws Exception {
TestHazelcastFactory factory = new TestHazelcastFactory();
valuePut = new AtomicInteger(0);
stop = new AtomicBoolean(false);
failed = new AtomicBoolean(false);
assertionViolationCount = new AtomicInteger(0);
Config config = new Config();
config.setProperty(GroupProperty.CACHE_INVALIDATION_MESSAGE_BATCH_FREQUENCY_SECONDS.getName(), "2");
member = factory.newHazelcastInstance(config);
ClientConfig clientConfig = getClientConfig(CACHE_NAME);
clientConfig.setProperty("hazelcast.invalidation.max.tolerated.miss.count", "0");
client = factory.newHazelcastClient(clientConfig);
CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
cache = cacheManager.createCache(CACHE_NAME, createCacheConfig(inMemoryFormat));
}
use of com.hazelcast.client.config.ClientConfig 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);
}
use of com.hazelcast.client.config.ClientConfig in project hazelcast by hazelcast.
the class ClientNearCacheInvalidationTest method setup.
@Before
public void setup() {
hazelcastFactory = new TestHazelcastFactory();
member = hazelcastFactory.newHazelcastInstance(getConfig());
if (MEMBER_COUNT > 1) {
HazelcastInstance[] allMembers = new HazelcastInstance[MEMBER_COUNT];
allMembers[0] = member;
for (int i = 1; i < MEMBER_COUNT; i++) {
allMembers[i] = hazelcastFactory.newHazelcastInstance(getConfig());
}
waitAllForSafeState(allMembers);
}
ClientConfig clientConfig = createClientConfig();
clientConfig.addNearCacheConfig(createNearCacheConfig(inMemoryFormat));
HazelcastClientProxy client = (HazelcastClientProxy) hazelcastFactory.newHazelcastClient(clientConfig);
NearCacheManager nearCacheManager = client.client.getNearCacheManager();
CachingProvider provider = HazelcastClientCachingProvider.createCachingProvider(client);
HazelcastClientCacheManager cacheManager = (HazelcastClientCacheManager) provider.getCacheManager();
HazelcastServerCacheManager memberCacheManager = (HazelcastServerCacheManager) HazelcastServerCachingProvider.createCachingProvider(member).getCacheManager();
ICache<Object, String> cache = cacheManager.createCache(DEFAULT_CACHE_NAME, createCacheConfig(inMemoryFormat));
ICache<Object, String> memberCache = member.getCacheManager().getCache(CacheUtil.getPrefixedCacheName(DEFAULT_CACHE_NAME, null, null));
NearCache<Data, String> nearCache = nearCacheManager.getNearCache(cacheManager.getCacheNameWithPrefix(DEFAULT_CACHE_NAME));
testContext = new NearCacheTestContext(client, member, cacheManager, memberCacheManager, nearCacheManager, cache, memberCache, nearCache);
// make sure several partitions are populated with data
for (int i = 0; i < 1000; i++) {
testContext.memberCache.put(Integer.toString(i), Integer.toString(i));
}
}
Aggregations