use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class WriteBehindExceptionTest method testWriteBehindStoreWithException.
@Test
public void testWriteBehindStoreWithException() throws InterruptedException {
final MapStore mapStore = new MapStore();
mapStore.setLoadAllKeys(false);
Config config = newConfig(mapStore, 5);
config.setProperty("hazelcast.local.localAddress", "127.0.0.1");
HazelcastInstance instance = createHazelcastInstance(config);
IMap<Integer, String> map = instance.getMap("map");
IMap<Integer, String> map2 = instance.getMap("map2");
IMap<Integer, String> map3 = instance.getMap("map3");
for (int i = 0; i < 10; i++) {
map.put(i, "value-" + i);
}
for (int i = 0; i < 10; i++) {
map2.put(i + 10, "value-" + i);
}
for (int i = 0; i < 10; i++) {
map3.put(i + 20, "value-" + i);
}
assertOpenEventually(latch1);
Thread.sleep(2000);
assertSizeEventually(29, mapStore.store);
for (int i = 0; i < 30; i++) {
map.delete(i);
}
assertOpenEventually(latch2);
Thread.sleep(2000);
assertSizeEventually(1, mapStore.store);
}
use of com.hazelcast.config.Config 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.config.Config in project hazelcast by hazelcast.
the class MapStoreWriteBehindTest method testIssue1085WriteBehindBackupTransactional.
@Test(timeout = 120000)
public void testIssue1085WriteBehindBackupTransactional() throws InterruptedException {
final String name = randomMapName();
final int size = 1000;
MapStoreTest.MapStoreWithStoreCount mapStore = new MapStoreTest.MapStoreWithStoreCount(size, 120);
Config config = newConfig(name, mapStore, 5);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
HazelcastInstance instance = factory.newHazelcastInstance(config);
HazelcastInstance instance2 = factory.newHazelcastInstance(config);
TransactionContext context = instance.newTransactionContext();
context.beginTransaction();
TransactionalMap<Object, Object> tmap = context.getMap(name);
for (int i = 0; i < size; i++) {
tmap.put(i, i);
}
context.commitTransaction();
instance2.getLifecycleService().shutdown();
mapStore.awaitStores();
}
use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class MapStoreWriteBehindTest method testWriteBehindDestroy.
@Test(timeout = 120000)
@Category(NightlyTest.class)
public // issue #2747: when MapStore configured with write behind, distributed objects' destroy method does not work
void testWriteBehindDestroy() throws InterruptedException {
final int writeDelaySeconds = 5;
String mapName = randomMapName();
final MapStore<String, String> store = new SimpleMapStore<String, String>();
Config config = newConfig(mapName, store, writeDelaySeconds);
HazelcastInstance hzInstance = createHazelcastInstance(config);
IMap<String, String> map = hzInstance.getMap(mapName);
map.put("key", "value");
map.destroy();
sleepSeconds(2 * writeDelaySeconds);
assertNotEquals("value", store.load("key"));
}
use of com.hazelcast.config.Config 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());
}
});
}
Aggregations