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