Search in sources :

Example 1 with TestAbstractMigrationAwareService

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));
            }
        }
    }
}
Also used : TestAbstractMigrationAwareService(com.hazelcast.internal.partition.service.TestAbstractMigrationAwareService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) TestPartitionUtils.getPartitionReplicaVersionsView(com.hazelcast.internal.partition.TestPartitionUtils.getPartitionReplicaVersionsView)

Aggregations

Address (com.hazelcast.cluster.Address)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 Node (com.hazelcast.instance.impl.Node)1 TestPartitionUtils.getPartitionReplicaVersionsView (com.hazelcast.internal.partition.TestPartitionUtils.getPartitionReplicaVersionsView)1 TestAbstractMigrationAwareService (com.hazelcast.internal.partition.service.TestAbstractMigrationAwareService)1 ServiceNamespace (com.hazelcast.internal.services.ServiceNamespace)1 Accessors.getNode (com.hazelcast.test.Accessors.getNode)1