Search in sources :

Example 6 with PartitionTableView

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

the class MigrationManagerTest method testCheckSnapshots_picksBest_whenMultipleSnapshotsMatch.

@Test
public void testCheckSnapshots_picksBest_whenMultipleSnapshotsMatch() throws UnknownHostException {
    List<Member> membersWhenRepartitioning = members(3);
    // cluster had 3 members; one crashed ->
    // snapshot partition table references 3 members
    PartitionTableView snapshotBestMatch = new PartitionTableView(partitions(membersWhenRepartitioning));
    // another crashed ->
    // snapshots contains another partition table with a single member
    List<Member> singleMemberCluster = cloneRemoving(membersWhenRepartitioning, 2);
    PartitionTableView snapshotSingleMember = new PartitionTableView(partitions(singleMemberCluster));
    // one member already rejoined -> current partition table references 2 members
    // crashed member is rejoining, cluster service reports 3 data members
    // -> snapshot partition table with 3 members is picked as better match
    List<Member> currentClusterMembers = cloneRemoving(membersWhenRepartitioning, 1);
    PartitionTableView currentPartitionTable = new PartitionTableView(partitions(currentClusterMembers));
    Collection<PartitionTableView> snapshots = new ArrayList<>();
    snapshots.add(snapshotSingleMember);
    snapshots.add(snapshotBestMatch);
    when(clusterService.getMembers(any())).thenReturn(membersWhenRepartitioning);
    when(partitionStateManager.getPartitionTable()).thenReturn(currentPartitionTable);
    when(partitionStateManager.snapshots()).thenReturn(snapshots);
    assertArrayEquals(snapshotBestMatch.toArray(new HashMap<>()), task.checkSnapshots());
}
Also used : PartitionTableView(com.hazelcast.internal.partition.PartitionTableView) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with PartitionTableView

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

the class InternalPartitionServiceImplTest method test_setInitialState_listenerShouldNOTBeCalled.

@Test
public void test_setInitialState_listenerShouldNOTBeCalled() {
    Address[][] addresses = new Address[partitionCount][MAX_REPLICA_COUNT];
    for (int i = 0; i < partitionCount; i++) {
        addresses[i][0] = thisAddress;
    }
    TestPartitionListener listener = new TestPartitionListener();
    partitionService.addPartitionListener(listener);
    partitionService.setInitialState(new PartitionTableView(addresses, 0));
    assertEquals(0, listener.eventCount);
}
Also used : Address(com.hazelcast.nio.Address) PartitionTableView(com.hazelcast.internal.partition.PartitionTableView) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with PartitionTableView

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

the class MigrationManagerTest method testCheckSnapshots_whenSingleMatchingSnapshotExists.

@Test
public void testCheckSnapshots_whenSingleMatchingSnapshotExists() throws UnknownHostException {
    // cluster had 3 members; one crashed ->
    // snapshot partition table references 3 members
    // current partition table references 2 remaining members
    // crashed member is rejoining, cluster service reports 3 data members
    List<Member> newClusterMembers = members(3);
    List<Member> currentClusterMembers = new ArrayList<>(newClusterMembers);
    currentClusterMembers.remove(2);
    PartitionTableView currentPartitionTable = new PartitionTableView(partitions(currentClusterMembers));
    PartitionTableView snapshot = new PartitionTableView(partitions(newClusterMembers));
    when(clusterService.getMembers(any())).thenReturn(newClusterMembers);
    when(partitionStateManager.getPartitionTable()).thenReturn(currentPartitionTable);
    when(partitionStateManager.snapshots()).thenReturn(Collections.singletonList(snapshot));
    assertArrayEquals(snapshot.toArray(new HashMap<>()), task.checkSnapshots());
}
Also used : PartitionTableView(com.hazelcast.internal.partition.PartitionTableView) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with PartitionTableView

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

the class MigrationManagerTest method testCheckSnapshots_picksMatching_whenOtherSnapshotsExist.

