Search in sources :

Example 91 with AssertTask

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

the class MapStoreWithPredicateTest method testValuesWithPredicate_checksMapStoreLoad.

@Test
public void testValuesWithPredicate_checksMapStoreLoad() {
    EventBasedMapStore<String, Integer> testMapStore = new EventBasedMapStore<String, Integer>();
    Map<String, Integer> mapForStore = new HashMap<String, Integer>();
    mapForStore.put("key1", 17);
    mapForStore.put("key2", 37);
    mapForStore.put("key3", 47);
    testMapStore.getStore().putAll(mapForStore);
    Config config = newConfig(testMapStore, 0);
    HazelcastInstance instance = createHazelcastInstance(config);
    final IMap map = instance.getMap("default");
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            final Collection values = map.values(Predicates.greaterThan("value", 1));
            assertEquals(3, values.size());
            assertContains(values, 17);
            assertContains(values, 37);
            assertContains(values, 47);
        }
    });
}
Also used : HashMap(java.util.HashMap) Config(com.hazelcast.config.Config) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) Collection(java.util.Collection) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 92 with AssertTask

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

the class MapStoreWithPredicateTest method testKeySetWithPredicate_checksMapStoreLoad.

@Test
public void testKeySetWithPredicate_checksMapStoreLoad() {
    EventBasedMapStore<String, Integer> testMapStore = new EventBasedMapStore<String, Integer>();
    Map<String, Integer> mapForStore = new HashMap<String, Integer>();
    mapForStore.put("key1", 17);
    mapForStore.put("key2", 37);
    mapForStore.put("key3", 47);
    testMapStore.getStore().putAll(mapForStore);
    Config config = newConfig(testMapStore, 0);
    HazelcastInstance instance = createHazelcastInstance(config);
    final IMap map = instance.getMap("default");
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            Set expected = map.keySet(Predicates.greaterThan("value", 1));
            assertEquals(3, expected.size());
            assertContains(expected, "key1");
            assertContains(expected, "key2");
            assertContains(expected, "key3");
        }
    });
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) Config(com.hazelcast.config.Config) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 93 with AssertTask

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

the class MapStoreWriteBehindTest method testWriteBehindUpdateSameKey.

@Test(timeout = 120000)
public void testWriteBehindUpdateSameKey() throws Exception {
    final TestMapStore testMapStore = new TestMapStore(2, 0, 0);
    testMapStore.setLoadAllKeys(false);
    Config config = newConfig(testMapStore, 5);
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    nodeFactory.newHazelcastInstance(config);
    IMap<Object, Object> map = instance.getMap("map");
    map.put("key", "value");
    Thread.sleep(2000);
    map.put("key", "value2");
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals("value2", testMapStore.getStore().get("key"));
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestMapStore(com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) 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 94 with AssertTask

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

the class MapReduceTest method testMapperReducerChunked.

@Test(timeout = TEST_TIMEOUT)
public void testMapperReducerChunked() throws Exception {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    HazelcastInstance h1 = nodeFactory.newHazelcastInstance();
    HazelcastInstance h2 = nodeFactory.newHazelcastInstance();
    HazelcastInstance h3 = nodeFactory.newHazelcastInstance();
    assertClusterSizeEventually(3, h1);
    assertClusterSizeEventually(3, h2);
    assertClusterSizeEventually(3, h3);
    try {
        IMap<Integer, Integer> m1 = h1.getMap(MAP_NAME);
        for (int i = 0; i < 10000; i++) {
            m1.put(i, i);
        }
        JobTracker tracker = h1.getJobTracker("default");
        Job<Integer, Integer> job = tracker.newJob(integerKvSource(m1));
        JobCompletableFuture<Map<String, Integer>> future = job.chunkSize(10).mapper(new GroupingTestMapper()).reducer(new TestReducerFactory()).submit();
        TrackableJob trackableJob = tracker.getTrackableJob(future.getJobId());
        final JobProcessInformation processInformation = trackableJob.getJobProcessInformation();
        Map<String, Integer> result = future.get();
        // pre-calculate results
        int[] expectedResults = new int[4];
        for (int i = 0; i < 10000; i++) {
            int index = i % 4;
            expectedResults[index] += i;
        }
        for (int i = 0; i < 4; i++) {
            assertEquals(expectedResults[i], (int) result.get(String.valueOf(i)));
        }
        assertTrueEventually(new AssertTask() {

            @Override
            public void run() {
                if (processInformation.getProcessedRecords() < 10000) {
                    System.err.println(processInformation.getProcessedRecords());
                }
                assertEquals(10000, processInformation.getProcessedRecords());
            }
        });
    } finally {
        tripTerminate(h1, h2, h3);
    }
}
Also used : BigInteger(java.math.BigInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 95 with AssertTask

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

the class PartitionLostListenerTest method test_partitionLostListenerInvoked_whenAllPartitionReplicasCrashed.

@Test
public void test_partitionLostListenerInvoked_whenAllPartitionReplicasCrashed() {
    HazelcastInstance lite = factory.newHazelcastInstance(new Config().setLiteMember(true));
    warmUpPartitions(instances);
    warmUpPartitions(lite);
    waitAllForSafeState(instances);
    waitInstanceForSafeState(lite);
    final EventCollectingPartitionLostListener listener = new EventCollectingPartitionLostListener();
    lite.getPartitionService().addPartitionLostListener(listener);
    instances[0].getLifecycleService().terminate();
    instances[1].getLifecycleService().terminate();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            List<PartitionLostEvent> events = listener.getEvents();
            assertFalse(events.isEmpty());
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) EventCollectingPartitionLostListener(com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) List(java.util.List) IOException(java.io.IOException) 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