Skip to content

Commit

Permalink
test: clean up state
Browse files Browse the repository at this point in the history
  • Loading branch information
yeikel committed Dec 16, 2024
1 parent 1436ec2 commit aba9684
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
7 changes: 7 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>kafka</artifactId>
Expand Down
18 changes: 14 additions & 4 deletions api/src/test/java/io/kafbat/ui/AbstractIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.clients.admin.NewTopic;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.function.ThrowingConsumer;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.util.TestSocketUtils;
Expand All @@ -31,6 +34,7 @@
@ActiveProfiles("test")
@AutoConfigureWebTestClient(timeout = "60000")
@ContextConfiguration(initializers = {AbstractIntegrationTest.Initializer.class})
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
public abstract class AbstractIntegrationTest {
public static final String LOCAL = "local";
public static final String SECOND_LOCAL = "secondLocal";
Expand Down Expand Up @@ -63,16 +67,22 @@ public abstract class AbstractIntegrationTest {
@TempDir
public static Path tmpDir;

static {
kafka.start();
schemaRegistry.start();
kafkaConnect.start();
@AfterEach
void afterEach() {
kafka.stop();
schemaRegistry.stop();
kafkaConnect.stop();
}


public static class Initializer
implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(@NotNull ConfigurableApplicationContext context) {
kafka.start();
schemaRegistry.start();
kafkaConnect.start();

System.setProperty("kafka.clusters.0.name", LOCAL);
System.setProperty("kafka.clusters.0.bootstrapServers", kafka.getBootstrapServers());
// List unavailable hosts to verify failover
Expand Down

0 comments on commit aba9684

Please sign in to comment.