Search in sources :

Example 16 with Partition

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

Example 17 with Partition

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

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

the class BackpressureTest method testBackpressure.

@Test
public void testBackpressure() {
    DAG dag = new DAG();
    final int member1Port = hz1.getCluster().getLocalMember().getAddress().getPort();
    final Member member2 = hz2.getCluster().getLocalMember();
    final int ptionOwnedByMember2 = hz1.getPartitionService().getPartitions().stream().filter(p -> p.getOwner().equals(member2)).map(Partition::getPartitionId).findAny().orElseThrow(() -> new RuntimeException("Can't find a partition owned by member " + hz2));
    Vertex source = dag.newVertex("source", ProcessorMetaSupplier.of((Address address) -> ProcessorSupplier.of(address.getPort() == member1Port ? GenerateP::new : noopP())));
    Vertex hiccup = dag.newVertex("hiccup", HiccupP::new);
    Vertex sink = dag.newVertex("sink", SinkProcessors.writeMapP("counts"));
    dag.edge(between(source, hiccup).distributed().partitioned(wholeItem(), (x, y) -> ptionOwnedByMember2)).edge(between(hiccup, sink));
    hz1.getJet().newJob(dag).join();
    assertCounts(hz1.getMap("counts"));
}
Also used : Address(com.hazelcast.cluster.Address) AbstractProcessor(com.hazelcast.jet.core.AbstractProcessor) Traverser(com.hazelcast.jet.Traverser) Member(com.hazelcast.cluster.Member) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) Partition(com.hazelcast.partition.Partition) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) Traversers.lazy(com.hazelcast.jet.Traversers.lazy) Traversers.traverseIterable(com.hazelcast.jet.Traversers.traverseIterable) Util.entry(com.hazelcast.jet.Util.entry) Map(java.util.Map) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) DAG(com.hazelcast.jet.core.DAG) Nonnull(javax.annotation.Nonnull) ProcessorSupplier(com.hazelcast.jet.core.ProcessorSupplier) Before(org.junit.Before) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) NightlyTest(com.hazelcast.test.annotation.NightlyTest) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) Assert.assertNotNull(org.junit.Assert.assertNotNull) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Test(org.junit.Test) Math.min(java.lang.Math.min) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Category(org.junit.experimental.categories.Category) Vertex(com.hazelcast.jet.core.Vertex) SinkProcessors(com.hazelcast.jet.core.processor.SinkProcessors) Entry(java.util.Map.Entry) Functions.wholeItem(com.hazelcast.function.Functions.wholeItem) Processors.noopP(com.hazelcast.jet.core.processor.Processors.noopP) Assert.assertEquals(org.junit.Assert.assertEquals) Edge.between(com.hazelcast.jet.core.Edge.between) Partition(com.hazelcast.partition.Partition) Vertex(com.hazelcast.jet.core.Vertex) Address(com.hazelcast.cluster.Address) DAG(com.hazelcast.jet.core.DAG) Member(com.hazelcast.cluster.Member) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 19 with Partition

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

the class AdvancedNetworkClientIntegrationTest method testPartitions.

@Test
public void testPartitions() {
    client = HazelcastClient.newHazelcastClient(getClientConfig());
    Iterator<Partition> memberPartitions = instances[0].getPartitionService().getPartitions().iterator();
    Set<Partition> partitions = client.getPartitionService().getPartitions();
    for (Partition partition : partitions) {
        Partition memberPartition = memberPartitions.next();
        assertEquals(memberPartition.getPartitionId(), partition.getPartitionId());
        assertTrueEventually(() -> {
            Member owner = partition.getOwner();
            assertNotNull(owner);
            assertEquals(memberPartition.getOwner().getAddressMap().get(CLIENT), owner.getAddress());
        });
    }
}
Also used : Partition(com.hazelcast.partition.Partition) Member(com.hazelcast.cluster.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 20 with Partition

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

Partition (com.hazelcast.partition.Partition)28 PartitionService (com.hazelcast.partition.PartitionService)13 Member (com.hazelcast.cluster.Member)12 Test (org.junit.Test)7 HazelcastInstance (com.hazelcast.core.HazelcastInstance)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 IPartition (com.hazelcast.internal.partition.IPartition)5 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)5 UUID (java.util.UUID)5 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Cluster (com.hazelcast.cluster.Cluster)3 PartitionIdSet (com.hazelcast.internal.util.collection.PartitionIdSet)3 Entry (java.util.Map.Entry)3 Config (com.hazelcast.config.Config)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Assert.assertEquals (org.junit.Assert.assertEquals)2