-
Notifications
You must be signed in to change notification settings - Fork 110
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
add unit test for MigrationInterceptor #956
Merged
shijiesheng
merged 3 commits into
cadence-workflow:master
from
shijiesheng:migration-test
Nov 8, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,9 +30,8 @@ | |
import com.uber.cadence.migration.MigrationActivitiesImpl; | ||
import com.uber.cadence.migration.MigrationIWorkflowService; | ||
import com.uber.cadence.migration.MigrationInterceptorFactory; | ||
import com.uber.cadence.serviceclient.ClientOptions; | ||
import com.uber.cadence.serviceclient.IWorkflowService; | ||
import com.uber.cadence.serviceclient.WorkflowServiceTChannel; | ||
import com.uber.cadence.testUtils.CadenceTestRule; | ||
import com.uber.cadence.worker.Worker; | ||
import com.uber.cadence.worker.WorkerFactory; | ||
import com.uber.cadence.worker.WorkerFactoryOptions; | ||
|
@@ -41,37 +40,33 @@ | |
import java.util.UUID; | ||
import java.util.concurrent.CancellationException; | ||
import org.apache.thrift.TException; | ||
import org.junit.After; | ||
import org.junit.Assume; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.*; | ||
|
||
public class WorkflowMigrationTest { | ||
private WorkflowClient migrationWorkflowClient, workflowClientCurr, workflowClientNew; | ||
private boolean useDockerService = Boolean.parseBoolean(System.getenv("USE_DOCKER_SERVICE")); | ||
private static final String TASKLIST = "TASKLIST"; | ||
private TracingWorkflowInterceptorFactory tracer; | ||
WorkerFactory factoryCurr, factoryNew; | ||
Worker workerCurr, workerNew; | ||
|
||
@Rule public CadenceTestRule testRuleCur = CadenceTestRule.builder().withDomain(DOMAIN).build(); | ||
|
||
@Rule public CadenceTestRule testRuleNew = CadenceTestRule.builder().withDomain(DOMAIN2).build(); | ||
|
||
@Before | ||
public void setUp() { | ||
IWorkflowService service = | ||
new WorkflowServiceTChannel( | ||
ClientOptions.newBuilder() | ||
.setFeatureFlags( | ||
new FeatureFlags().setWorkflowExecutionAlreadyCompletedErrorEnabled(true)) | ||
.build()); | ||
IWorkflowService serviceCur = testRuleCur.getWorkflowClient().getService(); | ||
IWorkflowService serviceNew = testRuleNew.getWorkflowClient().getService(); | ||
workflowClientCurr = | ||
WorkflowClient.newInstance( | ||
service, WorkflowClientOptions.newBuilder().setDomain(DOMAIN).build()); | ||
serviceCur, WorkflowClientOptions.newBuilder().setDomain(DOMAIN).build()); | ||
workflowClientNew = | ||
WorkflowClient.newInstance( | ||
service, WorkflowClientOptions.newBuilder().setDomain(DOMAIN2).build()); | ||
serviceNew, WorkflowClientOptions.newBuilder().setDomain(DOMAIN2).build()); | ||
MigrationIWorkflowService migrationService = | ||
new MigrationIWorkflowService( | ||
service, DOMAIN, | ||
service, DOMAIN2); | ||
serviceCur, DOMAIN, | ||
serviceNew, DOMAIN2); | ||
migrationWorkflowClient = | ||
WorkflowClient.newInstance( | ||
migrationService, WorkflowClientOptions.newBuilder().setDomain(DOMAIN).build()); | ||
|
@@ -154,8 +149,7 @@ public void execute(int iter) { | |
} | ||
|
||
@Test | ||
public void whenUseDockerService_cronWorkflowMigration() { | ||
Assume.assumeTrue(useDockerService); | ||
public void cronWorkflowMigration() { | ||
String workflowID = UUID.randomUUID().toString(); | ||
try { | ||
workflowClientCurr | ||
|
@@ -164,16 +158,15 @@ public void whenUseDockerService_cronWorkflowMigration() { | |
.execute("for test"); | ||
} catch (CancellationException e) { | ||
try { | ||
describeWorkflowExecution(workflowClientNew, workflowID); | ||
getWorkflowHistory(workflowClientNew, workflowID); | ||
} catch (Exception eDesc) { | ||
fail("fail to describe workflow execution in new domain: " + eDesc); | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void whenUseDockerService_continueAsNewWorkflowMigration() { | ||
Assume.assumeTrue(useDockerService); | ||
public void continueAsNewWorkflowMigration() { | ||
String workflowID = UUID.randomUUID().toString(); | ||
try { | ||
workflowClientCurr | ||
|
@@ -183,18 +176,18 @@ public void whenUseDockerService_continueAsNewWorkflowMigration() { | |
.execute(0); | ||
} catch (CancellationException e) { | ||
try { | ||
describeWorkflowExecution(workflowClientNew, workflowID); | ||
getWorkflowHistory(workflowClientNew, workflowID); | ||
} catch (Exception eDesc) { | ||
fail("fail to describe workflow execution in new domain: " + eDesc); | ||
} | ||
} | ||
} | ||
|
||
private DescribeWorkflowExecutionResponse describeWorkflowExecution( | ||
private GetWorkflowExecutionHistoryResponse getWorkflowHistory( | ||
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: Why change the type? Does this cover a different code path? 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. describe method is not implemented in test service |
||
WorkflowClient wc, String workflowID) throws TException { | ||
return wc.getService() | ||
.DescribeWorkflowExecution( | ||
new DescribeWorkflowExecutionRequest() | ||
.GetWorkflowExecutionHistory( | ||
new GetWorkflowExecutionHistoryRequest() | ||
.setExecution(new WorkflowExecution().setWorkflowId(workflowID)) | ||
.setDomain(wc.getOptions().getDomain())); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nit: See if you can remove useDockerService entirely, the test rule should handle most cases.
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 do want to have an integration test from end to end.
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.
Sorry, I don't think I explained this well, but the CadenceTestRule has the conditional logic within it already: https://github.com/uber/cadence-java-client/blob/704380bfaed0aa873fa19fe01d7bb0645c690c53/src/test/java/com/uber/cadence/testUtils/CadenceTestRule.java#L196
If
USE_DOCKER_SERVICE
is set to true then CadenceTestRule will connect to the docker instance instead of creating a test service. The goal of the test rule is to avoid every test needing to have conditional logic.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.
Oh, I don't know that. I'll remove it completely