Search in sources :

Example 6 with PartitionService

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

the class PartitionMigrationListenerTest method testAddMigrationListener_whenNullListener.

@Test(expected = NullPointerException.class)
public void testAddMigrationListener_whenNullListener() {
    HazelcastInstance hz = createHazelcastInstance();
    PartitionService partitionService = hz.getPartitionService();
    partitionService.addMigrationListener(null);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PartitionService(com.hazelcast.core.PartitionService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with PartitionService

use of com.hazelcast.core.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 : Partition(com.hazelcast.core.Partition) IPartition(com.hazelcast.spi.partition.IPartition) PartitionService(com.hazelcast.core.PartitionService) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService)

Example 8 with PartitionService

use of com.hazelcast.core.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 : Partition(com.hazelcast.core.Partition) IPartition(com.hazelcast.spi.partition.IPartition) Cluster(com.hazelcast.core.Cluster) PartitionService(com.hazelcast.core.PartitionService) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Member(com.hazelcast.core.Member)

Example 9 with PartitionService

use of com.hazelcast.core.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 : Partition(com.hazelcast.core.Partition) IPartition(com.hazelcast.spi.partition.IPartition) PartitionService(com.hazelcast.core.PartitionService) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Member(com.hazelcast.core.Member)

Example 10 with PartitionService

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

the class HazelcastTestSupport method generateKeyForPartition.

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

Aggregations

PartitionService (com.hazelcast.core.PartitionService)22 ParallelTest (com.hazelcast.test.annotation.ParallelTest)17 QuickTest (com.hazelcast.test.annotation.QuickTest)17 Test (org.junit.Test)17 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 Partition (com.hazelcast.core.Partition)7 Member (com.hazelcast.core.Member)4 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)4 IPartition (com.hazelcast.spi.partition.IPartition)4 Cluster (com.hazelcast.core.Cluster)2 MigrationListener (com.hazelcast.core.MigrationListener)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 Config (com.hazelcast.config.Config)1 MigrationEvent (com.hazelcast.core.MigrationEvent)1 AssertTask (com.hazelcast.test.AssertTask)1