File tree Expand file tree Collapse file tree
test/java/io/temporal/workflow Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -962,7 +962,8 @@ static void assertNotReadOnly(String action) {
962962 }
963963
964964 public static boolean isSubjectToReplay () {
965- return getRootWorkflowContext ().isSubjectToReplay ();
965+ Optional <WorkflowThread > thread = DeterministicRunnerImpl .currentThreadInternalIfPresent ();
966+ return thread .isPresent () && getRootWorkflowContext ().isSubjectToReplay ();
966967 }
967968
968969 static void assertNotInUpdateHandler (String message ) {
Original file line number Diff line number Diff line change @@ -56,9 +56,8 @@ public static boolean isReplaying() {
5656 * functions run once against the current state and are never re-executed, so they are not subject
5757 * to replay even while {@link #isReplaying()} reports true.
5858 *
59- * <p>Must be called from Workflow code.
60- *
61- * @return true if the calling context is re-executed on replay
59+ * @return true if the calling context is re-executed on replay. This method always returns false
60+ * if called from a non workflow thread.
6261 */
6362 @ Experimental
6463 public static boolean isSubjectToReplay () {
Original file line number Diff line number Diff line change 11package io .temporal .workflow ;
22
33import static org .junit .Assert .assertEquals ;
4+ import static org .junit .Assert .assertFalse ;
45
56import io .temporal .client .WorkflowClient ;
67import io .temporal .client .WorkflowStub ;
@@ -79,6 +80,11 @@ public void isSubjectToReplay() {
7980 assertEquals (expected , calls );
8081 }
8182
83+ @ Test
84+ public void isSubjectToReplayOffWorkflowThread () {
85+ assertFalse (WorkflowUnsafe .isSubjectToReplay ());
86+ }
87+
8288 private static void record (String name ) {
8389 calls .put (name , WorkflowUnsafe .isSubjectToReplay ());
8490 }
You can’t perform that action at this time.
0 commit comments