-
Notifications
You must be signed in to change notification settings - Fork 216
Add backoff start for CAN #2913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,50 @@ | ||
| package io.temporal.internal.sync; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.times; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import io.temporal.api.command.v1.ContinueAsNewWorkflowExecutionCommandAttributes; | ||
| import io.temporal.api.common.v1.SearchAttributes; | ||
| import io.temporal.api.common.v1.WorkflowType; | ||
| import io.temporal.common.interceptors.Header; | ||
| import io.temporal.common.interceptors.WorkflowOutboundCallsInterceptor.ContinueAsNewInput; | ||
| import io.temporal.internal.common.SearchAttributesUtil; | ||
| import io.temporal.internal.replay.ReplayWorkflowContext; | ||
| import io.temporal.workflow.ContinueAsNewOptions; | ||
| import java.time.Duration; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.Executors; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.mockito.ArgumentCaptor; | ||
|
|
||
| public class SyncWorkflowContextTest { | ||
| SyncWorkflowContext context; | ||
| ReplayWorkflowContext mockReplayWorkflowContext = mock(ReplayWorkflowContext.class); | ||
| ExecutorService threadPool; | ||
| DeterministicRunner runner; | ||
|
|
||
| @Before | ||
| public void setUp() { | ||
| this.threadPool = Executors.newCachedThreadPool(); | ||
| this.context = DummySyncWorkflowContext.newDummySyncWorkflowContext(); | ||
| this.context.setReplayContext(mockReplayWorkflowContext); | ||
| when(mockReplayWorkflowContext.getWorkflowType()) | ||
| .thenReturn(WorkflowType.newBuilder().setName("dummy-workflow").build()); | ||
| } | ||
|
Comment on lines
27
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| @After | ||
| public void tearDown() { | ||
| if (runner != null) { | ||
| runner.close(); | ||
| } | ||
| threadPool.shutdown(); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -32,6 +57,27 @@ public void testUpsertSearchAttributes() { | |
| verify(mockReplayWorkflowContext, times(1)).upsertSearchAttributes(serializedAttr); | ||
| } | ||
|
|
||
| @Test | ||
| public void testContinueAsNewBackoffStartInterval() { | ||
|
Comment on lines
+60
to
+61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: this test should be moved down as to not split up the two upsert SA tests. |
||
| Duration backoffStartInterval = Duration.ofSeconds(7); | ||
| ContinueAsNewOptions options = | ||
| ContinueAsNewOptions.newBuilder().setBackoffStartInterval(backoffStartInterval).build(); | ||
| runner = | ||
| DeterministicRunner.newRunner( | ||
| threadPool::submit, | ||
| context, | ||
| () -> | ||
| context.continueAsNew( | ||
| new ContinueAsNewInput(null, options, new Object[0], Header.empty()))); | ||
|
|
||
| runner.runUntilAllBlocked(DeterministicRunner.DEFAULT_DEADLOCK_DETECTION_TIMEOUT_MS); | ||
|
|
||
| ArgumentCaptor<ContinueAsNewWorkflowExecutionCommandAttributes> attributes = | ||
| ArgumentCaptor.forClass(ContinueAsNewWorkflowExecutionCommandAttributes.class); | ||
| verify(mockReplayWorkflowContext).continueAsNewOnCompletion(attributes.capture()); | ||
| assertEquals(7, attributes.getValue().getBackoffStartInterval().getSeconds()); | ||
| } | ||
|
|
||
| @Test(expected = IllegalArgumentException.class) | ||
| public void testUpsertSearchAttributesException() { | ||
| Map<String, Object> attr = new HashMap<>(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I consider it a mistake that the original constructor is public; it should be deprecated with a comment directing users to use the builder, and the new constructor should be made private.