Skip to content

Commit e6c7ee6

Browse files
authored
Added signalWorkflow and tests for both SignalWorkflowExecution and SignalWithStart (#873)
1 parent f230849 commit e6c7ee6

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

src/main/java/com/uber/cadence/migration/MigrationIWorkflowService.java

+20
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ public StartWorkflowExecutionResponse StartWorkflowExecution(
5656
return serviceOld.StartWorkflowExecution(startRequest);
5757
}
5858

59+
/**
60+
* SignalWithStartWorkflowExecution is used to ensure sending signal to a workflow. If the
61+
* workflow is running, this results in WorkflowExecutionSignaled event being recorded in the
62+
* history and a decision task being created for the execution. If the workflow is not running or
63+
* not found, this results in WorkflowExecutionStarted and WorkflowExecutionSignaled events being
64+
* recorded in history, and a decision task being created for the execution
65+
*/
5966
@Override
6067
public StartWorkflowExecutionResponse SignalWithStartWorkflowExecution(
6168
SignalWithStartWorkflowExecutionRequest signalWithStartRequest) throws TException {
@@ -64,6 +71,19 @@ public StartWorkflowExecutionResponse SignalWithStartWorkflowExecution(
6471
return serviceOld.SignalWithStartWorkflowExecution(signalWithStartRequest);
6572
}
6673

74+
/**
75+
* SignalWorkflowExecution is used to send a signal event to running workflow execution. This
76+
* results in WorkflowExecutionSignaled event recorded in the history and a decision task being
77+
* created for the execution.
78+
*/
79+
@Override
80+
public void SignalWorkflowExecution(SignalWorkflowExecutionRequest signalRequest)
81+
throws TException {
82+
if (shouldStartInNew(signalRequest.getWorkflowExecution().getWorkflowId()))
83+
serviceNew.SignalWorkflowExecution(signalRequest);
84+
else serviceOld.SignalWorkflowExecution(signalRequest);
85+
}
86+
6787
@Override
6888
public GetWorkflowExecutionHistoryResponse GetWorkflowExecutionHistory(
6989
GetWorkflowExecutionHistoryRequest getRequest) throws TException {

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

+89
Original file line numberDiff line numberDiff line change
@@ -1129,4 +1129,93 @@ public void testListClosedWorkflows_ResponseWithToken() throws TException {
11291129
response = migrationService.ListClosedWorkflowExecutions(requestTwoItems);
11301130
assertEquals(expectedResponseWithToken, response);
11311131
}
1132+
1133+
@Test
1134+
public void testSignalWithStartWorkflowExecution_NewService() throws TException {
1135+
SignalWithStartWorkflowExecutionRequest request =
1136+
new SignalWithStartWorkflowExecutionRequest()
1137+
.setWorkflowId("newSignalWorkflow")
1138+
.setSignalName("TestSignal")
1139+
.setDomain("domainNew");
1140+
1141+
when(serviceNew.SignalWithStartWorkflowExecution(request))
1142+
.thenReturn(new StartWorkflowExecutionResponse().setRunId("newRunId"));
1143+
1144+
StartWorkflowExecutionResponse response =
1145+
migrationService.SignalWithStartWorkflowExecution(request);
1146+
1147+
assertEquals("newRunId", response.getRunId());
1148+
verify(serviceNew, times(1)).SignalWithStartWorkflowExecution(request);
1149+
verify(serviceOld, never()).SignalWithStartWorkflowExecution(request);
1150+
}
1151+
1152+
@Test
1153+
public void testSignalWithStartWorkflowExecution_OldService() throws TException {
1154+
SignalWithStartWorkflowExecutionRequest signal =
1155+
new SignalWithStartWorkflowExecutionRequest()
1156+
.setWorkflowId("testSignal")
1157+
.setDomain("oldDomain")
1158+
.setSignalName("sampleSignal");
1159+
1160+
when(serviceNew.DescribeWorkflowExecution(any())).thenReturn(null);
1161+
1162+
DescribeWorkflowExecutionResponse describeWorkflowExecutionResponse =
1163+
new DescribeWorkflowExecutionResponse();
1164+
when(serviceOld.DescribeWorkflowExecution(any())).thenReturn(describeWorkflowExecutionResponse);
1165+
1166+
when(serviceOld.SignalWithStartWorkflowExecution(signal))
1167+
.thenReturn(new StartWorkflowExecutionResponse().setRunId("oldRunID"));
1168+
StartWorkflowExecutionResponse responseOld =
1169+
migrationService.SignalWithStartWorkflowExecution(signal);
1170+
1171+
verify(serviceNew, times(1)).DescribeWorkflowExecution(any());
1172+
verify(serviceOld, times(1)).DescribeWorkflowExecution(any());
1173+
verify(serviceOld, times(1)).SignalWithStartWorkflowExecution(any());
1174+
1175+
verifyNoMoreInteractions(serviceNew);
1176+
verifyNoMoreInteractions(serviceOld);
1177+
1178+
assertEquals(responseOld.getRunId(), "oldRunID");
1179+
}
1180+
1181+
@Test
1182+
public void testSignalWorkflowExecution_SignalNewService() throws TException {
1183+
SignalWorkflowExecutionRequest request =
1184+
new SignalWorkflowExecutionRequest()
1185+
.setWorkflowExecution(new WorkflowExecution().setWorkflowId("newSignal"))
1186+
.setSignalName("signalNew")
1187+
.setDomain("domainNew");
1188+
1189+
doNothing().when(serviceNew).SignalWorkflowExecution(request);
1190+
1191+
migrationService.SignalWorkflowExecution(request);
1192+
1193+
verify(serviceNew, times(1)).SignalWorkflowExecution(request);
1194+
verify(serviceOld, never()).SignalWorkflowExecution(any());
1195+
}
1196+
1197+
@Test
1198+
public void testSignalWorkflowExecution_SignalInOldService() throws TException {
1199+
SignalWorkflowExecutionRequest request =
1200+
new SignalWorkflowExecutionRequest()
1201+
.setWorkflowExecution(new WorkflowExecution().setWorkflowId("oldSignal"))
1202+
.setSignalName("signalOld")
1203+
.setDomain("domainOld");
1204+
1205+
when(serviceNew.DescribeWorkflowExecution(any())).thenReturn(null);
1206+
1207+
DescribeWorkflowExecutionResponse describeWorkflowExecutionResponse =
1208+
new DescribeWorkflowExecutionResponse();
1209+
when(serviceOld.DescribeWorkflowExecution(any())).thenReturn(describeWorkflowExecutionResponse);
1210+
1211+
doNothing().when(serviceOld).SignalWorkflowExecution(request);
1212+
migrationService.SignalWorkflowExecution(request);
1213+
1214+
verify(serviceNew, times(1)).DescribeWorkflowExecution(any());
1215+
verify(serviceOld, times(1)).DescribeWorkflowExecution(any());
1216+
verify(serviceOld, times(1)).SignalWorkflowExecution(any());
1217+
1218+
verifyNoMoreInteractions(serviceNew);
1219+
verifyNoMoreInteractions(serviceOld);
1220+
}
11321221
}

0 commit comments

Comments
 (0)