use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ListenerTest method testEntryListenerEvent_withMapReplaceFail.
@Test
public void testEntryListenerEvent_withMapReplaceFail() throws Exception {
HazelcastInstance instance = createHazelcastInstance(getConfig());
final IMap<Integer, Object> map = instance.getMap(randomString());
final CounterEntryListener listener = new CounterEntryListener();
map.addEntryListener(listener, true);
final int putTotal = 1000;
final int oldVal = 1;
for (int i = 0; i < putTotal; i++) {
map.put(i, oldVal);
}
final int replaceTotal = 1000;
final int newVal = 2;
for (int i = 0; i < replaceTotal; i++) {
map.replace(i, "WrongValue", newVal);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() {
for (int i = 0; i < replaceTotal; i++) {
assertEquals(oldVal, map.get(i));
}
assertEquals(putTotal, listener.addCount.get());
assertEquals(0, listener.updateCount.get());
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class EvictionTest method testEvictionAfterRemove.
/**
* Test for the issue 537.
* Eviction event is fired for an object already removed
*/
@Test
public void testEvictionAfterRemove() throws InterruptedException {
IMap<Object, Object> map = createSimpleMap();
final AtomicInteger count = new AtomicInteger(0);
map.addEntryListener(new EntryAdapter<Object, Object>() {
@Override
public void entryEvicted(EntryEvent<Object, Object> event) {
count.incrementAndGet();
}
}, true);
// ttl is 2 seconds.
map.put(1, 1, 2, TimeUnit.SECONDS);
final int expected = (map.remove(1) == null ? 1 : 0);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(expected, count.get());
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class EntryProcessorTest method executionOrderTest.
@Test
public void executionOrderTest() {
Config cfg = getConfig();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
HazelcastInstance instance1 = factory.newHazelcastInstance(cfg);
final int maxTasks = 20;
final Object key = "key";
final IMap<Object, List<Integer>> processorMap = instance1.getMap(MAP_NAME);
processorMap.put(key, new ArrayList<Integer>());
for (int i = 0; i < maxTasks; i++) {
processorMap.submitToKey(key, new SimpleEntryProcessor(i));
}
List<Integer> expectedOrder = new ArrayList<Integer>();
for (int i = 0; i < maxTasks; i++) {
expectedOrder.add(i);
}
assertTrueEventually(new AssertTask() {
public void run() throws Exception {
List<Integer> actualOrder = processorMap.get(key);
assertEquals("failed to execute all entry processor tasks", maxTasks, actualOrder.size());
}
});
List<Integer> actualOrder = processorMap.get(key);
assertEquals("entry processor tasks executed in unexpected order", expectedOrder, actualOrder);
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class MapLockTest method testTryLockLeaseTime_lockIsReleasedEventually.
@Test
public void testTryLockLeaseTime_lockIsReleasedEventually() throws InterruptedException {
final IMap<String, String> map = getMap();
final String key = randomString();
map.tryLock(key, 1000, TimeUnit.MILLISECONDS, 1000, TimeUnit.MILLISECONDS);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertFalse(map.isLocked(key));
}
}, 30);
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class EvictionTest method testIssue585SetWithoutTTL.
@Test
public void testIssue585SetWithoutTTL() throws InterruptedException {
final IMap<String, String> map = createSimpleMap();
final String key = "key";
map.set(key, "value", 5, TimeUnit.SECONDS);
// this `set` operation should not affect existing ttl.
// so "key" should be expired after 1 seconds.
map.set(key, "value2");
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertNull("Key should be expired after 1 seconds", map.get(key));
}
});
}
Aggregations