|
57 | 57 | import java.util.UUID;
|
58 | 58 | import java.util.concurrent.ConcurrentHashMap;
|
59 | 59 | import java.util.concurrent.CountDownLatch;
|
| 60 | +import java.util.concurrent.ExecutorService; |
| 61 | +import java.util.concurrent.Executors; |
60 | 62 | import java.util.concurrent.TimeUnit;
|
61 | 63 | import java.util.concurrent.atomic.AtomicLong;
|
62 | 64 | import java.util.concurrent.atomic.AtomicReference;
|
|
75 | 77 | import org.junit.jupiter.api.extension.ExecutionCondition;
|
76 | 78 | import org.junit.jupiter.api.extension.ExtendWith;
|
77 | 79 | import org.junit.jupiter.api.extension.ExtensionContext;
|
| 80 | +import org.junit.jupiter.api.extension.ExtensionContext.Namespace; |
| 81 | +import org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource; |
78 | 82 | import org.mockito.invocation.InvocationOnMock;
|
79 | 83 | import org.mockito.stubbing.Answer;
|
| 84 | +import org.slf4j.Logger; |
80 | 85 | import org.slf4j.LoggerFactory;
|
81 | 86 |
|
82 | 87 | public final class TestUtils {
|
83 | 88 |
|
| 89 | + private static final Logger LOGGER = LoggerFactory.getLogger(TestUtils.class); |
| 90 | + |
84 | 91 | private TestUtils() {}
|
85 | 92 |
|
86 | 93 | public static Duration waitAtMost(CallableBooleanSupplier condition) throws Exception {
|
@@ -574,9 +581,39 @@ public void afterEach(ExtensionContext context) throws Exception {
|
574 | 581 | }
|
575 | 582 |
|
576 | 583 | @Override
|
577 |
| - public void afterAll(ExtensionContext context) throws Exception { |
| 584 | + public void afterAll(ExtensionContext context) { |
578 | 585 | EventLoopGroup eventLoopGroup = eventLoopGroup(context);
|
579 |
| - eventLoopGroup.shutdownGracefully(1, 10, SECONDS).get(10, SECONDS); |
| 586 | + ExecutorServiceCloseableResourceWrapper wrapper = |
| 587 | + context |
| 588 | + .getRoot() |
| 589 | + .getStore(Namespace.GLOBAL) |
| 590 | + .getOrComputeIfAbsent(ExecutorServiceCloseableResourceWrapper.class); |
| 591 | + wrapper.executorService.submit( |
| 592 | + () -> { |
| 593 | + try { |
| 594 | + eventLoopGroup.shutdownGracefully(1, 10, SECONDS).get(10, SECONDS); |
| 595 | + } catch (InterruptedException e) { |
| 596 | + // happens at the end of the test suite |
| 597 | + LOGGER.debug("Error while asynchronously closing Netty event loop group", e); |
| 598 | + Thread.currentThread().interrupt(); |
| 599 | + } catch (Exception e) { |
| 600 | + LOGGER.warn("Error while asynchronously closing Netty event loop group", e); |
| 601 | + } |
| 602 | + }); |
| 603 | + } |
| 604 | + |
| 605 | + private static class ExecutorServiceCloseableResourceWrapper implements CloseableResource { |
| 606 | + |
| 607 | + private final ExecutorService executorService; |
| 608 | + |
| 609 | + private ExecutorServiceCloseableResourceWrapper() { |
| 610 | + this.executorService = Executors.newCachedThreadPool(); |
| 611 | + } |
| 612 | + |
| 613 | + @Override |
| 614 | + public void close() throws Throwable { |
| 615 | + this.executorService.shutdownNow(); |
| 616 | + } |
580 | 617 | }
|
581 | 618 | }
|
582 | 619 |
|
@@ -700,6 +737,7 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
|
700 | 737 | Client client = new Client(new ClientParameters().eventLoopGroup(eventLoopGroup));
|
701 | 738 | String expectedVersion = annotation.value();
|
702 | 739 | String brokerVersion = client.brokerVersion();
|
| 740 | + client.close(); |
703 | 741 | if (atLeastVersion(expectedVersion, brokerVersion)) {
|
704 | 742 | return ConditionEvaluationResult.enabled(
|
705 | 743 | "Broker version requirement met, expected "
|
|
0 commit comments