Search in sources :

Example 41 with PartitionReplica

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

the class MigrationPlannerCycleTest method testCycle4.

@Test
public void testCycle4() throws UnknownHostException {
    final PartitionReplica[] oldReplicas = { new PartitionReplica(new Address("localhost", 5701), uuids[0]), new PartitionReplica(new Address("localhost", 5702), uuids[1]), new PartitionReplica(new Address("localhost", 5703), uuids[2]), new PartitionReplica(new Address("localhost", 5704), uuids[3]), new PartitionReplica(new Address("localhost", 5705), uuids[4]), new PartitionReplica(new Address("localhost", 5706), uuids[5]), new PartitionReplica(new Address("localhost", 5707), uuids[6]) };
    final PartitionReplica[] newReplicas = { new PartitionReplica(new Address("localhost", 5705), uuids[4]), new PartitionReplica(new Address("localhost", 5702), uuids[1]), new PartitionReplica(new Address("localhost", 5701), uuids[0]), new PartitionReplica(new Address("localhost", 5704), uuids[3]), new PartitionReplica(new Address("localhost", 5703), uuids[2]), new PartitionReplica(new Address("localhost", 5707), uuids[6]), new PartitionReplica(new Address("localhost", 5706), uuids[5]) };
    assertTrue(migrationPlanner.isCyclic(oldReplicas, newReplicas));
}
Also used : Address(com.hazelcast.cluster.Address) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 42 with PartitionReplica

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

the class MigrationPlannerCycleTest method testNoCycle2.

@Test
public void testNoCycle2() throws UnknownHostException {
    final PartitionReplica[] oldReplicas = { new PartitionReplica(new Address("localhost", 5701), uuids[0]), new PartitionReplica(new Address("localhost", 5702), uuids[1]), new PartitionReplica(new Address("localhost", 5703), uuids[2]), new PartitionReplica(new Address("localhost", 5704), uuids[3]), new PartitionReplica(new Address("localhost", 5705), uuids[4]), null, null };
    final PartitionReplica[] newReplicas = { new PartitionReplica(new Address("localhost", 5706), uuids[5]), new PartitionReplica(new Address("localhost", 5702), uuids[1]), new PartitionReplica(new Address("localhost", 5701), uuids[0]), new PartitionReplica(new Address("localhost", 5704), uuids[3]), new PartitionReplica(new Address("localhost", 5703), uuids[2]), null, null };
    assertFalse(migrationPlanner.isCyclic(oldReplicas, newReplicas));
}
Also used : Address(com.hazelcast.cluster.Address) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 43 with PartitionReplica

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

the class PartitionReplicaStateCheckerTest method shouldNotBeSafe_whenUnknownReplicaOwnerPresent.

@Test
public void shouldNotBeSafe_whenUnknownReplicaOwnerPresent() throws UnknownHostException {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance hz = factory.newHazelcastInstance();
    InternalPartitionServiceImpl partitionService = getNode(hz).partitionService;
    partitionService.firstArrangement();
    PartitionStateManager partitionStateManager = partitionService.getPartitionStateManager();
    InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(0);
    PartitionReplica[] members = partition.replicas();
    PartitionReplica[] illegalMembers = Arrays.copyOf(members, members.length);
    Address address = members[0].address();
    illegalMembers[0] = new PartitionReplica(new Address(address.getInetAddress(), address.getPort() + 1000), members[0].uuid());
    partition.setReplicas(illegalMembers);
    PartitionReplicaStateChecker replicaStateChecker = partitionService.getPartitionReplicaStateChecker();
    assertEquals(PartitionServiceState.REPLICA_NOT_OWNED, replicaStateChecker.getPartitionServiceState());
    partition.setReplicas(members);
    assertEquals(PartitionServiceState.SAFE, replicaStateChecker.getPartitionServiceState());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.cluster.Address) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 44 with PartitionReplica

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

the class PartitionReplicaStateCheckerTest method shouldNotBeSafe_whenMissingReplicasPresent.

@Test
public void shouldNotBeSafe_whenMissingReplicasPresent() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance hz = factory.newHazelcastInstance();
    InternalPartitionServiceImpl partitionService = getNode(hz).partitionService;
    partitionService.firstArrangement();
    PartitionStateManager partitionStateManager = partitionService.getPartitionStateManager();
    InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(0);
    PartitionReplica[] members = partition.replicas();
    partition.setReplicas(new PartitionReplica[members.length]);
    PartitionReplicaStateChecker replicaStateChecker = partitionService.getPartitionReplicaStateChecker();
    assertEquals(PartitionServiceState.REPLICA_NOT_OWNED, replicaStateChecker.getPartitionServiceState());
    partition.setReplicas(members);
    assertEquals(PartitionServiceState.SAFE, replicaStateChecker.getPartitionServiceState());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 45 with PartitionReplica

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

the class MigrationPlannerTest method testRandom.

private void testRandom(int initialLen) throws UnknownHostException {
    PartitionReplica[] oldReplicas = new PartitionReplica[InternalPartition.MAX_REPLICA_COUNT];
    for (int i = 0; i < initialLen; i++) {
        oldReplicas[i] = new PartitionReplica(newAddress(5000 + i), UuidUtil.newUnsecureUUID());
    }
    PartitionReplica[] newReplicas = Arrays.copyOf(oldReplicas, oldReplicas.length);
    int newLen = (int) (Math.random() * (oldReplicas.length - initialLen + 1));
    for (int i = 0; i < newLen; i++) {
        newReplicas[i + initialLen] = new PartitionReplica(newAddress(6000 + i), UuidUtil.newUnsecureUUID());
    }
    shuffle(newReplicas, initialLen + newLen);
    migrationPlanner.planMigrations(0, oldReplicas, newReplicas, callback);
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica)

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