Search in sources :

Example 6 with Cluster

use of com.hazelcast.cluster.Cluster in project hazelcast by hazelcast.

the class TestSupportTest method mockHazelcastInstance.

private HazelcastInstance mockHazelcastInstance() {
    HazelcastInstance hzInstance = mock(HazelcastInstance.class);
    Cluster cluster = mock(Cluster.class);
    Member localMember = mock(Member.class);
    when(hzInstance.getCluster()).thenReturn(cluster);
    when(cluster.getLocalMember()).thenReturn(localMember);
    return hzInstance;
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Cluster(com.hazelcast.cluster.Cluster) Member(com.hazelcast.cluster.Member)

Example 7 with Cluster

use of com.hazelcast.cluster.Cluster in project hazelcast by hazelcast.

the class HazelcastTestSupport method generateKeyForPartition.

public static String generateKeyForPartition(HazelcastInstance instance, int partitionId) {
    Cluster cluster = instance.getCluster();
    checkPartitionCountGreaterOrEqualMemberCount(instance);
    PartitionService partitionService = instance.getPartitionService();
    while (true) {
        String id = 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 8 with Cluster

use of com.hazelcast.cluster.Cluster 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 9 with Cluster

use of com.hazelcast.cluster.Cluster 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 10 with Cluster

use of com.hazelcast.cluster.Cluster in project hazelcast by hazelcast.

the class AdvancedClusterStateTest method changeClusterStateEventually.

public static void changeClusterStateEventually(HazelcastInstance hz, ClusterState newState) {
    final Cluster cluster = hz.getCluster();
    long timeout = TimeUnit.SECONDS.toMillis(ASSERT_TRUE_EVENTUALLY_TIMEOUT);
    Throwable t = null;
    while (timeout > 0) {
        long start = Clock.currentTimeMillis();
        try {
            cluster.changeClusterState(newState);
            return;
        } catch (Throwable e) {
            t = e;
        }
        sleepMillis(500);
        long end = Clock.currentTimeMillis();
        timeout -= (end - start);
    }
    throw ExceptionUtil.rethrow(t);
}
Also used : Cluster(com.hazelcast.cluster.Cluster)

Aggregations

Cluster (com.hazelcast.cluster.Cluster)24 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 Member (com.hazelcast.cluster.Member)12 Test (org.junit.Test)12 QuickTest (com.hazelcast.test.annotation.QuickTest)11 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 ClientConfig (com.hazelcast.client.config.ClientConfig)5 Config (com.hazelcast.config.Config)5 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)4 MCClusterMetadata (com.hazelcast.client.impl.management.MCClusterMetadata)4 ClientClusterService (com.hazelcast.client.impl.spi.ClientClusterService)4 IPartition (com.hazelcast.internal.partition.IPartition)3 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)3 Partition (com.hazelcast.partition.Partition)3 PartitionService (com.hazelcast.partition.PartitionService)3 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)3 ExecutionException (java.util.concurrent.ExecutionException)3 HazelcastCommandLine.getHazelcastClientInstanceImpl (com.hazelcast.client.console.HazelcastCommandLine.getHazelcastClientInstanceImpl)2 RandomLB (com.hazelcast.client.util.RandomLB)2 RoundRobinLB (com.hazelcast.client.util.RoundRobinLB)2