Search in sources :

Example 56 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class MapAggregationJsonTest method testValueIsOmitted_whenObjectIsEmpty.

@Test
public void testValueIsOmitted_whenObjectIsEmpty() {
    IMap<Integer, HazelcastJsonValue> map = getPreloadedMap();
    map.put(OBJECT_COUNT, new HazelcastJsonValue(Json.object().toString()));
    long maxLongValue = map.aggregate(Aggregators.<Map.Entry<Integer, HazelcastJsonValue>>longMax("longValue"));
    assertEquals(OBJECT_COUNT - 1, maxLongValue);
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) Map(java.util.Map) IMap(com.hazelcast.map.IMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 57 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class MapAggregationJsonTest method testValueIsOmitted_whenValueIsNotAnObject.

@Test
public void testValueIsOmitted_whenValueIsNotAnObject() {
    IMap<Integer, HazelcastJsonValue> map = getPreloadedMap();
    map.put(OBJECT_COUNT, new HazelcastJsonValue(Json.value(5).toString()));
    long maxLongValue = map.aggregate(Aggregators.<Map.Entry<Integer, HazelcastJsonValue>>longMax("longValue"));
    assertEquals(OBJECT_COUNT - 1, maxLongValue);
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) Map(java.util.Map) IMap(com.hazelcast.map.IMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 58 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class MapAggregationJsonTest method testValueIsOmitted_whenAttributePathIsNotTerminal_count.

@Test
public void testValueIsOmitted_whenAttributePathIsNotTerminal_count() {
    IMap<Integer, HazelcastJsonValue> map = getPreloadedMap();
    map.put(OBJECT_COUNT, new HazelcastJsonValue(Json.object().add("longValue", Json.object()).toString()));
    long count = map.aggregate(Aggregators.<Map.Entry<Integer, HazelcastJsonValue>>count("longValue"));
    assertEquals(OBJECT_COUNT, count);
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) Map(java.util.Map) IMap(com.hazelcast.map.IMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 59 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class MapAggregationJsonTest method testValueIsOmitted_whenAttributePathDoesNotExist.

@Test
public void testValueIsOmitted_whenAttributePathDoesNotExist() {
    IMap<Integer, HazelcastJsonValue> map = getPreloadedMap();
    map.put(OBJECT_COUNT, new HazelcastJsonValue(Json.object().add("someField", "someValue").toString()));
    long maxLongValue = map.aggregate(Aggregators.<Map.Entry<Integer, HazelcastJsonValue>>longMax("longValue"));
    assertEquals(OBJECT_COUNT - 1, maxLongValue);
}
Also used : HazelcastJsonValue(com.hazelcast.core.HazelcastJsonValue) Map(java.util.Map) IMap(com.hazelcast.map.IMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 60 with IMap

use of com.hazelcast.map.IMap in project hazelcast by hazelcast.

the class MapStoreDataLoadingContinuesWhenNodeJoins method testLoadingFinishes_whenMemberJoinsWhileLoading.

@Test(timeout = 600000)
public void testLoadingFinishes_whenMemberJoinsWhileLoading() throws Exception {
    assumeThat("With LAZY InMemoryModel this test may fail due to a known issue reported in OS #11544 and #12384", initialLoadMode, not(LAZY));
    final Config config = createConfigWithDelayingMapStore();
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final CountDownLatch node1MapLoadingAboutToStart = new CountDownLatch(1);
    final CountDownLatch node1FinishedLoading = new CountDownLatch(1);
    final AtomicInteger mapSizeOnNode2 = new AtomicInteger();
    // thread 1: start a single node and trigger loading the data
    Thread thread1 = new Thread(new Runnable() {

        @Override
        public void run() {
            HazelcastInstance instance = factory.newHazelcastInstance(config);
            instances.set(0, instance);
            // get map and trigger loading the data
            IMap<String, String> map = instance.getMap(MAP_NAME);
            node1MapLoadingAboutToStart.countDown();
            LOGGER.info("Getting the size of the map on node1 -> load is triggered");
            int sizeOnNode1 = map.size();
            LOGGER.info("Map loading has been completed by now");
            LOGGER.info("Map size on node 1: " + sizeOnNode1);
            node1FinishedLoading.countDown();
        }
    }, "Thread 1");
    thread1.start();
    node1MapLoadingAboutToStart.await();
    // thread 2: second member joins the cluster while loading is in progress
    Thread thread2 = new Thread(new Runnable() {

        @Override
        public void run() {
            HazelcastInstance instance = factory.newHazelcastInstance(config);
            instances.set(1, instance);
            try {
                LOGGER.info("Getting the map " + MAP_NAME);
                IMap map = instance.getMap(MAP_NAME);
                final int loadTimeMillis = MS_PER_LOAD * PRELOAD_SIZE;
                boolean node1FinishedLoadingInTime = node1FinishedLoading.await(loadTimeMillis, TimeUnit.MILLISECONDS);
                // if node1 doesn't finish in time (unlikely because of the 5min timeout), we may execute GetSizeOperation
                // again on a not fully loaded map -> map size may not match to the expected value
                LOGGER.info("Node1 finished loading in time: " + node1FinishedLoadingInTime);
                LOGGER.info("Getting the size of the map on node2");
                mapSizeOnNode2.set(map.size());
                LOGGER.info("Map size on node 2: " + mapSizeOnNode2.get());
            } catch (InterruptedException e) {
                ignore(e);
            }
        }
    }, "Thread 2");
    thread2.start();
    // join threads
    thread1.join();
    thread2.join();
    assertEquals(PRELOAD_SIZE, mapSizeOnNode2.get());
}
Also used : IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapStoreConfig(com.hazelcast.config.MapStoreConfig) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

IMap (com.hazelcast.map.IMap)292 Test (org.junit.Test)259 QuickTest (com.hazelcast.test.annotation.QuickTest)237 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)228 HazelcastInstance (com.hazelcast.core.HazelcastInstance)139 Config (com.hazelcast.config.Config)103 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)82 Map (java.util.Map)73 CountDownLatch (java.util.concurrent.CountDownLatch)65 MapStoreConfig (com.hazelcast.config.MapStoreConfig)54 Category (org.junit.experimental.categories.Category)51 Assert.assertEquals (org.junit.Assert.assertEquals)50 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)48 HashMap (java.util.HashMap)48 Collection (java.util.Collection)41 RunWith (org.junit.runner.RunWith)41 MapConfig (com.hazelcast.config.MapConfig)36 Set (java.util.Set)34 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)33 AssertTask (com.hazelcast.test.AssertTask)32