Search in sources :

Example 11 with Partition

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

the class HazelcastTestSupport method generateKeyForPartition.

public static String generateKeyForPartition(HazelcastInstance instance, String prefix, int partitionId) {
    Cluster cluster = instance.getCluster();
    checkPartitionCountGreaterOrEqualMemberCount(instance);
    PartitionService partitionService = instance.getPartitionService();
    while (true) {
        String id = prefix + randomString();
        Partition partition = partitionService.getPartition(id);
        if (partition.getPartitionId() == partitionId) {
            return id;
        }
    }
}
Also used : IPartition(com.hazelcast.internal.partition.IPartition) Partition(com.hazelcast.partition.Partition) Cluster(com.hazelcast.cluster.Cluster) PartitionService(com.hazelcast.partition.PartitionService) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService)

Example 12 with Partition

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

the class HazelcastTestSupport method randomNameOwnedBy.

public static String randomNameOwnedBy(HazelcastInstance instance, String prefix) {
    Member localMember = instance.getCluster().getLocalMember();
    PartitionService partitionService = instance.getPartitionService();
    while (true) {
        String id = prefix + randomString();
        Partition partition = partitionService.getPartition(id);
        if (comparePartitionOwnership(true, localMember, partition)) {
            return id;
        }
    }
}
Also used : IPartition(com.hazelcast.internal.partition.IPartition) Partition(com.hazelcast.partition.Partition) PartitionService(com.hazelcast.partition.PartitionService) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Member(com.hazelcast.cluster.Member)

Example 13 with Partition

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

the class HazelcastTestSupport method generateKeyOwnedBy.

/**
 * Generates a key according to given reference instance by checking partition ownership for it.
 *
 * @param instance         reference instance for key generation.
 * @param generateOwnedKey {@code true} if we want a key which is owned by the given instance, otherwise
 *                         set to {@code false} which means generated key will not be owned by the given instance.
 * @return generated string.
 */
public static String generateKeyOwnedBy(HazelcastInstance instance, boolean generateOwnedKey) {
    Cluster cluster = instance.getCluster();
    checkMemberCount(generateOwnedKey, cluster);
    checkPartitionCountGreaterOrEqualMemberCount(instance);
    Member localMember = cluster.getLocalMember();
    PartitionService partitionService = instance.getPartitionService();
    while (true) {
        String id = randomString();
        Partition partition = partitionService.getPartition(id);
        if (comparePartitionOwnership(generateOwnedKey, localMember, partition)) {
            return id;
        }
    }
}
Also used : IPartition(com.hazelcast.internal.partition.IPartition) Partition(com.hazelcast.partition.Partition) Cluster(com.hazelcast.cluster.Cluster) PartitionService(com.hazelcast.partition.PartitionService) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Member(com.hazelcast.cluster.Member)

Example 14 with Partition

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

the class HazelcastTestSupport method getPartitionId.

public static int getPartitionId(HazelcastInstance hz, String partitionName) {
    PartitionService partitionService = hz.getPartitionService();
    Partition partition = partitionService.getPartition(partitionName);
    return partition.getPartitionId();
}
Also used : IPartition(com.hazelcast.internal.partition.IPartition) Partition(com.hazelcast.partition.Partition) PartitionService(com.hazelcast.partition.PartitionService) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService)

Example 15 with Partition

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

the class RingbufferStoreFailureConsistencyTest method getBackupInstance.

private HazelcastInstance getBackupInstance(HazelcastInstance instance, HazelcastInstance instance2) {
    Partition primaryPartition = instance.getPartitionService().getPartition(RINGBUFFER_NAME);
    UUID primaryInstanceUuid = primaryPartition.getOwner().getUuid();
    UUID instanceOneUuid = instance.getCluster().getLocalMember().getUuid();
    return primaryInstanceUuid.equals(instanceOneUuid) ? instance2 : instance;
}
Also used : Partition(com.hazelcast.partition.Partition) UUID(java.util.UUID)

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