|
41 | 41 | import org.apache.kafka.common.utils.MockTime;
|
42 | 42 | import org.apache.kafka.test.TestUtils;
|
43 | 43 |
|
44 |
| -import org.junit.jupiter.api.Disabled; |
45 | 44 | import org.junit.jupiter.api.Test;
|
46 | 45 |
|
47 | 46 | import java.time.Duration;
|
@@ -266,45 +265,34 @@ public void testMetadataFailurePropagated() {
|
266 | 265 | assertEquals(metadataException, exc);
|
267 | 266 | }
|
268 | 267 |
|
269 |
| - @Disabled("KAFKA-17554") |
270 | 268 | @Test
|
271 | 269 | public void testFutureCompletionOutsidePoll() throws Exception {
|
272 | 270 | // Tests the scenario in which the request that is being awaited in one thread
|
273 | 271 | // is received and completed in another thread.
|
274 |
| - |
275 |
| - final CountDownLatch t1TheardCountDownLatch = new CountDownLatch(1); |
276 |
| - final CountDownLatch t2ThreadCountDownLatch = new CountDownLatch(2); |
277 |
| - |
278 | 272 | final RequestFuture<ClientResponse> future = consumerClient.send(node, heartbeat());
|
279 | 273 | consumerClient.pollNoWakeup(); // dequeue and send the request
|
280 | 274 |
|
| 275 | + CountDownLatch bothThreadsReady = new CountDownLatch(2); |
| 276 | + |
281 | 277 | client.enableBlockingUntilWakeup(2);
|
282 |
| - Thread t1 = new Thread(() -> { |
283 |
| - t1TheardCountDownLatch.countDown(); |
| 278 | + |
| 279 | + Thread t1 = new Thread(() -> { |
| 280 | + bothThreadsReady.countDown(); |
284 | 281 | consumerClient.pollNoWakeup();
|
285 |
| - t2ThreadCountDownLatch.countDown(); |
286 | 282 | });
|
287 |
| - |
288 |
| - t1.start(); |
289 | 283 |
|
290 | 284 | Thread t2 = new Thread(() -> {
|
291 |
| - try { |
292 |
| - t2ThreadCountDownLatch.await(); |
293 |
| - consumerClient.poll(future); |
294 |
| - } catch (InterruptedException e) { |
295 |
| - throw new RuntimeException(e); |
296 |
| - } |
| 285 | + bothThreadsReady.countDown(); |
| 286 | + consumerClient.poll(future); |
297 | 287 | });
|
| 288 | + |
| 289 | + t1.start(); |
298 | 290 | t2.start();
|
299 |
| - |
300 |
| - // Simulate a network response and return from the poll in t1 |
| 291 | + |
| 292 | + // Wait until both threads are blocked in poll |
| 293 | + bothThreadsReady.await(); |
301 | 294 | client.respond(heartbeatResponse(Errors.NONE));
|
302 |
| - // Wait for t1 to block in poll |
303 |
| - t1TheardCountDownLatch.await(); |
304 |
| - |
305 | 295 | client.wakeup();
|
306 |
| - // while t1 is blocked in poll, t2 should be able to complete the future |
307 |
| - t2ThreadCountDownLatch.countDown(); |
308 | 296 |
|
309 | 297 | // Both threads should complete since t1 should wakeup t2
|
310 | 298 | t1.join();
|
|
0 commit comments