use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ReplicatedMapWriteOrderTest method testDataIntegrity.
@Test
public void testDataIntegrity() throws InterruptedException {
System.out.println("nodeCount = " + nodeCount);
System.out.println("operations = " + operations);
System.out.println("keyCount = " + keyCount);
Config config = new Config();
config.getReplicatedMapConfig("test").setReplicationDelayMillis(0);
TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(nodeCount);
final HazelcastInstance[] instances = factory.newInstances(config);
String replicatedMapName = "test";
final List<ReplicatedMap> maps = createMapOnEachInstance(instances, replicatedMapName);
ArrayList<Integer> keys = generateRandomIntegerList(keyCount);
Thread[] threads = createThreads(nodeCount, maps, keys, operations);
for (Thread thread : threads) {
thread.start();
}
for (Thread thread : threads) {
thread.join();
}
for (int i = 0; i < keyCount; i++) {
final String key = "foo-" + keys.get(i);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
System.out.println("---------------------");
System.out.println("key = " + key);
printValues();
assertValuesAreEqual();
}
private void printValues() throws Exception {
for (int j = 0; j < maps.size(); j++) {
ReplicatedMap map = maps.get(j);
System.out.println("value[" + j + "] = " + map.get(key) + " , store version : " + getStore(map, key).getVersion());
}
}
private void assertValuesAreEqual() {
for (int i = 0; i < maps.size() - 1; i++) {
ReplicatedMap map1 = maps.get(i);
ReplicatedMap map2 = maps.get(i + 1);
Object v1 = map1.get(key);
Object v2 = map2.get(key);
assertNotNull(v1);
assertNotNull(v2);
assertEquals(v1, v2);
}
}
}, 120);
}
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ReplicatedMapStatsTest method testHitsGenerated_updatedConcurrently.
@Test
public void testHitsGenerated_updatedConcurrently() throws Exception {
final ReplicatedMap<Integer, Integer> replicatedMap = getReplicatedMap();
final int actionCount = 100;
for (int i = 0; i < actionCount; i++) {
replicatedMap.put(i, i);
replicatedMap.get(i);
}
final LocalReplicatedMapStats stats = replicatedMap.getReplicatedMapStats();
final long initialHits = stats.getHits();
new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < actionCount; i++) {
replicatedMap.get(i);
}
// causes the local stats object to update
replicatedMap.getReplicatedMapStats();
}
}).start();
assertEquals(actionCount, initialHits);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(actionCount * 2, stats.getHits());
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ReplicatedMapStatsTest method testLastUpdateTime_updatedConcurrently.
@Test
public void testLastUpdateTime_updatedConcurrently() throws InterruptedException {
final long startTime = Clock.currentTimeMillis();
final ReplicatedMap<String, String> map = getReplicatedMap();
final String key = "key";
map.put(key, "value");
final LocalReplicatedMapStats stats = map.getReplicatedMapStats();
final long lastUpdateTime = stats.getLastUpdateTime();
new Thread(new Runnable() {
@Override
public void run() {
sleepAtLeastMillis(1);
map.put(key, "value2");
// causes the local stats object to update
map.getReplicatedMapStats();
}
}).start();
assertTrue(lastUpdateTime >= startTime);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(stats.getLastUpdateTime() >= lastUpdateTime);
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ReplicatedMapTest method testContainsValue.
private void testContainsValue(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);
int half = keys.size() / 2, i = 0;
for (String key : keys) {
final ReplicatedMap<String, String> map = i++ < half ? map1 : map2;
map.put(key, key);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
for (String key : keys) {
assertTrue(map1.containsValue(key));
assertTrue(map2.containsValue(key));
}
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class ReplicatedMapTest method testPutAll.
private void testPutAll(Config config) throws TimeoutException {
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 Map<String, String> mapTest = new HashMap<String, String>();
for (String key : keys) {
mapTest.put(key, "bar");
}
map1.putAll(mapTest);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
for (String key : keys) {
assertEquals("bar", map1.get(key));
assertEquals("bar", map2.get(key));
}
}
});
}
Aggregations