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);
}
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);
}
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());
}
});
}
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);
}
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);
}
Aggregations