Search in sources :

Example 26 with EntryAdapter

use of com.hazelcast.core.EntryAdapter in project hazelcast by hazelcast.

the class ClientSplitBrainTest method testClientListeners_InSplitBrain.

@Test
public void testClientListeners_InSplitBrain() throws Throwable {
    Config config = new Config();
    config.setProperty(GroupProperty.MERGE_FIRST_RUN_DELAY_SECONDS.getName(), "5");
    config.setProperty(GroupProperty.MERGE_NEXT_RUN_DELAY_SECONDS.getName(), "5");
    HazelcastInstance h1 = Hazelcast.newHazelcastInstance(config);
    HazelcastInstance h2 = Hazelcast.newHazelcastInstance(config);
    final ClientConfig clientConfig = new ClientConfig();
    final HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
    final String mapName = randomMapName();
    final IMap mapNode1 = h1.getMap(mapName);
    final IMap mapNode2 = h2.getMap(mapName);
    final IMap mapClient = client.getMap(mapName);
    final AtomicBoolean[] listenerGotEventFlags = new AtomicBoolean[3];
    for (int i = 0; i < 3; i++) {
        listenerGotEventFlags[i] = new AtomicBoolean();
    }
    final CountDownLatch mergedLatch = new CountDownLatch(1);
    final LifecycleListener mergeListener = createMergeListener(mergedLatch);
    h1.getLifecycleService().addLifecycleListener(mergeListener);
    h2.getLifecycleService().addLifecycleListener(mergeListener);
    final EntryAdapter entryListener1 = createEntryListener(listenerGotEventFlags[0]);
    mapNode1.addEntryListener(entryListener1, true);
    final EntryAdapter entryListener2 = createEntryListener(listenerGotEventFlags[1]);
    mapNode2.addEntryListener(entryListener2, true);
    final EntryAdapter entryListener3 = createEntryListener(listenerGotEventFlags[2]);
    mapClient.addEntryListener(entryListener3, true);
    closeConnectionBetween(h2, h1);
    assertTrue(mergedLatch.await(30, TimeUnit.SECONDS));
    assertEquals(2, h1.getCluster().getMembers().size());
    assertEquals(2, h2.getCluster().getMembers().size());
    AtomicBoolean testFinished = new AtomicBoolean(false);
    final Thread clientThread = startClientPutThread(mapClient, testFinished);
    try {
        checkEventsEventually(listenerGotEventFlags);
    } catch (Throwable t) {
        throw t;
    } finally {
        testFinished.set(true);
        clientThread.interrupt();
        clientThread.join();
    }
}
Also used : Config(com.hazelcast.config.Config) ClientConfig(com.hazelcast.client.config.ClientConfig) EntryAdapter(com.hazelcast.core.EntryAdapter) LifecycleListener(com.hazelcast.core.LifecycleListener) CountDownLatch(java.util.concurrent.CountDownLatch) IMap(com.hazelcast.core.IMap) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

EntryAdapter (com.hazelcast.core.EntryAdapter)26 Test (org.junit.Test)23 EntryEvent (com.hazelcast.core.EntryEvent)21 QuickTest (com.hazelcast.test.annotation.QuickTest)21 ParallelTest (com.hazelcast.test.annotation.ParallelTest)20 HazelcastInstance (com.hazelcast.core.HazelcastInstance)14 CountDownLatch (java.util.concurrent.CountDownLatch)13 Config (com.hazelcast.config.Config)12 AssertTask (com.hazelcast.test.AssertTask)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)6 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)6 NightlyTest (com.hazelcast.test.annotation.NightlyTest)6 MapConfig (com.hazelcast.config.MapConfig)5 IMap (com.hazelcast.core.IMap)4 MapEvent (com.hazelcast.core.MapEvent)4 SqlPredicate (com.hazelcast.query.SqlPredicate)4 MaxSizeConfig (com.hazelcast.config.MaxSizeConfig)3 ArrayList (java.util.ArrayList)3 MultiMapConfig (com.hazelcast.config.MultiMapConfig)2