use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class ClusterViewListenerService method getPartitions.
/**
* If any partition does not have an owner, this method returns empty collection
*
* @param partitionTableView will be converted to address->partitions mapping
* @return address->partitions mapping, where address is the client address of the member
*/
public Map<UUID, List<Integer>> getPartitions(PartitionTableView partitionTableView) {
Map<UUID, List<Integer>> partitionsMap = new HashMap<>();
int partitionCount = partitionTableView.length();
for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
PartitionReplica owner = partitionTableView.getReplica(partitionId, 0);
if (owner == null || owner.uuid() == null) {
partitionsMap.clear();
return partitionsMap;
}
partitionsMap.computeIfAbsent(owner.uuid(), k -> new LinkedList<>()).add(partitionId);
}
return partitionsMap;
}
use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class InternalPartitionImplConstructorTest method testConstructor.
@Test
public void testConstructor() throws Exception {
PartitionReplica local = new PartitionReplica(new Address("172.16.16.1", 4223), UuidUtil.newUnsecureUUID());
PartitionReplica[] replicas = new PartitionReplica[] { new PartitionReplica(new Address("127.0.0.1", 2342), UuidUtil.newUnsecureUUID()) };
InternalPartition partition = new InternalPartitionImpl(42, local, replicas, 1, null);
InternalPartitionImplConstructor constructor = new InternalPartitionImplConstructor(InternalPartitionImpl.class);
InternalPartition clonedPartition = (InternalPartition) constructor.createNew(partition);
assertEquals(partition.getPartitionId(), clonedPartition.getPartitionId());
assertEquals(partition.version(), clonedPartition.version());
assertEquals(partition.getOwnerOrNull(), clonedPartition.getOwnerOrNull());
assertEquals(partition.getReplicaAddress(0), clonedPartition.getReplicaAddress(0));
assertEquals(partition.getReplica(0), clonedPartition.getReplica(0));
assertEquals(partition.getReplicaIndex(replicas[0]), clonedPartition.getReplicaIndex(replicas[0]));
}
use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class PartitionReplicaConstructorTest method testConstructor.
@Test
public void testConstructor() {
HazelcastInstance hz = createHazelcastInstance();
warmUpPartitions(hz);
InternalPartitionService partitionService = getNode(hz).getPartitionService();
InternalPartition[] partitions = partitionService.getInternalPartitions();
InternalPartitionImpl partition = (InternalPartitionImpl) partitions[0];
PartitionReplica replica = partition.getReplica(0);
PartitionReplicaConstructor constructor = new PartitionReplicaConstructor(PartitionReplica.class);
PartitionReplica clonedReplica = (PartitionReplica) constructor.createNew(replica);
assertEquals(replica.address(), clonedReplica.address());
assertEquals(replica.uuid(), clonedReplica.uuid());
}
use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class InternalPartitionImplTest method testVersion_setReplicas.
@Test
public void testVersion_setReplicas() {
replicaOwners[0] = localReplica;
partition.setReplicas(replicaOwners);
assertEquals(1, partition.version());
PartitionReplica[] newReplicas = Arrays.copyOf(replicaOwners, replicaOwners.length);
newReplicas[0] = new PartitionReplica(newAddress(6000), UuidUtil.newUnsecureUUID());
newReplicas[1] = localReplica;
partition.setReplicas(newReplicas);
assertEquals(3, partition.version());
}
use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class InternalPartitionImplTest method testIsOwnerOrBackup.
@Test
public void testIsOwnerOrBackup() {
replicaOwners[0] = localReplica;
Address otherAddress = newAddress(5001);
replicaOwners[1] = new PartitionReplica(otherAddress, UuidUtil.newUnsecureUUID());
partition.setReplicas(replicaOwners);
assertTrue(partition.isOwnerOrBackup(replicaOwners[0]));
assertTrue(partition.isOwnerOrBackup(localReplica));
assertTrue(partition.isOwnerOrBackup(replicaOwners[1]));
assertTrue(partition.isOwnerOrBackup(otherAddress));
assertFalse(partition.isOwnerOrBackup(new PartitionReplica(newAddress(6000), UuidUtil.newUnsecureUUID())));
assertFalse(partition.isOwnerOrBackup(newAddress(6000)));
}
Aggregations