Skip to content

Commit aba9684

Browse files
committed
test: clean up state
1 parent 1436ec2 commit aba9684

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

api/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@
155155
<artifactId>testcontainers</artifactId>
156156
<scope>test</scope>
157157
</dependency>
158+
159+
<dependency>
160+
<groupId>org.springframework</groupId>
161+
<artifactId>spring-test</artifactId>
162+
<scope>test</scope>
163+
</dependency>
164+
158165
<dependency>
159166
<groupId>org.testcontainers</groupId>
160167
<artifactId>kafka</artifactId>

api/src/test/java/io/kafbat/ui/AbstractIntegrationTest.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
import org.apache.kafka.clients.admin.AdminClientConfig;
1313
import org.apache.kafka.clients.admin.NewTopic;
1414
import org.jetbrains.annotations.NotNull;
15+
import org.junit.jupiter.api.AfterEach;
16+
import org.junit.jupiter.api.BeforeEach;
1517
import org.junit.jupiter.api.function.ThrowingConsumer;
1618
import org.junit.jupiter.api.io.TempDir;
1719
import org.springframework.beans.factory.annotation.Autowired;
1820
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
1921
import org.springframework.boot.test.context.SpringBootTest;
2022
import org.springframework.context.ApplicationContextInitializer;
2123
import org.springframework.context.ConfigurableApplicationContext;
24+
import org.springframework.test.annotation.DirtiesContext;
2225
import org.springframework.test.context.ActiveProfiles;
2326
import org.springframework.test.context.ContextConfiguration;
2427
import org.springframework.test.util.TestSocketUtils;
@@ -31,6 +34,7 @@
3134
@ActiveProfiles("test")
3235
@AutoConfigureWebTestClient(timeout = "60000")
3336
@ContextConfiguration(initializers = {AbstractIntegrationTest.Initializer.class})
37+
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
3438
public abstract class AbstractIntegrationTest {
3539
public static final String LOCAL = "local";
3640
public static final String SECOND_LOCAL = "secondLocal";
@@ -63,16 +67,22 @@ public abstract class AbstractIntegrationTest {
6367
@TempDir
6468
public static Path tmpDir;
6569

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();
7075
}
7176

77+
7278
public static class Initializer
7379
implements ApplicationContextInitializer<ConfigurableApplicationContext> {
7480
@Override
7581
public void initialize(@NotNull ConfigurableApplicationContext context) {
82+
kafka.start();
83+
schemaRegistry.start();
84+
kafkaConnect.start();
85+
7686
System.setProperty("kafka.clusters.0.name", LOCAL);
7787
System.setProperty("kafka.clusters.0.bootstrapServers", kafka.getBootstrapServers());
7888
// List unavailable hosts to verify failover

0 commit comments

Comments
 (0)