use of org.apache.kafka.clients.consumer.internals.AbstractPartitionAssignor.MemberInfo in project kafka by apache.
the class RangeAssignorTest method setUp.
@BeforeEach
public void setUp() {
staticMemberInfos = new ArrayList<>();
staticMemberInfos.add(new MemberInfo(consumer1, Optional.of(instance1)));
staticMemberInfos.add(new MemberInfo(consumer2, Optional.of(instance2)));
staticMemberInfos.add(new MemberInfo(consumer3, Optional.of(instance3)));
}
use of org.apache.kafka.clients.consumer.internals.AbstractPartitionAssignor.MemberInfo in project kafka by apache.
the class RangeAssignorTest method testStaticMemberRangeAssignmentPersistent.
@Test
public void testStaticMemberRangeAssignmentPersistent() {
Map<String, Integer> partitionsPerTopic = setupPartitionsPerTopicWithTwoTopics(5, 4);
Map<String, Subscription> consumers = new HashMap<>();
for (MemberInfo m : staticMemberInfos) {
Subscription subscription = new Subscription(topics(topic1, topic2), null, Collections.emptyList());
subscription.setGroupInstanceId(m.groupInstanceId);
consumers.put(m.memberId, subscription);
}
// Consumer 4 is a dynamic member.
String consumer4 = "consumer4";
consumers.put(consumer4, new Subscription(topics(topic1, topic2)));
Map<String, List<TopicPartition>> expectedAssignment = new HashMap<>();
// Have 3 static members instance1, instance2, instance3 to be persistent
// across generations. Their assignment shall be the same.
expectedAssignment.put(consumer1, partitions(tp(topic1, 0), tp(topic1, 1), tp(topic2, 0)));
expectedAssignment.put(consumer2, partitions(tp(topic1, 2), tp(topic2, 1)));
expectedAssignment.put(consumer3, partitions(tp(topic1, 3), tp(topic2, 2)));
expectedAssignment.put(consumer4, partitions(tp(topic1, 4), tp(topic2, 3)));
Map<String, List<TopicPartition>> assignment = assignor.assign(partitionsPerTopic, consumers);
assertEquals(expectedAssignment, assignment);
// Replace dynamic member 4 with a new dynamic member 5.
consumers.remove(consumer4);
String consumer5 = "consumer5";
consumers.put(consumer5, new Subscription(topics(topic1, topic2)));
expectedAssignment.remove(consumer4);
expectedAssignment.put(consumer5, partitions(tp(topic1, 4), tp(topic2, 3)));
assignment = assignor.assign(partitionsPerTopic, consumers);
assertEquals(expectedAssignment, assignment);
}
use of org.apache.kafka.clients.consumer.internals.AbstractPartitionAssignor.MemberInfo in project kafka by apache.
the class RangeAssignorTest method testStaticMemberRangeAssignmentPersistentAfterMemberIdChanges.
@Test
public void testStaticMemberRangeAssignmentPersistentAfterMemberIdChanges() {
Map<String, Integer> partitionsPerTopic = setupPartitionsPerTopicWithTwoTopics(5, 5);
Map<String, Subscription> consumers = new HashMap<>();
for (MemberInfo m : staticMemberInfos) {
Subscription subscription = new Subscription(topics(topic1, topic2), null, Collections.emptyList());
subscription.setGroupInstanceId(m.groupInstanceId);
consumers.put(m.memberId, subscription);
}
Map<String, List<TopicPartition>> expectedInstanceAssignment = new HashMap<>();
expectedInstanceAssignment.put(instance1, partitions(tp(topic1, 0), tp(topic1, 1), tp(topic2, 0), tp(topic2, 1)));
expectedInstanceAssignment.put(instance2, partitions(tp(topic1, 2), tp(topic1, 3), tp(topic2, 2), tp(topic2, 3)));
expectedInstanceAssignment.put(instance3, partitions(tp(topic1, 4), tp(topic2, 4)));
Map<String, List<TopicPartition>> staticAssignment = checkStaticAssignment(assignor, partitionsPerTopic, consumers);
assertEquals(expectedInstanceAssignment, staticAssignment);
// 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 RoundRobinAssignorTest method testStaticMemberRoundRobinAssignmentPersistent.
@Test
public void testStaticMemberRoundRobinAssignmentPersistent() {
// Have 3 static members instance1, instance2, instance3 to be persistent
// across generations. Their assignment shall be the same.
String consumer1 = "consumer1";
String instance1 = "instance1";
String consumer2 = "consumer2";
String instance2 = "instance2";
String consumer3 = "consumer3";
String instance3 = "instance3";
List<MemberInfo> staticMemberInfos = new ArrayList<>();
staticMemberInfos.add(new MemberInfo(consumer1, Optional.of(instance1)));
staticMemberInfos.add(new MemberInfo(consumer2, Optional.of(instance2)));
staticMemberInfos.add(new MemberInfo(consumer3, Optional.of(instance3)));
// Consumer 4 is a dynamic member.
String consumer4 = "consumer4";
Map<String, Integer> partitionsPerTopic = setupPartitionsPerTopicWithTwoTopics(3, 3);
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);
}
consumers.put(consumer4, new Subscription(topics(topic1, topic2)));
Map<String, List<TopicPartition>> expectedAssignment = new HashMap<>();
expectedAssignment.put(consumer1, partitions(tp(topic1, 0), tp(topic2, 1)));
expectedAssignment.put(consumer2, partitions(tp(topic1, 1), tp(topic2, 2)));
expectedAssignment.put(consumer3, partitions(tp(topic1, 2)));
expectedAssignment.put(consumer4, partitions(tp(topic2, 0)));
Map<String, List<TopicPartition>> assignment = assignor.assign(partitionsPerTopic, consumers);
assertEquals(expectedAssignment, assignment);
// Replace dynamic member 4 with a new dynamic member 5.
consumers.remove(consumer4);
String consumer5 = "consumer5";
consumers.put(consumer5, new Subscription(topics(topic1, topic2)));
expectedAssignment.remove(consumer4);
expectedAssignment.put(consumer5, partitions(tp(topic2, 0)));
assignment = assignor.assign(partitionsPerTopic, consumers);
assertEquals(expectedAssignment, assignment);
}
Aggregations