use of com.hazelcast.config.InMemoryFormat.OBJECT in project hazelcast by hazelcast.
the class EntryProcessorTest method testIssue969MapEntryProcessorAllKeys.
@Test
public void testIssue969MapEntryProcessorAllKeys() throws Exception {
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
Config cfg = getConfig();
HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(cfg);
nodeFactory.newHazelcastInstance(cfg);
IMap<Integer, Integer> map = instance1.getMap(MAP_NAME);
AtomicInteger addCount = new AtomicInteger(0);
AtomicInteger updateCount = new AtomicInteger(0);
AtomicInteger removeCount = new AtomicInteger(0);
CountDownLatch latch = new CountDownLatch(300);
map.addEntryListener((EntryAddedListener<Integer, Integer>) event -> {
addCount.incrementAndGet();
latch.countDown();
}, true);
map.addEntryListener((EntryRemovedListener<Integer, Integer>) event -> {
removeCount.incrementAndGet();
latch.countDown();
}, true);
map.addEntryListener((EntryUpdatedListener<Integer, Integer>) event -> {
updateCount.incrementAndGet();
latch.countDown();
}, true);
int size = 100;
for (int i = 0; i < size; i++) {
map.put(i, i);
}
IncrementorEntryProcessor<Integer> entryProcessor = new IncrementorEntryProcessor<>();
Map<Integer, Integer> res = map.executeOnEntries(entryProcessor);
for (int i = 0; i < size; i++) {
assertEquals(map.get(i), (Object) (i + 1));
}
for (int i = 0; i < size; i++) {
assertEquals(map.get(i), res.get(i));
}
RemoveEntryProcessor removeEntryProcessor = new RemoveEntryProcessor();
map.executeOnEntries(removeEntryProcessor);
assertEquals(0, map.size());
assertTrue(latch.await(100, TimeUnit.SECONDS));
assertEquals(100, addCount.get());
assertEquals(100, removeCount.get());
assertEquals(100, updateCount.get());
}
use of com.hazelcast.config.InMemoryFormat.OBJECT in project hazelcast by hazelcast.
the class EntryProcessorTest method testExecuteOnEntriesWithEntryListener.
@Test
public void testExecuteOnEntriesWithEntryListener() {
IMap<String, String> map = createHazelcastInstance(getConfig()).getMap(MAP_NAME);
map.put("key", "value");
CountDownLatch latch = new CountDownLatch(1);
map.addEntryListener((EntryUpdatedListener<String, String>) event -> {
String val = event.getValue();
String oldValue = event.getOldValue();
if ("newValue".equals(val) && ((inMemoryFormat == BINARY || inMemoryFormat == NATIVE) && "value".equals(oldValue) || inMemoryFormat == OBJECT && null == oldValue)) {
latch.countDown();
}
}, true);
map.executeOnEntries(entry -> {
entry.setValue("newValue");
return 5;
});
assertOpenEventually(latch, 5);
}
use of com.hazelcast.config.InMemoryFormat.OBJECT in project hazelcast by hazelcast.
the class EntryProcessorTest method testExecuteOnKeysWithEntryListener.
@Test
public void testExecuteOnKeysWithEntryListener() {
IMap<String, String> map = createHazelcastInstance(getConfig()).getMap(MAP_NAME);
map.put("key", "value");
final CountDownLatch latch = new CountDownLatch(1);
map.addEntryListener((EntryUpdatedListener<String, String>) event -> {
String val = event.getValue();
String oldValue = event.getOldValue();
if ("newValue".equals(val) && ((inMemoryFormat == BINARY || inMemoryFormat == NATIVE) && "value".equals(oldValue) || inMemoryFormat == OBJECT && null == oldValue)) {
latch.countDown();
}
}, true);
HashSet<String> keys = new HashSet<>();
keys.add("key");
map.executeOnKeys(keys, entry -> {
entry.setValue("newValue");
return 5;
});
assertOpenEventually(latch, 5);
}
Aggregations