|
12 | 12 | import org.apache.kafka.clients.admin.AdminClientConfig; |
13 | 13 | import org.apache.kafka.clients.admin.NewTopic; |
14 | 14 | import org.jetbrains.annotations.NotNull; |
| 15 | +import org.junit.jupiter.api.AfterEach; |
| 16 | +import org.junit.jupiter.api.BeforeEach; |
15 | 17 | import org.junit.jupiter.api.function.ThrowingConsumer; |
16 | 18 | import org.junit.jupiter.api.io.TempDir; |
17 | 19 | import org.springframework.beans.factory.annotation.Autowired; |
18 | 20 | import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; |
19 | 21 | import org.springframework.boot.test.context.SpringBootTest; |
20 | 22 | import org.springframework.context.ApplicationContextInitializer; |
21 | 23 | import org.springframework.context.ConfigurableApplicationContext; |
| 24 | +import org.springframework.test.annotation.DirtiesContext; |
22 | 25 | import org.springframework.test.context.ActiveProfiles; |
23 | 26 | import org.springframework.test.context.ContextConfiguration; |
24 | 27 | import org.springframework.test.util.TestSocketUtils; |
|
31 | 34 | @ActiveProfiles("test") |
32 | 35 | @AutoConfigureWebTestClient(timeout = "60000") |
33 | 36 | @ContextConfiguration(initializers = {AbstractIntegrationTest.Initializer.class}) |
| 37 | +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) |
34 | 38 | public abstract class AbstractIntegrationTest { |
35 | 39 | public static final String LOCAL = "local"; |
36 | 40 | public static final String SECOND_LOCAL = "secondLocal"; |
@@ -63,16 +67,22 @@ public abstract class AbstractIntegrationTest { |
63 | 67 | @TempDir |
64 | 68 | public static Path tmpDir; |
65 | 69 |
|
66 | | - static { |
67 | | - kafka.start(); |
68 | | - schemaRegistry.start(); |
69 | | - kafkaConnect.start(); |
| 70 | + @AfterEach |
| 71 | + void afterEach() { |
| 72 | + kafka.stop(); |
| 73 | + schemaRegistry.stop(); |
| 74 | + kafkaConnect.stop(); |
70 | 75 | } |
71 | 76 |
|
| 77 | + |
72 | 78 | public static class Initializer |
73 | 79 | implements ApplicationContextInitializer<ConfigurableApplicationContext> { |
74 | 80 | @Override |
75 | 81 | public void initialize(@NotNull ConfigurableApplicationContext context) { |
| 82 | + kafka.start(); |
| 83 | + schemaRegistry.start(); |
| 84 | + kafkaConnect.start(); |
| 85 | + |
76 | 86 | System.setProperty("kafka.clusters.0.name", LOCAL); |
77 | 87 | System.setProperty("kafka.clusters.0.bootstrapServers", kafka.getBootstrapServers()); |
78 | 88 | // List unavailable hosts to verify failover |
|
0 commit comments