Search in sources :

Example 1 with TestMigrationAwareService

use of com.hazelcast.internal.partition.service.TestMigrationAwareService in project hazelcast by hazelcast.

the class PartitionCorrectnessTestSupport method assertSizeAndData.

private void assertSizeAndData(boolean allowDirty) throws InterruptedException {
    Collection<HazelcastInstance> instances = factory.getAllHazelcastInstances();
    final int actualBackupCount = Math.min(backupCount, instances.size() - 1);
    final int expectedSize = partitionCount * (actualBackupCount + 1);
    int total = 0;
    for (HazelcastInstance hz : instances) {
        TestMigrationAwareService service = getService(hz);
        total += service.size();
        Node node = getNode(hz);
        InternalPartitionService partitionService = node.getPartitionService();
        InternalPartition[] partitions = partitionService.getInternalPartitions();
        Address thisAddress = node.getThisAddress();
        // find leaks
        assertNoLeakingData(service, partitions, thisAddress);
        // find missing
        assertNoMissingData(service, partitions, thisAddress);
        // check values
        assertPartitionVersionsAndBackupValues(actualBackupCount, service, node, partitions, allowDirty);
        assertMigrationEvents(service, thisAddress);
    }
    assertEquals("Missing data!", expectedSize, total);
}
Also used : TestMigrationAwareService(com.hazelcast.internal.partition.service.TestMigrationAwareService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) Node(com.hazelcast.instance.Node)

Example 2 with TestMigrationAwareService

use of com.hazelcast.internal.partition.service.TestMigrationAwareService in project hazelcast by hazelcast.

the class MigrationCommitServiceTest method assertReplicaVersionsAndServiceData.

private void assertReplicaVersionsAndServiceData(String msg, Address address, int partitionId, int replicaIndex) throws Exception {
    TestMigrationAwareService service = getService(address);
    boolean shouldContainData = replicaIndex != -1 && replicaIndex <= BACKUP_COUNT;
    assertEquals(msg, shouldContainData, service.contains(partitionId));
    long[] replicaVersions = getReplicaVersions(factory.getInstance(address), partitionId);
    msg = msg + " , ReplicaVersions: " + Arrays.toString(replicaVersions);
    if (shouldContainData) {
        if (replicaIndex == 0) {
            assertArrayEquals(msg, replicaVersions, new long[] { 1, 1, 1, 1, 1, 1 });
        } else {
            for (int i = 1; i < InternalPartition.MAX_BACKUP_COUNT; i++) {
                if (i < replicaIndex || i > BACKUP_COUNT) {
                    assertEquals(msg + " at index: " + i, 0, replicaVersions[i - 1]);
                } else {
                    assertEquals(msg + " at index: " + i, 1, replicaVersions[i - 1]);
                }
            }
        }
    } else {
        assertArrayEquals(msg, replicaVersions, new long[] { 0, 0, 0, 0, 0, 0 });
    }
}
Also used : TestMigrationAwareService(com.hazelcast.internal.partition.service.TestMigrationAwareService)

Example 3 with TestMigrationAwareService

use of com.hazelcast.internal.partition.service.TestMigrationAwareService in project hazelcast by hazelcast.

the class MigrationCommitServiceTest method setup.

