use of com.hazelcast.test.TestPartitionUtils.PartitionReplicaVersionsView in project hazelcast by hazelcast.
the class PartitionCorrectnessTestSupport method assertPartitionVersionsAndBackupValues.
private void assertPartitionVersionsAndBackupValues(int actualBackupCount, TestMigrationAwareService service, Node node, InternalPartition[] partitions, boolean allowDirty) throws InterruptedException {
Address thisAddress = node.getThisAddress();
for (InternalPartition partition : partitions) {
if (partition.isLocal()) {
int partitionId = partition.getPartitionId();
long[] replicaVersions = getReplicaVersions(node, partitionId);
for (int replica = 1; replica <= actualBackupCount; replica++) {
Address address = partition.getReplicaAddress(replica);
assertNotNull("Replica: " + replica + " is not found in " + partition, address);
HazelcastInstance backupInstance = factory.getInstance(address);
assertNotNull("Instance for " + address + " is not found! -> " + partition, backupInstance);
Node backupNode = getNode(backupInstance);
assertNotNull(backupNode);
PartitionReplicaVersionsView backupReplicaVersionsView = getPartitionReplicaVersionsView(backupNode, partitionId);
long[] backupReplicaVersions = backupReplicaVersionsView.getVersions();
assertNotNull("Versions null on " + backupNode.address + ", partitionId: " + partitionId, backupReplicaVersions);
for (int i = replica - 1; i < actualBackupCount; i++) {
assertEquals("Replica version mismatch! Owner: " + thisAddress + ", Backup: " + address + ", Partition: " + partition + ", Replica: " + (i + 1) + " owner versions: " + Arrays.toString(replicaVersions) + " backup versions: " + Arrays.toString(backupReplicaVersions), replicaVersions[i], backupReplicaVersions[i]);
}
if (!allowDirty) {
assertFalse("Backup replica is dirty! Owner: " + thisAddress + ", Backup: " + address + ", Partition: " + partition, backupReplicaVersionsView.isDirty());
}
TestMigrationAwareService backupService = getService(backupInstance);
assertEquals("Wrong data! Partition: " + partitionId + ", replica: " + replica + " on " + address + " has stale value! " + Arrays.toString(backupReplicaVersions), service.get(partitionId), backupService.get(partitionId));
}
}
}
}
Aggregations