Skip to content

Commit

Permalink
allow to pass protocol version via environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
alexott committed Nov 29, 2017
1 parent 69fc792 commit f09b813
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Expand Up @@ -3,9 +3,10 @@ before_install:
- "ulimit -u 4096"
script: ./bin/ci.sh
env:
- CASSANDRA_VERSION=2.1.19
- CASSANDRA_VERSION=2.2.11
- CASSANDRA_VERSION=3.0.15
- CASSANDRA_VERSION=3.1.1
- CASSANDRA_VERSION=2.0.17 CASSANDRA_PROTOCOL_VERSION=2
- CASSANDRA_VERSION=2.1.19 CASSANDRA_PROTOCOL_VERSION=3
- CASSANDRA_VERSION=2.2.11 CASSANDRA_PROTOCOL_VERSION=4
- CASSANDRA_VERSION=3.0.15 CASSANDRA_PROTOCOL_VERSION=4
- CASSANDRA_VERSION=3.11.1 CASSANDRA_PROTOCOL_VERSION=4
jdk:
- oraclejdk8
25 changes: 14 additions & 11 deletions test/clojure/clojurewerkz/cassaforte/client_test.clj
Expand Up @@ -2,12 +2,13 @@
(:refer-clojure :exclude [update])
(:require [clojurewerkz.cassaforte.client :as client]
[clojurewerkz.cassaforte.cql :refer :all]
[clojure.test :refer :all])
[clojure.test :refer :all]
[clojurewerkz.cassaforte.test-helper :refer [get-cass-proto-version]])
(:import [com.datastax.driver.core.policies TokenAwarePolicy RoundRobinPolicy]))


(deftest ^:client test-disconnect
(let [s (client/connect ["127.0.0.1"])
(let [s (client/connect ["127.0.0.1"] {:protocol-version (get-cass-proto-version)})
cluster (.getCluster s)]
(is (= (.isClosed s) false))
(client/disconnect s)
Expand All @@ -18,7 +19,7 @@


(deftest ^:client test-disconnect!
(let [s (client/connect ["127.0.0.1"])
(let [s (client/connect ["127.0.0.1"] {:protocol-version (get-cass-proto-version)})
cluster (.getCluster s)]
(is (= (.isClosed s) false))
(is (= (.isClosed cluster) false))
Expand All @@ -28,15 +29,15 @@


(deftest ^:client test-connect-via-uri
(let [s (client/connect ["127.0.0.1"])]
(let [s (client/connect ["127.0.0.1"] {:protocol-version (get-cass-proto-version)})]
(try
(drop-keyspace s :new_cql_keyspace)
(catch Exception _ nil))
(create-keyspace s "new_cql_keyspace"
(with {:replication
{"class" "SimpleStrategy"
"replication_factor" 1 }}))
(let [s2 (client/connect-with-uri "cql://127.0.0.1:9042/new_cql_keyspace")]
(let [s2 (client/connect-with-uri "cql://127.0.0.1:9042/new_cql_keyspace" {:protocol-version (get-cass-proto-version)})]
(is (= (.isClosed s2) false))
(client/disconnect s2)
(is (= (.isClosed s2) true)))
Expand All @@ -45,7 +46,7 @@

(deftest ^:client test-connect
(testing "Connect without options or keyspace"
(let [session (client/connect ["127.0.0.1"])
(let [session (client/connect ["127.0.0.1"] {:protocol-version (get-cass-proto-version)})
cluster (.getCluster session)]
(is (= false (.isClosed session)))
(is (= false (.isClosed cluster)))
Expand All @@ -54,7 +55,7 @@
(client/disconnect session)))

(testing "Connect with keyspace, without options"
(let [session (client/connect ["127.0.0.1"] "system")
(let [session (client/connect ["127.0.0.1"] "system" {:protocol-version (get-cass-proto-version)})
cluster (.getCluster session)]
(is (= false (.isClosed session)))
(is (= false (.isClosed cluster)))
Expand All @@ -63,7 +64,7 @@
(client/disconnect session)))

(testing "Connect with keyspace in options"
(let [session (client/connect ["127.0.0.1"] {:keyspace "system"})
(let [session (client/connect ["127.0.0.1"] {:keyspace "system" :protocol-version (get-cass-proto-version)})
cluster (.getCluster session)]
(is (= false (.isClosed session)))
(is (= false (.isClosed cluster)))
Expand All @@ -72,7 +73,7 @@
(client/disconnect session)))

(testing "Connect with options"
(let [session (client/connect ["127.0.0.1"] {:load-balancing-policy (RoundRobinPolicy.)})
(let [session (client/connect ["127.0.0.1"] {:load-balancing-policy (RoundRobinPolicy.) :protocol-version (get-cass-proto-version)})
cluster (.getCluster session)]
(is (= false (.isClosed session)))
(is (= false (.isClosed cluster)))
Expand All @@ -81,7 +82,8 @@
(client/disconnect session)))

(testing "Connect with options and keyspace (in options)"
(let [session (client/connect ["127.0.0.1"] {:load-balancing-policy (RoundRobinPolicy.) :keyspace "system"})
(let [session (client/connect ["127.0.0.1"] {:load-balancing-policy (RoundRobinPolicy.) :keyspace "system"
:protocol-version (get-cass-proto-version)})
cluster (.getCluster session)]
(is (= false (.isClosed session)))
(is (= false (.isClosed cluster)))
Expand All @@ -90,7 +92,8 @@
(client/disconnect session)))

(testing "Connect with options and keyspace (separate args)"
(let [session (client/connect ["127.0.0.1"] "system" {:load-balancing-policy (RoundRobinPolicy.)})
(let [session (client/connect ["127.0.0.1"] "system" {:load-balancing-policy (RoundRobinPolicy.)
:protocol-version (get-cass-proto-version)})
cluster (.getCluster session)]
(is (= false (.isClosed session)))
(is (= false (.isClosed cluster)))
Expand Down
9 changes: 7 additions & 2 deletions test/clojure/clojurewerkz/cassaforte/test_helper.clj
Expand Up @@ -11,9 +11,14 @@
:episode_title :text
:primary-key [:series_title :episode_id]}})

(defn get-cass-proto-version []
(if-let [env-value (System/getenv "CASSANDRA_PROTOCOL_VERSION")]
(Integer/parseInt env-value)
4))

(defn with-temporary-keyspace
[f]
(let [session (client/connect ["127.0.0.1"])]
(let [session (client/connect ["127.0.0.1"] {:protocol-version (get-cass-proto-version)})]
(try
(drop-keyspace session :new_cql_keyspace (if-exists))

Expand Down Expand Up @@ -76,7 +81,7 @@

(defn with-keyspace
[f]
(let [session (client/connect ["127.0.0.1"])]
(let [session (client/connect ["127.0.0.1"] {:protocol-version (get-cass-proto-version)})]
(try
(drop-keyspace session "new_cql_keyspace"
(if-exists))
Expand Down

0 comments on commit f09b813

Please sign in to comment.