use of com.hazelcast.spi.partition.IPartition in project hazelcast by hazelcast.
the class HazelcastTestSupport method getPartitionId.
// ##################################
// ########## partition id ##########
// ##################################
/**
* Gets a partition id owned by this particular member.
*/
public static int getPartitionId(HazelcastInstance hz) {
warmUpPartitions(hz);
InternalPartitionService partitionService = getPartitionService(hz);
for (IPartition partition : partitionService.getPartitions()) {
if (partition.isLocal()) {
return partition.getPartitionId();
}
}
throw new RuntimeException("No local partitions are found for hz: " + hz.getName());
}
use of com.hazelcast.spi.partition.IPartition in project hazelcast by hazelcast.
the class AbstractPartitionLostListenerTest method getMinReplicaIndicesByPartitionId.
protected final Map<Integer, Integer> getMinReplicaIndicesByPartitionId(List<HazelcastInstance> instances) {
Map<Integer, Integer> survivingPartitions = new HashMap<Integer, Integer>();
for (HazelcastInstance instance : instances) {
Node survivingNode = getNode(instance);
Address survivingNodeAddress = survivingNode.getThisAddress();
for (IPartition partition : survivingNode.getPartitionService().getPartitions()) {
if (partition.isOwnerOrBackup(survivingNodeAddress)) {
for (int replicaIndex = 0; replicaIndex < getNodeCount(); replicaIndex++) {
if (survivingNodeAddress.equals(partition.getReplicaAddress(replicaIndex))) {
Integer replicaIndexOfOtherInstance = survivingPartitions.get(partition.getPartitionId());
if (replicaIndexOfOtherInstance != null) {
survivingPartitions.put(partition.getPartitionId(), Math.min(replicaIndex, replicaIndexOfOtherInstance));
} else {
survivingPartitions.put(partition.getPartitionId(), replicaIndex);
}
break;
}
}
}
}
}
return survivingPartitions;
}
Aggregations