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