Search in sources :

Example 21 with PartitionReplica

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

the class InternalPartitionImplTest method testIsLocal_whenNOTOwnedByThis.

@Test
public void testIsLocal_whenNOTOwnedByThis() {
    replicaOwners[0] = new PartitionReplica(newAddress(6000), UuidUtil.newUnsecureUUID());
    partition.setReplicas(replicaOwners);
    assertFalse(partition.isLocal());
    assertEquals(1, partition.version());
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 22 with PartitionReplica

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

the class InternalPartitionImplTest method testVersion_setReplica.

@Test
public void testVersion_setReplica() {
    partition.setReplica(1, new PartitionReplica(newAddress(6000), UuidUtil.newUnsecureUUID()));
    assertEquals(1, partition.version());
    partition.setReplica(0, new PartitionReplica(newAddress(7000), UuidUtil.newUnsecureUUID()));
    assertEquals(2, partition.version());
    partition.setReplica(0, partition.getReplica(0));
    assertEquals(2, partition.version());
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with PartitionReplica

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

the class FrozenPartitionTableTest method partitionTable_isFrozen_whenMemberReJoins_duringClusterStateIs.

private void partitionTable_isFrozen_whenMemberReJoins_duringClusterStateIs(ClusterState state) {
    Config config = new Config();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(4);
    HazelcastInstance[] instances = factory.newInstances(config, 3);
    HazelcastInstance hz1 = instances[0];
    HazelcastInstance hz2 = instances[1];
    HazelcastInstance hz3 = instances[2];
    Address hz3Address = getNode(hz3).getThisAddress();
    warmUpPartitions(instances);
    final PartitionTableView partitionTable = getPartitionTable(hz1);
    changeClusterStateEventually(hz2, state);
    final Member member3 = getClusterService(hz3).getLocalMember();
    terminateInstance(hz2);
    terminateInstance(hz3);
    hz3 = factory.newHazelcastInstance(hz3Address);
    final Member newMember3 = getClusterService(hz3).getLocalMember();
    assertClusterSizeEventually(2, hz1, hz3);
    final List<HazelcastInstance> instanceList = asList(hz1, hz3);
    assertTrueAllTheTime(new AssertTask() {

        @Override
        public void run() {
            for (HazelcastInstance instance : instanceList) {
                PartitionTableView newPartitionTable = getPartitionTable(instance);
                for (int i = 0; i < newPartitionTable.length(); i++) {
                    for (int j = 0; j < InternalPartition.MAX_REPLICA_COUNT; j++) {
                        PartitionReplica replica = partitionTable.getReplica(i, j);
                        PartitionReplica newReplica = newPartitionTable.getReplica(i, j);
                        if (replica == null) {
                            assertNull(newReplica);
                        } else if (replica.equals(PartitionReplica.from(member3))) {
                            assertEquals(PartitionReplica.from(newMember3), newReplica);
                        } else {
                            assertEquals(replica, newReplica);
                        }
                    }
                }
            }
        }
    }, 5);
}
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) Config(com.hazelcast.config.Config) TestHazelcastInstanceFactory.initOrCreateConfig(com.hazelcast.test.TestHazelcastInstanceFactory.initOrCreateConfig) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.cluster.Member)

Example 24 with PartitionReplica

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

the class InternalPartitionServiceImplTest method test_setInitialState_multipleTimes.

@Test(expected = IllegalStateException.class)
public void test_setInitialState_multipleTimes() {
    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));
    partitionService.setInitialState(new PartitionTableView(partitions));
}
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 25 with PartitionReplica

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

the class MigrationCommitServiceTest method createMoveMigration.

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

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