@Before
public void setup() throws Exception {
    blockMigrationStartLatch = new CountDownLatch(1);
    factory = createHazelcastInstanceFactory(NODE_COUNT);
    instances = factory.newInstances(createConfig(), NODE_COUNT);
    warmUpPartitions(instances);
    waitAllForSafeState(instances);
    InternalOperationService operationService = getOperationService(instances[0]);
    for (int partitionId = 0; partitionId < PARTITION_COUNT; partitionId++) {
        operationService.invokeOnPartition(null, new TestIncrementOperation(), partitionId).get();
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            for (int partitionId = 0; partitionId < PARTITION_COUNT; partitionId++) {
                InternalPartitionService partitionService = getPartitionService(instances[0]);
                InternalPartition partition = partitionService.getPartition(partitionId);
                for (int i = 0; i <= BACKUP_COUNT; i++) {
                    Address replicaAddress = partition.getReplicaAddress(i);
                    if (replicaAddress != null) {
                        TestMigrationAwareService service = getService(replicaAddress);
                        assertNotNull(service.get(partitionId));
                    }
                }
            }
        }
    });
    for (HazelcastInstance instance : instances) {
        TestMigrationAwareService service = getNodeEngineImpl(instance).getService(TestMigrationAwareService.SERVICE_NAME);
        service.clearEvents();
    }
}
Also used : TestMigrationAwareService(com.hazelcast.internal.partition.service.TestMigrationAwareService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) AssertTask(com.hazelcast.test.AssertTask) TestIncrementOperation(com.hazelcast.internal.partition.service.TestIncrementOperation) InternalOperationService(com.hazelcast.spi.impl.operationservice.InternalOperationService) InternalPartition(com.hazelcast.internal.partition.InternalPartition) CountDownLatch(java.util.concurrent.CountDownLatch) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) Before(org.junit.Before)

Example 4 with TestMigrationAwareService

use of com.hazelcast.internal.partition.service.TestMigrationAwareService in project hazelcast by hazelcast.

the class MigrationCommitServiceTest method clearReplicaIndex.

private Address clearReplicaIndex(final int partitionId, int replicaIndexToClear) {
    final InternalPartitionServiceImpl partitionService = (InternalPartitionServiceImpl) getPartitionService(instances[0]);
    InternalPartitionImpl partition = (InternalPartitionImpl) partitionService.getPartition(partitionId);
    final Address oldReplicaOwner = partition.getReplicaAddress(replicaIndexToClear);
    partition.setReplicaAddress(replicaIndexToClear, null);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrue(partitionService.syncPartitionRuntimeState());
        }
    });
    HazelcastInstance oldReplicaOwnerInstance = factory.getInstance(oldReplicaOwner);
    ClearReplicaRunnable op = new ClearReplicaRunnable(partitionId, getNodeEngineImpl(oldReplicaOwnerInstance));
    getOperationService(oldReplicaOwnerInstance).execute(op);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            long[] replicaVersions = getReplicaVersions(factory.getInstance(oldReplicaOwner), partitionId);
            assertArrayEquals(new long[InternalPartition.MAX_BACKUP_COUNT], replicaVersions);
        }
    });
    TestMigrationAwareService migrationAwareService = getService(oldReplicaOwner);
    migrationAwareService.clearPartitionReplica(partitionId);
    for (HazelcastInstance instance : instances) {
        TestMigrationAwareService service = getNodeEngineImpl(instance).getService(TestMigrationAwareService.SERVICE_NAME);
        service.clearEvents();
    }
    return oldReplicaOwner;
}
Also used : TestMigrationAwareService(com.hazelcast.internal.partition.service.TestMigrationAwareService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) AssertTask(com.hazelcast.test.AssertTask) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException)

Example 5 with TestMigrationAwareService

use of com.hazelcast.internal.partition.service.TestMigrationAwareService 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

TestMigrationAwareService (com.hazelcast.internal.partition.service.TestMigrationAwareService)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 Address (com.hazelcast.nio.Address)4 Node (com.hazelcast.instance.Node)2 AssertTask (com.hazelcast.test.AssertTask)2 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)2 InternalPartition (com.hazelcast.internal.partition.InternalPartition)1 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)1 TestIncrementOperation (com.hazelcast.internal.partition.service.TestIncrementOperation)1 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)1 PartitionReplicaVersionsView (com.hazelcast.test.TestPartitionUtils.PartitionReplicaVersionsView)1 TestPartitionUtils.getPartitionReplicaVersionsView (com.hazelcast.test.TestPartitionUtils.getPartitionReplicaVersionsView)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Before (org.junit.Before)1