All Downloads are FREE. Search and download functionalities are using the official Maven repository.

generator.server.springboot.broker.kafka.KafkaTestContainerExtension.mustache Maven / Gradle / Ivy

There is a newer version: 1.22.0
Show newest version
package {{packageName}};

import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.testcontainers.kafka.KafkaContainer;
import org.testcontainers.utility.DockerImageName;

public class KafkaTestContainerExtension implements BeforeAllCallback {

  private static final AtomicBoolean kafkaContainerStarted = new AtomicBoolean(false);
  private static KafkaContainer kafkaContainer;

  @Override
  public void beforeAll(final ExtensionContext context) {
    if (!kafkaContainerStarted.get()) {
      kafkaContainer = new KafkaContainer(DockerImageName.parse("{{kafkaDockerImage}}")).withNetwork(null);
      kafkaContainer.start();
      kafkaContainerStarted.set(true);
      System.setProperty("kafka.bootstrap.servers", kafkaContainer.getBootstrapServers());
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy