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());
}
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);
}
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());
}
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());
}
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());
}
Aggregations