Search in sources :

Example 1 with PartitionService

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

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

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

the class HazelcastOSGiInstanceTest method getPartitionServiceCalledSuccessfullyOverOSGiInstance.

@Test
public void getPartitionServiceCalledSuccessfullyOverOSGiInstance() {
    PartitionService mockPartitionService = mock(PartitionService.class);
    HazelcastInstance mockHazelcastInstance = mock(HazelcastInstance.class);
    HazelcastOSGiInstance hazelcastOSGiInstance = createHazelcastOSGiInstance(mockHazelcastInstance);
    when(mockHazelcastInstance.getPartitionService()).thenReturn(mockPartitionService);
    assertEquals(mockPartitionService, hazelcastOSGiInstance.getPartitionService());
    verify(mockHazelcastInstance).getPartitionService();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastOSGiTestUtil.createHazelcastOSGiInstance(com.hazelcast.osgi.impl.HazelcastOSGiTestUtil.createHazelcastOSGiInstance) PartitionService(com.hazelcast.partition.PartitionService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with PartitionService

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

the class InMemoryFormatTest method countDeserializationsOnContainsValue.

@Test
public void countDeserializationsOnContainsValue() {
    final Config config = new Config().addMapConfig(new MapConfig("default").setInMemoryFormat(InMemoryFormat.OBJECT));
    final HazelcastInstance hz = createHazelcastInstance(config);
    final PartitionService partitionService = hz.getPartitionService();
    final IMap<Integer, Object> m = hz.getMap("mappy");
    final HashSet<Integer> nonEmptyPartitions = new HashSet<Integer>();
    for (int i = 0; i < MemberPartitionStateImpl.DEFAULT_PARTITION_COUNT * 5; i++) {
        m.put(i, i);
        nonEmptyPartitions.add(partitionService.getPartition(i).getPartitionId());
    }
    final SerializationCounting value = new SerializationCounting();
    m.containsValue(value);
    assertEquals(nonEmptyPartitions.size(), SerializationCounting.deserializationCount.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) PartitionService(com.hazelcast.partition.PartitionService) MapConfig(com.hazelcast.config.MapConfig) HashSet(java.util.HashSet) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with PartitionService

use of com.hazelcast.partition.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);
    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)

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