Search in sources :

Example 86 with AssertTask

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);
}
Also used : AssertTask(com.hazelcast.test.AssertTask)

Example 87 with 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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 88 with AssertTask

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

Example 89 with AssertTask

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);
        }
    });
}
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 90 with AssertTask

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);
            }
        });
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) GroupConfig(com.hazelcast.config.GroupConfig) AssertTask(com.hazelcast.test.AssertTask) MapStoreConfig(com.hazelcast.config.MapStoreConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

AssertTask (com.hazelcast.test.AssertTask)575 Test (org.junit.Test)489 QuickTest (com.hazelcast.test.annotation.QuickTest)428 ParallelTest (com.hazelcast.test.annotation.ParallelTest)347 HazelcastInstance (com.hazelcast.core.HazelcastInstance)263 Config (com.hazelcast.config.Config)113 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)94 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)75 ExecutionException (java.util.concurrent.ExecutionException)57 MapConfig (com.hazelcast.config.MapConfig)49 NightlyTest (com.hazelcast.test.annotation.NightlyTest)48 IOException (java.io.IOException)46 CountDownLatch (java.util.concurrent.CountDownLatch)42 IMap (com.hazelcast.core.IMap)39 NearCacheConfig (com.hazelcast.config.NearCacheConfig)38 TimeoutException (java.util.concurrent.TimeoutException)33 ClientConfig (com.hazelcast.client.config.ClientConfig)32 MapStoreConfig (com.hazelcast.config.MapStoreConfig)29 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)23 AtomicReference (java.util.concurrent.atomic.AtomicReference)20