Search in sources :

Example 11 with PartitionService

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

the class PartitionServiceSafetyCheckTest method clusterShouldNotBeSafe_whenBackupsBlocked_withoutAntiEntropy.

@Test
public void clusterShouldNotBeSafe_whenBackupsBlocked_withoutAntiEntropy() throws InterruptedException {
    Config config = getConfig(true, false);
    HazelcastInstance hz = factory.newHazelcastInstance(config);
    startNodes(config, nodeCount - 1);
    final Collection<HazelcastInstance> instances = factory.getAllHazelcastInstances();
    warmUpPartitions(instances);
    for (HazelcastInstance instance : instances) {
        setBackupPacketDropFilter(instance, BLOCK_RATIO);
    }
    fillData(hz);
    assertTrueFiveSeconds(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertFalse(isAllInSafeState(instances));
            for (HazelcastInstance instance : instances) {
                PartitionService ps = instance.getPartitionService();
                assertFalse(ps.isClusterSafe());
            }
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) PartitionService(com.hazelcast.partition.PartitionService) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with PartitionService

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

the class LocalAddressRegistryIntegrationTest method randomKeyNameOwnedByPartition.

private String randomKeyNameOwnedByPartition(HazelcastInstance hz, int partitionId) {
    PartitionService partitionService = hz.getPartitionService();
    while (true) {
        String name = randomString();
        Partition partition = partitionService.getPartition(name);
        if (partition.getPartitionId() == partitionId) {
            return name;
        }
    }
}
Also used : Partition(com.hazelcast.partition.Partition) PartitionService(com.hazelcast.partition.PartitionService)

Example 13 with PartitionService

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

the class ClientMigrationListenerTest method testRemoveMigrationListener_whenExistingRegistrationId.

@Test
public void testRemoveMigrationListener_whenExistingRegistrationId() {
    HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    PartitionService clientPartitionService = client.getPartitionService();
    MigrationListener listener = mock(MigrationListener.class);
    UUID registrationId = clientPartitionService.addMigrationListener(listener);
    assertRegistrationsSizeEventually(instance, 1);
    boolean removed = clientPartitionService.removeMigrationListener(registrationId);
    assertRegistrationsSizeEventually(instance, 0);
    assertTrue(removed);
    HazelcastInstance hz2 = hazelcastFactory.newHazelcastInstance();
    warmUpPartitions(instance, hz2);
    verifyMigrationListenerNeverInvoked(listener);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PartitionService(com.hazelcast.partition.PartitionService) UUID(java.util.UUID) MigrationListener(com.hazelcast.partition.MigrationListener) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) PartitionMigrationListenerTest(com.hazelcast.partition.PartitionMigrationListenerTest)

Example 14 with PartitionService

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

the class MapFetchIndexOperationTest method getLocalPartitions.

private static PartitionIdSet getLocalPartitions(HazelcastInstance member) {
    PartitionService partitionService = member.getPartitionService();
    PartitionIdSet res = new PartitionIdSet(partitionService.getPartitions().size());
    for (Partition partition : partitionService.getPartitions()) {
        if (partition.getOwner().localMember()) {
            res.add(partition.getPartitionId());
        }
    }
    return res;
}
Also used : Partition(com.hazelcast.partition.Partition) PartitionIdSet(com.hazelcast.internal.util.collection.PartitionIdSet) PartitionService(com.hazelcast.partition.PartitionService)

Example 15 with PartitionService

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

the class SqlIndexTestSupport method getLocalEntries.

protected static <K, V> Map<K, V> getLocalEntries(HazelcastInstance member, int count, IntFunction<K> keyProducer, IntFunction<V> valueProducer) {
    if (count == 0) {
        return Collections.emptyMap();
    }
    PartitionService partitionService = member.getPartitionService();
    Map<K, V> res = new LinkedHashMap<>();
    for (int i = 0; i < Integer.MAX_VALUE; i++) {
        K key = keyProducer.apply(i);
        if (key == null) {
            continue;
        }
        Partition partition = partitionService.getPartition(key);
        if (!partition.getOwner().localMember()) {
            continue;
        }
        V value = valueProducer.apply(i);
        if (value == null) {
            continue;
        }
        res.put(key, value);
        if (res.size() == count) {
            break;
        }
    }
    if (res.size() < count) {
        throw new RuntimeException("Failed to get the necessary number of keys: " + res.size());
    }
    return res;
}
Also used : Partition(com.hazelcast.partition.Partition) PartitionService(com.hazelcast.partition.PartitionService) LinkedHashMap(java.util.LinkedHashMap)

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