-
Notifications
You must be signed in to change notification settings - Fork 8
/
env.clj
53 lines (44 loc) · 1.47 KB
/
env.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
;; Copyright © 2022 Manetu, Inc. All rights reserved
(ns temporal.testing.env
"Methods and utilities to assist with unit-testing Temporal workflows"
(:require [temporal.client.worker :as worker]
[temporal.internal.utils :as u])
(:import [io.temporal.testing TestWorkflowEnvironment]))
(defn create
"
Creates a mock environment and an associated client connection for emulating the combination of a worker and a Temporal
backend, suitable for unit testing.
Arguments:
- `options`: See [[temporal.client.worker/worker-options]]
```clojure
(let [{:keys [client] :as instance} (create {:task-queue ::my-queue :ctx {:some \"context\"}}]
;; create and invoke workflows
(stop instance))
```
"
[{:keys [task-queue] :as options}]
(let [env (TestWorkflowEnvironment/newInstance)
worker (.newWorker env (u/namify task-queue))]
(worker/init worker options)
(.start env)
{:env env :worker worker :client (.getWorkflowClient env)}))
(defn stop
"
Stops the test environment created by [[create]]. Does not wait for shutdown to complete. For coordinated shutdown,
see [[synchronized-stop]].
```clojure
(stop instance)
```
"
[{:keys [^TestWorkflowEnvironment env]}]
(.shutdown env))
(defn synchronized-stop
"
Stops the test environment created by [[create]]. Blocks until the environment has shut down. For async termination,
see [[stop]]
```clojure
(synchronized-stop instance)
```
"
[{:keys [^TestWorkflowEnvironment env]}]
(.close env))