Skip to content

Commit

Permalink
implementing getIsReplaying() method for Authoring API (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
julioalex-rezende authored and macromania committed Jun 14, 2023
1 parent 85903b2 commit 13b0577
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ public void complete(Object output) {
public Task<Void> waitForExternalEvent(String eventName, Duration timeout) {
return this.innerContext.waitForExternalEvent(eventName, timeout);
}

@Override
public boolean getIsReplaying() {
return this.innerContext.getIsReplaying();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,21 @@ public interface WorkflowContext {
* @return Asynchronous task to {@code await()}.
*/
Task waitForExternalEvent(String eventName, Duration timeout);

/**
* Gets a value indicating whether the workflow is currently replaying a previous execution.
*
* <p>Workflow functions are "replayed" after being unloaded from memory to reconstruct local variable state.
* During a replay, previously executed tasks will be completed automatically with previously seen values
* that are stored in the workflow history. Once the workflow reaches the point where it's no longer
* replaying existing history, this method will return {@code false}.
*
* <p>You can use this method if you have logic that needs to run only when <em>not</em> replaying. For example,
* certain types of application logging may become too noisy when duplicated as part of replay. The
* application code could check to see whether the function is being replayed and then issue the log statements
* when this value is {@code false}.
*
* @return {@code true} if the workflow is replaying, otherwise {@code false}
*/
boolean getIsReplaying();
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,16 @@ public void completeTest() {
verify(mockInnerContext, times(1)).complete(null);
}

@Test
public void getIsReplaying() {
context.getIsReplaying();
verify(mockInnerContext, times(1)).getIsReplaying();
}

@Test
public void getLoggerReplayingTest() {
Logger mockLogger = mock(Logger.class);
when(mockInnerContext.getIsReplaying()).thenReturn(true);
when(context.getIsReplaying()).thenReturn(true);
DaprWorkflowContextImpl testContext = new DaprWorkflowContextImpl(mockInnerContext, mockLogger);

String expectedArg = "test print";
Expand All @@ -80,7 +86,7 @@ public void getLoggerReplayingTest() {
@Test
public void getLoggerFirstTimeTest() {
Logger mockLogger = mock(Logger.class);
when(mockInnerContext.getIsReplaying()).thenReturn(false);
when(context.getIsReplaying()).thenReturn(false);
DaprWorkflowContextImpl testContext = new DaprWorkflowContextImpl(mockInnerContext, mockLogger);

String expectedArg = "test print";
Expand Down

0 comments on commit 13b0577

Please sign in to comment.