Search in sources :

Example 1 with PartitionReplicaVersionsView

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));
            }
        }
    }
}
Also used : TestMigrationAwareService(com.hazelcast.internal.partition.service.TestMigrationAwareService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) Node(com.hazelcast.instance.Node) PartitionReplicaVersionsView(com.hazelcast.test.TestPartitionUtils.PartitionReplicaVersionsView) TestPartitionUtils.getPartitionReplicaVersionsView(com.hazelcast.test.TestPartitionUtils.getPartitionReplicaVersionsView)

Aggregations

HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 Node (com.hazelcast.instance.Node)1 TestMigrationAwareService (com.hazelcast.internal.partition.service.TestMigrationAwareService)1 Address (com.hazelcast.nio.Address)1 PartitionReplicaVersionsView (com.hazelcast.test.TestPartitionUtils.PartitionReplicaVersionsView)1 TestPartitionUtils.getPartitionReplicaVersionsView (com.hazelcast.test.TestPartitionUtils.getPartitionReplicaVersionsView)1