Skip to content

Commit

Permalink
Make port configurable in tests via env var
Browse files Browse the repository at this point in the history
  • Loading branch information
jbropho committed Mar 7, 2024
1 parent 3291ffd commit 88e227c
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 29 deletions.
2 changes: 1 addition & 1 deletion test/jackdaw/client/partitioning_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


(deftest test->ProducerRecord
(with-open [p (client/producer {"bootstrap.servers" (str (utils/bootstrap-servers) ":9092")
(with-open [p (client/producer {"bootstrap.servers" (utils/bootstrap-servers)
"key.serializer" "org.apache.kafka.common.serialization.StringSerializer"
"value.serializer" "org.apache.kafka.common.serialization.StringSerializer"})]
(testing "absent key-fn"
Expand Down
4 changes: 2 additions & 2 deletions test/jackdaw/client_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"high-partition-topic" high-partition-topic})

(defn broker-config []
{"bootstrap.servers" (str (utils/bootstrap-servers) ":9092")})
{"bootstrap.servers" (utils/bootstrap-servers)})

(defn producer-config []
(-> (broker-config)
Expand Down Expand Up @@ -160,7 +160,7 @@

(deftest ^:integration consumer-test
(let [config {"group.id" "jackdaw-client-test-consumer-test"
"bootstrap.servers" (str (utils/bootstrap-servers) ":9092")
"bootstrap.servers" (utils/bootstrap-servers)
"key.deserializer" "org.apache.kafka.common.serialization.StringDeserializer"
"value.deserializer" "org.apache.kafka.common.serialization.StringDeserializer"}
key-serde (:key-serde foo-topic)
Expand Down
6 changes: 3 additions & 3 deletions test/jackdaw/serdes/avro/integration_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
(set! *warn-on-reflection* false)

(def +real-schema-registry-url+
(format "http://%s:8081" (utils/schema-registry-host)))
(str "http://" (utils/schema-registry-address)))

(def +type-registry+
(merge avro/+base-schema-type-registry+
Expand Down Expand Up @@ -66,8 +66,8 @@
"A Kafka consumer or streams config."
(let [id (str "dev-" (java.util.UUID/randomUUID))]
{"replication.factor" "1", "group.id" id, "application.id" id,
"bootstrap.servers" (str (utils/bootstrap-servers) ":9092")
"zookeeper.connect" (str (utils/zookeeper-host) ":2181")
"bootstrap.servers" (utils/bootstrap-servers)
"zookeeper.connect" (utils/zookeeper-address)
"request.timeout.ms" "1000"}))

;;;; Schemas
Expand Down
2 changes: 1 addition & 1 deletion test/jackdaw/serdes/avro_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
serde-config)
schema-registry-config
{:avro.schema-registry/client registry-client
:avro.schema-registry/url (str (utils/schema-registry-host) ":8081")}]
:avro.schema-registry/url (utils/schema-registry-address)}]
(avro/serde +registry+ schema-registry-config serde-config))))

(defn deserialize [serde topic x]
Expand Down
2 changes: 1 addition & 1 deletion test/jackdaw/serdes/json_schema/confluent_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{"json.fail.invalid.schema" false}
:serializer-properties
{"json.fail.invalid.schema" false}})))
schema-registry-url (str (utils/schema-registry-host) ":8081")
schema-registry-url (utils/schema-registry-address)
key? false]
(jsco/serde schema-registry-url schema-str key? serde-config))))

Expand Down
2 changes: 1 addition & 1 deletion test/jackdaw/test/commands/write_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
:key-serde :long
:value-serde :json}))

(def kafka-config {"bootstrap.servers" (str (utils/bootstrap-servers) ":9092")
(def kafka-config {"bootstrap.servers" (utils/bootstrap-servers)
"group.id" "kafka-write-test"})

(defn with-transport
Expand Down
4 changes: 2 additions & 2 deletions test/jackdaw/test/fixtures_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
:config {}})

(def kafka-config
{"bootstrap.servers" (str (utils/bootstrap-servers) ":9092")})
{"bootstrap.servers" (utils/bootstrap-servers)})

