Search in sources :

Example 21 with MaxSizeConfig

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

the class MapMaxSizeConfigTest method setMaxSize_withSetter_toZero.

@Test
public void setMaxSize_withSetter_toZero() throws Exception {
    MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
    maxSizeConfig.setSize(0);
    assertEquals(Integer.MAX_VALUE, maxSizeConfig.getSize());
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 22 with MaxSizeConfig

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

the class MapMaxSizeConfigTest method setMaxSize_withSetter_toPositive.

@Test
public void setMaxSize_withSetter_toPositive() throws Exception {
    final int expectedMaxSize = 123456;
    MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
    maxSizeConfig.setSize(expectedMaxSize);
    assertEquals(expectedMaxSize, maxSizeConfig.getSize());
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 23 with MaxSizeConfig

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

the class MapMaxSizeConfigTest method setMaxSize_withSetter_toNegative.

@Test
public void setMaxSize_withSetter_toNegative() throws Exception {
    MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
    maxSizeConfig.setSize(-2131);
    assertEquals(Integer.MAX_VALUE, maxSizeConfig.getSize());
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 24 with MaxSizeConfig

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

the class IndexIntegrationTest method loadFromStore_whenEvicted.

@Test
public void loadFromStore_whenEvicted() {
    // GIVEN
    String name = randomString();
    String attributeName = "currency";
    String currency = "dollar";
    long amount = 5L;
    Config config = new Config();
    config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
    MapConfig mapConfig = config.getMapConfig(name);
    mapConfig.setEvictionPolicy(EvictionPolicy.LFU);
    mapConfig.setMinEvictionCheckMillis(0);
    // size=1 means each put/load will trigger eviction
    MaxSizeConfig maxSizeConfig = new MaxSizeConfig(1, PER_PARTITION);
    mapConfig.setMaxSizeConfig(maxSizeConfig);
    // Dummy map loader which returns a Trade object with amount=5, currency=dollar
    MapStoreConfig mapStoreConfig = mapConfig.getMapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(new DummyLoader(amount, currency));
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<String, Trade> map = instance.getMap(name);
    map.addIndex(attributeName, false);
    // WHEN
    // This `get` will trigger load from map-loader but since eviction kicks in, entry will get removed
    // We should be able to get the value loaded from store but index should be removed
    Trade trade = map.get(randomString());
    map.get(randomString());
    // THEN
    assertEquals(1, map.size());
    assertEquals(5L, (long) trade.amount);
    assertEquals(currency, trade.currency);
    Index index = getIndexOfAttributeForMap(instance, name, attributeName);
    Set<QueryableEntry> dollars = index.getRecords(currency);
    assertEquals(1, dollars.size());
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 25 with MaxSizeConfig

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

the class MapStoreWriteThroughTest method testOneMemberWriteThroughWithLRU.

@Test(timeout = 120000)
public void testOneMemberWriteThroughWithLRU() throws Exception {
    final int size = 10000;
    TestMapStore testMapStore = new TestMapStore(size * 2, 1, 1);
    testMapStore.setLoadAllKeys(false);
    Config config = newConfig(testMapStore, 0);
    config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
    MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
    maxSizeConfig.setSize(size);
    MapConfig mapConfig = config.getMapConfig("default");
    mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
    mapConfig.setMaxSizeConfig(maxSizeConfig);
    mapConfig.setMinEvictionCheckMillis(0);
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    IMap<Integer, Employee> map = instance.getMap("default");
    final CountDownLatch countDownLatch = new CountDownLatch(size);
    map.addEntryListener(new EntryAdapter() {

        @Override
        public void entryEvicted(EntryEvent event) {
            countDownLatch.countDown();
        }
    }, false);
    for (int i = 0; i < size * 2; i++) {
        // trigger eviction.
        if (i == (size * 2) - 1 || i == size) {
            sleepMillis(1001);
        }
        map.put(i, new Employee("joe", i, true, 100.00));
    }
    assertEquals(testMapStore.getStore().size(), size * 2);
    assertOpenEventually(countDownLatch);
    final String msgFailure = String.format("map size: %d put count: %d", map.size(), size);
    assertTrue(msgFailure, map.size() > size / 2);
    assertTrue(msgFailure, map.size() <= size);
    assertEquals(testMapStore.getStore().size(), size * 2);
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) EntryAdapter(com.hazelcast.core.EntryAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleObjects.Employee) TestMapStore(com.hazelcast.map.impl.mapstore.MapStoreTest.TestMapStore) EntryEvent(com.hazelcast.core.EntryEvent) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MaxSizeConfig (com.hazelcast.config.MaxSizeConfig)26 MapConfig (com.hazelcast.config.MapConfig)18 QuickTest (com.hazelcast.test.annotation.QuickTest)15 Test (org.junit.Test)15 Config (com.hazelcast.config.Config)13 ParallelTest (com.hazelcast.test.annotation.ParallelTest)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)9 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)7 NearCacheConfig (com.hazelcast.config.NearCacheConfig)7 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)5 NightlyTest (com.hazelcast.test.annotation.NightlyTest)5 IMap (com.hazelcast.core.IMap)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 MapStoreConfig (com.hazelcast.config.MapStoreConfig)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 EvictionPolicy (com.hazelcast.config.EvictionPolicy)1 GroupConfig (com.hazelcast.config.GroupConfig)1 MapIndexConfig (com.hazelcast.config.MapIndexConfig)1 MultiMapConfig (com.hazelcast.config.MultiMapConfig)1