Search in sources :

Example 46 with Config

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

the class EvictionTest method testIssue304EvictionDespitePut.

@Test
public void testIssue304EvictionDespitePut() throws InterruptedException {
    Config config = getConfig();
    config.getGroupConfig().setName("testIssue304EvictionDespitePut");
    MapConfig mapConfig = config.getMapConfig("testIssue304EvictionDespitePut");
    mapConfig.setMaxIdleSeconds(5);
    HazelcastInstance hazelcastInstance = createHazelcastInstance(config);
    IMap<String, Long> map = hazelcastInstance.getMap("testIssue304EvictionDespitePut");
    final AtomicInteger evictCount = new AtomicInteger(0);
    map.addEntryListener(new EntryAdapter<String, Long>() {

        public void entryEvicted(EntryEvent<String, Long> event) {
            evictCount.incrementAndGet();
        }
    }, true);
    String key = "key";
    for (int i = 0; i < 5; i++) {
        map.put(key, System.currentTimeMillis());
        sleepMillis(500);
    }
    assertEquals(evictCount.get(), 0);
    assertNotNull(map.get(key));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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 47 with Config

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

the class EvictionTest method testEvictionSpeedTest.

// current eviction check period is 1 second.
// about 30000 records can be put in one second, so the size should be adapted
@Test
public void testEvictionSpeedTest() throws InterruptedException {
    final int k = 3;
    final int size = 10000;
    final CountDownLatch latch = new CountDownLatch(k);
    final String mapName = "testEvictionSpeedTest";
    Config config = getConfig();
    final MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
    mapConfig.setEvictionPercentage(25);
    final MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
    maxSizeConfig.setMaxSizePolicy(MaxSizeConfig.MaxSizePolicy.PER_NODE);
    maxSizeConfig.setSize(size);
    mapConfig.setMaxSizeConfig(maxSizeConfig);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(k);
    final HazelcastInstance[] instances = factory.newInstances(config);
    final AtomicBoolean success = new AtomicBoolean(true);
    new Thread() {

        final IMap map = instances[0].getMap(mapName);

        public void run() {
            try {
                Thread.sleep(1000);
                while (latch.getCount() != 0) {
                    try {
                        int mapSize = map.size();
                        if (mapSize > (size * k + size * k * 10 / 100)) {
                            success.set(false);
                            break;
                        }
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }.start();
    for (int i = 0; i < k; i++) {
        final IMap<String, Integer> map = instances[i].getMap(mapName);
        new Thread() {

            public void run() {
                for (int j = 0; j < size; j++) {
                    map.put(k + "-" + j, j);
                }
                latch.countDown();
            }
        }.start();
    }
    assertTrue(latch.await(10, TimeUnit.MINUTES));
    assertTrue(success.get());
}
Also used : 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) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) 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 48 with Config

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

the class EvictionTest method createMapWithReadBackupDataEnabled.

private IMap<Integer, Integer> createMapWithReadBackupDataEnabled(int maxIdleSeconds) {
    final String mapName = randomMapName();
    Config config = getConfig();
    config.getMapConfig(mapName).setMaxIdleSeconds(maxIdleSeconds).setReadBackupData(true);
    TestHazelcastInstanceFactory hazelcastInstanceFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance[] hazelcastInstances = hazelcastInstanceFactory.newInstances(config);
    return hazelcastInstances[0].getMap(mapName);
}
Also used : 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) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 49 with Config

use of com.hazelcast.config.Config 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 50 with Config

use of com.hazelcast.config.Config 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)

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