(def test-topics
(let [topics {"foo" topic-foo}]
Expand Down Expand Up @@ -73,7 +73,7 @@

(deftest test-reset-application-fixture-failure
(test-resetter {:app-config {"application.id" "yolo"
"bootstrap.servers" (str (utils/bootstrap-servers) ":9092")}
"bootstrap.servers" (utils/bootstrap-servers)}
:reset-params ["--foo" "foo"
"--bar" "bar"]
:reset-fn (fn [reset-args rt args]
Expand Down
4 changes: 2 additions & 2 deletions test/jackdaw/test/transports/kafka_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

(set! *warn-on-reflection* false)

(def kafka-config {"bootstrap.servers" (str (utils/bootstrap-servers) ":9092")
(def kafka-config {"bootstrap.servers" (utils/bootstrap-servers)
"group.id" "kafka-write-test"})

(defn kstream-config
[app app-id]
{:topology app
:config {"bootstrap.servers" (str (utils/bootstrap-servers) ":9092")
:config {"bootstrap.servers" (utils/bootstrap-servers)
"application.id" app-id}})

(defn echo-stream
Expand Down
2 changes: 1 addition & 1 deletion test/jackdaw/test/transports/mock_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
[]
(trns/transport {:type :mock
:driver (test-driver (echo-stream test-in test-out)
{"bootstrap.servers" (str (utils/bootstrap-servers) ":9092")
{"bootstrap.servers" (utils/bootstrap-servers)
"application.id" "test-echo-stream"})
:topics {"test-in" test-in
"test-out" test-out}}))
Expand Down
8 changes: 4 additions & 4 deletions test/jackdaw/test/transports/rest_proxy_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

(set! *warn-on-reflection* false)

(def kafka-config {"bootstrap.servers" (str (utils/bootstrap-servers) ":9092")
(def kafka-config {"bootstrap.servers" (utils/bootstrap-servers)
"group.id" "kafka-write-test"})

(def +real-rest-proxy-url+
(format "http://%s:8082" (utils/kafka-rest-proxy-host)))
(format "http://%s" (utils/kafka-rest-proxy-address)))

(defn rest-proxy-config
[group-id]
Expand All @@ -31,7 +31,7 @@
(defn kstream-config
[app app-id]
{:topology app
:config {"bootstrap.servers" (str (utils/bootstrap-servers) ":9092")
:config {"bootstrap.servers" (utils/bootstrap-servers)
"application.id" app-id}})

(defn echo-stream
Expand Down Expand Up @@ -174,7 +174,7 @@
:consumer.fetch.timeout.ms 200})))
(proxy/with-consumer))
[url options] (first @http-reqs)]
(is (= "http://kafka-rest:8082/consumers/test-group-config" url))
(is (= (str "http://" (utils/kafka-rest-proxy-address) "/consumers/test-group-config") url))
(is (= {"Accept" "application/vnd.kafka.v2+json"
"Content-Type" "application/vnd.kafka.v2+json"}
(:headers options)))
Expand Down
8 changes: 4 additions & 4 deletions test/jackdaw/test_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
:key-serde :string
:value-serde :json}))

(def kafka-config {"bootstrap.servers" (str (utils/bootstrap-servers) ":9092")
(def kafka-config {"bootstrap.servers" (utils/bootstrap-servers)
"group.id" "kafka-write-test"})

(defn kafka-transport
Expand Down Expand Up @@ -258,7 +258,7 @@
(try
(jd.test/with-test-machine (trns/transport {:type :mock
:driver (jd.test/mock-test-driver (bad-topology test-in test-out)
{"bootstrap.servers" (str (utils/bootstrap-servers) ":9092")
{"bootstrap.servers" (utils/bootstrap-servers)
"application.id" "test-echo-stream"})
:topics {:in test-in
:out test-out}})
Expand All @@ -280,7 +280,7 @@
(try
(jd.test/with-test-machine (trns/transport {:type :mock
:driver (jd.test/mock-test-driver (echo-stream test-in test-out)
{"bootstrap.servers" (str (utils/bootstrap-servers) ":9092")
{"bootstrap.servers" (utils/bootstrap-servers)
"application.id" "test-echo-stream"})
:topics {:in test-in
:out test-out}})
Expand All @@ -302,7 +302,7 @@
(try
(jd.test/with-test-machine (trns/transport {:type :mock
:driver (jd.test/mock-test-driver (echo-stream test-in test-out)
{"bootstrap.servers" (str (utils/bootstrap-servers) ":9092")
{"bootstrap.servers" (utils/bootstrap-servers)
"application.id" "test-echo-stream"})
:topics {:in test-in
:out test-out}})
Expand Down
22 changes: 15 additions & 7 deletions test/jackdaw/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@

(defn bootstrap-servers
[]
(or (System/getenv "KAFKA_BOOTSTRAP_SERVERS") "localhost"))
(str (or (System/getenv "KAFKA_BOOTSTRAP_SERVERS") "localhost")
":"
(or (System/getenv "KAFKA_PORT") "9092")))

(defn zookeeper-host
(defn zookeeper-address
[]
(or (System/getenv "ZOOKEEPER_HOST") "localhost"))
(str (or (System/getenv "ZOOKEEPER_HOST") "localhost")
":"
(or (System/getenv "ZOOKEEPER_PORT") "2181")))

(defn schema-registry-host
(defn schema-registry-address
[]
(or (System/getenv "SCHEMA_REGISTRY_HOST") "localhost"))
(str (or (System/getenv "SCHEMA_REGISTRY_HOST") "localhost")
":"
(or (System/getenv "SCHEMA_REGISTRY_PORT") "8081")))

(defn kafka-rest-proxy-host
(defn kafka-rest-proxy-address
[]
(or (System/getenv "KAFKA_REST_PROXY_HOST") "localhost"))
(str (or (System/getenv "KAFKA_REST_PROXY_HOST") "localhost")
":"
(or (System/getenv "KAFKA_REST_PROXY_PORT") "8082")))

0 comments on commit 88e227c

Please sign in to comment.