Search in sources :

Example 66 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class MapLockTest method testLockOwnership.

@Test(expected = IllegalMonitorStateException.class)
public void testLockOwnership() throws Exception {
    final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    final Config config = getConfig();
    String name = randomString();
    final HazelcastInstance node1 = nodeFactory.newHazelcastInstance(config);
    final HazelcastInstance node2 = nodeFactory.newHazelcastInstance(config);
    final IMap<Integer, Object> map1 = node1.getMap(name);
    final IMap<Integer, Object> map2 = node2.getMap(name);
    map1.lock(1);
    map2.unlock(1);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) NightlyTest(com.hazelcast.test.annotation.NightlyTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 67 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class EvictionTest method testMapRecordIdleEviction.

@Test
public void testMapRecordIdleEviction() throws InterruptedException {
    final String mapName = randomMapName("testMapRecordIdleEviction");
    final int maxIdleSeconds = 1;
    final int size = 100;
    Config config = getConfig();
    MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.setMaxIdleSeconds(maxIdleSeconds);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Integer, Integer> map = instance.getMap(mapName);
    for (int i = 0; i < size; i++) {
        map.put(i, i);
    }
    assertSizeEventually(0, map);
}
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) MapConfig(com.hazelcast.config.MapConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 68 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class EvictionTest method testLastAddedKey_canBeEvicted_whenFreeHeapNeeded.

/**
     * Eviction of last added key can only be triggered with one of heap based max-size-policies.
     */
@Test
public void testLastAddedKey_canBeEvicted_whenFreeHeapNeeded() {
    // don't use getConfig(), this test is OSS specific
    Config config = new Config();
    config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
    config.getMapConfig("test").setEvictionPolicy(LFU).getMaxSizeConfig().setSize(90).setMaxSizePolicy(FREE_HEAP_PERCENTAGE);
    HazelcastInstance node = createHazelcastInstance(config);
    IMap<Integer, Integer> map = node.getMap("test");
    final AtomicReference<Integer> evictedKey = new AtomicReference<Integer>(null);
    map.addEntryListener(new EntryEvictedListener<Integer, Integer>() {

        @Override
        public void entryEvicted(EntryEvent<Integer, Integer> event) {
            evictedKey.set(event.getKey());
        }
    }, false);
    // 1. Make available free-heap-percentage 10. availableFree = maxMemoryMB - (totalMemoryMB - freeMemoryMB)
    // free-heap-percentage = availableFree/maxMemoryMB;
    int totalMemoryMB = 90;
    int freeMemoryMB = 0;
    int maxMemoryMB = 100;
    setMockRuntimeMemoryInfoAccessor(map, totalMemoryMB, freeMemoryMB, maxMemoryMB);
    // 2. This `put` should trigger eviction because we used 90% heap already.
    // And max used-heap-percentage was set 10% in map-config.
    map.put(1, 1);
    final Integer expected = 1;
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals("Eviction impl. should evict latest added key when heap based max-size-policy is used", expected, evictedKey.get());
        }
    });
}
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) AssertTask(com.hazelcast.test.AssertTask) AtomicReference(java.util.concurrent.atomic.AtomicReference) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 69 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class EvictionTest method testEvictionLFUInternal.

/**
     * This test is only testing occurrence of LFU eviction.
     */
protected void testEvictionLFUInternal(boolean disableStats) {
    int mapMaxSize = 10000;
    String mapName = randomMapName();
    MaxSizeConfig msc = new MaxSizeConfig();
    msc.setMaxSizePolicy(PER_NODE);
    msc.setSize(mapMaxSize);
    Config config = getConfig();
    MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.setStatisticsEnabled(disableStats);
    mapConfig.setEvictionPolicy(LFU);
    mapConfig.setMinEvictionCheckMillis(0);
    mapConfig.setMaxSizeConfig(msc);
    HazelcastInstance node = createHazelcastInstance(config);
    IMap<Object, Object> map = node.getMap(mapName);
    for (int i = 0; i < 2 * mapMaxSize; i++) {
        map.put(i, i);
    }
    int mapSize = map.size();
    assertTrue("Eviction did not work, map size " + mapSize + " should be smaller than allowed max size = " + mapMaxSize, mapSize < mapMaxSize);
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) 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) MapConfig(com.hazelcast.config.MapConfig)

Example 70 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class ExpirationListenerTest method init.

@Before
public void init() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(instanceCount);
    Config config = new Config();
    instances = factory.newInstances(config);
    HazelcastInstance node = getInstance();
    map = node.getMap(randomMapName());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Before(org.junit.Before)

Aggregations

Config (com.hazelcast.config.Config)1190 Test (org.junit.Test)838 HazelcastInstance (com.hazelcast.core.HazelcastInstance)815 QuickTest (com.hazelcast.test.annotation.QuickTest)718 ParallelTest (com.hazelcast.test.annotation.ParallelTest)648 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)361 MapConfig (com.hazelcast.config.MapConfig)341 MapStoreConfig (com.hazelcast.config.MapStoreConfig)211 CountDownLatch (java.util.concurrent.CountDownLatch)145 NightlyTest (com.hazelcast.test.annotation.NightlyTest)142 NearCacheConfig (com.hazelcast.config.NearCacheConfig)125 Before (org.junit.Before)115 AssertTask (com.hazelcast.test.AssertTask)113 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)93 MapIndexConfig (com.hazelcast.config.MapIndexConfig)91 ClientConfig (com.hazelcast.client.config.ClientConfig)83 IMap (com.hazelcast.core.IMap)81 GroupConfig (com.hazelcast.config.GroupConfig)69 ListenerConfig (com.hazelcast.config.ListenerConfig)60 JoinConfig (com.hazelcast.config.JoinConfig)59