Skip to content

Commit c6308d5

Browse files
author
Artur Ciocanu
committed
Move workflow context implementation to runtime
Signed-off-by: Artur Ciocanu <[email protected]>
1 parent 06331fc commit c6308d5

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

sdk-workflows/src/main/java/io/dapr/workflows/DaprWorkflowContextImpl.java renamed to sdk-workflows/src/main/java/io/dapr/workflows/runtime/DaprWorkflowContext.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
limitations under the License.
1212
*/
1313

14-
package io.dapr.workflows;
14+
package io.dapr.workflows.runtime;
1515

1616
import com.microsoft.durabletask.CompositeTaskFailedException;
1717
import com.microsoft.durabletask.Task;
1818
import com.microsoft.durabletask.TaskCanceledException;
1919
import com.microsoft.durabletask.TaskOptions;
2020
import com.microsoft.durabletask.TaskOrchestrationContext;
21+
import io.dapr.workflows.WorkflowContext;
2122
import io.dapr.workflows.saga.DaprSagaContextImpl;
2223
import io.dapr.workflows.saga.Saga;
2324
import io.dapr.workflows.saga.SagaContext;
@@ -32,7 +33,7 @@
3233
import java.util.List;
3334
import java.util.UUID;
3435

35-
public class DaprWorkflowContextImpl implements WorkflowContext {
36+
public class DaprWorkflowContext implements WorkflowContext {
3637
private final TaskOrchestrationContext innerContext;
3738
private final Logger logger;
3839
private final Saga saga;
@@ -43,7 +44,7 @@ public class DaprWorkflowContextImpl implements WorkflowContext {
4344
* @param context TaskOrchestrationContext
4445
* @throws IllegalArgumentException if context is null
4546
*/
46-
public DaprWorkflowContextImpl(TaskOrchestrationContext context) throws IllegalArgumentException {
47+
public DaprWorkflowContext(TaskOrchestrationContext context) throws IllegalArgumentException {
4748
this(context, LoggerFactory.getLogger(WorkflowContext.class));
4849
}
4950

@@ -54,11 +55,11 @@ public DaprWorkflowContextImpl(TaskOrchestrationContext context) throws IllegalA
5455
* @param logger Logger
5556
* @throws IllegalArgumentException if context or logger is null
5657
*/
57-
public DaprWorkflowContextImpl(TaskOrchestrationContext context, Logger logger) throws IllegalArgumentException {
58+
public DaprWorkflowContext(TaskOrchestrationContext context, Logger logger) throws IllegalArgumentException {
5859
this(context, logger, null);
5960
}
6061

61-
public DaprWorkflowContextImpl(TaskOrchestrationContext context, Saga saga) throws IllegalArgumentException {
62+
public DaprWorkflowContext(TaskOrchestrationContext context, Saga saga) throws IllegalArgumentException {
6263
this(context, LoggerFactory.getLogger(WorkflowContext.class), saga);
6364
}
6465

@@ -70,7 +71,7 @@ public DaprWorkflowContextImpl(TaskOrchestrationContext context, Saga saga) thro
7071
* @param saga saga object, if null, saga is disabled
7172
* @throws IllegalArgumentException if context or logger is null
7273
*/
73-
public DaprWorkflowContextImpl(TaskOrchestrationContext context, Logger logger, Saga saga)
74+
public DaprWorkflowContext(TaskOrchestrationContext context, Logger logger, Saga saga)
7475
throws IllegalArgumentException {
7576
if (context == null) {
7677
throw new IllegalArgumentException("Context cannot be null");

sdk-workflows/src/main/java/io/dapr/workflows/runtime/WorkflowWrapper.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import com.microsoft.durabletask.TaskOrchestration;
1717
import com.microsoft.durabletask.TaskOrchestrationFactory;
18-
import io.dapr.workflows.DaprWorkflowContextImpl;
1918
import io.dapr.workflows.Workflow;
2019
import io.dapr.workflows.saga.Saga;
2120

@@ -59,9 +58,9 @@ public TaskOrchestration create() {
5958

6059
if (workflow.getSagaOption() != null) {
6160
Saga saga = new Saga(workflow.getSagaOption());
62-
workflow.run(new DaprWorkflowContextImpl(ctx, saga));
61+
workflow.run(new DaprWorkflowContext(ctx, saga));
6362
} else {
64-
workflow.run(new DaprWorkflowContextImpl(ctx));
63+
workflow.run(new DaprWorkflowContext(ctx));
6564
}
6665
};
6766

sdk-workflows/src/test/java/io/dapr/workflows/DaprWorkflowContextImplTest.java renamed to sdk-workflows/src/test/java/io/dapr/workflows/DaprWorkflowContextTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.microsoft.durabletask.TaskOptions;
2121
import com.microsoft.durabletask.TaskOrchestrationContext;
2222

23+
import io.dapr.workflows.runtime.DaprWorkflowContext;
2324
import io.dapr.workflows.saga.Saga;
2425
import io.dapr.workflows.saga.SagaContext;
2526

@@ -43,15 +44,15 @@
4344
import static org.mockito.Mockito.when;
4445
import static org.junit.jupiter.api.Assertions.assertThrows;
4546

46-
public class DaprWorkflowContextImplTest {
47-
private DaprWorkflowContextImpl context;
47+
public class DaprWorkflowContextTest {
48+
private DaprWorkflowContext context;
4849
private TaskOrchestrationContext mockInnerContext;
4950
private WorkflowContext testWorkflowContext;
5051

5152
@BeforeEach
5253
public void setUp() {
5354
mockInnerContext = mock(TaskOrchestrationContext.class);
54-
context = new DaprWorkflowContextImpl(mockInnerContext);
55+
context = new DaprWorkflowContext(mockInnerContext);
5556
testWorkflowContext = new WorkflowContext() {
5657
@Override
5758
public Logger getLogger() {
@@ -190,13 +191,13 @@ public void callActivityTest() {
190191
@Test
191192
public void DaprWorkflowContextWithEmptyInnerContext() {
192193
assertThrows(IllegalArgumentException.class, () -> {
193-
context = new DaprWorkflowContextImpl(mockInnerContext, (Logger)null);
194+
context = new DaprWorkflowContext(mockInnerContext, (Logger)null);
194195
}); }
195196

196197
@Test
197198
public void DaprWorkflowContextWithEmptyLogger() {
198199
assertThrows(IllegalArgumentException.class, () -> {
199-
context = new DaprWorkflowContextImpl(null, (Logger)null);
200+
context = new DaprWorkflowContext(null, (Logger)null);
200201
});
201202
}
202203

@@ -216,7 +217,7 @@ public void getIsReplayingTest() {
216217
public void getLoggerReplayingTest() {
217218
Logger mockLogger = mock(Logger.class);
218219
when(context.isReplaying()).thenReturn(true);
219-
DaprWorkflowContextImpl testContext = new DaprWorkflowContextImpl(mockInnerContext, mockLogger);
220+
DaprWorkflowContext testContext = new DaprWorkflowContext(mockInnerContext, mockLogger);
220221

221222
String expectedArg = "test print";
222223
testContext.getLogger().info(expectedArg);
@@ -228,7 +229,7 @@ public void getLoggerReplayingTest() {
228229
public void getLoggerFirstTimeTest() {
229230
Logger mockLogger = mock(Logger.class);
230231
when(context.isReplaying()).thenReturn(false);
231-
DaprWorkflowContextImpl testContext = new DaprWorkflowContextImpl(mockInnerContext, mockLogger);
232+
DaprWorkflowContext testContext = new DaprWorkflowContext(mockInnerContext, mockLogger);
232233

233234
String expectedArg = "test print";
234235
testContext.getLogger().info(expectedArg);
@@ -322,15 +323,15 @@ public void newUuidTestNoImplementationExceptionTest() {
322323
@Test
323324
public void getSagaContextTest_sagaEnabled() {
324325
Saga saga = mock(Saga.class);
325-
WorkflowContext context = new DaprWorkflowContextImpl(mockInnerContext, saga);
326+
WorkflowContext context = new DaprWorkflowContext(mockInnerContext, saga);
326327

327328
SagaContext sagaContext = context.getSagaContext();
328329
assertNotNull("SagaContext should not be null", sagaContext);
329330
}
330331

331332
@Test
332333
public void getSagaContextTest_sagaDisabled() {
333-
WorkflowContext context = new DaprWorkflowContextImpl(mockInnerContext);
334+
WorkflowContext context = new DaprWorkflowContext(mockInnerContext);
334335
assertThrows(UnsupportedOperationException.class, () -> {
335336
context.getSagaContext();
336337
});

0 commit comments

Comments
 (0)