use of com.hazelcast.core.EntryEvent in project wildfly-camel by wildfly-extras.
the class HazelcastMapConsumerIntegrationTest method testRemove.
@Test
@SuppressWarnings("unchecked")
public void testRemove() throws Exception {
CamelContext camelctx = createCamelContext();
camelctx.start();
try {
MockEndpoint mock = camelctx.getEndpoint("mock:removed", MockEndpoint.class);
mock.expectedMessageCount(1);
EntryEvent<Object, Object> event = new EntryEvent<Object, Object>("foo", null, EntryEventType.REMOVED.getType(), "4711", "my-foo");
argument.getValue().entryRemoved(event);
mock.assertIsSatisfied(3000);
checkHeaders(mock.getExchanges().get(0).getIn().getHeaders(), HazelcastConstants.REMOVED);
} finally {
camelctx.stop();
}
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class AllTest method loadMapOperations.
private List<Runnable> loadMapOperations() {
ArrayList<Runnable> operations = new ArrayList<Runnable>();
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
map.evict(random.nextInt(SIZE));
}
}, 5);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
try {
map.getAsync(random.nextInt(SIZE)).toCompletableFuture().get();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
}
}, 1);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
map.containsKey(random.nextInt(SIZE));
}
}, 2);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
map.containsValue(new Customer(random.nextInt(100), String.valueOf(random.nextInt(100000))));
}
}, 2);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
int key = random.nextInt(SIZE);
map.lock(key);
try {
Thread.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
map.unlock(key);
}
}
}, 1);
// addOperation(operations, new Runnable() {
// public void run() {
// IMap map = hazelcast.getMap("myMap");
// int key = random.nextInt(SIZE);
// map.lockMap(10, TimeUnit.MILLISECONDS);
// try {
// Thread.sleep(1);
// } catch (InterruptedException e) {
// } finally {
// map.unlockMap();
// }
// }
// }, 1);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
int key = random.nextInt(SIZE);
boolean locked = map.tryLock(key);
if (locked) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
map.unlock(key);
}
}
}
}, 1);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
int key = random.nextInt(SIZE);
boolean locked = false;
try {
locked = map.tryLock(key, 10, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
if (locked) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
map.unlock(key);
}
}
}
}, 1);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
Iterator it = map.entrySet().iterator();
for (int i = 0; i < 10 && it.hasNext(); i++) {
it.next();
}
}
}, 1);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
map.getEntryView(random.nextInt(SIZE));
}
}, 2);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
map.isEmpty();
}
}, 3);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
map.put(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))));
}
}, 50);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
map.tryPut(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))), 10, TimeUnit.MILLISECONDS);
}
}, 5);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
try {
map.putAsync(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000)))).toCompletableFuture().get();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
}
}, 5);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
map.put(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))), 10, TimeUnit.MILLISECONDS);
}
}, 5);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
map.putIfAbsent(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))), 10, TimeUnit.MILLISECONDS);
}
}, 5);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
map.putIfAbsent(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))));
}
}, 5);
addOperation(operations, () -> {
MapProxyImpl<Object, Object> map = (MapProxyImpl<Object, Object>) hazelcast.getMap("myMap");
map.putIfAbsentAsync(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))), 10, TimeUnit.MILLISECONDS);
}, 5);
addOperation(operations, () -> {
MapProxyImpl<Object, Object> map = (MapProxyImpl<Object, Object>) hazelcast.getMap("myMap");
map.putIfAbsentAsync(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))));
}, 5);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
Map localMap = new HashMap();
for (int i = 0; i < 10; i++) {
localMap.put(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))));
}
map.putAll(localMap);
}
}, 1);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
map.get(random.nextInt(SIZE));
}
}, 100);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
map.remove(random.nextInt(SIZE));
}
}, 10);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
map.tryRemove(random.nextInt(SIZE), 10, TimeUnit.MILLISECONDS);
}
}, 10);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
map.removeAsync(random.nextInt(SIZE));
}
}, 10);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
map.remove(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))));
}
}, 10);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
map.replace(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))));
}
}, 4);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
map.replace(random.nextInt(SIZE), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))), new Customer(random.nextInt(100), String.valueOf(random.nextInt(10000))));
}
}, 5);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
map.size();
}
}, 4);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
Iterator it = map.entrySet(Predicates.sql("year=" + random.nextInt(100))).iterator();
while (it.hasNext()) {
it.next();
}
}
}, 1);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
Iterator it = map.entrySet(Predicates.sql("name=" + random.nextInt(10000))).iterator();
while (it.hasNext()) {
it.next();
}
}
}, 10);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
Iterator it = map.keySet(Predicates.sql("name=" + random.nextInt(10000))).iterator();
while (it.hasNext()) {
it.next();
}
}
}, 10);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
Iterator it = map.localKeySet().iterator();
while (it.hasNext()) {
it.next();
}
}
}, 10);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
Iterator it = map.localKeySet(Predicates.sql("name=" + random.nextInt(10000))).iterator();
while (it.hasNext()) {
it.next();
}
}
}, 10);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
final CountDownLatch latch = new CountDownLatch(1);
EntryListener listener = new EntryAdapter() {
@Override
public void onEntryEvent(EntryEvent event) {
latch.countDown();
}
};
UUID id = map.addEntryListener(listener, true);
try {
latch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
map.removeEntryListener(id);
}
}, 1);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
map.addIndex(IndexType.SORTED, "year");
}
}, 1);
addOperation(operations, new Runnable() {
public void run() {
IMap map = hazelcast.getMap("myMap");
final CountDownLatch latch = new CountDownLatch(1);
EntryListener listener = new EntryAdapter() {
@Override
public void onEntryEvent(EntryEvent event) {
latch.countDown();
}
};
UUID id = map.addLocalEntryListener(listener);
try {
latch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
map.removeEntryListener(id);
}
}, 1);
return operations;
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class BasicMapTest method testMapListenersWithValue.
@Test
public void testMapListenersWithValue() {
IMap<Object, Object> map = getInstance().getMap("testMapListenersWithValue");
final Object[] addedKey = new Object[1];
final Object[] addedValue = new Object[1];
final Object[] updatedKey = new Object[1];
final Object[] oldValue = new Object[1];
final Object[] newValue = new Object[1];
final Object[] removedKey = new Object[1];
final Object[] removedValue = new Object[1];
EntryListener<Object, Object> listener = new EntryAdapter<Object, Object>() {
@Override
public void entryAdded(EntryEvent<Object, Object> event) {
addedKey[0] = event.getKey();
addedValue[0] = event.getValue();
}
@Override
public void entryRemoved(EntryEvent<Object, Object> event) {
removedKey[0] = event.getKey();
removedValue[0] = event.getOldValue();
}
@Override
public void entryUpdated(EntryEvent<Object, Object> event) {
updatedKey[0] = event.getKey();
oldValue[0] = event.getOldValue();
newValue[0] = event.getValue();
}
public void entryEvicted(EntryEvent<Object, Object> event) {
}
@Override
public void mapEvicted(MapEvent event) {
}
@Override
public void mapCleared(MapEvent event) {
}
};
map.addEntryListener(listener, true);
map.put("key", "value");
map.put("key", "value2");
map.remove("key");
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(addedKey[0], "key");
assertEquals(addedValue[0], "value");
assertEquals(updatedKey[0], "key");
assertEquals(oldValue[0], "value");
assertEquals(newValue[0], "value2");
assertEquals(removedKey[0], "key");
assertEquals(removedValue[0], "value2");
}
});
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class EntryLoadedListenerTest method load_listener_notified_when_getAll_loads_from_map_loader.
@Test
public void load_listener_notified_when_getAll_loads_from_map_loader() {
final Queue<EntryEvent> entryEvents = new ConcurrentLinkedQueue<EntryEvent>();
IMap<Integer, Integer> map = node.getMap("noInitialLoading_test_getAll");
map.addEntryListener(new EntryLoadedListener<Integer, Integer>() {
@Override
public void entryLoaded(EntryEvent<Integer, Integer> event) {
entryEvents.add(event);
}
}, true);
final List<Integer> keyList = Arrays.asList(1, 2, 3, 4, 5);
map.getAll(new HashSet<Integer>(keyList));
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(keyList.size(), entryEvents.size());
for (EntryEvent entryEvent : entryEvents) {
assertEquals(LOADED, entryEvent.getEventType());
}
}
});
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class ServerQueryCacheRecreationTest method listeners_still_works_after_query_cache_recreation.
@Test
public void listeners_still_works_after_query_cache_recreation() {
IMap<Object, Object> map = serverWithQueryCache.getMap(mapName);
QueryCache<Object, Object> queryCache = map.getQueryCache(queryCacheName, Predicates.alwaysTrue(), true);
final AtomicInteger entryAddedCounter = new AtomicInteger();
queryCache.addEntryListener(new EntryAdapter() {
@Override
public void entryAdded(EntryEvent event) {
entryAddedCounter.incrementAndGet();
}
}, Predicates.sql("__key >= 10"), true);
// Restart server
server.shutdown();
server = factory.newHazelcastInstance(getConfig());
// Recreate query cache on same reference
// Recreation empties query cache.
((InternalQueryCache) queryCache).recreate();
for (int i = 0; i < 100; i++) {
map.put(i, i);
}
AssertTask assertTask = () -> assertEquals(90, entryAddedCounter.get());
assertTrueEventually(assertTask);
assertTrueAllTheTime(assertTask, 3);
}
Aggregations