|
27 | 27 | import org.apache.kafka.clients.producer.ProducerRecord;
|
28 | 28 | import org.apache.kafka.common.GroupState;
|
29 | 29 | import org.apache.kafka.common.TopicPartition;
|
| 30 | +import org.apache.kafka.common.errors.LeaderNotAvailableException; |
| 31 | +import org.apache.kafka.common.errors.UnknownTopicOrPartitionException; |
30 | 32 | import org.apache.kafka.common.serialization.ByteArraySerializer;
|
31 | 33 | import org.apache.kafka.common.serialization.StringDeserializer;
|
32 | 34 | import org.apache.kafka.common.test.ClusterInstance;
|
|
81 | 83 | import static org.apache.kafka.coordinator.group.GroupCoordinatorConfig.OFFSETS_TOPIC_PARTITIONS_CONFIG;
|
82 | 84 | import static org.apache.kafka.coordinator.group.GroupCoordinatorConfig.OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG;
|
83 | 85 | import static org.apache.kafka.test.TestUtils.DEFAULT_MAX_WAIT_MS;
|
| 86 | +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
84 | 87 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
85 | 88 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
86 | 89 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
@@ -659,6 +662,41 @@ public void testResetWithUnrecognizedNewConsumerOption(ClusterInstance cluster)
|
659 | 662 | assertThrows(OptionException.class, () -> getConsumerGroupService(cgcArgs));
|
660 | 663 | }
|
661 | 664 |
|
| 665 | + @ClusterTest(brokers = 3, serverProperties = {@ClusterConfigProperty(key = OFFSETS_TOPIC_REPLICATION_FACTOR_CONFIG, value = "2")}) |
| 666 | + public void testResetOffsetsWithPartitionNoneLeader(ClusterInstance cluster) throws Exception { |
| 667 | + String group = generateRandomGroupId(); |
| 668 | + String topic = generateRandomTopic(); |
| 669 | + String[] args = buildArgsForGroup(cluster, group, "--topic", topic + ":0,1,2", |
| 670 | + "--to-earliest", "--execute"); |
| 671 | + |
| 672 | + try (Admin admin = cluster.admin(); |
| 673 | + ConsumerGroupCommand.ConsumerGroupService service = getConsumerGroupService(args)) { |
| 674 | + |
| 675 | + admin.createTopics(singleton(new NewTopic(topic, 3, (short) 1))).all().get(); |
| 676 | + produceConsumeAndShutdown(cluster, topic, group, 2, GroupProtocol.CLASSIC); |
| 677 | + assertDoesNotThrow(() -> resetOffsets(service)); |
| 678 | + // shutdown a broker to make some partitions missing leader |
| 679 | + cluster.shutdownBroker(0); |
| 680 | + assertThrows(LeaderNotAvailableException.class, () -> resetOffsets(service)); |
| 681 | + } |
| 682 | + } |
| 683 | + |
| 684 | + @ClusterTest |
| 685 | + public void testResetOffsetsWithPartitionNotExist(ClusterInstance cluster) throws Exception { |
| 686 | + String group = generateRandomGroupId(); |
| 687 | + String topic = generateRandomTopic(); |
| 688 | + String[] args = buildArgsForGroup(cluster, group, "--topic", topic + ":2,3", |
| 689 | + "--to-earliest", "--execute"); |
| 690 | + |
| 691 | + try (Admin admin = cluster.admin(); |
| 692 | + ConsumerGroupCommand.ConsumerGroupService service = getConsumerGroupService(args)) { |
| 693 | + |
| 694 | + admin.createTopics(singleton(new NewTopic(topic, 1, (short) 1))).all().get(); |
| 695 | + produceConsumeAndShutdown(cluster, topic, group, 2, GroupProtocol.CLASSIC); |
| 696 | + assertThrows(UnknownTopicOrPartitionException.class, () -> resetOffsets(service)); |
| 697 | + } |
| 698 | + } |
| 699 | + |
662 | 700 | private String generateRandomTopic() {
|
663 | 701 | return TOPIC_PREFIX + TestUtils.randomString(10);
|
664 | 702 | }
|
|
0 commit comments