Search in sources :

Example 1 with Partition

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

the class SqlErrorAbstractTest method newHazelcastInstance.

/**
 * Start the new Hazelcast instance.
 *
 * @param awaitAssignment whether to wait for a partition assignment to a new member
 * @return created instance
 */
protected HazelcastInstance newHazelcastInstance(boolean awaitAssignment) {
    HazelcastInstance instance = factory.newHazelcastInstance(getConfig());
    if (awaitAssignment) {
        assertTrueEventually(() -> {
            Set<UUID> memberIds = new HashSet<>();
            for (Member member : instance.getCluster().getMembers()) {
                memberIds.add(member.getUuid());
            }
            PartitionService partitionService = instance.getPartitionService();
            Set<UUID> assignedMemberIds = new HashSet<>();
            for (Partition partition : partitionService.getPartitions()) {
                Member owner = partition.getOwner();
                assertNotNull(owner);
                assignedMemberIds.add(owner.getUuid());
            }
            assertEquals(memberIds, assignedMemberIds);
        });
    }
    return instance;
}
Also used : Partition(com.hazelcast.partition.Partition) HazelcastInstance(com.hazelcast.core.HazelcastInstance) PartitionService(com.hazelcast.partition.PartitionService) UUID(java.util.UUID) Member(com.hazelcast.cluster.Member) HashSet(java.util.HashSet)

Example 2 with Partition

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

the class PartitionServiceProxy method getPartitions.

@Override
public Set<Partition> getPartitions() {
    final int partitionCount = partitionService.getPartitionCount();
    Set<Partition> partitions = new LinkedHashSet<>(partitionCount);
    for (int i = 0; i < partitionCount; i++) {
        final Partition partition = partitionService.getPartition(i);
        partitions.add(partition);
    }
    return partitions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Partition(com.hazelcast.partition.Partition)

Example 3 with Partition

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

the class ClientConsoleApp method handlePartitions.

protected void handlePartitions(String[] args) {
    Set<Partition> partitions = client.getPartitionService().getPartitions();
    Map<Member, Integer> partitionCounts = new HashMap<Member, Integer>();
    for (Partition partition : partitions) {
        Member owner = partition.getOwner();
        if (owner != null) {
            Integer count = partitionCounts.get(owner);
            int newCount = 1;
            if (count != null) {
                newCount = count + 1;
            }
            partitionCounts.put(owner, newCount);
        }
        println(partition);
    }
    Set<Entry<Member, Integer>> entries = partitionCounts.entrySet();
    for (Entry<Member, Integer> entry : entries) {
        println(entry.getKey() + ":" + entry.getValue());
    }
}
Also used : Partition(com.hazelcast.partition.Partition) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) Member(com.hazelcast.cluster.Member)

Example 4 with Partition

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

the class WriteBehindOnBackupsTest method getOwnerNode.

private HazelcastInstance getOwnerNode(String key, HazelcastInstance[] nodes) {
    PartitionService partitionService = nodes[0].getPartitionService();
    Partition partition = partitionService.getPartition(key);
    Member owner = partition.getOwner();
    for (HazelcastInstance node : nodes) {
        Member localMember = node.getCluster().getLocalMember();
        if (localMember.equals(owner)) {
            return node;
        }
    }
    throw new IllegalStateException("This should not be happen...");
}
Also used : Partition(com.hazelcast.partition.Partition) HazelcastInstance(com.hazelcast.core.HazelcastInstance) PartitionService(com.hazelcast.partition.PartitionService) Member(com.hazelcast.cluster.Member)

Example 5 with Partition

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

the class SimpleReplicatedMapTest method load.

private void load(ExecutorService es) throws Exception {
    if (!load) {
        return;
    }
    final ReplicatedMap<String, Object> map = instance.getReplicatedMap(NAMESPACE);
    final Member thisMember = instance.getCluster().getLocalMember();
    List<String> lsOwnedEntries = new LinkedList<String>();
    for (int i = 0; i < entryCount; i++) {
        final String key = String.valueOf(i);
        Partition partition = instance.getPartitionService().getPartition(key);
        if (thisMember.equals(partition.getOwner())) {
            lsOwnedEntries.add(key);
        }
    }
    final CountDownLatch latch = new CountDownLatch(lsOwnedEntries.size());
    for (final String ownedKey : lsOwnedEntries) {
        es.execute(new Runnable() {

            public void run() {
                map.put(ownedKey, createValue());
                latch.countDown();
            }
        });
    }
    latch.await();
}
Also used : Partition(com.hazelcast.partition.Partition) CountDownLatch(java.util.concurrent.CountDownLatch) Member(com.hazelcast.cluster.Member) LinkedList(java.util.LinkedList)

Aggregations

Partition (com.hazelcast.partition.Partition)28 PartitionService (com.hazelcast.partition.PartitionService)13 Member (com.hazelcast.cluster.Member)12 Test (org.junit.Test)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 IPartition (com.hazelcast.internal.partition.IPartition)5 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)5 UUID (java.util.UUID)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Cluster (com.hazelcast.cluster.Cluster)3 PartitionIdSet (com.hazelcast.internal.util.collection.PartitionIdSet)3 Entry (java.util.Map.Entry)3 Config (com.hazelcast.config.Config)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Assert.assertEquals (org.junit.Assert.assertEquals)2