Search in sources :

Example 16 with InternalPartition

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

the class TestPartitionUtils method getReplicaAddresses.

public static List<Address> getReplicaAddresses(Node node, int partitionId) {
    List<Address> replicaAddresses = new ArrayList<Address>();
    InternalPartitionService partitionService = node.getPartitionService();
    InternalPartition partition = partitionService.getPartition(partitionId);
    for (int i = 0; i < MAX_REPLICA_COUNT; i++) {
        replicaAddresses.add(partition.getReplicaAddress(i));
    }
    return replicaAddresses;
}
Also used : Address(com.hazelcast.nio.Address) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) ArrayList(java.util.ArrayList) InternalPartition(com.hazelcast.internal.partition.InternalPartition)

Example 17 with InternalPartition

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

the class PartitionLostListenerTest method test_partitionLostListenerInvoked_whenNodeCrashed.

@Test
public void test_partitionLostListenerInvoked_whenNodeCrashed() {
    HazelcastInstance survivingInstance = instances[0];
    HazelcastInstance terminatingInstance = instances[1];
    warmUpPartitions(instances);
    waitAllForSafeState(instances);
    final EventCollectingPartitionLostListener listener = new EventCollectingPartitionLostListener();
    survivingInstance.getPartitionService().addPartitionLostListener(listener);
    Node survivingNode = getNode(survivingInstance);
    final Address survivingAddress = survivingNode.getThisAddress();
    final Set<Integer> survivingPartitionIds = new HashSet<Integer>();
    for (InternalPartition partition : survivingNode.getPartitionService().getInternalPartitions()) {
        if (survivingAddress.equals(partition.getReplicaAddress(0))) {
            survivingPartitionIds.add(partition.getPartitionId());
        }
    }
    terminatingInstance.getLifecycleService().terminate();
    waitAllForSafeState(survivingInstance);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            List<PartitionLostEvent> events = listener.getEvents();
            assertFalse(events.isEmpty());
            for (PartitionLostEvent event : events) {
                assertEquals(survivingAddress, event.getEventSource());
                assertFalse(survivingPartitionIds.contains(event.getPartitionId()));
                assertEquals(0, event.getLostBackupCount());
            }
        }
    });
}
Also used : Address(com.hazelcast.nio.Address) EventCollectingPartitionLostListener(com.hazelcast.partition.PartitionLostListenerStressTest.EventCollectingPartitionLostListener) Node(com.hazelcast.instance.Node) InternalPartition(com.hazelcast.internal.partition.InternalPartition) IOException(java.io.IOException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) List(java.util.List) IPartitionLostEvent(com.hazelcast.spi.partition.IPartitionLostEvent) HashSet(java.util.HashSet) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 18 with InternalPartition

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

the class MigrationCommitServiceTest method createMoveMigration.

private MigrationInfo createMoveMigration(int partitionId, int replicaIndex, Address destination) {
    InternalPartition partition = getPartition(instances[0], partitionId);
    Address source = partition.getReplicaAddress(replicaIndex);
    String sourceUuid = getMemberUuid(source);
    String destinationUuid = getMemberUuid(destination);
    return new MigrationInfo(partitionId, source, sourceUuid, destination, destinationUuid, replicaIndex, -1, -1, replicaIndex);
}
Also used : MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) Address(com.hazelcast.nio.Address) InternalPartition(com.hazelcast.internal.partition.InternalPartition)

Example 19 with InternalPartition

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

the class MigrationCommitTest method shouldCommitMigrationWhenMasterIsDestination.

@Test
public void shouldCommitMigrationWhenMasterIsDestination() {
    HazelcastInstance hz1 = factory.newHazelcastInstance(createConfig());
    warmUpPartitions(hz1);
    HazelcastInstance hz2 = factory.newHazelcastInstance(createConfig());
    warmUpPartitions(hz1, hz2);
    waitAllForSafeState(hz1, hz2);
    hz2.getLifecycleService().terminate();
    assertClusterSizeEventually(1, hz1);
    waitAllForSafeState(hz1);
    InternalPartition partition0 = getPartitionService(hz1).getPartition(0);
    InternalPartition partition1 = getPartitionService(hz1).getPartition(1);
    assertEquals(getAddress(hz1), partition0.getOwnerOrNull());
    assertEquals(getAddress(hz1), partition1.getOwnerOrNull());
    assertFalse(partition0.isMigrating());
    assertFalse(partition1.isMigrating());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalPartition(com.hazelcast.internal.partition.InternalPartition) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 20 with InternalPartition

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

the class MigrationCommitTest method shouldCommitMigrationWhenMasterIsNotMigrationEndpoint.

@Test
public void shouldCommitMigrationWhenMasterIsNotMigrationEndpoint() {
    Config config1 = createConfig();
    config1.setLiteMember(true);
    HazelcastInstance hz1 = factory.newHazelcastInstance(config1);
    HazelcastInstance hz2 = factory.newHazelcastInstance(createConfig());
    warmUpPartitions(hz1, hz2);
    waitAllForSafeState(hz1, hz2);
    HazelcastInstance hz3 = factory.newHazelcastInstance(createConfig());
    warmUpPartitions(hz3);
    waitAllForSafeState(hz1, hz2, hz3);
    InternalPartition hz2Partition = getOwnedPartition(hz2);
    InternalPartition hz3Partition = getOwnedPartition(hz3);
    assertNotNull(hz2Partition);
    assertNotNull(hz3Partition);
    assertNotEquals(hz2Partition, hz3Partition);
    assertFalse(hz2Partition.isMigrating());
    assertFalse(hz3Partition.isMigrating());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) 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