|
4 | 4 | import static java.util.Objects.requireNonNull;
|
5 | 5 | import static org.apache.kafka.clients.admin.ListOffsetsResult.ListOffsetsResultInfo;
|
6 | 6 | import static org.assertj.core.api.Assertions.assertThat;
|
| 7 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 8 | +import static org.assertj.core.api.ThrowableAssert.ThrowingCallable; |
7 | 9 |
|
8 | 10 | import com.provectus.kafka.ui.AbstractIntegrationTest;
|
| 11 | +import com.provectus.kafka.ui.exception.ValidationException; |
9 | 12 | import com.provectus.kafka.ui.producer.KafkaTestProducer;
|
10 | 13 | import java.time.Duration;
|
11 | 14 | import java.util.ArrayList;
|
|
22 | 25 | import org.apache.kafka.clients.admin.ConfigEntry;
|
23 | 26 | import org.apache.kafka.clients.admin.NewTopic;
|
24 | 27 | import org.apache.kafka.clients.admin.OffsetSpec;
|
| 28 | +import org.apache.kafka.clients.admin.TopicDescription; |
25 | 29 | import org.apache.kafka.clients.consumer.ConsumerConfig;
|
26 | 30 | import org.apache.kafka.clients.consumer.KafkaConsumer;
|
27 | 31 | import org.apache.kafka.clients.consumer.OffsetAndMetadata;
|
28 | 32 | import org.apache.kafka.clients.producer.ProducerRecord;
|
29 | 33 | import org.apache.kafka.common.KafkaFuture;
|
| 34 | +import org.apache.kafka.common.Node; |
30 | 35 | import org.apache.kafka.common.TopicPartition;
|
| 36 | +import org.apache.kafka.common.TopicPartitionInfo; |
31 | 37 | import org.apache.kafka.common.config.ConfigResource;
|
32 | 38 | import org.apache.kafka.common.errors.UnknownTopicOrPartitionException;
|
33 | 39 | import org.apache.kafka.common.internals.KafkaFutureImpl;
|
34 | 40 | import org.apache.kafka.common.serialization.StringDeserializer;
|
| 41 | +import org.assertj.core.api.ThrowableAssert; |
35 | 42 | import org.junit.function.ThrowingRunnable;
|
36 | 43 | import org.junit.jupiter.api.AfterEach;
|
37 | 44 | import org.junit.jupiter.api.BeforeEach;
|
@@ -133,6 +140,56 @@ void testToMonoWithExceptionFilter() {
|
133 | 140 | .verifyComplete();
|
134 | 141 | }
|
135 | 142 |
|
| 143 | + @Test |
| 144 | + void filterPartitionsWithLeaderCheckSkipsPartitionsFromTopicWhereSomePartitionsHaveNoLeader() { |
| 145 | + var filteredPartitions = ReactiveAdminClient.filterPartitionsWithLeaderCheck( |
| 146 | + List.of( |
| 147 | + // contains partitions with no leader |
| 148 | + new TopicDescription("noLeaderTopic", false, |
| 149 | + List.of( |
| 150 | + new TopicPartitionInfo(0, new Node(1, "n1", 9092), List.of(), List.of()), |
| 151 | + new TopicPartitionInfo(1, null, List.of(), List.of()))), |
| 152 | + // should be skipped by predicate |
| 153 | + new TopicDescription("skippingByPredicate", false, |
| 154 | + List.of( |
| 155 | + new TopicPartitionInfo(0, new Node(1, "n1", 9092), List.of(), List.of()))), |
| 156 | + // good topic |
| 157 | + new TopicDescription("good", false, |
| 158 | + List.of( |
| 159 | + new TopicPartitionInfo(0, new Node(1, "n1", 9092), List.of(), List.of()), |
| 160 | + new TopicPartitionInfo(1, new Node(2, "n2", 9092), List.of(), List.of())) |
| 161 | + )), |
| 162 | + p -> !p.topic().equals("skippingByPredicate"), |
| 163 | + false |
| 164 | + ); |
| 165 | + |
| 166 | + assertThat(filteredPartitions) |
| 167 | + .containsExactlyInAnyOrder( |
| 168 | + new TopicPartition("good", 0), |
| 169 | + new TopicPartition("good", 1) |
| 170 | + ); |
| 171 | + } |
| 172 | + |
| 173 | + @Test |
| 174 | + void filterPartitionsWithLeaderCheckThrowExceptionIfThereIsSomePartitionsWithoutLeaderAndFlagSet() { |
| 175 | + ThrowingCallable call = () -> ReactiveAdminClient.filterPartitionsWithLeaderCheck( |
| 176 | + List.of( |
| 177 | + // contains partitions with no leader |
| 178 | + new TopicDescription("t1", false, |
| 179 | + List.of( |
| 180 | + new TopicPartitionInfo(0, new Node(1, "n1", 9092), List.of(), List.of()), |
| 181 | + new TopicPartitionInfo(1, null, List.of(), List.of()))), |
| 182 | + new TopicDescription("t2", false, |
| 183 | + List.of( |
| 184 | + new TopicPartitionInfo(0, new Node(1, "n1", 9092), List.of(), List.of())) |
| 185 | + )), |
| 186 | + p -> true, |
| 187 | + // setting failOnNoLeader flag |
| 188 | + true |
| 189 | + ); |
| 190 | + assertThatThrownBy(call).isInstanceOf(ValidationException.class); |
| 191 | + } |
| 192 | + |
136 | 193 | @Test
|
137 | 194 | void testListOffsetsUnsafe() {
|
138 | 195 | String topic = UUID.randomUUID().toString();
|
|
0 commit comments