Search in sources :

Example 16 with Partition

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

the class PartitionServiceProxyTest method testGetPartitions.

@Test
public void testGetPartitions() {
    String key = "Key";
    PartitionService clientPartitionService = client.getPartitionService();
    Set<Partition> clientPartitions = clientPartitionService.getPartitions();
    PartitionService serverPartitionService = server.getPartitionService();
    Set<Partition> serverPartitions = serverPartitionService.getPartitions();
    assertEquals(clientPartitions.size(), serverPartitions.size());
}
Also used : Partition(com.hazelcast.core.Partition) PartitionService(com.hazelcast.core.PartitionService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 17 with Partition

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

the class PartitionServiceProxyTest method testGetPartition.

@Test
public void testGetPartition() {
    String key = "Key";
    PartitionService clientPartitionService = client.getPartitionService();
    Partition clientPartition = clientPartitionService.getPartition(key);
    PartitionService serverPartitionService = server.getPartitionService();
    Partition serverPartition = serverPartitionService.getPartition(key);
    assertEquals(clientPartition.getPartitionId(), serverPartition.getPartitionId());
}
Also used : Partition(com.hazelcast.core.Partition) PartitionService(com.hazelcast.core.PartitionService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 18 with Partition

use of com.hazelcast.core.Partition in project gora by apache.

the class JCacheStore method getPartitions.

@Override
public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query) throws IOException {
    List<PartitionQuery<K, T>> partitions = new ArrayList<>();
    try {
        Member[] clusterMembers = new Member[hazelcastInstance.getCluster().getMembers().size()];
        this.hazelcastInstance.getCluster().getMembers().toArray(clusterMembers);
        for (Member member : clusterMembers) {
            JCacheResult<K, T> result = ((JCacheResult<K, T>) query.execute());
            ConcurrentSkipListSet<K> memberOwnedCacheEntries = new ConcurrentSkipListSet<>();
            while (result.next()) {
                K key = result.getKey();
                Partition partition = hazelcastInstance.getPartitionService().getPartition(key);
                if (partition.getOwner().getUuid().equals(member.getUuid())) {
                    memberOwnedCacheEntries.add(key);
                }
            }
            PartitionQueryImpl<K, T> partition = new PartitionQueryImpl<>(query, memberOwnedCacheEntries.first(), memberOwnedCacheEntries.last(), member.getSocketAddress().getHostString());
            partition.setConf(this.getConf());
            partitions.add(partition);
        }
    } catch (java.lang.Exception ex) {
        LOG.error("Exception occurred while partitioning the query based on Hazelcast partitions.", ex);
        return null;
    }
    LOG.info("Query is partitioned to {} number of partitions.", partitions.size());
    return partitions;
}
Also used : Partition(com.hazelcast.core.Partition) PartitionQueryImpl(org.apache.gora.query.impl.PartitionQueryImpl) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) ArrayList(java.util.ArrayList) PartitionQuery(org.apache.gora.query.PartitionQuery) Member(com.hazelcast.core.Member)

Aggregations

Partition (com.hazelcast.core.Partition)18 Member (com.hazelcast.core.Member)13 PartitionService (com.hazelcast.core.PartitionService)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)4 IPartition (com.hazelcast.spi.partition.IPartition)4 ParallelTest (com.hazelcast.test.annotation.ParallelTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 Cluster (com.hazelcast.core.Cluster)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Entry (java.util.Map.Entry)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 InternalLockNamespace (com.hazelcast.concurrent.lock.InternalLockNamespace)1 LockServiceImpl (com.hazelcast.concurrent.lock.LockServiceImpl)1 LockStore (com.hazelcast.concurrent.lock.LockStore)1 ILock (com.hazelcast.core.ILock)1 IMap (com.hazelcast.core.IMap)1 MultiMap (com.hazelcast.core.MultiMap)1