aboutsummaryrefslogblamecommitdiff
path: root/script/jepsen.garage/src/jepsen/garage/reg.clj
blob: f3d5cec5e6f31a3b7f567b33d9e53303e80a687f (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11










                                               
                            



                                                  

                                          









                                                                         
                                         




                            


                                                    
                                                 
                                                                        
              


                                                    

                                        
                                       





                                       
                                     





                                                                
                                                      

                              



                                                               

 
(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]
             [util :as util]
             [tests :as tests]]
            [jepsen.checker.timeline :as timeline]
            [jepsen.control.util :as cu]
            [jepsen.os.debian :as debian]
            [jepsen.garage.daemon :as grg]
            [jepsen.garage.s3api :as s3]
            [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]
    (assoc this :creds (grg/creds node)))
  (setup! [this test])
  (invoke! [this test op]
    (let [[k v] (:value op)]
      (case (:f op)
        :read
          (util/timeout
            10000
            (assoc op :type :fail, :error ::timeout)
            (let [value (s3/get (:creds this) k)]
              (assoc op :type :ok, :value (independent/tuple k value))))
        :write
          (util/timeout
            10000
            (assoc op :type :info, :error ::timeout)
            (do
              (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/limit (:ops-per-key opts)))))})