jable/src/jable/cli.clj

61 lines
2.4 KiB
Clojure

; Copyright (C) 2023 Val Lorentz
;
; This program is free software: you can redistribute it and/or modify it under the
; terms of the GNU Affero General Public License version 3, as published by the Free
; Software Foundation.
;
; This program is distributed in the hope that it will be useful, but WITHOUT ANY
; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
; PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
;
; You should have received a copy of the GNU Affero General Public License along with
; this program. If not, see <http://www.gnu.org/licenses/>.
(ns jable.cli
(:require [jepsen [cli :as cli]
[tests :as tests]
[checker :as checker]
[generator :as gen]
[independent :as independent]
[nemesis :as nemesis]]
[jepsen.tests.causal :as causal]
[jepsen.os.debian :as debian]
[knossos.model :as model]
[jable.client :as client]
[jable.db :as db])
(:import (knossos.model Model)))
(defn r [_ _] {:type :invoke, :f :read, :value nil})
(defn w [_ _] {:type :invoke, :f :write, :value (str (rand-int 5))})
(defn sable-test
"Given an options map from the command line runner (e.g. :nodes, :ssh,
:concurrency, ...), constructs a test map."
[opts]
(merge tests/noop-test
opts
{:pure-generators true
:name "etcd"
:os debian/os
:db (db/sable (:sable-bin opts) (:nodes opts))
:client (client/jable.client.Client. nil nil nil)
:nemesis (nemesis/partition-random-halves)
:checker (independent/checker (causal/check causal/causal-register))
:generator (->> (gen/mix [r w])
(gen/stagger 1)
(gen/nemesis nil)
(gen/time-limit (:time-limit opts)))}))
(def cli-opts
"Additional command line options."
[[nil "--sable-bin SABLE/BIN/" "Path to a directory containing Sable's binary (eg. ~/sable/target/debug/)"]])
(defn -main
"Handles command line arguments. Can either run a test, or a web server for
browsing results."
[& args]
(cli/run! (merge (cli/single-test-cmd {:test-fn sable-test
:opt-spec cli-opts})
(cli/serve-cmd))
args))