use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class WriteBehindOnBackupsTest method assertWriteBehindQueuesEmptyOnOwnerAndOnBackups.
private void assertWriteBehindQueuesEmptyOnOwnerAndOnBackups(final String mapName, final long numberOfItems, final MapStoreWithCounter mapStore, final HazelcastInstance[] nodes) {
AssertTask assertTask = new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(0, writeBehindQueueSize(nodes[0], mapName));
assertEquals(0, writeBehindQueueSize(nodes[1], mapName));
assertEquals(numberOfItems, mapStore.size());
}
};
assertTrueEventually(assertTask);
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class MapStoreWriteBehindTest method testOneMemberWriteBehindWithEvictions.
@Test(timeout = 120000)
public void testOneMemberWriteBehindWithEvictions() throws Exception {
final String mapName = "testOneMemberWriteBehindWithEvictions";
final EventBasedMapStore testMapStore = new EventBasedMapStore();
testMapStore.loadAllLatch = new CountDownLatch(1);
final Config config = newConfig(testMapStore, 2, InitialLoadMode.EAGER);
final HazelcastInstance instance = createHazelcastInstance(config);
final IMap<Integer, String> map = instance.getMap(mapName);
// check if load all called.
assertTrue("map store loadAllKeys must be called", testMapStore.loadAllLatch.await(10, SECONDS));
// map population count.
final int populationCount = 100;
// latch for store & storeAll events.
testMapStore.storeLatch = new CountDownLatch(populationCount);
//populate map.
for (int i = 0; i < populationCount; i++) {
map.put(i, "value" + i);
}
//wait for all store ops.
assertOpenEventually(testMapStore.storeLatch);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(0, writeBehindQueueSize(instance, mapName));
}
});
// init before eviction
testMapStore.storeLatch = new CountDownLatch(populationCount);
//evict.
for (int i = 0; i < populationCount; i++) {
map.evict(i);
}
// expect no store op
assertEquals(populationCount, testMapStore.storeLatch.getCount());
// check store size
assertEquals(populationCount, testMapStore.getStore().size());
// check map size
assertEquals(0, map.size());
// re-populate map
for (int i = 0; i < populationCount; i++) {
map.put(i, "value" + i);
}
// evict again
for (int i = 0; i < populationCount; i++) {
map.evict(i);
}
// wait for all store ops
testMapStore.storeLatch.await(10, SECONDS);
// check store size
assertEquals(populationCount, testMapStore.getStore().size());
// check map size
assertEquals(0, map.size());
// re-populate map
for (int i = 0; i < populationCount; i++) {
map.put(i, "value" + i);
}
testMapStore.deleteLatch = new CountDownLatch(populationCount);
// clear map
for (int i = 0; i < populationCount; i++) {
map.remove(i);
}
testMapStore.deleteLatch.await(10, SECONDS);
// check map size
assertEquals(0, map.size());
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class MapStoreWriteBehindTest method testOneMemberWriteBehind2.
@Test(timeout = 120000)
public void testOneMemberWriteBehind2() throws Exception {
final EventBasedMapStore testMapStore = new EventBasedMapStore();
testMapStore.setLoadAllKeys(false);
Config config = newConfig(testMapStore, 1, InitialLoadMode.EAGER);
HazelcastInstance instance = createHazelcastInstance(config);
IMap<String, String> map = instance.getMap("default");
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
Object event = testMapStore.getEvents().poll();
assertEquals(EventBasedMapStore.STORE_EVENTS.LOAD_ALL_KEYS, event);
}
});
map.put("1", "value1");
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(EventBasedMapStore.STORE_EVENTS.LOAD, testMapStore.getEvents().poll());
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(EventBasedMapStore.STORE_EVENTS.STORE, testMapStore.getEvents().poll());
}
});
map.remove("1");
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(EventBasedMapStore.STORE_EVENTS.DELETE, testMapStore.getEvents().poll());
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class MapStoreWriteBehindTest method testIssue1085WriteBehindBackupWithLongRunnigMapStore.
@Test(timeout = 120000)
public void testIssue1085WriteBehindBackupWithLongRunnigMapStore() throws InterruptedException {
final String name = randomMapName("testIssue1085WriteBehindBackup");
final int expectedStoreCount = 3;
final int nodeCount = 3;
Config config = getConfig();
config.setProperty(GroupProperty.MAP_REPLICA_SCHEDULED_TASK_DELAY_SECONDS.getName(), "30");
MapConfig writeBehindBackupConfig = config.getMapConfig(name);
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setWriteDelaySeconds(5);
final MapStoreWithStoreCount mapStore = new MapStoreWithStoreCount(expectedStoreCount, 300, 50);
mapStoreConfig.setImplementation(mapStore);
writeBehindBackupConfig.setMapStoreConfig(mapStoreConfig);
// create nodes.
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
HazelcastInstance node1 = factory.newHazelcastInstance(config);
HazelcastInstance node2 = factory.newHazelcastInstance(config);
HazelcastInstance node3 = factory.newHazelcastInstance(config);
// create corresponding keys.
final String keyOwnedByNode1 = generateKeyOwnedBy(node1);
final String keyOwnedByNode2 = generateKeyOwnedBy(node2);
final String keyOwnedByNode3 = generateKeyOwnedBy(node3);
// put one key value pair per node.
final IMap<String, Integer> map = node1.getMap(name);
map.put(keyOwnedByNode1, 1);
map.put(keyOwnedByNode2, 2);
map.put(keyOwnedByNode3, 3);
// shutdown node2.
node2.getLifecycleService().shutdown();
// wait store ops. finish.
mapStore.awaitStores();
// we should see at least expected store count.
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
int storeOperationCount = mapStore.count.intValue();
assertTrue("expected : " + expectedStoreCount + ", actual : " + storeOperationCount, expectedStoreCount <= storeOperationCount);
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class MapStoreTest method testSlowStore.
@Test(timeout = 120000)
public void testSlowStore() {
final TestMapStore store = new WaitingOnFirstTestMapStore();
Config config = getConfig();
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setEnabled(true);
mapStoreConfig.setWriteDelaySeconds(1);
mapStoreConfig.setImplementation(store);
config.getMapConfig("default").setMapStoreConfig(mapStoreConfig);
HazelcastInstance h1 = createHazelcastInstance(config);
final IMap<Integer, Integer> map = h1.getMap("testSlowStore");
int count = 1000;
for (int i = 0; i < count; i++) {
map.put(i, 1);
}
// sleep for scheduling following puts to a different second
sleepSeconds(2);
for (int i = 0; i < count; i++) {
map.put(i, 2);
}
for (int i = 0; i < count; i++) {
final int index = i;
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
final Integer valueInMap = map.get(index);
final Integer valueInStore = (Integer) store.getStore().get(index);
assertEquals(valueInMap, valueInStore);
}
});
}
}
Aggregations