|
| 1 | +;; Copyright © Manetu, Inc. All rights reserved |
| 2 | + |
| 3 | +(ns temporal.test.vthreads |
| 4 | + (:require [clojure.test :refer :all] |
| 5 | + [taoensso.timbre :as log] |
| 6 | + [promesa.core :as p] |
| 7 | + [promesa.exec :refer [vthreads-supported?]] |
| 8 | + [temporal.client.core :as c] |
| 9 | + [temporal.testing.env :as e] |
| 10 | + [temporal.workflow :refer [defworkflow]]) |
| 11 | + (:import [java.time Duration])) |
| 12 | + |
| 13 | +(def task-queue ::default) |
| 14 | + |
| 15 | +(defworkflow vthread-workflow |
| 16 | + [args] |
| 17 | + (-> (Thread/currentThread) |
| 18 | + (.isVirtual))) |
| 19 | + |
| 20 | +(defn execute [opts] |
| 21 | + (let [env (e/create opts) |
| 22 | + client (e/get-client env) |
| 23 | + _ (e/start env {:task-queue task-queue}) |
| 24 | + workflow (c/create-workflow client vthread-workflow {:task-queue task-queue :workflow-execution-timeout (Duration/ofSeconds 1) :retry-options {:maximum-attempts 1}})] |
| 25 | + (c/start workflow {}) |
| 26 | + @(-> (c/get-result workflow) |
| 27 | + (p/finally (fn [_ _] |
| 28 | + (e/stop env)))))) |
| 29 | + |
| 30 | +(deftest the-test |
| 31 | + (testing "Verifies that we do not use vthreads by default" |
| 32 | + (is (false? (execute {})))) |
| 33 | + (testing "Verifies that we do not use vthreads if we specifically disable them" |
| 34 | + (is (false? (execute {:worker-factory-options {:using-virtual-workflow-threads false}})))) |
| 35 | + (testing "Verifies that we can enable vthread support" |
| 36 | + (if vthreads-supported? |
| 37 | + (is (true? (execute {:worker-factory-options {:using-virtual-workflow-threads true}}))) |
| 38 | + (log/info "vthreads require JDK >= 21, skipping test")))) |
0 commit comments