Search in sources :

Example 86 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class EvictionTest method testRandomEvictionPolicyWorks.

@Test
public void testRandomEvictionPolicyWorks() throws Exception {
    Config config = getConfig();
    int maxSize = 300;
    config.getMapConfig("test").setEvictionPolicy(RANDOM).getMaxSizeConfig().setSize(maxSize).setMaxSizePolicy(PER_NODE);
    HazelcastInstance node = createHazelcastInstance(config);
    IMap<Integer, Integer> map = node.getMap("test");
    for (int i = 0; i < 500; i++) {
        map.put(i, i);
    }
    int size = map.size();
    String message = "map-size should be smaller than max-size but found [map-size = %d and max-size = %d]";
    assertTrue(format(message, size, maxSize), size <= maxSize);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 87 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class InMemoryFormatTest method testIssue2622.

/**
     * if statistics enabled InMemoryFormat.Object does not work
     */
@Test
public void testIssue2622() {
    final String mapName = randomString();
    Config config = new Config();
    final MapConfig mapConfig = new MapConfig(mapName);
    mapConfig.setInMemoryFormat(InMemoryFormat.OBJECT);
    mapConfig.setStatisticsEnabled(true);
    config.addMapConfig(mapConfig);
    final HazelcastInstance instance = createHazelcastInstance(config);
    final IMap<String, SerializationValue> map = instance.getMap(mapName);
    final SerializationValue serializationValue = new SerializationValue();
    map.put("key", serializationValue);
    // EntryProcessor should not trigger de-serialization
    map.executeOnKey("key", new AbstractEntryProcessor<String, SerializationValue>() {

        @Override
        public Object process(final Map.Entry<String, SerializationValue> entry) {
            return null;
        }
    });
    assertEquals(1, SerializationValue.deSerializeCount.get());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) MapConfig(com.hazelcast.config.MapConfig) 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 88 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class InMemoryFormatTest method testNativeNearCache_throwsException.

@Test(expected = IllegalArgumentException.class)
public void testNativeNearCache_throwsException() throws Exception {
    NearCacheConfig nearCacheConfig = new NearCacheConfig();
    nearCacheConfig.setInMemoryFormat(InMemoryFormat.NATIVE);
    Config config = getConfig();
    config.getMapConfig("default").setNearCacheConfig(nearCacheConfig);
    HazelcastInstance member = createHazelcastInstance(config);
    member.getMap("default");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) NearCacheConfig(com.hazelcast.config.NearCacheConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 89 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class InMemoryFormatTest method testNativeIMap_throwsException.

@Test(expected = IllegalArgumentException.class)
public void testNativeIMap_throwsException() throws Exception {
    Config config = getConfig();
    config.getMapConfig("default").setInMemoryFormat(InMemoryFormat.NATIVE);
    HazelcastInstance member = createHazelcastInstance(config);
    member.getMap("default");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 90 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class InterceptorTest method testGetAll_withGetInterceptor.

@Test
public void testGetAll_withGetInterceptor() throws InterruptedException {
    HazelcastInstance instance1 = createHazelcastInstance(getConfig());
    IMap<Integer, String> map = instance1.getMap(randomString());
    map.addInterceptor(new SimpleInterceptor());
    Set<Integer> set = new HashSet<Integer>();
    for (int i = 0; i < 100; i++) {
        map.put(i, String.valueOf(i));
        set.add(i);
    }
    Map<Integer, String> allValues = map.getAll(set);
    for (int i = 0; i < 100; i++) {
        assertEquals(String.valueOf(i) + ":", allValues.get(i));
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HashSet(java.util.HashSet) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

HazelcastInstance (com.hazelcast.core.HazelcastInstance)2084 Test (org.junit.Test)1684 QuickTest (com.hazelcast.test.annotation.QuickTest)1466 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1389 Config (com.hazelcast.config.Config)815 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)665 AssertTask (com.hazelcast.test.AssertTask)263 MapConfig (com.hazelcast.config.MapConfig)254 CountDownLatch (java.util.concurrent.CountDownLatch)251 NightlyTest (com.hazelcast.test.annotation.NightlyTest)230 MapStoreConfig (com.hazelcast.config.MapStoreConfig)169 IMap (com.hazelcast.core.IMap)149 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)144 ClientConfig (com.hazelcast.client.config.ClientConfig)137 Before (org.junit.Before)111 NearCacheConfig (com.hazelcast.config.NearCacheConfig)106 Member (com.hazelcast.core.Member)99 Map (java.util.Map)96 SlowTest (com.hazelcast.test.annotation.SlowTest)94 SqlPredicate (com.hazelcast.query.SqlPredicate)83