Search in sources :

Example 1 with EventCollectingCachePartitionLostListener

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());
}
Also used : EventCollectingCachePartitionLostListener(com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener) CachePartitionLostListener(com.hazelcast.cache.impl.event.CachePartitionLostListener) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) EventCollectingCachePartitionLostListener(com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with EventCollectingCachePartitionLostListener

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());
}
Also used : EventCollectingCachePartitionLostListener(com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener) CachePartitionLostListener(com.hazelcast.cache.impl.event.CachePartitionLostListener) CachePartitionLostListenerConfig(com.hazelcast.config.CachePartitionLostListenerConfig) EventCollectingCachePartitionLostListener(com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with EventCollectingCachePartitionLostListener

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;
}
Also used : ArrayList(java.util.ArrayList) EventCollectingCachePartitionLostListener(com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener) CacheConfig(com.hazelcast.config.CacheConfig)

Example 4 with EventCollectingCachePartitionLostListener

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();
}
Also used : ArrayList(java.util.ArrayList) EventCollectingCachePartitionLostListener(com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) AbstractPartitionLostListenerTest(com.hazelcast.partition.AbstractPartitionLostListenerTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

EventCollectingCachePartitionLostListener (com.hazelcast.cache.CachePartitionLostListenerTest.EventCollectingCachePartitionLostListener)4 Test (org.junit.Test)3 CachePartitionLostListener (com.hazelcast.cache.impl.event.CachePartitionLostListener)2 CachePartitionLostListenerConfig (com.hazelcast.config.CachePartitionLostListenerConfig)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 ArrayList (java.util.ArrayList)2 HazelcastServerCachingProvider (com.hazelcast.cache.impl.HazelcastServerCachingProvider)1 CacheConfig (com.hazelcast.config.CacheConfig)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 AbstractPartitionLostListenerTest (com.hazelcast.partition.AbstractPartitionLostListenerTest)1 AssertTask (com.hazelcast.test.AssertTask)1 SlowTest (com.hazelcast.test.annotation.SlowTest)1 CacheManager (javax.cache.CacheManager)1