use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class EvictionTest method testMapRecordIdleEvictionOnMigration.
@Test
@Category(NightlyTest.class)
public void testMapRecordIdleEvictionOnMigration() {
final String name = "testMapRecordIdleEvictionOnMigration";
Config cfg = getConfig();
cfg.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
MapConfig mapConfig = cfg.getMapConfig(name);
int maxIdleSeconds = 30;
int size = 100;
final int nsize = size / 5;
mapConfig.setMaxIdleSeconds(maxIdleSeconds);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
HazelcastInstance instance1 = factory.newHazelcastInstance(cfg);
final IMap<Integer, Integer> map = instance1.getMap(name);
final CountDownLatch latch = new CountDownLatch(size - nsize);
map.addEntryListener(new EntryAdapter() {
public void entryEvicted(EntryEvent event) {
latch.countDown();
}
}, false);
// put sample data
for (int i = 0; i < size; i++) {
map.put(i, i);
}
// wait until some time that is close to eviction
sleepSeconds(maxIdleSeconds - 5);
// touch the ones you dont want to be evicted.
for (int i = 0; i < nsize; i++) {
map.get(i);
}
factory.newHazelcastInstance(cfg);
factory.newHazelcastInstance(cfg);
//wait until eviction is complete
assertOpenEventually(latch, 240);
assertSizeEventually(nsize, map);
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class QueryAdvancedTest method testQueryWithTTL.
@Test
@SuppressWarnings("deprecation")
public void testQueryWithTTL() throws Exception {
Config config = getConfig();
String mapName = "default";
config.getMapConfig(mapName).setTimeToLiveSeconds(5);
HazelcastInstance instance = createHazelcastInstance(config);
IMap<String, Employee> map = instance.getMap(mapName);
map.addIndex("name", false);
map.addIndex("age", false);
map.addIndex("active", true);
int passiveEmployees = 5;
int activeEmployees = 5;
int allEmployees = passiveEmployees + activeEmployees;
final CountDownLatch latch = new CountDownLatch(allEmployees);
map.addEntryListener(new EntryAdapter() {
@Override
public void entryEvicted(EntryEvent event) {
latch.countDown();
}
}, false);
for (int i = 0; i < activeEmployees; i++) {
Employee employee = new Employee("activeEmployee" + i, 60, true, i);
map.put("activeEmployee" + i, employee);
}
for (int i = 0; i < passiveEmployees; i++) {
Employee employee = new Employee("passiveEmployee" + i, 60, false, i);
map.put("passiveEmployee" + i, employee);
}
// check the query result before eviction
Collection values = map.values(new SqlPredicate("active"));
assertEquals(activeEmployees, values.size());
// wait until eviction is completed
assertOpenEventually(latch);
// check the query result after eviction
values = map.values(new SqlPredicate("active"));
assertEquals(0, values.size());
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class MapPreconditionsTest method testAddLocalEntryListenerWithMapListenerAndPredicate_NullPredicate.
@Test(expected = NullPointerException.class)
public void testAddLocalEntryListenerWithMapListenerAndPredicate_NullPredicate() {
MapListener mapListener = new MapListenerAdapter() {
public void onEntryEvent(EntryEvent event) {
System.out.println("-");
}
};
Predicate predicate = null;
map.addLocalEntryListener(mapListener, predicate, true);
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class ListenerTest method testConfigListenerRegistration.
@Test
public void testConfigListenerRegistration() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
String name = randomString();
Config config = getConfig();
MapConfig mapConfig = config.getMapConfig(name);
EntryListenerConfig entryListenerConfig = new EntryListenerConfig();
entryListenerConfig.setImplementation(new EntryAdapter() {
public void entryAdded(EntryEvent event) {
latch.countDown();
}
});
mapConfig.addEntryListenerConfig(entryListenerConfig);
HazelcastInstance instance = createHazelcastInstance(config);
IMap<Object, Object> map = instance.getMap(name);
map.put(1, 1);
assertTrue(latch.await(10, TimeUnit.SECONDS));
}
use of com.hazelcast.core.EntryEvent in project hazelcast by hazelcast.
the class MapPreconditionsTest method testAddEntryListenerWithMapListenerAndPredicate_NullPredicate.
@Test(expected = NullPointerException.class)
public void testAddEntryListenerWithMapListenerAndPredicate_NullPredicate() {
MapListener mapListener = new MapListenerAdapter() {
public void onEntryEvent(EntryEvent event) {
System.out.println("-");
}
};
Predicate predicate = null;
map.addEntryListener(mapListener, predicate, true);
}
Aggregations