Search in sources :

Example 81 with AssertTask

use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.

the class PartitionListenerTest method test_whenMemberAdded.

@Test
public void test_whenMemberAdded() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance hz = factory.newHazelcastInstance();
    InternalPartitionServiceImpl partitionService = getNode(hz).partitionService;
    final int partitionCount = partitionService.getPartitionCount();
    warmUpPartitionsAndDrainEvents(hz, partitionCount);
    final AtomicInteger count = addEventCountingPartitionListener(partitionService);
    factory.newHazelcastInstance();
    assertClusterSizeEventually(2, hz);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            int currentCount = count.get();
            assertTrue("Expecting events equal or greater than partition-count! Count: " + currentCount, currentCount >= partitionCount);
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 82 with AssertTask

use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.

the class WriteBehindWithEntryProcessorTest method assertStoreOperationCount.

private void assertStoreOperationCount(MapStore mapStore, final int expectedStoreCallCount) {
    final CustomerDataStore store = (CustomerDataStore) mapStore;
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            final int storeCallCount = store.getStoreCallCount();
            assertEquals(expectedStoreCallCount, storeCallCount);
        }
    });
}
Also used : AssertTask(com.hazelcast.test.AssertTask) IOException(java.io.IOException)

Example 83 with AssertTask

use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.

the class WriteBehindFailAndRetryTest method testStoreOperationDone_afterTemporaryMapStoreFailure_whenNonWriteCoalescingModeOn.

@Test
public void testStoreOperationDone_afterTemporaryMapStoreFailure_whenNonWriteCoalescingModeOn() throws Exception {
    final SelfHealingMapStore<Integer, Integer> mapStore = new SelfHealingMapStore<Integer, Integer>();
    final IMap<Integer, Integer> map = TestMapUsingMapStoreBuilder.<Integer, Integer>create().withMapStore(mapStore).withNodeCount(1).withNodeFactory(createHazelcastInstanceFactory(1)).withWriteDelaySeconds(1).withWriteCoalescing(false).withPartitionCount(1).build();
    map.put(1, 2);
    map.put(1, 3);
    map.put(1, 4);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(1, mapStore.size());
        }
    });
}
Also used : AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 84 with AssertTask

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

Example 85 with AssertTask

use of com.hazelcast.test.AssertTask 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));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) AssertTask(com.hazelcast.test.AssertTask) MapStoreConfig(com.hazelcast.config.MapStoreConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) 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