-
Notifications
You must be signed in to change notification settings - Fork 19
/
core.clj
63 lines (57 loc) · 3.35 KB
/
core.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(ns clj-gatling.core
(:require [trombi.core :as trombi]
[trombi.report :as report]
[trombi.simulation :as simulation]
[trombi.progress-tracker :as progress-tracker]
[trombi-gatling-highcharts-reporter.core :as highcharts]
[trombi-gatling-highcharts-reporter.reporter :refer [csv-writer]]
[trombi-gatling-highcharts-reporter.generator :refer [create-chart]]
[trombi.legacy-util :refer [legacy-scenarios->scenarios]]
[trombi.simulation-util :refer [create-dir
path-join
weighted-scenarios
choose-runner
create-report-name]])
(:import (java.time ZonedDateTime)))
(def buffer-size 20000)
(defn- create-results-dir
([root] (create-results-dir root nil))
([root simulation-name]
(let [results-dir (path-join root (create-report-name simulation-name))]
(create-dir (path-join results-dir "input"))
results-dir)))
;;Legacy function for running tests with old format (pre 0.8)
(defn run-simulation [legacy-scenarios concurrency & [options]]
(let [start-time (ZonedDateTime/now)
results-dir (create-results-dir (or (:root options) "target/results"))
step-timeout (or (:timeout-in-ms options) 5000)
scenarios (legacy-scenarios->scenarios legacy-scenarios)
{:keys [results]} (simulation/run-scenarios {:runner (choose-runner scenarios concurrency options)
:timeout-in-ms step-timeout
:concurrency concurrency
:context (:context options)
:error-file (or (:error-file options)
(path-join results-dir "error.log"))
:progress-tracker (progress-tracker/create-console-progress-tracker)}
(weighted-scenarios (range concurrency) scenarios))
summary (report/create-result-lines {:name "Simulation" :scenarios scenarios}
buffer-size
results
(partial csv-writer
(path-join results-dir "input")
start-time))]
(create-chart results-dir)
(println (str "Open " results-dir "/index.html"))
summary))
;clj-gatling used to have both short summary and highcharts reporters as default reporters
;Trombi has only short summary as a default
(defn- add-backwards-compatible-reporters [options]
(let [final-reporters (when-not (:reporters options)
(concat trombi/default-reporters
[highcharts/reporter]))
final-options (assoc options :reporters final-reporters)]
final-options))
(defn run [simulation options]
(trombi/run simulation (add-backwards-compatible-reporters options)))
(defn run-async [simulation options]
(trombi/run-async simulation (add-backwards-compatible-reporters options)))