use of org.apache.kafka.clients.consumer.internals.AbstractPartitionAssignor.MemberInfo in project kafka by apache.
the class AbstractPartitionAssignorTest method testMemberInfoSortingWithAllGroupInstanceId.
@Test
public void testMemberInfoSortingWithAllGroupInstanceId() {
MemberInfo m1 = new MemberInfo("a", Optional.of("y"));
MemberInfo m2 = new MemberInfo("b", Optional.of("z"));
MemberInfo m3 = new MemberInfo("c", Optional.of("x"));
List<MemberInfo> memberInfoList = Arrays.asList(m1, m2, m3);
assertEquals(Arrays.asList(m3, m1, m2), Utils.sorted(memberInfoList));
}
use of org.apache.kafka.clients.consumer.internals.AbstractPartitionAssignor.MemberInfo in project kafka by apache.
the class AbstractPartitionAssignorTest method testMemberInfoSortingSomeGroupInstanceId.
@Test
public void testMemberInfoSortingSomeGroupInstanceId() {
MemberInfo m1 = new MemberInfo("a", Optional.empty());
MemberInfo m2 = new MemberInfo("b", Optional.of("y"));
MemberInfo m3 = new MemberInfo("c", Optional.of("x"));
List<MemberInfo> memberInfoList = Arrays.asList(m1, m2, m3);
assertEquals(Arrays.asList(m3, m2, m1), Utils.sorted(memberInfoList));
}
use of org.apache.kafka.clients.consumer.internals.AbstractPartitionAssignor.MemberInfo in project kafka by apache.
the class RoundRobinAssignorTest method testStaticMemberRoundRobinAssignmentPersistentAfterMemberIdChanges.
@Test
public void testStaticMemberRoundRobinAssignmentPersistentAfterMemberIdChanges() {
String consumer1 = "consumer1";
String instance1 = "instance1";
String consumer2 = "consumer2";
String instance2 = "instance2";
String consumer3 = "consumer3";
String instance3 = "instance3";
Map<String, String> memberIdToInstanceId = new HashMap<>();
memberIdToInstanceId.put(consumer1, instance1);
memberIdToInstanceId.put(consumer2, instance2);
memberIdToInstanceId.put(consumer3, instance3);
Map<String, Integer> partitionsPerTopic = setupPartitionsPerTopicWithTwoTopics(5, 5);
Map<String, List<TopicPartition>> expectedInstanceAssignment = new HashMap<>();
expectedInstanceAssignment.put(instance1, partitions(tp(topic1, 0), tp(topic1, 3), tp(topic2, 1), tp(topic2, 4)));
expectedInstanceAssignment.put(instance2, partitions(tp(topic1, 1), tp(topic1, 4), tp(topic2, 2)));
expectedInstanceAssignment.put(instance3, partitions(tp(topic1, 2), tp(topic2, 0), tp(topic2, 3)));
List<AbstractPartitionAssignor.MemberInfo> staticMemberInfos = new ArrayList<>();
for (Map.Entry<String, String> entry : memberIdToInstanceId.entrySet()) {
staticMemberInfos.add(new AbstractPartitionAssignor.MemberInfo(entry.getKey(), Optional.of(entry.getValue())));
}
Map<String, Subscription> consumers = new HashMap<>();
for (MemberInfo m : staticMemberInfos) {
Subscription subscription = new Subscription(topics(topic1, topic2), null);
subscription.setGroupInstanceId(m.groupInstanceId);
consumers.put(m.memberId, subscription);
}
Map<String, List<TopicPartition>> staticAssignment = checkStaticAssignment(assignor, partitionsPerTopic, consumers);
assertEquals(expectedInstanceAssignment, staticAssignment);
memberIdToInstanceId.clear();
// Now switch the member.id fields for each member info, the assignment should
// stay the same as last time.
String consumer4 = "consumer4";
String consumer5 = "consumer5";
consumers.put(consumer4, consumers.get(consumer3));
consumers.remove(consumer3);
consumers.put(consumer5, consumers.get(consumer2));
consumers.remove(consumer2);
Map<String, List<TopicPartition>> newStaticAssignment = checkStaticAssignment(assignor, partitionsPerTopic, consumers);
assertEquals(staticAssignment, newStaticAssignment);
}
use of org.apache.kafka.clients.consumer.internals.AbstractPartitionAssignor.MemberInfo in project kafka by apache.
the class AbstractPartitionAssignorTest method testMergeSortManyMemberInfo.
@Test
public void testMergeSortManyMemberInfo() {
Random rand = new Random();
int bound = 2;
List<MemberInfo> memberInfoList = new ArrayList<>();
List<MemberInfo> staticMemberList = new ArrayList<>();
List<MemberInfo> dynamicMemberList = new ArrayList<>();
for (int i = 0; i < 100; i++) {
// Need to make sure all the ids are defined as 3-digits otherwise
// the comparison result will break.
String id = Integer.toString(i + 100);
Optional<String> groupInstanceId = rand.nextInt(bound) < bound / 2 ? Optional.of(id) : Optional.empty();
MemberInfo m = new MemberInfo(id, groupInstanceId);
memberInfoList.add(m);
if (m.groupInstanceId.isPresent()) {
staticMemberList.add(m);
} else {
dynamicMemberList.add(m);
}
}
staticMemberList.addAll(dynamicMemberList);
Collections.shuffle(memberInfoList);
assertEquals(staticMemberList, Utils.sorted(memberInfoList));
}
use of org.apache.kafka.clients.consumer.internals.AbstractPartitionAssignor.MemberInfo in project kafka by apache.
the class AbstractPartitionAssignorTest method testMemberInfoSortingWithoutGroupInstanceId.
@Test
public void testMemberInfoSortingWithoutGroupInstanceId() {
MemberInfo m1 = new MemberInfo("a", Optional.empty());
MemberInfo m2 = new MemberInfo("b", Optional.empty());
MemberInfo m3 = new MemberInfo("c", Optional.empty());
List<MemberInfo> memberInfoList = Arrays.asList(m1, m2, m3);
assertEquals(memberInfoList, Utils.sorted(memberInfoList));
}
Aggregations