Skip to content

Commit 705ba69

Browse files
authored
add unit test for MigrationInterceptor (#956)
What changed? add unit test along with integration test for migration interceptor Why? unit test coverage How did you test it? Unit test
1 parent cc571fc commit 705ba69

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

src/test/java/com/uber/cadence/migration/MigrationIWorkflowServiceTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static org.mockito.Mockito.*;
2222

2323
import com.uber.cadence.*;
24+
import com.uber.cadence.serviceclient.ClientOptions;
2425
import com.uber.cadence.serviceclient.IWorkflowService;
2526
import java.util.ArrayList;
2627
import org.apache.thrift.TException;
@@ -1218,4 +1219,12 @@ public void testSignalWorkflowExecution_SignalInOldService() throws TException {
12181219
verifyNoMoreInteractions(serviceNew);
12191220
verifyNoMoreInteractions(serviceOld);
12201221
}
1222+
1223+
@Test
1224+
public void testGetOptions() {
1225+
when(serviceOld.getOptions())
1226+
.thenReturn(ClientOptions.newBuilder().setServiceName("serviceName").build());
1227+
ClientOptions options = migrationService.getOptions();
1228+
assertEquals("serviceName", options.getServiceName());
1229+
}
12211230
}

src/test/java/com/uber/cadence/workflow/WorkflowMigrationTest.java

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030
import com.uber.cadence.migration.MigrationActivitiesImpl;
3131
import com.uber.cadence.migration.MigrationIWorkflowService;
3232
import com.uber.cadence.migration.MigrationInterceptorFactory;
33-
import com.uber.cadence.serviceclient.ClientOptions;
3433
import com.uber.cadence.serviceclient.IWorkflowService;
35-
import com.uber.cadence.serviceclient.WorkflowServiceTChannel;
34+
import com.uber.cadence.testUtils.CadenceTestRule;
3635
import com.uber.cadence.worker.Worker;
3736
import com.uber.cadence.worker.WorkerFactory;
3837
import com.uber.cadence.worker.WorkerFactoryOptions;
@@ -41,37 +40,33 @@
4140
import java.util.UUID;
4241
import java.util.concurrent.CancellationException;
4342
import org.apache.thrift.TException;
44-
import org.junit.After;
45-
import org.junit.Assume;
46-
import org.junit.Before;
47-
import org.junit.Test;
43+
import org.junit.*;
4844

4945
public class WorkflowMigrationTest {
5046
private WorkflowClient migrationWorkflowClient, workflowClientCurr, workflowClientNew;
51-
private boolean useDockerService = Boolean.parseBoolean(System.getenv("USE_DOCKER_SERVICE"));
5247
private static final String TASKLIST = "TASKLIST";
5348
private TracingWorkflowInterceptorFactory tracer;
5449
WorkerFactory factoryCurr, factoryNew;
5550
Worker workerCurr, workerNew;
5651

52+
@Rule public CadenceTestRule testRuleCur = CadenceTestRule.builder().withDomain(DOMAIN).build();
53+
54+
@Rule public CadenceTestRule testRuleNew = CadenceTestRule.builder().withDomain(DOMAIN2).build();
55+
5756
@Before
5857
public void setUp() {
59-
IWorkflowService service =
60-
new WorkflowServiceTChannel(
61-
ClientOptions.newBuilder()
62-
.setFeatureFlags(
63-
new FeatureFlags().setWorkflowExecutionAlreadyCompletedErrorEnabled(true))
64-
.build());
58+
IWorkflowService serviceCur = testRuleCur.getWorkflowClient().getService();
59+
IWorkflowService serviceNew = testRuleNew.getWorkflowClient().getService();
6560
workflowClientCurr =
6661
WorkflowClient.newInstance(
67-
service, WorkflowClientOptions.newBuilder().setDomain(DOMAIN).build());
62+
serviceCur, WorkflowClientOptions.newBuilder().setDomain(DOMAIN).build());
6863
workflowClientNew =
6964
WorkflowClient.newInstance(
70-
service, WorkflowClientOptions.newBuilder().setDomain(DOMAIN2).build());
65+
serviceNew, WorkflowClientOptions.newBuilder().setDomain(DOMAIN2).build());
7166
MigrationIWorkflowService migrationService =
7267
new MigrationIWorkflowService(
73-
service, DOMAIN,
74-
service, DOMAIN2);
68+
serviceCur, DOMAIN,
69+
serviceNew, DOMAIN2);
7570
migrationWorkflowClient =
7671
WorkflowClient.newInstance(
7772
migrationService, WorkflowClientOptions.newBuilder().setDomain(DOMAIN).build());
@@ -154,8 +149,7 @@ public void execute(int iter) {
154149
}
155150

156151
@Test
157-
public void whenUseDockerService_cronWorkflowMigration() {
158-
Assume.assumeTrue(useDockerService);
152+
public void cronWorkflowMigration() {
159153
String workflowID = UUID.randomUUID().toString();
160154
try {
161155
workflowClientCurr
@@ -164,16 +158,15 @@ public void whenUseDockerService_cronWorkflowMigration() {
164158
.execute("for test");
165159
} catch (CancellationException e) {
166160
try {
167-
describeWorkflowExecution(workflowClientNew, workflowID);
161+
getWorkflowHistory(workflowClientNew, workflowID);
168162
} catch (Exception eDesc) {
169163
fail("fail to describe workflow execution in new domain: " + eDesc);
170164
}
171165
}
172166
}
173167

174168
@Test
175-
public void whenUseDockerService_continueAsNewWorkflowMigration() {
176-
Assume.assumeTrue(useDockerService);
169+
public void continueAsNewWorkflowMigration() {
177170
String workflowID = UUID.randomUUID().toString();
178171
try {
179172
workflowClientCurr
@@ -183,18 +176,18 @@ public void whenUseDockerService_continueAsNewWorkflowMigration() {
183176
.execute(0);
184177
} catch (CancellationException e) {
185178
try {
186-
describeWorkflowExecution(workflowClientNew, workflowID);
179+
getWorkflowHistory(workflowClientNew, workflowID);
187180
} catch (Exception eDesc) {
188181
fail("fail to describe workflow execution in new domain: " + eDesc);
189182
}
190183
}
191184
}
192185

193-
private DescribeWorkflowExecutionResponse describeWorkflowExecution(
186+
private GetWorkflowExecutionHistoryResponse getWorkflowHistory(
194187
WorkflowClient wc, String workflowID) throws TException {
195188
return wc.getService()
196-
.DescribeWorkflowExecution(
197-
new DescribeWorkflowExecutionRequest()
189+
.GetWorkflowExecutionHistory(
190+
new GetWorkflowExecutionHistoryRequest()
198191
.setExecution(new WorkflowExecution().setWorkflowId(workflowID))
199192
.setDomain(wc.getOptions().getDomain()));
200193
}

0 commit comments

Comments
 (0)