use of com.hazelcast.core.DistributedObjectEvent in project hazelcast by hazelcast.
the class QueueEvictionTest method testQueueEviction_whenTtlIsZero_thenListenersAreNeverthelessExecuted.
@Test
public void testQueueEviction_whenTtlIsZero_thenListenersAreNeverthelessExecuted() throws Exception {
String queueName = randomString();
Config config = smallInstanceConfig();
config.getQueueConfig("default").setPriorityComparatorClassName(comparatorClassName);
config.getQueueConfig(queueName).setEmptyQueueTtl(0);
HazelcastInstance hz = createHazelcastInstance(config);
final CountDownLatch latch = new CountDownLatch(2);
hz.addDistributedObjectListener(new DistributedObjectListener() {
public void distributedObjectCreated(DistributedObjectEvent event) {
latch.countDown();
}
public void distributedObjectDestroyed(DistributedObjectEvent event) {
latch.countDown();
}
});
IQueue<VersionedObject<String>> queue = hz.getQueue(queueName);
assertTrue(queue.offer(new VersionedObject<>("item")));
assertEquals(new VersionedObject<>("item"), queue.poll());
assertTrue(latch.await(10, TimeUnit.SECONDS));
}
use of com.hazelcast.core.DistributedObjectEvent in project hazelcast by hazelcast.
the class TestCacheManager method testCacheNames.
@Test
public void testCacheNames() {
// create a test instance, to reproduce the behavior described in the GitHub issue
// https://github.com/hazelcast/hazelcast/issues/492
final String testMap = "test-map";
final CountDownLatch distributionSignal = new CountDownLatch(1);
instance.addDistributedObjectListener(new DistributedObjectListener() {
@Override
public void distributedObjectCreated(DistributedObjectEvent event) {
DistributedObject distributedObject = event.getDistributedObject();
if (distributedObject instanceof IMap) {
IMap<?, ?> map = (IMap) distributedObject;
if (testMap.equals(map.getName())) {
distributionSignal.countDown();
}
}
}
@Override
public void distributedObjectDestroyed(DistributedObjectEvent event) {
}
});
HazelcastInstance testInstance = Hazelcast.newHazelcastInstance(extractConfig());
testInstance.getMap(testMap);
// be sure that test-map is distributed
HazelcastTestSupport.assertOpenEventually(distributionSignal);
Collection<String> test = cacheManager.getCacheNames();
assertContains(test, testMap);
testInstance.shutdown();
}
use of com.hazelcast.core.DistributedObjectEvent in project hazelcast by hazelcast.
the class DistributedObjectListenerTest method destroyedNotReceivedOnClient.
@Test
public void destroyedNotReceivedOnClient() throws Exception {
HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
final HazelcastInstance client = hazelcastFactory.newHazelcastClient();
final CountDownLatch createdLatch = new CountDownLatch(1);
final CountDownLatch destroyedLatch = new CountDownLatch(1);
client.addDistributedObjectListener(new DistributedObjectListener() {
@Override
public void distributedObjectCreated(DistributedObjectEvent event) {
createdLatch.countDown();
}
@Override
public void distributedObjectDestroyed(DistributedObjectEvent event) {
destroyedLatch.countDown();
}
});
final String name = randomString();
final ITopic<Object> topic = instance.getTopic(name);
assertOpenEventually(createdLatch, 10);
assertEquals(1, client.getDistributedObjects().size());
topic.destroy();
assertOpenEventually(destroyedLatch, 10);
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() throws Exception {
Collection<DistributedObject> distributedObjects = client.getDistributedObjects();
assertTrue(distributedObjects.isEmpty());
}
}, 5);
}
use of com.hazelcast.core.DistributedObjectEvent in project hazelcast by hazelcast.
the class QueueListenerTest method testListener_withEvictionViaTTL.
@Test
public void testListener_withEvictionViaTTL() throws Exception {
Config config = getConfig();
config.getQueueConfig("queueWithTTL").setEmptyQueueTtl(0);
HazelcastInstance hz = createHazelcastInstance(config);
final CountDownLatch latch = new CountDownLatch(2);
hz.addDistributedObjectListener(new DistributedObjectListener() {
@Override
public void distributedObjectCreated(DistributedObjectEvent event) {
latch.countDown();
}
@Override
public void distributedObjectDestroyed(DistributedObjectEvent event) {
latch.countDown();
}
});
IQueue<VersionedObject<String>> queue = hz.getQueue("queueWithTTL");
queue.offer(new VersionedObject<>("item"));
queue.poll();
assertTrue(latch.await(10, TimeUnit.SECONDS));
}
Aggregations