Search in sources :

Example 6 with PartitionService

use of com.hazelcast.partition.PartitionService 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 7 with PartitionService

use of com.hazelcast.partition.PartitionService 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 8 with PartitionService

use of com.hazelcast.partition.PartitionService 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 9 with PartitionService

use of com.hazelcast.partition.PartitionService 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 10 with PartitionService

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

the class TestUtil method warmupPartitions.

private static void warmupPartitions(HazelcastInstance instance) {
    if (instance == null) {
        return;
    }
    final int maxRetryCount = 15;
    IntervalFunction intervalFunction = IntervalFunctions.exponentialBackoffWithCap(10L, 2, 1000L);
    PartitionService ps = instance.getPartitionService();
    for (Partition partition : ps.getPartitions()) {
        int i = 1;
        while (partition.getOwner() == null) {
            if (i > maxRetryCount) {
                fail("The owner of Partition{partitionId=" + partition.getPartitionId() + "}" + " could not be obtained after " + maxRetryCount + " retries.");
            }
            sleepMillis((int) intervalFunction.waitAfterAttempt(i));
            ++i;
        }
    }
}
Also used : Partition(com.hazelcast.partition.Partition) PartitionService(com.hazelcast.partition.PartitionService) Endpoint(com.hazelcast.cluster.Endpoint) IntervalFunction(com.hazelcast.jet.retry.IntervalFunction)

Aggregations

PartitionService (com.hazelcast.partition.PartitionService)20 Partition (com.hazelcast.partition.Partition)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)9 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Test (org.junit.Test)9 IPartition (com.hazelcast.internal.partition.IPartition)5 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)5 Member (com.hazelcast.cluster.Member)4 PartitionMigrationListenerTest (com.hazelcast.partition.PartitionMigrationListenerTest)4 Cluster (com.hazelcast.cluster.Cluster)3 UUID (java.util.UUID)3 Config (com.hazelcast.config.Config)2 MigrationListener (com.hazelcast.partition.MigrationListener)2 HashSet (java.util.HashSet)2 Endpoint (com.hazelcast.cluster.Endpoint)1 MapConfig (com.hazelcast.config.MapConfig)1 NearCacheConfig (com.hazelcast.config.NearCacheConfig)1 PartitionIdSet (com.hazelcast.internal.util.collection.PartitionIdSet)1 IntervalFunction (com.hazelcast.jet.retry.IntervalFunction)1