use of com.hazelcast.internal.partition.PartitionStateGenerator in project hazelcast by hazelcast.
the class PartitionStateGeneratorTest method test.
private void test(MemberGroupFactory memberGroupFactory) throws Exception {
PartitionStateGenerator generator = new PartitionStateGeneratorImpl();
int maxSameHostCount = 3;
int[] partitionCounts = new int[] { 271, 787, 1549, 3217 };
int[] members = new int[] { 3, 6, 9, 10, 11, 17, 57, 100, 130, 77, 179, 93, 37, 26, 15, 5 };
for (int partitionCount : partitionCounts) {
int memberCount = members[0];
List<Member> memberList = createMembers(memberCount, maxSameHostCount);
Collection<MemberGroup> groups = memberGroupFactory.createMemberGroups(memberList);
PartitionReplica[][] state = generator.arrange(groups, emptyPartitionArray(partitionCount));
checkTestResult(state, groups, partitionCount);
int previousMemberCount = memberCount;
for (int j = 1; j < members.length; j++) {
memberCount = members[j];
if (partitionCount / memberCount < 10) {
break;
}
if ((float) partitionCount / memberCount > 2) {
if (previousMemberCount == 0) {
memberList = createMembers(memberCount, maxSameHostCount);
} else if (memberCount > previousMemberCount) {
MemberImpl last = (MemberImpl) memberList.get(previousMemberCount - 1);
List<Member> extra = createMembers(last, (memberCount - previousMemberCount), maxSameHostCount);
memberList.addAll(extra);
} else {
List<Member> removedMembers = memberList.subList(memberCount, memberList.size());
memberList = memberList.subList(0, memberCount);
remove(state, removedMembers);
}
groups = memberGroupFactory.createMemberGroups(memberList);
state = generator.arrange(groups, toPartitionArray(state));
checkTestResult(state, groups, partitionCount);
previousMemberCount = memberCount;
}
}
}
}
use of com.hazelcast.internal.partition.PartitionStateGenerator in project hazelcast by hazelcast.
the class PartitionStateGeneratorTest method testOnlyUnassignedArrangement.
@Test
public void testOnlyUnassignedArrangement() throws Exception {
List<Member> memberList = createMembers(10, 1);
MemberGroupFactory memberGroupFactory = new SingleMemberGroupFactory();
Collection<MemberGroup> groups = memberGroupFactory.createMemberGroups(memberList);
PartitionStateGenerator generator = new PartitionStateGeneratorImpl();
PartitionReplica[][] state = generator.arrange(groups, emptyPartitionArray(100));
// unassign some partitions entirely
Collection<Integer> unassignedPartitions = new ArrayList<Integer>();
for (int i = 0; i < state.length; i++) {
if (i % 3 == 0) {
state[i] = new PartitionReplica[InternalPartition.MAX_REPLICA_COUNT];
unassignedPartitions.add(i);
}
}
// unassign only backup replicas of some partitions
for (int i = 0; i < state.length; i++) {
if (i % 10 == 0) {
Arrays.fill(state[i], 1, InternalPartition.MAX_REPLICA_COUNT, null);
}
}
InternalPartition[] partitions = toPartitionArray(state);
state = generator.arrange(groups, partitions, unassignedPartitions);
for (int pid = 0; pid < state.length; pid++) {
PartitionReplica[] addresses = state[pid];
if (unassignedPartitions.contains(pid)) {
for (PartitionReplica address : addresses) {
assertNotNull(address);
}
} else {
InternalPartition partition = partitions[pid];
for (int replicaIx = 0; replicaIx < InternalPartition.MAX_REPLICA_COUNT; replicaIx++) {
assertEquals(partition.getReplica(replicaIx), addresses[replicaIx]);
}
}
}
}
Aggregations