use of com.hazelcast.client.proxy.NearCachedClientMapProxy in project hazelcast by hazelcast.
the class ClientMapNearCacheTest method receives_one_clearEvent_after_mapEvictAll_call_from_member.
@Test
public void receives_one_clearEvent_after_mapEvictAll_call_from_member() {
// populate Near Cache
IMap<Integer, Integer> clientMap = getNearCachedMapFromClient(newNearCacheConfig());
populateMap(clientMap, 1000);
populateNearCache(clientMap, 1000);
// member comes
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(newConfig());
// add test listener to count clear events
final ClearEventCounterEventHandler handler = new ClearEventCounterEventHandler();
((NearCachedClientMapProxy) clientMap).addNearCacheInvalidationListener(handler);
// call evictAll
IMap memberMap = member.getMap(clientMap.getName());
memberMap.evictAll();
// sleep for a while to see there is another clear event coming
sleepSeconds(2);
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals("Expecting only 1 clear event", 1, handler.getClearEventCount());
}
});
}
use of com.hazelcast.client.proxy.NearCachedClientMapProxy in project hazelcast by hazelcast.
the class ClientMapNearCacheTest method receives_one_clearEvent_after_mapClear_call_from_member.
@Test
public void receives_one_clearEvent_after_mapClear_call_from_member() {
// start new member and populate map
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(newConfig());
IMap<Integer, Integer> memberMap = member.getMap("test");
populateMap(memberMap, 1000);
// populate client near cache
NearCacheConfig nearCacheConfig = newNearCacheConfig();
ClientConfig clientConfig = newClientConfig();
clientConfig.addNearCacheConfig(nearCacheConfig);
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
IMap<Integer, Integer> clientMap = client.getMap("test");
populateNearCache(clientMap, 1000);
// add test listener to count clear events
final ClearEventCounterEventHandler handler = new ClearEventCounterEventHandler();
((NearCachedClientMapProxy) clientMap).addNearCacheInvalidationListener(handler);
// clear map from member side
memberMap.clear();
// sleep for a while to see there is another clear event coming
sleepSeconds(2);
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals("Expecting only 1 clear event", 1, handler.getClearEventCount());
}
});
}
use of com.hazelcast.client.proxy.NearCachedClientMapProxy in project hazelcast by hazelcast.
the class GetAllTest method ensure_supplied_number_of_keys_are_in_near_cache.
@Test
public void ensure_supplied_number_of_keys_are_in_near_cache() throws Exception {
final int entryCount = 100000;
final String mapName = "test";
factory.newHazelcastInstance();
NearCacheConfig nearCacheConfig = new NearCacheConfig(mapName);
nearCacheConfig.setInvalidateOnChange(true);
ClientConfig clientConfig = new ClientConfig();
clientConfig.addNearCacheConfig(nearCacheConfig);
HazelcastInstance client = factory.newHazelcastClient(clientConfig);
IMap map = client.getMap(mapName);
for (int i = 0; i < entryCount; i++) {
map.put(i, i);
}
HashSet keys = new HashSet();
for (int i = 0; i < entryCount; i++) {
keys.add(i);
}
map.getAll(keys);
assertEquals(entryCount, ((NearCachedClientMapProxy) map).getNearCache().size());
}
use of com.hazelcast.client.proxy.NearCachedClientMapProxy in project hazelcast by hazelcast.
the class ClientMapMetaDataFetcherTest method getRepairingTask.
private RepairingTask getRepairingTask(String mapName, int partition, long givenSequence, UUID givenUuid) {
HazelcastInstance member = factory.newHazelcastInstance();
distortRandomPartitionSequence(mapName, partition, givenSequence, member);
distortRandomPartitionUuid(partition, givenUuid, member);
ClientConfig clientConfig = new ClientConfig().addNearCacheConfig(new NearCacheConfig(mapName));
HazelcastInstance client = factory.newHazelcastClient(clientConfig);
IMap<Integer, Integer> clientMap = client.getMap(mapName);
ClientContext clientContext = ((NearCachedClientMapProxy) clientMap).getClientContext();
return clientContext.getRepairingTask(SERVICE_NAME);
}
use of com.hazelcast.client.proxy.NearCachedClientMapProxy in project hazelcast by hazelcast.
the class InvalidationMemberAddRemoveTest method ensure_nearCachedClient_and_member_data_sync_eventually.
@Test
public void ensure_nearCachedClient_and_member_data_sync_eventually() throws Exception {
final String mapName = "default";
final AtomicBoolean stopTest = new AtomicBoolean();
// members are created.
final Config config = createConfig();
HazelcastInstance member = factory.newHazelcastInstance(config);
factory.newHazelcastInstance(config);
// map is populated form member.
final IMap<Integer, Integer> memberMap = member.getMap(mapName);
for (int i = 0; i < KEY_COUNT; i++) {
memberMap.put(i, i);
}
// a new client comes.
ClientConfig clientConfig = createClientConfig().addNearCacheConfig(createNearCacheConfig(mapName));
final HazelcastInstance client = factory.newHazelcastClient(clientConfig);
final IMap<Integer, Integer> clientMap = client.getMap(mapName);
ArrayList<Thread> threads = new ArrayList<Thread>();
// continuously adds and removes member
Thread shadowMember = new Thread(new Runnable() {
@Override
public void run() {
while (!stopTest.get()) {
HazelcastInstance member = factory.newHazelcastInstance(config);
sleepSeconds(5);
member.getLifecycleService().terminate();
}
}
});
threads.add(shadowMember);
// populates client near-cache
for (int i = 0; i < NEAR_CACHE_POPULATOR_THREAD_COUNT; i++) {
Thread populateClientNearCache = new Thread(new Runnable() {
public void run() {
while (!stopTest.get()) {
for (int i = 0; i < KEY_COUNT; i++) {
clientMap.get(i);
}
}
}
});
threads.add(populateClientNearCache);
}
// updates map data from member.
Thread putFromMember = new Thread(new Runnable() {
public void run() {
while (!stopTest.get()) {
int key = getInt(KEY_COUNT);
int value = getInt(Integer.MAX_VALUE);
memberMap.put(key, value);
sleepAtLeastMillis(2);
}
}
});
threads.add(putFromMember);
Thread clearFromMember = new Thread(new Runnable() {
public void run() {
while (!stopTest.get()) {
memberMap.clear();
sleepSeconds(5);
}
}
});
threads.add(clearFromMember);
for (Thread thread : threads) {
thread.start();
}
// stress system some seconds
sleepSeconds(TEST_RUN_SECONDS);
//stop threads
stopTest.set(true);
for (Thread thread : threads) {
thread.join();
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
for (int i = 0; i < KEY_COUNT; i++) {
Integer valueSeenFromMember = memberMap.get(i);
Integer valueSeenFromClient = clientMap.get(i);
int nearCacheSize = ((NearCachedClientMapProxy) clientMap).getNearCache().size();
assertEquals("Stale value found. (nearCacheSize=" + nearCacheSize + ")", valueSeenFromMember, valueSeenFromClient);
}
}
});
}
Aggregations