Search in sources :

Example 71 with HazelcastInstance

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

the class MapEvictAllTest method testEvictAll_firesEvent.

@Test
public void testEvictAll_firesEvent() throws Exception {
    final CountDownLatch countDownLatch = new CountDownLatch(1000);
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<Integer, Integer> map = instance.getMap(randomMapName());
    map.addLocalEntryListener(new EntryAdapter<Integer, Integer>() {

        @Override
        public void mapEvicted(MapEvent event) {
            int numberOfEntries = event.getNumberOfEntriesAffected();
            for (int i = 0; i < numberOfEntries; i++) {
                countDownLatch.countDown();
            }
        }
    });
    for (int i = 0; i < 1000; i++) {
        map.put(i, i);
    }
    map.evictAll();
    assertOpenEventually(countDownLatch);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapEvent(com.hazelcast.core.MapEvent) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 72 with HazelcastInstance

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

the class ListenerTest method testPutAll_whenExistsEntryListenerWithIncludeValueSetToTrue_thenFireEventWithValue.

@Test
public void testPutAll_whenExistsEntryListenerWithIncludeValueSetToTrue_thenFireEventWithValue() throws InterruptedException {
    int key = 1;
    String initialValue = "foo";
    String newValue = "bar";
    HazelcastInstance instance = createHazelcastInstance(getConfig());
    IMap<Integer, String> map = instance.getMap(randomMapName());
    map.put(key, initialValue);
    UpdateListenerRecordingOldValue<Integer, String> listener = new UpdateListenerRecordingOldValue<Integer, String>();
    map.addEntryListener(listener, true);
    Map<Integer, String> newMap = createMapWithEntry(key, newValue);
    map.putAll(newMap);
    String oldValue = listener.waitForOldValue();
    assertEquals(initialValue, oldValue);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 73 with HazelcastInstance

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

the class ListenerTest method testMapPartitionLostListener_registeredViaImplementationInConfigObject.

@Test
public void testMapPartitionLostListener_registeredViaImplementationInConfigObject() {
    final String name = randomString();
    Config config = getConfig();
    MapConfig mapConfig = config.getMapConfig(name);
    MapPartitionLostListener listener = mock(MapPartitionLostListener.class);
    mapConfig.addMapPartitionLostListenerConfig(new MapPartitionLostListenerConfig(listener));
    mapConfig.setBackupCount(0);
    HazelcastInstance instance = createHazelcastInstance(config);
    instance.getMap(name);
    final EventService eventService = getNode(instance).getNodeEngine().getEventService();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            final Collection<EventRegistration> registrations = eventService.getRegistrations(MapService.SERVICE_NAME, name);
            assertFalse(registrations.isEmpty());
        }
    });
}
Also used : MapPartitionLostListener(com.hazelcast.map.listener.MapPartitionLostListener) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig) AssertTask(com.hazelcast.test.AssertTask) Collection(java.util.Collection) EventService(com.hazelcast.spi.EventService) MapConfig(com.hazelcast.config.MapConfig) IOException(java.io.IOException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 74 with HazelcastInstance

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

the class ListenerTest method globalListenerTest.

@Test
public void globalListenerTest() throws InterruptedException {
    Config config = getConfig();
    String name = randomString();
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    IMap<String, String> map1 = instance1.getMap(name);
    IMap<String, String> map2 = instance2.getMap(name);
    map1.addEntryListener(createEntryListener(false), false);
    map1.addEntryListener(createEntryListener(false), true);
    map2.addEntryListener(createEntryListener(false), true);
    int k = 3;
    putDummyData(map1, k);
    checkCountWithExpected(k * 3, 0, k * 2);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 75 with HazelcastInstance

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

the class ListenerTest method globalListenerRemoveTest.

@Test
public void globalListenerRemoveTest() throws InterruptedException {
    Config config = getConfig();
    String name = randomString();
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    IMap<String, String> map1 = instance1.getMap(name);
    IMap<String, String> map2 = instance2.getMap(name);
    String id1 = map1.addEntryListener(createEntryListener(false), false);
    String id2 = map1.addEntryListener(createEntryListener(false), true);
    String id3 = map2.addEntryListener(createEntryListener(false), true);
    int k = 3;
    map1.removeEntryListener(id1);
    map1.removeEntryListener(id2);
    map1.removeEntryListener(id3);
    putDummyData(map2, k);
    checkCountWithExpected(0, 0, 0);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

HazelcastInstance (com.hazelcast.core.HazelcastInstance)2084 Test (org.junit.Test)1684 QuickTest (com.hazelcast.test.annotation.QuickTest)1466 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1389 Config (com.hazelcast.config.Config)815 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)665 AssertTask (com.hazelcast.test.AssertTask)263 MapConfig (com.hazelcast.config.MapConfig)254 CountDownLatch (java.util.concurrent.CountDownLatch)251 NightlyTest (com.hazelcast.test.annotation.NightlyTest)230 MapStoreConfig (com.hazelcast.config.MapStoreConfig)169 IMap (com.hazelcast.core.IMap)149 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)144 ClientConfig (com.hazelcast.client.config.ClientConfig)137 Before (org.junit.Before)111 NearCacheConfig (com.hazelcast.config.NearCacheConfig)106 Member (com.hazelcast.core.Member)99 Map (java.util.Map)96 SlowTest (com.hazelcast.test.annotation.SlowTest)94 SqlPredicate (com.hazelcast.query.SqlPredicate)83