-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplified the kafka integration tests
- Using `testcontainers` instead of `org.apache.kafka/kafka_2.12`, to spin a Kafka dind container. This simplified the Kafka cluster startup and leaves the configuration to the battle tested `testcontainers`.
- Loading branch information
yevgeni.t
committed
May 31, 2021
1 parent
deadce6
commit b532c06
Showing
4 changed files
with
59 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
(ns ketu.test.kafka-setup | ||
(:require [clj-test-containers.core :as tc]) | ||
(:import (org.testcontainers.containers KafkaContainer) | ||
(org.testcontainers.utility DockerImageName))) | ||
|
||
(def ^:private kafka-container (atom nil)) | ||
(def ^:private ^:const container-port (KafkaContainer/KAFKA_PORT)) | ||
|
||
(defn get-bootstrap-servers | ||
([] | ||
(get-bootstrap-servers @kafka-container)) | ||
([container] | ||
(.getBootstrapServers ^KafkaContainer (:container container)))) | ||
|
||
(defn start-container [] | ||
(-> {:container (KafkaContainer. (DockerImageName/parse "confluentinc/cp-kafka:5.5.3")) | ||
:exposed-ports [container-port]} | ||
tc/init | ||
tc/start!)) | ||
|
||
(defn- stop-container! [container] | ||
(tc/stop! container)) | ||
|
||
(defn with-kafka-container [test-fn] | ||
(let [container (start-container)] | ||
(reset! kafka-container container) | ||
(test-fn) | ||
(stop-container! container) | ||
(reset! kafka-container nil))) |