aboutsummaryrefslogtreecommitdiff
path: root/script/jepsen.garage/src/jepsen/garage/reg.clj
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2023-04-19 14:14:22 +0200
committerAlex Auvolat <alex@adnab.me>2023-10-18 12:03:11 +0200
commiteb86eaa6d2702ad5171c4fdfcbceb3dfba21833c (patch)
treed9275681dc33fda5c4a78b1bc0696c124b3d6228 /script/jepsen.garage/src/jepsen/garage/reg.clj
parent80d7b7d8582171d7ecd0e7745893792d10dd3038 (diff)
downloadgarage-eb86eaa6d2702ad5171c4fdfcbceb3dfba21833c.tar.gz
garage-eb86eaa6d2702ad5171c4fdfcbceb3dfba21833c.zip
refactor jepsen test
Diffstat (limited to 'script/jepsen.garage/src/jepsen/garage/reg.clj')
-rw-r--r--script/jepsen.garage/src/jepsen/garage/reg.clj69
1 files changed, 69 insertions, 0 deletions
diff --git a/script/jepsen.garage/src/jepsen/garage/reg.clj b/script/jepsen.garage/src/jepsen/garage/reg.clj
new file mode 100644
index 00000000..557b4a99
--- /dev/null
+++ b/script/jepsen.garage/src/jepsen/garage/reg.clj
@@ -0,0 +1,69 @@
+(ns jepsen.garage.reg
+ (:require [clojure.tools.logging :refer :all]
+ [clojure.string :as str]
+ [jepsen [checker :as checker]
+ [cli :as cli]
+ [client :as client]
+ [control :as c]
+ [db :as db]
+ [generator :as gen]
+ [independent :as independent]
+ [nemesis :as nemesis]
+ [tests :as tests]]
+ [jepsen.checker.timeline :as timeline]
+ [jepsen.control.util :as cu]
+ [jepsen.os.debian :as debian]
+ [jepsen.garage.grg :as grg]
+ [knossos.model :as model]
+ [slingshot.slingshot :refer [try+]]))
+
+(defn op-get [_ _] {:type :invoke, :f :read, :value nil})
+(defn op-put [_ _] {:type :invoke, :f :write, :value (str (rand-int 9))})
+(defn op-del [_ _] {:type :invoke, :f :write, :value nil})
+
+(defrecord RegClient [creds]
+ client/Client
+ (open! [this test node]
+ (let [creds (grg/s3-creds node)]
+ (info node "s3 credentials:" creds)
+ (assoc this :creds creds)))
+ (setup! [this test])
+ (invoke! [this test op]
+ (let [[k v] (:value op)]
+ (case (:f op)
+ :read
+ (let [value (grg/s3-get (:creds this) k)]
+ (assoc op :type :ok, :value (independent/tuple k value)))
+ :write
+ (do
+ (grg/s3-put (:creds this) k v)
+ (assoc op :type :ok)))))
+ (teardown! [this test])
+ (close! [this test]))
+
+(defn workload
+ "Tests linearizable reads and writes"
+ [opts]
+ {:client (RegClient. nil)
+ :checker (independent/checker
+ (checker/compose
+ {:linear (checker/linearizable
+ {:model (model/register)
+ :algorithm :linear})
+ :timeline (timeline/html)}))
+ :generator (->> (independent/concurrent-generator
+ 10
+ (range)
+ (fn [k]
+ (->>
+ (gen/mix [op-get op-put op-del])
+ (gen/stagger (/ (:rate opts)))
+ (gen/limit (:ops-per-key opts)))))
+ (gen/nemesis
+ (cycle [(gen/sleep 5)
+ {:type :info, :f :start}
+ (gen/sleep 5)
+ {:type :info, :f :stop}]))
+ (gen/time-limit (:time-limit opts)))})
+
+