@Test
public void testCheckSnapshots_picksMatching_whenOtherSnapshotsExist() throws UnknownHostException {
    // cluster had 3 members; one crashed ->
    // snapshot partition table references 3 members
    // current partition table references 2 remaining members
    // crashed member is rejoining, cluster service reports 3 data members
    List<Member> newClusterMembers = members(3);
    List<Member> currentClusterMembers = new ArrayList<>(newClusterMembers);
    currentClusterMembers.remove(2);
    PartitionTableView currentPartitionTable = new PartitionTableView(partitions(currentClusterMembers));
    PartitionTableView matchingSnapshot = new PartitionTableView(partitions(newClusterMembers));
    // add an unrelated snapshot
    PartitionTableView unrelated = new PartitionTableView(partitions(members(3)));
    Collection<PartitionTableView> snapshots = new ArrayList<>();
    snapshots.add(matchingSnapshot);
    snapshots.add(unrelated);
    when(clusterService.getMembers(any())).thenReturn(newClusterMembers);
    when(partitionStateManager.getPartitionTable()).thenReturn(currentPartitionTable);
    when(partitionStateManager.snapshots()).thenReturn(snapshots);
    assertArrayEquals(matchingSnapshot.toArray(new HashMap<>()), task.checkSnapshots());
}
Also used : PartitionTableView(com.hazelcast.internal.partition.PartitionTableView) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with PartitionTableView

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

the class MigrationManagerTest method testCheckSnapshots_picksMatchingSnapshot_whenAddressChanged.

@Test
public void testCheckSnapshots_picksMatchingSnapshot_whenAddressChanged() throws UnknownHostException {
    // setup same as testCheckSnapshots_picksBest_whenMultipleSnapshotsMatch
    List<Member> membersWhenRepartitioning = members(3);
    PartitionTableView snapshotBestMatch = new PartitionTableView(partitions(membersWhenRepartitioning));
    List<Member> singleMemberCluster = cloneRemoving(membersWhenRepartitioning, 2);
    PartitionTableView snapshotSingleMember = new PartitionTableView(partitions(singleMemberCluster));
    List<Member> currentClusterMembers = cloneRemoving(membersWhenRepartitioning, 1);
    PartitionTableView currentPartitionTable = new PartitionTableView(partitions(currentClusterMembers));
    // but member 3 changed address as it is rejoining
    Member crashedMember = membersWhenRepartitioning.remove(2);
    Member rejoiningWithChangedAddress = new MemberImpl(new Address("127.0.0.1", crashedMember.getAddress().getPort() + 10), crashedMember.getVersion(), crashedMember.localMember(), crashedMember.getUuid());
    membersWhenRepartitioning.add(rejoiningWithChangedAddress);
    Collection<PartitionTableView> snapshots = new ArrayList<>();
    snapshots.add(snapshotSingleMember);
    snapshots.add(snapshotBestMatch);
    when(clusterService.getMembers(any())).thenReturn(membersWhenRepartitioning);
    when(partitionStateManager.getPartitionTable()).thenReturn(currentPartitionTable);
    when(partitionStateManager.snapshots()).thenReturn(snapshots);
    // apply address change in snapshotBestMatch for assertion
    Map<UUID, Address> addressTranslationMap = new HashMap<>();
    addressTranslationMap.put(rejoiningWithChangedAddress.getUuid(), rejoiningWithChangedAddress.getAddress());
    assertArrayEquals(snapshotBestMatch.toArray(addressTranslationMap), task.checkSnapshots());
}
Also used : Address(com.hazelcast.cluster.Address) PartitionTableView(com.hazelcast.internal.partition.PartitionTableView) HashMap(java.util.HashMap) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

PartitionTableView (com.hazelcast.internal.partition.PartitionTableView)12 ArrayList (java.util.ArrayList)8 QuickTest (com.hazelcast.test.annotation.QuickTest)7 Test (org.junit.Test)7 Member (com.hazelcast.cluster.Member)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)5 HashMap (java.util.HashMap)5 Address (com.hazelcast.cluster.Address)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)3 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)3 UUID (java.util.UUID)3 InternalPartition (com.hazelcast.internal.partition.InternalPartition)2 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)2 ReadonlyInternalPartition (com.hazelcast.internal.partition.ReadonlyInternalPartition)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)1 ClientAddClusterViewListenerCodec (com.hazelcast.client.impl.protocol.codec.ClientAddClusterViewListenerCodec)1