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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations