|
35 | 35 | import java.time.Duration; |
36 | 36 | import java.util.Collections; |
37 | 37 | import java.util.List; |
| 38 | +import java.util.Set; |
38 | 39 | import java.util.concurrent.ConcurrentHashMap; |
39 | 40 | import java.util.concurrent.ConcurrentMap; |
40 | 41 | import java.util.concurrent.CountDownLatch; |
41 | 42 | import java.util.concurrent.atomic.AtomicInteger; |
42 | | -import org.junit.jupiter.api.AfterEach; |
43 | | -import org.junit.jupiter.api.BeforeEach; |
44 | | -import org.junit.jupiter.api.Test; |
45 | | -import org.junit.jupiter.api.TestInfo; |
| 43 | +import java.util.concurrent.atomic.AtomicReference; |
| 44 | +import org.junit.jupiter.api.*; |
46 | 45 | import org.junit.jupiter.api.extension.ExtendWith; |
47 | 46 |
|
48 | 47 | @ExtendWith(TestUtils.StreamTestInfrastructureExtension.class) |
@@ -300,4 +299,65 @@ void autoOffsetTrackingShouldStoreOffsetZero() throws Exception { |
300 | 299 | }); |
301 | 300 | })); |
302 | 301 | } |
| 302 | + |
| 303 | + @Test |
| 304 | + @Disabled |
| 305 | + void rebalancedPartitionShouldGetMessagesWhenItComesBackToOriginalConsumerInstance() |
| 306 | + throws Exception { |
| 307 | + declareSuperStreamTopology(connection, superStream, partitionCount); |
| 308 | + Client client = cf.get(); |
| 309 | + List<String> partitions = client.partitions(superStream); |
| 310 | + int messageCount = 10_000; |
| 311 | + publishToPartitions(cf, partitions, messageCount); |
| 312 | + String consumerName = "my-app"; |
| 313 | + Set<String> receivedPartitions = ConcurrentHashMap.newKeySet(partitionCount); |
| 314 | + Runnable processing = |
| 315 | + () -> { |
| 316 | + try { |
| 317 | + Thread.sleep(10); |
| 318 | + } catch (InterruptedException e) { |
| 319 | + // OK |
| 320 | + } |
| 321 | + }; |
| 322 | + Consumer consumer1 = |
| 323 | + environment |
| 324 | + .consumerBuilder() |
| 325 | + .superStream(superStream) |
| 326 | + .singleActiveConsumer() |
| 327 | + .offset(OffsetSpecification.first()) |
| 328 | + .name(consumerName) |
| 329 | + .autoTrackingStrategy() |
| 330 | + .messageCountBeforeStorage(messageCount / partitionCount / 50) |
| 331 | + .builder() |
| 332 | + .messageHandler( |
| 333 | + (context, message) -> { |
| 334 | + receivedPartitions.add(context.stream()); |
| 335 | + processing.run(); |
| 336 | + }) |
| 337 | + .build(); |
| 338 | + waitAtMost(() -> receivedPartitions.size() == partitions.size()); |
| 339 | + |
| 340 | + AtomicReference<String> partition = new AtomicReference<>(); |
| 341 | + Consumer consumer2 = |
| 342 | + environment |
| 343 | + .consumerBuilder() |
| 344 | + .superStream(superStream) |
| 345 | + .singleActiveConsumer() |
| 346 | + .offset(OffsetSpecification.first()) |
| 347 | + .name(consumerName) |
| 348 | + .autoTrackingStrategy() |
| 349 | + .messageCountBeforeStorage(messageCount / partitionCount / 50) |
| 350 | + .builder() |
| 351 | + .messageHandler( |
| 352 | + (context, message) -> { |
| 353 | + partition.set(context.stream()); |
| 354 | + processing.run(); |
| 355 | + }) |
| 356 | + .build(); |
| 357 | + waitAtMost(() -> partition.get() != null); |
| 358 | + consumer2.close(); |
| 359 | + receivedPartitions.clear(); |
| 360 | + waitAtMost(() -> receivedPartitions.size() == partitions.size()); |
| 361 | + consumer1.close(); |
| 362 | + } |
303 | 363 | } |
0 commit comments