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;
}
}
}
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;
}
}
}
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"));
}
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());
});
}
}
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;
}
Aggregations