Skip to content

Commit f3ac116

Browse files
committed
Add new namespace for client and move all operations to it
It's needed to add other tests.
1 parent 23f9677 commit f3ac116

File tree

2 files changed

+51
-43
lines changed

2 files changed

+51
-43
lines changed

src/tarantool/client.clj

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
(ns tarantool.client
2+
"Access to Tarantool with JDBC connector"
3+
(:require [clojure.string :as str]
4+
[clojure.tools.logging :refer [info warn]]
5+
[next.jdbc :as j]
6+
[next.jdbc.connection :as connection]))
7+
8+
(def max-timeout "Longest timeout, in ms" 30000)
9+
10+
(defn conn-spec
11+
"JDBC connection spec for a node."
12+
[node]
13+
{:classname "org.tarantool.jdbc.SQLDriver"
14+
:dbtype "tarantool"
15+
:dbname "jepsen"
16+
:host (name node)
17+
:port 3301
18+
:user "jepsen"
19+
:password "jepsen"
20+
:loginTimeout (/ max-timeout 1000)
21+
:connectTimeout (/ max-timeout 1000)
22+
:socketTimeout (/ max-timeout 1000)})
23+
24+
(defn open
25+
"Opens a connection to the given node."
26+
[node test]
27+
(j/get-datasource (conn-spec node)))
28+
29+
(defn read-v-by-k
30+
"Reads the current value of a key."
31+
[conn k]
32+
(first (vals (first (j/execute! conn ["SELECT _READ(?, 'JEPSEN')" k])))))
33+
34+
(defn write-v-by-k
35+
"Writes the current value of a key."
36+
[conn k v]
37+
(j/execute! conn ["SELECT _WRITE(?, ?, 'JEPSEN')"
38+
k v]))
39+
40+
(defn compare-and-set
41+
[conn id old new]
42+
(first (vals (first (j/execute! conn ["SELECT _CAS(?, ?, ?, 'JEPSEN')"
43+
id old new])))))

src/tarantool/register.clj

Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
"Run Tarantool tests."
33
(:require [clojure.tools.logging :refer [info warn]]
44
[clojure.string :as str]
5-
[clojure.java.io :as io]
6-
[next.jdbc :as j]
7-
[next.jdbc.connection :as connection]
8-
[slingshot.slingshot :refer [try+]]
95
[jepsen [cli :as cli]
106
[client :as client]
117
[checker :as checker]
@@ -19,54 +15,23 @@
1915
[knossos.model :as model]
2016
[jepsen.checker.timeline :as timeline]
2117
[jepsen.os.ubuntu :as ubuntu]
18+
[tarantool.client :as cl]
2219
[tarantool.db :as db]))
2320

2421
(defn r [_ _] {:type :invoke, :f :read, :value nil})
2522
(defn w [_ _] {:type :invoke, :f :write, :value (rand-int 5)})
2623
(defn cas [_ _] {:type :invoke, :f :cas, :value [(rand-int 5) (rand-int 5)]})
2724

28-
(defn conn-spec
29-
"JDBC connection spec for a node."
30-
[node]
31-
{:classname "org.tarantool.jdbc.SQLDriver"
32-
:dbtype "tarantool"
33-
:dbname "jepsen"
34-
:host (name node)
35-
:port 3301
36-
:user "jepsen"
37-
:password "jepsen"})
38-
39-
(defn open
40-
"Opens a connection to the given node."
41-
[node test]
42-
(j/get-datasource (conn-spec node)))
43-
44-
(defn read-v-by-k
45-
"Reads the current value of a key."
46-
[conn k]
47-
(first (vals (first (j/execute! conn ["SELECT _READ(?, 'JEPSEN')" k])))))
48-
49-
(defn write-v-by-k
50-
"Writes the current value of a key."
51-
[conn k v]
52-
(j/execute! conn ["SELECT _WRITE(?, ?, 'JEPSEN')"
53-
k v]))
54-
55-
(defn compare-and-set
56-
[conn id old new]
57-
(first (vals (first (j/execute! conn ["SELECT _CAS(?, ?, ?, 'JEPSEN')"
58-
id old new])))))
59-
6025
(defrecord Client [conn]
6126
client/Client
6227

6328
(open! [this test node]
64-
(let [conn (open node test)]
29+
(let [conn (cl/open node test)]
6530
(assert conn)
6631
(assoc this :conn conn :node node)))
6732

6833
(setup! [this test node]
69-
(let [conn (open node test)]
34+
(let [conn (cl/open node test)]
7035
(assert conn)
7136
;(when (= node (jepsen/primary test))
7237
; (j/execute! conn ["CREATE TABLE IF NOT EXISTS jepsen (key INT, value INT, PRIMARY KEY (key))"])
@@ -77,13 +42,13 @@
7742
(case (:f op)
7843
:read (assoc op
7944
:type :ok
80-
:value (read-v-by-k conn 1))
81-
:write (do (let [con (open (jepsen/primary test) test)]
82-
(write-v-by-k con 1 (:value op)))
45+
:value (cl/read-v-by-k conn 1))
46+
:write (do (let [con (cl/open (jepsen/primary test) test)]
47+
(cl/write-v-by-k con 1 (:value op)))
8348
(assoc op :type :ok))
8449
:cas (let [[old new] (:value op)
85-
con (open (jepsen/primary test) test)]
86-
(assoc op :type (if (compare-and-set con 1 old new)
50+
con (cl/open (jepsen/primary test) test)]
51+
(assoc op :type (if (cl/compare-and-set con 1 old new)
8752
:ok
8853
:fail)))))
8954

0 commit comments

Comments
 (0)