Search in sources :

Example 16 with DistributedObject

use of com.hazelcast.core.DistributedObject in project hazelcast by hazelcast.

the class ClientRegressionWithMockNetworkTest method testMapDestroyIssue764.

@Test
public void testMapDestroyIssue764() throws Exception {
    HazelcastInstance server = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    assertNoOfDistributedObject("Initially the server should have %d distributed objects, but had %d", 0, server.getDistributedObjects());
    assertNoOfDistributedObject("Initially the client should have %d distributed objects, but had %d", 0, client.getDistributedObjects());
    IMap map = client.getMap("mapToDestroy");
    assertNoOfDistributedObject("After getMap() the server should have %d distributed objects, but had %d", 1, server.getDistributedObjects());
    assertNoOfDistributedObject("After getMap() the client should have %d distributed objects, but had %d", 1, client.getDistributedObjects());
    map.destroy();
    // Get the distributed objects as fast as possible to catch a race condition more likely
    Collection<DistributedObject> serverDistributedObjects = server.getDistributedObjects();
    Collection<DistributedObject> clientDistributedObjects = client.getDistributedObjects();
    assertNoOfDistributedObject("After destroy() the server should should have %d distributed objects, but had %d", 0, serverDistributedObjects);
    assertNoOfDistributedObject("After destroy() the client should should have %d distributed objects, but had %d", 0, clientDistributedObjects);
}
Also used : IMap(com.hazelcast.core.IMap) DistributedObject(com.hazelcast.core.DistributedObject) HazelcastInstance(com.hazelcast.core.HazelcastInstance) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 17 with DistributedObject

use of com.hazelcast.core.DistributedObject 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

DistributedObject (com.hazelcast.core.DistributedObject)17 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 ParallelTest (com.hazelcast.test.annotation.ParallelTest)5 IMap (com.hazelcast.core.IMap)3 MapProxyImpl (com.hazelcast.map.impl.proxy.MapProxyImpl)3 AbstractDistributedObject (com.hazelcast.spi.AbstractDistributedObject)3 Collection (java.util.Collection)3 DistributedObjectInfo (com.hazelcast.client.impl.client.DistributedObjectInfo)2 DistributedObjectEvent (com.hazelcast.core.DistributedObjectEvent)2 DistributedObjectListener (com.hazelcast.core.DistributedObjectListener)2 MapService (com.hazelcast.map.impl.MapService)2 InternalEventService (com.hazelcast.spi.impl.eventservice.InternalEventService)2 AssertTask (com.hazelcast.test.AssertTask)2 NightlyTest (com.hazelcast.test.annotation.NightlyTest)2 HashSet (java.util.HashSet)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 ClientGetDistributedObjectsCodec (com.hazelcast.client.impl.protocol.codec.ClientGetDistributedObjectsCodec)1