use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class RingbufferAbstractTest method readOne_whenOneAfterTail_thenBlock.
@Test
public void readOne_whenOneAfterTail_thenBlock() throws Exception {
ringbuffer.add("1");
ringbuffer.add("2");
final long tail = ringbuffer.tailSequence();
// first we do the invocation. This invocation is going to block
final Future f = spawn(new Callable<String>() {
@Override
public String call() throws Exception {
return ringbuffer.readOne(tail + 1);
}
});
// then we check if the future is not going to complete.
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() throws Exception {
assertFalse(f.isDone());
}
}, 2);
// then we add the item
ringbuffer.add("3");
// and eventually the future should complete
assertCompletesEventually(f);
assertEquals("3", f.get());
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ReplicatedMapHitsAndLastAccessTimeTest method testHitsAndLastAccessTimeIsSetToAnyValueAfterStartTime.
private void testHitsAndLastAccessTimeIsSetToAnyValueAfterStartTime(Config config) throws Exception {
final long startTime = Clock.currentTimeMillis();
final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
final HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
final HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
warmUpPartitions(instance1, instance2);
final String mapName = randomMapName();
final ReplicatedMap<String, String> map1 = instance1.getReplicatedMap(mapName);
final ReplicatedMap<String, String> map2 = instance2.getReplicatedMap(mapName);
final int partitionCount = getPartitionService(instance1).getPartitionCount();
final Set<String> keys = generateRandomKeys(instance1, partitionCount);
for (String key : keys) {
map1.put(key, "bar");
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
for (Map.Entry<String, String> entry : map1.entrySet()) {
assertRecord(getReplicatedRecord(map1, entry.getKey()), startTime);
}
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
for (Map.Entry<String, String> entry : map2.entrySet()) {
assertRecord(getReplicatedRecord(map2, entry.getKey()), startTime);
}
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ReplicatedMapListenerTest method testRegisterListenerViaConfiguration.
@Test
public void testRegisterListenerViaConfiguration() throws Exception {
String mapName = randomMapName();
Config config = new Config();
ReplicatedMapConfig replicatedMapConfig = config.getReplicatedMapConfig(mapName);
EntryListenerConfig listenerConfig = new EntryListenerConfig();
final EventCountingListener listener = new EventCountingListener();
listenerConfig.setImplementation(listener);
replicatedMapConfig.addEntryListenerConfig(listenerConfig);
HazelcastInstance instance = createHazelcastInstance(config);
ReplicatedMap<Object, Object> replicatedMap = instance.getReplicatedMap(mapName);
replicatedMap.put(3, 3);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, listener.addCount.get());
assertEquals(3, listener.keys.peek());
}
}, 10);
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ReplicatedMapListenerTest method testListenToKeyWithPredicate.
@Test
public void testListenToKeyWithPredicate() throws Exception {
ReplicatedMap<Object, Object> replicatedMap = createClusterAndGetRandomReplicatedMap();
final EventCountingListener listener = new EventCountingListener();
replicatedMap.addEntryListener(listener, new InstanceOfPredicate(Integer.class), 2);
replicatedMap.put(1, 1);
replicatedMap.put(2, 2);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, listener.keys.size());
assertEquals(2, listener.keys.peek());
assertEquals(1, listener.addCount.get());
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ReplicatedMapListenerTest method testMapClear.
@Test
public void testMapClear() throws Exception {
ReplicatedMap<Object, Object> replicatedMap = createClusterAndGetRandomReplicatedMap();
final EventCountingListener listener = new EventCountingListener();
replicatedMap.addEntryListener(listener);
replicatedMap.put(1, 1);
replicatedMap.clear();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, listener.mapClearCount.get());
}
});
}
Aggregations