use of com.hazelcast.internal.partition.service.TestAbstractMigrationAwareService in project hazelcast by hazelcast.
the class PartitionCorrectnessTestSupport method assertReplicaVersionsAndBackupValues.
private <N> void assertReplicaVersionsAndBackupValues(int actualBackupCount, TestAbstractMigrationAwareService<N> service, Node node, InternalPartition[] partitions, N name, boolean allowDirty) {
Address thisAddress = node.getThisAddress();
ServiceNamespace namespace = service.getNamespace(name);
for (InternalPartition partition : partitions) {
if (partition.isLocal()) {
int partitionId = partition.getPartitionId();
long[] replicaVersions = getPartitionReplicaVersionsView(node, partitionId).getVersions(namespace);
for (int replica = 1; replica <= actualBackupCount; replica++) {
Address address = partition.getReplicaAddress(replica);
assertNotNull("On " + thisAddress + ", 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(namespace);
assertNotNull(namespace + " replica versions are null on " + backupNode.address + ", partitionId: " + partitionId + ", replicaIndex: " + replica, 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(namespace));
}
TestAbstractMigrationAwareService backupService = getService(backupInstance, service.getServiceName());
assertEquals("Wrong data! Partition: " + partitionId + ", replica: " + replica + " on " + address + " has stale value! " + Arrays.toString(backupReplicaVersions), service.get(name, partitionId), backupService.get(name, partitionId));
}
}
}
}
Aggregations