Search in sources :

Example 11 with InternalPartition

use of com.hazelcast.internal.partition.InternalPartition in project hazelcast by hazelcast.

the class MigrationCommitTest method shouldRollbackMigrationWhenDestinationCrashesBeforeCommit.

@Test
public void shouldRollbackMigrationWhenDestinationCrashesBeforeCommit() {
    CountDownLatch migrationStartLatch = new CountDownLatch(1);
    Config config1 = createConfig();
    config1.setLiteMember(true);
    TerminateOtherMemberOnMigrationComplete masterListener = new TerminateOtherMemberOnMigrationComplete(migrationStartLatch);
    config1.addListenerConfig(new ListenerConfig(masterListener));
    HazelcastInstance hz1 = factory.newHazelcastInstance(config1);
    HazelcastInstance hz2 = factory.newHazelcastInstance(createConfig());
    warmUpPartitions(hz1, hz2);
    waitAllForSafeState(hz1, hz2);
    masterListener.other = factory.newHazelcastInstance(createConfig());
    migrationStartLatch.countDown();
    sleepAtLeastSeconds(10);
    waitAllForSafeState(hz1, hz2);
    InternalPartition partition0 = getPartitionService(hz2).getPartition(0);
    InternalPartition partition1 = getPartitionService(hz2).getPartition(1);
    assertEquals(getAddress(hz2), partition0.getOwnerOrNull());
    assertEquals(getAddress(hz2), partition1.getOwnerOrNull());
    assertFalse(partition0.isMigrating());
    assertFalse(partition1.isMigrating());
    assertTrue(masterListener.rollback);
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) InternalPartition(com.hazelcast.internal.partition.InternalPartition) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with InternalPartition

use of com.hazelcast.internal.partition.InternalPartition 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 13 with InternalPartition

use of com.hazelcast.internal.partition.InternalPartition in project hazelcast by hazelcast.

the class PartitionReplicaStateChecker_triggerAndWaitForReplicaSyncTest method whenHasMissingReplicaOwners_withAddress_thenWaitForMissingReplicaOwners.

@Test
public void whenHasMissingReplicaOwners_withAddress_thenWaitForMissingReplicaOwners() throws Exception {
    configureNeedsReplicaStateCheckResponse();
    Address address = new Address("127.0.0.1", 5701);
    InternalPartition partition = new DummyInternalPartition(new Address[] { address }, 1);
    partitions.add(partition);
    assertEquals(REPLICA_NOT_OWNED, replicaStateChecker.getPartitionServiceState());
    assertFalse(replicaStateChecker.triggerAndWaitForReplicaSync(10, TimeUnit.MILLISECONDS, 5));
}
Also used : Address(com.hazelcast.nio.Address) InternalPartition(com.hazelcast.internal.partition.InternalPartition) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with InternalPartition

use of com.hazelcast.internal.partition.InternalPartition in project hazelcast by hazelcast.

the class PartitionReplicaStateChecker_triggerAndWaitForReplicaSyncTest method whenCheckAndTriggerReplicaSync.

@Test
public void whenCheckAndTriggerReplicaSync() throws Exception {
    configureNeedsReplicaStateCheckResponseOnEachSecondCall();
    InternalPartition partition = new DummyInternalPartition(new Address[] { null }, 1);
    partitions.add(partition);
    assertEquals(REPLICA_NOT_SYNC, replicaStateChecker.getPartitionServiceState());
    assertFalse(replicaStateChecker.triggerAndWaitForReplicaSync(10, TimeUnit.MILLISECONDS, 5));
}
Also used : InternalPartition(com.hazelcast.internal.partition.InternalPartition) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with InternalPartition

use of com.hazelcast.internal.partition.InternalPartition in project hazelcast by hazelcast.

the class PartitionReplicaStateChecker_triggerAndWaitForReplicaSyncTest method whenHasMissingReplicaOwners_withoutAddress_thenWaitForMissingReplicaOwners.

@Test
public void whenHasMissingReplicaOwners_withoutAddress_thenWaitForMissingReplicaOwners() {
    configureNeedsReplicaStateCheckResponse();
    InternalPartition partition = new DummyInternalPartition(new Address[0], 1);
    partitions.add(partition);
    assertEquals(REPLICA_NOT_OWNED, replicaStateChecker.getPartitionServiceState());
    assertFalse(replicaStateChecker.triggerAndWaitForReplicaSync(10, TimeUnit.MILLISECONDS, 5));
}
Also used : InternalPartition(com.hazelcast.internal.partition.InternalPartition) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

InternalPartition (com.hazelcast.internal.partition.InternalPartition)26 ParallelTest (com.hazelcast.test.annotation.ParallelTest)13 QuickTest (com.hazelcast.test.annotation.QuickTest)13 Test (org.junit.Test)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)12 Address (com.hazelcast.nio.Address)12 Config (com.hazelcast.config.Config)8 ListenerConfig (com.hazelcast.config.ListenerConfig)6 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AssertTask (com.hazelcast.test.AssertTask)4 ClusterState (com.hazelcast.cluster.ClusterState)3 MigrationInfo (com.hazelcast.internal.partition.MigrationInfo)3 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)2 Node (com.hazelcast.instance.Node)2 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)2 PartitionRuntimeState (com.hazelcast.internal.partition.PartitionRuntimeState)2 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 TransactionException (com.hazelcast.transaction.TransactionException)2