forked from mhjort/trombi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.clj
95 lines (90 loc) · 5.17 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
(ns clj-gatling.core
(:import [org.joda.time LocalDateTime])
(:require [clojider-gatling-highcharts-reporter.core :refer [gatling-highcharts-reporter]]
[clojider-gatling-highcharts-reporter.reporter :refer [csv-writer]]
[clojider-gatling-highcharts-reporter.generator :refer [create-chart]]
[clj-gatling.report :as report]
[clj-gatling.reporters.short-summary :as short-summary]
[clj-gatling.schema :as schema]
[schema.core :refer [validate]]
[clj-gatling.pipeline :as pipeline]
[clj-gatling.legacy-util :refer [legacy-scenarios->scenarios
legacy-reporter->reporter]]
[clj-gatling.simulation-util :refer [create-dir
path-join
weighted-scenarios
eval-if-needed
choose-runner
create-report-name]]
[clj-gatling.simulation :as simulation]))
(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 (LocalDateTime.)
results-dir (create-results-dir (or (:root options) "target/results"))
step-timeout (or (:timeout-in-ms options) 5000)
scenarios (legacy-scenarios->scenarios legacy-scenarios)
result (simulation/run-scenarios {:runner (choose-runner scenarios concurrency options)
:timeout-in-ms step-timeout
:context (:context options)
:error-file (or (:error-file options)
(path-join results-dir "error.log"))}
(weighted-scenarios (range concurrency) scenarios))
summary (report/create-result-lines {:name "Simulation" :scenarios scenarios}
buffer-size
result
(partial csv-writer
(path-join results-dir "input")
start-time))]
(create-chart results-dir)
(println (str "Open " results-dir "/index.html"))
summary))
(defn- create-reporters [reporter results-dir simulation]
(let [r (if reporter
(do
(println "Warn! :reporter option is deprecated. Use :reporters instead")
(legacy-reporter->reporter :custom
reporter
simulation))
(legacy-reporter->reporter :highcharts
(gatling-highcharts-reporter results-dir)
simulation))]
[short-summary/reporter r]))
(defn run [simulation {:keys [concurrency concurrency-distribution root timeout-in-ms context
requests duration reporter reporters error-file executor nodes] :as options
:or {concurrency 1
root "target/results"
executor pipeline/local-executor
nodes 1
timeout-in-ms 5000
context {}}}]
(validate schema/Options options)
(let [simulation-name (:name (eval-if-needed simulation))
results-dir (create-results-dir root simulation-name)
multiple-reporters? (not (nil? reporters))
reporters (or reporters
(create-reporters reporter results-dir simulation))
summary (pipeline/run simulation (assoc options
:concurrency concurrency
:concurrency-distribution concurrency-distribution
:timeout-in-ms timeout-in-ms
:context context
:executor executor
:reporters reporters
:results-dir results-dir
:nodes nodes
:batch-size buffer-size
:requests requests
:error-file (or error-file
(path-join results-dir "error.log"))
:duration duration))]
(println "Simulation" simulation-name "finished.")
(if multiple-reporters?
summary
(:short summary))))