Search in sources :

Example 1 with DistributedObject

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

the class ClientRegressionWithMockNetworkTest method assertNoOfDistributedObject.

private void assertNoOfDistributedObject(String message, int expected, Collection<DistributedObject> distributedObjects) {
    StringBuilder sb = new StringBuilder(message + "\n");
    for (DistributedObject distributedObject : distributedObjects) {
        sb.append("Name: ").append(distributedObject.getName()).append(", Service: ").append(distributedObject.getServiceName()).append(", PartitionKey: ").append(distributedObject.getPartitionKey()).append("\n");
    }
    assertEqualsStringFormat(sb.toString(), expected, distributedObjects.size());
}
Also used : DistributedObject(com.hazelcast.core.DistributedObject)

Example 2 with DistributedObject

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

the class ClientRegressionWithMockNetworkTest method testGetDistributedObjectsIssue678.

@Test
public void testGetDistributedObjectsIssue678() {
    final HazelcastInstance hz = hazelcastFactory.newHazelcastInstance();
    hz.getQueue("queue");
    hz.getMap("map");
    hz.getSemaphore("s");
    final HazelcastInstance instance = hazelcastFactory.newHazelcastClient();
    final Collection<DistributedObject> distributedObjects = instance.getDistributedObjects();
    assertEquals(3, distributedObjects.size());
}
Also used : 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 3 with DistributedObject

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

the class HazelcastCacheManager method getCacheNames.

@Override
public Collection<String> getCacheNames() {
    Set<String> cacheNames = new HashSet<String>();
    final Collection<DistributedObject> distributedObjects = hazelcastInstance.getDistributedObjects();
    for (DistributedObject distributedObject : distributedObjects) {
        if (distributedObject instanceof IMap) {
            final IMap<?, ?> map = (IMap) distributedObject;
            cacheNames.add(map.getName());
        }
    }
    return cacheNames;
}
Also used : DistributedObject(com.hazelcast.core.DistributedObject) IMap(com.hazelcast.core.IMap) HashSet(java.util.HashSet)

Example 4 with DistributedObject

use of com.hazelcast.core.DistributedObject 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();
    testInstance.getMap(testMap);
    // be sure that test-map is distributed
    HazelcastTestSupport.assertOpenEventually(distributionSignal);
    Collection<String> test = cacheManager.getCacheNames();
    assertContains(test, testMap);
    testInstance.shutdown();
}
Also used : DistributedObject(com.hazelcast.core.DistributedObject) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) DistributedObjectEvent(com.hazelcast.core.DistributedObjectEvent) CountDownLatch(java.util.concurrent.CountDownLatch) DistributedObjectListener(com.hazelcast.core.DistributedObjectListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with DistributedObject

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

the class GetDistributedObjectsMessageTask method call.

@Override
protected Object call() throws Exception {
    Collection<DistributedObject> distributedObjects = clientEngine.getProxyService().getAllDistributedObjects();
    List<DistributedObjectInfo> coll = new ArrayList<DistributedObjectInfo>(distributedObjects.size());
    for (DistributedObject distributedObject : distributedObjects) {
        String name = DistributedObjectUtil.getName(distributedObject);
        coll.add(new DistributedObjectInfo(distributedObject.getServiceName(), name));
    }
    return coll;
}
Also used : DistributedObject(com.hazelcast.core.DistributedObject) ArrayList(java.util.ArrayList) DistributedObjectInfo(com.hazelcast.client.impl.client.DistributedObjectInfo)

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