use of com.hazelcast.config.MapStoreConfig in project hazelcast by hazelcast.
the class TestMapUsingMapStoreBuilder method build.
public IMap<K, V> build() {
if (backupCount != 0 && backupCount > nodeCount - 1) {
throw new IllegalArgumentException("backupCount > nodeCount - 1");
}
final MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setImplementation(mapStore).setWriteDelaySeconds(writeDelaySeconds).setWriteBatchSize(writeBatchSize).setWriteCoalescing(writeCoalescing);
final Config config = new Config();
config.getMapConfig(mapName).setBackupCount(backupCount).setMapStoreConfig(mapStoreConfig).setInMemoryFormat(inMemoryFormat);
if (writeBehindQueueCapacity > 0) {
config.setProperty(GroupProperty.MAP_WRITE_BEHIND_QUEUE_CAPACITY.getName(), String.valueOf(writeBehindQueueCapacity));
}
config.setProperty(GroupProperty.PARTITION_COUNT.getName(), String.valueOf(partitionCount));
if (backupDelaySeconds > 0) {
config.setProperty(GroupProperty.MAP_REPLICA_SCHEDULED_TASK_DELAY_SECONDS.getName(), String.valueOf(backupDelaySeconds));
}
// nodes
nodes = new HazelcastInstance[nodeCount];
for (int i = 0; i < nodeCount; i++) {
nodes[i] = instanceFactory.newHazelcastInstance(config);
}
return nodes[0].getMap(mapName);
}
use of com.hazelcast.config.MapStoreConfig in project hazelcast by hazelcast.
the class WriteBehindFlushTest method testWriteBehindQueues_flushed_onNodeShutdown.
@Test
public void testWriteBehindQueues_flushed_onNodeShutdown() throws Exception {
int nodeCount = 3;
String mapName = randomName();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
MapStoreConfig mapStoreConfig = new MapStoreConfig();
final MapStoreWithCounter mapStore = new MapStoreWithCounter<Integer, String>();
mapStoreConfig.setImplementation(mapStore).setWriteDelaySeconds(3000);
Config config = getConfig();
config.getMapConfig(mapName).setBackupCount(0).setMapStoreConfig(mapStoreConfig);
HazelcastInstance member = factory.newHazelcastInstance(config);
factory.newHazelcastInstance(config);
factory.newHazelcastInstance(config);
IMap<Integer, Integer> map = member.getMap(mapName);
for (int i = 0; i < 1000; i++) {
map.put(i, i);
}
factory.shutdownAll();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
for (int i = 0; i < 1000; i++) {
assertEquals(i, mapStore.store.get(i));
}
}
});
}
use of com.hazelcast.config.MapStoreConfig in project hazelcast by hazelcast.
the class WriteBehindFlushTest method testWriteBehindQueues_flushed_uponEviction.
@Test
public void testWriteBehindQueues_flushed_uponEviction() throws Exception {
int nodeCount = 3;
String mapName = randomName();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
MapStoreConfig mapStoreConfig = new MapStoreConfig();
final MapStoreWithCounter mapStore = new MapStoreWithCounter<Integer, String>();
mapStoreConfig.setImplementation(mapStore).setWriteDelaySeconds(3000);
Config config = getConfig();
config.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);
HazelcastInstance node1 = factory.newHazelcastInstance(config);
HazelcastInstance node2 = factory.newHazelcastInstance(config);
HazelcastInstance node3 = factory.newHazelcastInstance(config);
IMap<Integer, Integer> map = node1.getMap(mapName);
for (int i = 0; i < 1000; i++) {
map.put(i, i);
}
for (int i = 0; i < 1000; i++) {
map.evict(i);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1000, mapStore.countStore.get());
}
});
assertWriteBehindQueuesEmpty(mapName, asList(node1, node2, node3));
}
use of com.hazelcast.config.MapStoreConfig 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.config.MapStoreConfig in project hazelcast by hazelcast.
the class MapLoaderTest method testMapCanBeLoaded_whenLoadAllKeysThrowsExceptionFirstTime.
@Test(timeout = MINUTE)
public void testMapCanBeLoaded_whenLoadAllKeysThrowsExceptionFirstTime() throws InterruptedException {
Config config = getConfig();
MapLoader failingMapLoader = new FailingMapLoader();
MapStoreConfig mapStoreConfig = new MapStoreConfig().setImplementation(failingMapLoader);
MapConfig mapConfig = config.getMapConfig(getClass().getName()).setMapStoreConfig(mapStoreConfig);
HazelcastInstance[] hz = createHazelcastInstanceFactory(2).newInstances(config, 2);
IMap map = hz[0].getMap(mapConfig.getName());
Throwable exception = null;
try {
map.get(generateKeyNotOwnedBy(hz[0]));
} catch (Throwable e) {
exception = e;
}
assertNotNull("Exception wasn't propagated", exception);
map.loadAll(true);
assertEquals(1, map.size());
}
Aggregations