use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class MapPreconditionsTest method testAddLocalEntryListenerWithMapListenerAndPredicateAndKey_NullPredicate.
@Test(expected = NullPointerException.class)
public void testAddLocalEntryListenerWithMapListenerAndPredicateAndKey_NullPredicate() {
MapListener mapListener = new MapListenerAdapter() {
public void onEntryEvent(EntryEvent event) {
System.out.println("-");
}
};
Predicate predicate = null;
map.addLocalEntryListener(mapListener, predicate, null, true);
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class MapPreconditionsTest method testAddEntryListenerWithMapListenerAndKey_NullKey.
@Test(expected = NullPointerException.class)
public void testAddEntryListenerWithMapListenerAndKey_NullKey() {
MapListener mapListener = new MapListenerAdapter() {
public void onEntryEvent(EntryEvent event) {
System.out.println("-");
}
};
map.addEntryListener(mapListener, null, false);
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class MapStoreWriteThroughTest method testOneMemberWriteThroughWithLRU.
@Test(timeout = 120000)
public void testOneMemberWriteThroughWithLRU() throws Exception {
final int size = 10000;
TestMapStore testMapStore = new TestMapStore(size * 2, 1, 1);
testMapStore.setLoadAllKeys(false);
Config config = newConfig(testMapStore, 0);
config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
maxSizeConfig.setSize(size);
MapConfig mapConfig = config.getMapConfig("default");
mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
mapConfig.setMaxSizeConfig(maxSizeConfig);
mapConfig.setMinEvictionCheckMillis(0);
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
IMap<Integer, Employee> map = instance.getMap("default");
final CountDownLatch countDownLatch = new CountDownLatch(size);
map.addEntryListener(new EntryAdapter() {
@Override
public void entryEvicted(EntryEvent event) {
countDownLatch.countDown();
}
}, false);
for (int i = 0; i < size * 2; i++) {
// trigger eviction.
if (i == (size * 2) - 1 || i == size) {
sleepMillis(1001);
}
map.put(i, new Employee("joe", i, true, 100.00));
}
assertEquals(testMapStore.getStore().size(), size * 2);
assertOpenEventually(countDownLatch);
final String msgFailure = String.format("map size: %d put count: %d", map.size(), size);
assertTrue(msgFailure, map.size() > size / 2);
assertTrue(msgFailure, map.size() <= size);
assertEquals(testMapStore.getStore().size(), size * 2);
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class MultiMapListenerTest method testConfigListenerRegistration.
@Test
public void testConfigListenerRegistration() throws InterruptedException {
Config config = new Config();
final String name = "default";
final CountDownLatch latch = new CountDownLatch(1);
config.getMultiMapConfig(name).addEntryListenerConfig(new EntryListenerConfig().setImplementation(new EntryAdapter() {
public void entryAdded(EntryEvent event) {
latch.countDown();
}
}));
final HazelcastInstance hz = createHazelcastInstance(config);
hz.getMultiMap(name).put(1, 1);
assertTrue(latch.await(10, TimeUnit.SECONDS));
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class EventPublishOrderWithEvictionTest method assertEmittedEventsOrder.
private void assertEmittedEventsOrder(EventOrderAwareEntryListener entryListener) {
Map<Integer, List<EntryEventType>> eventsPerKey = new HashMap<Integer, List<EntryEventType>>();
List<EntryEvent> events = entryListener.getOrderedEvents();
for (EntryEvent event : events) {
Integer key = (Integer) event.getKey();
List<EntryEventType> eventTypes = eventsPerKey.get(key);
if (eventTypes == null) {
eventTypes = new ArrayList<EntryEventType>();
eventsPerKey.put(key, eventTypes);
}
EntryEventType eventType = event.getEventType();
eventTypes.add(eventType);
}
Set<Map.Entry<Integer, List<EntryEventType>>> entries = eventsPerKey.entrySet();
for (Map.Entry<Integer, List<EntryEventType>> entry : entries) {
List<EntryEventType> eventTypes = entry.getValue();
EntryEventType prev = null;
for (int i = 0; i < eventTypes.size(); i++) {
final EntryEventType eventType = eventTypes.get(i);
if (i == 0) {
assertEquals(EntryEventType.ADDED, eventType);
prev = eventType;
continue;
}
if (prev.equals(EntryEventType.ADDED)) {
assertEquals(EntryEventType.EVICTED, eventType);
} else if (prev.equals(EntryEventType.EVICTED)) {
assertEquals(EntryEventType.ADDED, eventType);
}
prev = eventType;
}
}
}
Aggregations