-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdev.clj
50 lines (44 loc) · 2.07 KB
/
dev.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
(ns dev
(:require
[clojure.tools.namespace.repl :as repl]
[com.example.core :as core]
[com.example.io.reporter :as reporter]
[com.example.sample-backend :as sample-backend]
[ring.adapter.jetty :as jetty])
(:import
(java.io Closeable)))
(repl/set-refresh-dirs "dev" "src")
(defonce server (atom nil))
(def scenario
{:workflows {:listeners [{:task :register-user}
{:task :listen-to-friend-requests}]
:inviter [{:task :register-user}
{:task :wait :duration 1}
{:task :send-friend-request :to {:behavior {:accept-friend-request true}}}
{:task :send-friend-request :to {:accept-friend-request false}}
{:task :send-friend-request :to {:workflow :listeners}}
{:task :send-friend-request :to {:tags [:singleton]}}
{:task :wait :duration 3}
{:task :terminate-scenario}]}
:actor-pools [{:workflow :listeners :actors 10 :behavior {:accept-friend-request true}}
{:workflow :listeners :actors 10 :behavior {:accept-friend-request false}}
{:workflow :listeners :actors 1 :tags [:singleton]}
{:workflow :inviter :actors 10}]})
(defn- count-actors
[scenario]
(reduce #(+ %1 (:actors %2)) 0 (:actor-pools scenario)))
(defn go []
(reset! server
(let [jetty (jetty/run-jetty sample-backend/handler {:port 3000 :join? false})
system (core/start-system {:reporter #_(reporter/create-csv-reporter "output.csv" (count-actors scenario) true)
(reporter/create-log-reporter (count-actors scenario))
:api-url "http://localhost:3000/api"
:scenario scenario})]
(reify Closeable
(close [_this]
(.close system)
(.stop jetty))))))
(defn reset []
(when-let [server (deref server)]
(.close server))
(repl/refresh :after 'dev/go))