Search in sources :

Example 96 with PartitionReplica

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

the class FrozenPartitionTableTest method testPartitionTableIsHealedWhenClusterStateIsActiveAfter.

private void testPartitionTableIsHealedWhenClusterStateIsActiveAfter(final ClusterState clusterState) {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance[] instances = factory.newInstances();
    warmUpPartitions(instances);
    changeClusterStateEventually(instances[0], clusterState);
    List<HazelcastInstance> instancesList = new ArrayList<HazelcastInstance>(asList(instances));
    Collections.shuffle(instancesList);
    final HazelcastInstance instanceToShutdown = instancesList.remove(0);
    final Address addressToShutdown = getNode(instanceToShutdown).getThisAddress();
    instanceToShutdown.shutdown();
    for (HazelcastInstance instance : instancesList) {
        assertClusterSizeEventually(2, instance);
    }
    changeClusterStateEventually(instancesList.get(0), ClusterState.ACTIVE);
    waitAllForSafeState(instancesList);
    for (HazelcastInstance instance : instancesList) {
        PartitionTableView partitionTable = getPartitionTable(instance);
        for (int i = 0; i < partitionTable.length(); i++) {
            for (PartitionReplica replica : partitionTable.getReplicas(i)) {
                if (replica == null) {
                    continue;
                }
                assertNotEquals(addressToShutdown, replica.address());
            }
        }
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastInstanceFactory.newHazelcastInstance(com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance) Address(com.hazelcast.cluster.Address) PartitionTableView(com.hazelcast.internal.partition.PartitionTableView) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ArrayList(java.util.ArrayList) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 97 with PartitionReplica

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

the class InternalPartitionServiceImplTest method test_setInitialState.

@Test
public void test_setInitialState() {
    InternalPartition[] partitions = new InternalPartition[partitionCount];
    for (int i = 0; i < partitionCount; i++) {
        PartitionReplica[] replicas = new PartitionReplica[MAX_REPLICA_COUNT];
        replicas[0] = PartitionReplica.from(localMember);
        partitions[i] = new ReadonlyInternalPartition(replicas, i, RandomPicker.getInt(1, 10));
    }
    partitionService.setInitialState(new PartitionTableView(partitions));
    for (int i = 0; i < partitionCount; i++) {
        assertTrue(partitionService.isPartitionOwner(i));
    }
    assertNotEquals(0, partitionService.getPartitionStateStamp());
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) PartitionTableView(com.hazelcast.internal.partition.PartitionTableView) InternalPartition(com.hazelcast.internal.partition.InternalPartition) ReadonlyInternalPartition(com.hazelcast.internal.partition.ReadonlyInternalPartition) ReadonlyInternalPartition(com.hazelcast.internal.partition.ReadonlyInternalPartition) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 98 with PartitionReplica

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

the class MigrationCommitServiceTest method createShiftUpMigration.

private MigrationInfo createShiftUpMigration(int partitionId, int oldReplicaIndex, int newReplicaIndex) {
    InternalPartitionImpl partition = getPartition(instances[0], partitionId);
    PartitionReplica source = partition.getReplica(newReplicaIndex);
    PartitionReplica destination = partition.getReplica(oldReplicaIndex);
    return new MigrationInfo(partitionId, source, destination, newReplicaIndex, -1, oldReplicaIndex, newReplicaIndex);
}
Also used : MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica)

Example 99 with PartitionReplica

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

the class MigrationCommitServiceTest method testSuccessfulMoveMigration.

private void testSuccessfulMoveMigration(int partitionId, int replicaIndexToClear, int replicaIndexToMigrate) throws Exception {
    PartitionReplica destination = clearReplicaIndex(partitionId, replicaIndexToClear);
    MigrationInfo migration = createMoveMigration(partitionId, replicaIndexToMigrate, destination);
    migrateWithSuccess(migration);
    assertMigrationSourceCommit(migration);
    assertMigrationDestinationCommit(migration);
    assertPartitionDataAfterMigrations();
}
Also used : MigrationInfo(com.hazelcast.internal.partition.MigrationInfo) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica)

Example 100 with PartitionReplica

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

the class InternalPartitionImplTest method testSetReplicaAddresses_ListenerShouldBeCalled.

@Test
public void testSetReplicaAddresses_ListenerShouldBeCalled() {
    replicaOwners[0] = localReplica;
    replicaOwners[1] = new PartitionReplica(newAddress(5001), UuidUtil.newUnsecureUUID());
    partition.setReplicas(replicaOwners);
    assertEquals(2, partitionListener.eventCount);
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)103 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)51 QuickTest (com.hazelcast.test.annotation.QuickTest)51 Test (org.junit.Test)51 Address (com.hazelcast.cluster.Address)44 InternalPartition (com.hazelcast.internal.partition.InternalPartition)17 MigrationInfo (com.hazelcast.internal.partition.MigrationInfo)17 ArrayList (java.util.ArrayList)10 Member (com.hazelcast.cluster.Member)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)7 PartitionTableView (com.hazelcast.internal.partition.PartitionTableView)6 ReadonlyInternalPartition (com.hazelcast.internal.partition.ReadonlyInternalPartition)6 ClusterState (com.hazelcast.cluster.ClusterState)5 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)5 NodeEngine (com.hazelcast.spi.impl.NodeEngine)4 Operation (com.hazelcast.spi.impl.operationservice.Operation)4 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)3 MemberLeftException (com.hazelcast.core.MemberLeftException)3 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)3