Search in sources :

Example 1 with MapStoreWithStoreCount

use of com.hazelcast.map.impl.mapstore.MapStoreTest.MapStoreWithStoreCount 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);
        }
    });
}
Also used : MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) MapStoreWithStoreCount(com.hazelcast.map.impl.mapstore.MapStoreTest.MapStoreWithStoreCount) MapStoreConfig(com.hazelcast.config.MapStoreConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with MapStoreWithStoreCount

use of com.hazelcast.map.impl.mapstore.MapStoreTest.MapStoreWithStoreCount in project hazelcast by hazelcast.

the class MapStoreWriteBehindTest method testIssue1085WriteBehindBackup.

@Test(timeout = 120000)
public void testIssue1085WriteBehindBackup() throws InterruptedException {
    Config config = getConfig();
    String name = "testIssue1085WriteBehindBackup";
    MapConfig writeBehindBackup = config.getMapConfig(name);
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setWriteDelaySeconds(5);
    int size = 1000;
    MapStoreWithStoreCount mapStore = new MapStoreWithStoreCount(size, 120);
    mapStoreConfig.setImplementation(mapStore);
    writeBehindBackup.setMapStoreConfig(mapStoreConfig);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance instance = factory.newHazelcastInstance(config);
    HazelcastInstance instance2 = factory.newHazelcastInstance(config);
    final IMap<Integer, Integer> map = instance.getMap(name);
    for (int i = 0; i < size; i++) {
        map.put(i, i);
    }
    instance2.getLifecycleService().shutdown();
    mapStore.awaitStores();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) MapStoreWithStoreCount(com.hazelcast.map.impl.mapstore.MapStoreTest.MapStoreWithStoreCount) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Config (com.hazelcast.config.Config)2 MapConfig (com.hazelcast.config.MapConfig)2 MapStoreConfig (com.hazelcast.config.MapStoreConfig)2 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 MapStoreWithStoreCount (com.hazelcast.map.impl.mapstore.MapStoreTest.MapStoreWithStoreCount)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 NightlyTest (com.hazelcast.test.annotation.NightlyTest)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Test (org.junit.Test)2 AssertTask (com.hazelcast.test.AssertTask)1