This repository has been archived by the owner on Apr 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fr33m0nk]: adds the macro method and bumps the release version
- Loading branch information
Prashant Sinha
committed
Apr 28, 2021
1 parent
34d3cf0
commit 03b9689
Showing
10 changed files
with
103 additions
and
58 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,48 @@ | ||
(ns kafka-cluster-test-utility.topic-management | ||
(:require [kafka-cluster-test-utility.kafka-cluster-state :as s] | ||
[kafka-cluster-test-utility.utility :as utils]) | ||
(:import (org.apache.kafka.streams.integration.utils EmbeddedKafkaCluster))) | ||
|
||
(defn create-topics | ||
"Creates topic(s) on supplied Kafka cluster" | ||
[kafka-cluster ^EmbeddedKafkaCluster & topic-names] | ||
(try (.createTopics kafka-cluster (into-array topic-names)) | ||
true | ||
(catch Exception e | ||
false))) | ||
[& topic-names] | ||
(utils/when-let* [running? (:running? @s/state) | ||
kafka-cluster (:cluster @s/state)] | ||
(try (.createTopics ^EmbeddedKafkaCluster kafka-cluster (into-array topic-names)) | ||
true | ||
(catch Exception e | ||
false)))) | ||
|
||
(defn delete-topics | ||
"Deletes topic(s) on supplied Kafka cluster" | ||
[kafka-cluster ^EmbeddedKafkaCluster & topic-names] | ||
(try (.deleteTopicsAndWait kafka-cluster (into-array topic-names)) | ||
true | ||
(catch Exception e | ||
false))) | ||
[& topic-names] | ||
(utils/when-let* [running? (:running? @s/state) | ||
kafka-cluster (:cluster @s/state)] | ||
(try (.deleteTopicsAndWait ^EmbeddedKafkaCluster kafka-cluster (into-array topic-names)) | ||
true | ||
(catch Exception e | ||
false)))) | ||
|
||
(defn recreate-topic | ||
"Recreates topic on supplied Kafka cluster" | ||
[kafka-cluster ^EmbeddedKafkaCluster topic-name] | ||
(try | ||
(delete-topics kafka-cluster topic-name) | ||
(finally | ||
(create-topics kafka-cluster topic-name)))) | ||
[topic-name] | ||
(utils/when-let* [running? (:running? @s/state) | ||
kafka-cluster (:cluster @s/state)] | ||
(try | ||
(delete-topics topic-name) | ||
(finally | ||
(create-topics topic-name))))) | ||
|
||
(defn recreate-topics | ||
"Recreates topics on supplied Kafka cluster" | ||
[kafka-cluster ^EmbeddedKafkaCluster topic-names] | ||
[topic-names] | ||
{:pre [(sequential? topic-names)]} | ||
(try | ||
(apply (partial delete-topics kafka-cluster) topic-names) | ||
(finally | ||
(apply (partial create-topics kafka-cluster) topic-names)))) | ||
(utils/when-let* [running? (:running? @s/state) | ||
kafka-cluster (:cluster @s/state)] | ||
(try | ||
(apply delete-topics topic-names) | ||
(finally | ||
(apply create-topics topic-names))))) | ||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(ns kafka-cluster-test-utility.core-macro-test | ||
(:require [clojure.test :refer :all] | ||
[kafka-cluster-test-utility.core :as core])) | ||
|
||
(deftest with-embedded-kafka-cluster-test | ||
(testing "should produce and consume message with in the with-embedded-kafka-cluster macro" | ||
(core/with-embedded-kafka-cluster 3 | ||
["test-1"] | ||
(core/send-with-producer "test-topic" (.getBytes "hello dost")) | ||
(is (= "hello dost" | ||
(->> (core/with-consumer-read-one "test-topic" 2) | ||
String.)))))) |
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