Search in sources :

Example 6 with DistributedObjectListener

use of com.hazelcast.core.DistributedObjectListener 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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) DistributedObjectEvent(com.hazelcast.core.DistributedObjectEvent) AssertTask(com.hazelcast.test.AssertTask) Collection(java.util.Collection) DistributedObject(com.hazelcast.core.DistributedObject) CountDownLatch(java.util.concurrent.CountDownLatch) DistributedObjectListener(com.hazelcast.core.DistributedObjectListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

DistributedObjectListener (com.hazelcast.core.DistributedObjectListener)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 DistributedObjectEvent (com.hazelcast.core.DistributedObjectEvent)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 Config (com.hazelcast.config.Config)2 DistributedObject (com.hazelcast.core.DistributedObject)2 ItemListenerConfig (com.hazelcast.config.ItemListenerConfig)1 ListenerConfig (com.hazelcast.config.ListenerConfig)1 QueueConfig (com.hazelcast.config.QueueConfig)1 ClientListener (com.hazelcast.core.ClientListener)1 HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)1 IMap (com.hazelcast.core.IMap)1 LifecycleListener (com.hazelcast.core.LifecycleListener)1 MembershipListener (com.hazelcast.core.MembershipListener)1 MigrationListener (com.hazelcast.core.MigrationListener)1 InternalMigrationListener (com.hazelcast.internal.partition.impl.InternalMigrationListener)1 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)1