Skip to content

Commit df80a81

Browse files
committed
[testenv] Add support for custom search attributes
Signed-off-by: Greg Haskins <[email protected]>
1 parent 98910c9 commit df80a81

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@
3636
:cloverage {:runner :eftest
3737
:runner-opts {:multithread? false
3838
:fail-fast? true}
39-
:fail-threshold 90
39+
:fail-threshold 91
4040
:ns-exclude-regex [#"temporal.client.worker"]})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(ns temporal.internal.search-attributes
2+
(:import [io.temporal.api.enums.v1 IndexedValueType]))
3+
4+
(def indexvalue-type->
5+
{:unspecified IndexedValueType/INDEXED_VALUE_TYPE_UNSPECIFIED
6+
:text IndexedValueType/INDEXED_VALUE_TYPE_TEXT
7+
:keyword IndexedValueType/INDEXED_VALUE_TYPE_KEYWORD
8+
:int IndexedValueType/INDEXED_VALUE_TYPE_INT
9+
:double IndexedValueType/INDEXED_VALUE_TYPE_DOUBLE
10+
:bool IndexedValueType/INDEXED_VALUE_TYPE_BOOL
11+
:datetime IndexedValueType/INDEXED_VALUE_TYPE_DATETIME
12+
:keyword-list IndexedValueType/INDEXED_VALUE_TYPE_KEYWORD_LIST})

src/temporal/testing/env.clj

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@
22

33
(ns temporal.testing.env
44
"Methods and utilities to assist with unit-testing Temporal workflows"
5-
(:require [temporal.client.worker :as worker]
5+
(:require [medley.core :as m]
6+
[temporal.client.worker :as worker]
67
[temporal.client.options :as copts]
7-
[temporal.internal.utils :as u])
8+
[temporal.internal.utils :as u]
9+
[temporal.internal.search-attributes :as search-attributes])
810
(:import [io.temporal.testing TestWorkflowEnvironment TestEnvironmentOptions TestEnvironmentOptions$Builder]))
911

12+
(defn set-search-attributes [^TestEnvironmentOptions$Builder builder attributes]
13+
(run! (fn [[name value]]
14+
(.registerSearchAttribute builder name (search-attributes/indexvalue-type-> value)))
15+
attributes))
16+
1017
(def ^:no-doc test-env-options
1118
{:worker-factory-options #(.setWorkerFactoryOptions ^TestEnvironmentOptions$Builder %1 (worker/worker-factory-options-> %2))
1219
:workflow-client-options #(.setWorkflowClientOptions ^TestEnvironmentOptions$Builder %1 (copts/workflow-client-options-> %2))
1320
:workflow-service-stub-options #(.setWorkflowServiceStubsOptions ^TestEnvironmentOptions$Builder %1 (copts/stub-options-> %2))
14-
:metrics-scope #(.setMetricsScope ^TestEnvironmentOptions$Builder %1 %2)})
21+
:metrics-scope #(.setMetricsScope ^TestEnvironmentOptions$Builder %1 %2)
22+
:search-attributes set-search-attributes})
1523

1624
(defn ^:no-doc test-env-options->
1725
^TestEnvironmentOptions [params]
@@ -35,7 +43,7 @@ Arguments:
3543
| :workflow-client-options | | [[copts/client-options]] | |
3644
| :workflow-service-stub-options | | [[copts/stub-options]] | |
3745
| :metrics-scope | The scope to be used for metrics reporting | [Scope](https://github.com/uber-java/tally/blob/master/core/src/main/java/com/uber/m3/tally/Scope.java) | |
38-
46+
| :search-attributes | Add a map of search attributes to be registered on the Temporal Server | map | |
3947
4048
"
4149
([]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
;; Copyright © Manetu, Inc. All rights reserved
2+
3+
(ns temporal.test.search-attributes
4+
(:require [clojure.test :refer :all]
5+
[temporal.client.core :as c]
6+
[temporal.testing.env :as e]
7+
[temporal.workflow :refer [defworkflow]])
8+
(:import [java.time Duration]))
9+
10+
;; do not use the shared fixture, since we want to control the env creation
11+
12+
(def task-queue ::default)
13+
14+
(defworkflow searchable-workflow
15+
[args]
16+
:ok)
17+
18+
(defn execute []
19+
(let [env (e/create {:search-attributes {"foo" :keyword}})
20+
client (e/get-client env)
21+
_ (e/start env {:task-queue task-queue})
22+
workflow (c/create-workflow client searchable-workflow {:task-queue task-queue
23+
:search-attributes {"foo" "bar"}
24+
:workflow-execution-timeout (Duration/ofSeconds 1)
25+
:retry-options {:maximum-attempts 1}})]
26+
(c/start workflow {})
27+
@(c/get-result workflow)))
28+
29+
(deftest the-test
30+
(testing "Verifies that we can utilize custom search attributes"
31+
(is (= (execute) :ok))))

0 commit comments

Comments
 (0)