use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ReplicatedMapListenerTest method testEntryAdded.
@Test
public void testEntryAdded() throws Exception {
ReplicatedMap<Object, Object> replicatedMap = createClusterAndGetRandomReplicatedMap();
final EventCountingListener listener = new EventCountingListener();
replicatedMap.addEntryListener(listener);
replicatedMap.put(1, 1);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, listener.addCount.get());
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ReplicatedMapLiteMemberTest method testLiteMembersWithReplicatedMap.
@Test
public void testLiteMembersWithReplicatedMap() throws Exception {
final Config config = buildConfig(false);
final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
final HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
final HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
final HazelcastInstance lite = nodeFactory.newHazelcastInstance(buildConfig(true));
final ReplicatedMap<String, String> map1 = instance1.getReplicatedMap("default");
map1.put("key", "value");
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(instance2.getReplicatedMap("default").containsKey("key"));
}
});
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() throws Exception {
final ReplicatedMapService service = getReplicatedMapService(lite);
assertEquals(0, service.getAllReplicatedRecordStores("default").size());
}
}, 5);
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ReplicatedMapTest method testSize.
private void testSize(Config config) throws Exception {
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
final ReplicatedMap<String, String> map1 = instance1.getReplicatedMap("default");
final ReplicatedMap<String, String> map2 = instance2.getReplicatedMap("default");
final int partitionCount = getPartitionService(instance1).getPartitionCount();
final Set<String> keys = generateRandomKeys(instance1, partitionCount);
final SimpleEntry<String, String>[] testValues = buildTestValues(keys);
int half = testValues.length / 2;
for (int i = 0; i < testValues.length; i++) {
final ReplicatedMap<String, String> map = i < half ? map1 : map2;
final SimpleEntry<String, String> entry = testValues[i];
map.put(entry.getKey(), entry.getValue());
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(keys.size(), map1.size());
assertEquals(keys.size(), map2.size());
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ReplicatedMapTest method testKeySet_notIncludes_removedKeys.
@Test
public void testKeySet_notIncludes_removedKeys() throws Exception {
HazelcastInstance node = createHazelcastInstance();
final ReplicatedMap<Integer, Integer> map = node.getReplicatedMap("default");
map.put(1, Integer.MAX_VALUE);
map.put(2, Integer.MIN_VALUE);
map.remove(1);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
Set<Integer> keys = new HashSet<Integer>(map.keySet());
assertFalse(keys.contains(1));
}
}, 20);
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ReplicatedMapTest method testRemove.
private void testRemove(Config config) throws Exception {
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
final ReplicatedMap<String, String> map1 = instance1.getReplicatedMap("default");
final ReplicatedMap<String, String> map2 = instance2.getReplicatedMap("default");
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 (String key : keys) {
assertEquals("map1 should return value for key " + key, "bar", map1.get(key));
assertEquals("map2 should return value for key " + key, "bar", map2.get(key));
}
}
});
for (String key : keys) {
map2.remove(key);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
for (String key : keys) {
assertFalse("map1 should not contain key " + key, map1.containsKey(key));
assertFalse("map2 should not contain key " + key, map2.containsKey(key));
}
}
});
}
Aggregations