use of com.hazelcast.map.listener.EntryExpiredListener in project hazelcast by hazelcast.
the class ExpirationManagerTest method stops_running_when_clusterState_turns_passive.
@Test
public void stops_running_when_clusterState_turns_passive() throws Exception {
Config config = new Config();
config.setProperty(SYS_PROP_EXPIRATION_TASK_PERIOD_SECONDS, "1");
HazelcastInstance node = createHazelcastInstance(config);
final AtomicInteger expirationCounter = new AtomicInteger();
IMap map = node.getMap("test");
map.addEntryListener(new EntryExpiredListener() {
@Override
public void entryExpired(EntryEvent event) {
expirationCounter.incrementAndGet();
}
}, true);
map.put(1, 1, 3, TimeUnit.SECONDS);
node.getCluster().changeClusterState(PASSIVE);
// wait a little to see if any expiration is occurring
sleepSeconds(3);
int expirationCount = expirationCounter.get();
assertEquals(format("Expecting no expiration but found:%d", expirationCount), 0, expirationCount);
}
use of com.hazelcast.map.listener.EntryExpiredListener in project hazelcast by hazelcast.
the class ExpirationManagerTest method starts_running_when_clusterState_turns_active.
@Test
public void starts_running_when_clusterState_turns_active() throws Exception {
Config config = new Config();
config.setProperty(SYS_PROP_EXPIRATION_TASK_PERIOD_SECONDS, "1");
HazelcastInstance node = createHazelcastInstance(config);
final AtomicInteger expirationCounter = new AtomicInteger();
IMap map = node.getMap("test");
map.addEntryListener(new EntryExpiredListener() {
@Override
public void entryExpired(EntryEvent event) {
expirationCounter.incrementAndGet();
}
}, true);
map.put(1, 1, 3, SECONDS);
node.getCluster().changeClusterState(PASSIVE);
node.getCluster().changeClusterState(ACTIVE);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
int expirationCount = expirationCounter.get();
assertEquals(format("Expecting 1 expiration but found:%d", expirationCount), 1, expirationCount);
}
});
}
Aggregations