use of com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener in project hazelcast by hazelcast.
the class CachePartitionLostListenerConfigTest method testEqualsAndHashCode.
@Test
public void testEqualsAndHashCode() {
CachePartitionLostListener listener = new EventCollectingCachePartitionLostListener(0);
CachePartitionLostListenerConfig listenerConfig1 = new CachePartitionLostListenerConfig();
CachePartitionLostListenerConfig listenerConfig2 = new CachePartitionLostListenerConfig();
assertEquals(listenerConfig1, listenerConfig1);
assertEquals(listenerConfig1, new CachePartitionLostListenerConfig());
assertNotEquals(listenerConfig1, null);
assertNotEquals(listenerConfig1, new Object());
listenerConfig1.setImplementation(listener);
assertNotEquals(listenerConfig1, listenerConfig2);
assertNotEquals(listenerConfig1.hashCode(), listenerConfig2.hashCode());
listenerConfig2.setImplementation(listener);
assertEquals(listenerConfig1, listenerConfig2);
assertEquals(listenerConfig1.hashCode(), listenerConfig2.hashCode());
listenerConfig1.setClassName("EventCollectingCachePartitionLostListener");
listenerConfig2.setClassName("CachePartitionLostListenerConfig");
assertNotEquals(listenerConfig1, listenerConfig2);
assertNotEquals(listenerConfig1.hashCode(), listenerConfig2.hashCode());
listenerConfig2.setClassName("EventCollectingCachePartitionLostListener");
assertEquals(listenerConfig1, listenerConfig2);
assertEquals(listenerConfig1.hashCode(), listenerConfig2.hashCode());
}
use of com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener in project hazelcast by hazelcast.
the class CachePartitionLostListenerConfigTest method testGetImplementation.
@Test
public void testGetImplementation() {
CachePartitionLostListener listener = new EventCollectingCachePartitionLostListener(0);
CachePartitionLostListenerConfig listenerConfig = new CachePartitionLostListenerConfig(listener);
assertEquals(listener, listenerConfig.getImplementation());
}
use of com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener in project hazelcast by hazelcast.
the class CachePartitionLostListenerStressTest method registerListeners.
private List<EventCollectingCachePartitionLostListener> registerListeners(CacheManager cacheManager) {
CacheConfig<Integer, Integer> config = new CacheConfig<Integer, Integer>();
List<EventCollectingCachePartitionLostListener> listeners = new ArrayList<EventCollectingCachePartitionLostListener>();
for (int i = 0; i < getNodeCount(); i++) {
EventCollectingCachePartitionLostListener listener = new EventCollectingCachePartitionLostListener(i);
listeners.add(listener);
config.setBackupCount(i);
Cache<Integer, Integer> cache = cacheManager.createCache(getIthCacheName(i), config);
ICache iCache = cache.unwrap(ICache.class);
iCache.addPartitionLostListener(listener);
}
return listeners;
}
use of com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener in project hazelcast by hazelcast.
the class CachePartitionLostListenerStressTest method testCachePartitionLostListener.
@Test
public void testCachePartitionLostListener() {
List<HazelcastInstance> instances = getCreatedInstancesShuffledAfterWarmedUp();
List<HazelcastInstance> survivingInstances = new ArrayList<HazelcastInstance>(instances);
List<HazelcastInstance> terminatingInstances = survivingInstances.subList(0, numberOfNodesToCrash);
survivingInstances = survivingInstances.subList(numberOfNodesToCrash, instances.size());
HazelcastInstance instance = survivingInstances.get(0);
HazelcastServerCachingProvider cachingProvider = createServerCachingProvider(instance);
CacheManager cacheManager = cachingProvider.getCacheManager();
List<EventCollectingCachePartitionLostListener> listeners = registerListeners(cacheManager);
if (withData) {
for (int i = 0; i < getNodeCount(); i++) {
Cache<Integer, Integer> cache = cacheManager.getCache(getIthCacheName(i));
for (int j = 0; j < getCacheEntryCount(); j++) {
cache.put(j, j);
}
}
}
final String log = "Surviving: " + survivingInstances + " Terminating: " + terminatingInstances;
Map<Integer, Integer> survivingPartitions = getMinReplicaIndicesByPartitionId(survivingInstances);
stopInstances(terminatingInstances, nodeLeaveType);
waitAllForSafeState(survivingInstances);
if (shouldExpectPartitionLostEvents) {
for (int i = 0; i < getNodeCount(); i++) {
assertListenerInvocationsEventually(log, i, numberOfNodesToCrash, listeners.get(i), survivingPartitions);
}
} else {
for (final EventCollectingCachePartitionLostListener listener : listeners) {
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(listener.getEvents().isEmpty());
}
}, 1);
}
}
for (int i = 0; i < getNodeCount(); i++) {
cacheManager.destroyCache(getIthCacheName(i));
}
cacheManager.close();
cachingProvider.close();
}
Aggregations