Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
:cloverage {:runner :eftest
:runner-opts {:multithread? false
:fail-fast? true}
:fail-threshold 90
:fail-threshold 91
:ns-exclude-regex [#"temporal.client.worker"]})
12 changes: 12 additions & 0 deletions src/temporal/internal/search_attributes.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(ns temporal.internal.search-attributes
(:import [io.temporal.api.enums.v1 IndexedValueType]))

(def indexvalue-type->
{:unspecified IndexedValueType/INDEXED_VALUE_TYPE_UNSPECIFIED
:text IndexedValueType/INDEXED_VALUE_TYPE_TEXT
:keyword IndexedValueType/INDEXED_VALUE_TYPE_KEYWORD
:int IndexedValueType/INDEXED_VALUE_TYPE_INT
:double IndexedValueType/INDEXED_VALUE_TYPE_DOUBLE
:bool IndexedValueType/INDEXED_VALUE_TYPE_BOOL
:datetime IndexedValueType/INDEXED_VALUE_TYPE_DATETIME
:keyword-list IndexedValueType/INDEXED_VALUE_TYPE_KEYWORD_LIST})
16 changes: 12 additions & 4 deletions src/temporal/testing/env.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@

(ns temporal.testing.env
"Methods and utilities to assist with unit-testing Temporal workflows"
(:require [temporal.client.worker :as worker]
(:require [medley.core :as m]
[temporal.client.worker :as worker]
[temporal.client.options :as copts]
[temporal.internal.utils :as u])
[temporal.internal.utils :as u]
[temporal.internal.search-attributes :as search-attributes])
(:import [io.temporal.testing TestWorkflowEnvironment TestEnvironmentOptions TestEnvironmentOptions$Builder]))

(defn set-search-attributes [^TestEnvironmentOptions$Builder builder attributes]
(run! (fn [[name value]]
(.registerSearchAttribute builder name (search-attributes/indexvalue-type-> value)))
attributes))

(def ^:no-doc test-env-options
{:worker-factory-options #(.setWorkerFactoryOptions ^TestEnvironmentOptions$Builder %1 (worker/worker-factory-options-> %2))
:workflow-client-options #(.setWorkflowClientOptions ^TestEnvironmentOptions$Builder %1 (copts/workflow-client-options-> %2))
:workflow-service-stub-options #(.setWorkflowServiceStubsOptions ^TestEnvironmentOptions$Builder %1 (copts/stub-options-> %2))
:metrics-scope #(.setMetricsScope ^TestEnvironmentOptions$Builder %1 %2)})
:metrics-scope #(.setMetricsScope ^TestEnvironmentOptions$Builder %1 %2)
:search-attributes set-search-attributes})

(defn ^:no-doc test-env-options->
^TestEnvironmentOptions [params]
Expand All @@ -35,7 +43,7 @@ Arguments:
| :workflow-client-options | | [[copts/client-options]] | |
| :workflow-service-stub-options | | [[copts/stub-options]] | |
| :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) | |

| :search-attributes | Add a map of search attributes to be registered on the Temporal Server | map | |

"
([]
Expand Down
31 changes: 31 additions & 0 deletions test/temporal/test/search_attributes.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
;; Copyright © Manetu, Inc. All rights reserved

(ns temporal.test.search-attributes
(:require [clojure.test :refer :all]
[temporal.client.core :as c]
[temporal.testing.env :as e]
[temporal.workflow :refer [defworkflow]])
(:import [java.time Duration]))

;; do not use the shared fixture, since we want to control the env creation

(def task-queue ::default)

(defworkflow searchable-workflow
[args]
:ok)

(defn execute []
(let [env (e/create {:search-attributes {"foo" :keyword}})
client (e/get-client env)
_ (e/start env {:task-queue task-queue})
workflow (c/create-workflow client searchable-workflow {:task-queue task-queue
:search-attributes {"foo" "bar"}
:workflow-execution-timeout (Duration/ofSeconds 1)
:retry-options {:maximum-attempts 1}})]
(c/start workflow {})
@(c/get-result workflow)))

(deftest the-test
(testing "Verifies that we can utilize custom search attributes"
(is (= (execute) :ok))))