Skip to content

Commit 88499a4

Browse files
author
Artur Ciocanu
committed
Move saga internals to runtime.saga package
Signed-off-by: Artur Ciocanu <[email protected]>
1 parent b1bc41a commit 88499a4

File tree

11 files changed

+46
-47
lines changed

11 files changed

+46
-47
lines changed

docs/dapr-sdk-workflows/io/dapr/workflows/runtime/class-use/WorkflowActivity.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<!-- Generated by javadoc (17) on Tue Aug 13 18:03:07 PDT 2024 -->
5-
<title>Uses of Interface io.dapr.workflows.WorkflowActivity (dapr-sdk-workflows 0.12.0 API)</title>
5+
<title>Uses of Interface io.dapr.workflows.runtime.WorkflowActivity (dapr-sdk-workflows 0.12.0 API)</title>
66
<meta name="viewport" content="width=device-width, initial-scale=1">
77
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
88
<meta name="dc.created" content="2024-08-13">
@@ -49,7 +49,7 @@
4949
<div class="flex-content">
5050
<main role="main">
5151
<div class="header">
52-
<h1 title="Uses of Interface io.dapr.workflows.WorkflowActivity" class="title">Uses of Interface<br>io.dapr.workflows.WorkflowActivity</h1>
52+
<h1 title="Uses of Interface io.dapr.workflows.runtime.WorkflowActivity" class="title">Uses of Interface<br>io.dapr.workflows.runtime.WorkflowActivity</h1>
5353
</div>
5454
<div class="caption"><span>Packages that use <a href="../WorkflowActivity.html" title="interface in io.dapr.workflows.runtime">WorkflowActivity</a></span></div>
5555
<div class="summary-table two-column-summary">

docs/io/dapr/workflows/runtime/class-use/WorkflowActivity.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html lang="en">
33
<head>
44
<!-- Generated by javadoc (17) on Tue Aug 13 18:02:32 PDT 2024 -->
5-
<title>Uses of Interface io.dapr.workflows.WorkflowActivity (dapr-sdk-parent 1.12.0 API)</title>
5+
<title>Uses of Interface io.dapr.workflows.runtime.WorkflowActivity (dapr-sdk-parent 1.12.0 API)</title>
66
<meta name="viewport" content="width=device-width, initial-scale=1">
77
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
88
<meta name="dc.created" content="2024-08-13">

sdk-tests/src/test/java/io/dapr/it/testcontainers/TestWorkflow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import java.time.Duration;
2121

22-
public class TestWorkflow extends Workflow {
22+
public class TestWorkflow implements Workflow {
2323

2424
@Override
2525
public WorkflowStub create() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/**
2020
* Wrapper for Durable Task Framework {@link TaskActivityContext}.
2121
*/
22-
public class DaprWorkflowActivityContext implements WorkflowActivityContext {
22+
class DaprWorkflowActivityContext implements WorkflowActivityContext {
2323
private final TaskActivityContext innerContext;
2424

2525
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import com.microsoft.durabletask.TaskOptions;
2020
import com.microsoft.durabletask.TaskOrchestrationContext;
2121
import io.dapr.workflows.WorkflowContext;
22-
import io.dapr.workflows.saga.DaprSagaContextImpl;
22+
import io.dapr.workflows.runtime.saga.DaprSagaContext;
2323
import io.dapr.workflows.saga.Saga;
2424
import io.dapr.workflows.saga.SagaContext;
2525
import org.slf4j.Logger;
@@ -249,6 +249,6 @@ public SagaContext getSagaContext() {
249249
throw new UnsupportedOperationException("Saga is not enabled");
250250
}
251251

252-
return new DaprSagaContextImpl(this.saga, this);
252+
return new DaprSagaContext(this.saga, this);
253253
}
254254
}

sdk-workflows/src/main/java/io/dapr/workflows/saga/DaprSagaContextImpl.java renamed to sdk-workflows/src/main/java/io/dapr/workflows/runtime/saga/DaprSagaContext.java

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

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

1616
import io.dapr.workflows.WorkflowContext;
17+
import io.dapr.workflows.saga.Saga;
18+
import io.dapr.workflows.saga.SagaContext;
1719

1820
/**
1921
* Dapr Saga Context implementation.
2022
*/
21-
public class DaprSagaContextImpl implements SagaContext {
23+
public class DaprSagaContext implements SagaContext {
2224

2325
private final Saga saga;
2426
private final WorkflowContext workflowContext;
@@ -30,7 +32,7 @@ public class DaprSagaContextImpl implements SagaContext {
3032
* @param workflowContext Workflow context.
3133
* @throws IllegalArgumentException if saga or workflowContext is null.
3234
*/
33-
public DaprSagaContextImpl(Saga saga, WorkflowContext workflowContext) {
35+
public DaprSagaContext(Saga saga, WorkflowContext workflowContext) {
3436
if (saga == null) {
3537
throw new IllegalArgumentException("Saga should not be null");
3638
}

sdk-workflows/src/main/java/io/dapr/workflows/saga/CompensatationInformation.java renamed to sdk-workflows/src/main/java/io/dapr/workflows/saga/CompensationInformation.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@
1818
/**
1919
* Information for a compensation activity.
2020
*/
21-
class CompensatationInformation {
22-
private final String compensatationActivityClassName;
23-
private final Object compensatationActivityInput;
21+
class CompensationInformation {
22+
private final String compensationActivityClassName;
23+
private final Object compensationActivityInput;
2424
private final TaskOptions taskOptions;
2525

2626
/**
2727
* Constructor for a compensation information.
2828
*
29-
* @param compensatationActivityClassName Class name of the activity to do
30-
* compensatation.
31-
* @param compensatationActivityInput Input of the activity to do
32-
* compensatation.
29+
* @param compensationActivityClassName Class name of the activity to do
30+
* compensation.
31+
* @param compensationActivityInput Input of the activity to do
32+
* compensation.
3333
* @param taskOptions task options to set retry strategy
3434
*/
35-
public CompensatationInformation(String compensatationActivityClassName,
36-
Object compensatationActivityInput, TaskOptions taskOptions) {
37-
this.compensatationActivityClassName = compensatationActivityClassName;
38-
this.compensatationActivityInput = compensatationActivityInput;
35+
public CompensationInformation(String compensationActivityClassName,
36+
Object compensationActivityInput, TaskOptions taskOptions) {
37+
this.compensationActivityClassName = compensationActivityClassName;
38+
this.compensationActivityInput = compensationActivityInput;
3939
this.taskOptions = taskOptions;
4040
}
4141

@@ -44,17 +44,17 @@ public CompensatationInformation(String compensatationActivityClassName,
4444
*
4545
* @return the class name of the activity.
4646
*/
47-
public String getCompensatationActivityClassName() {
48-
return compensatationActivityClassName;
47+
public String getCompensationActivityClassName() {
48+
return compensationActivityClassName;
4949
}
5050

5151
/**
5252
* Gets the input of the activity.
5353
*
5454
* @return the input of the activity.
5555
*/
56-
public Object getCompensatationActivityInput() {
57-
return compensatationActivityInput;
56+
public Object getCompensationActivityInput() {
57+
return compensationActivityInput;
5858
}
5959

6060
/**
@@ -65,4 +65,4 @@ public Object getCompensatationActivityInput() {
6565
public TaskOptions getTaskOptions() {
6666
return taskOptions;
6767
}
68-
}
68+
}

sdk-workflows/src/main/java/io/dapr/workflows/saga/Saga.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
public final class Saga {
2626
private final SagaOption option;
27-
private final List<CompensatationInformation> compensationActivities = new ArrayList<>();
27+
private final List<CompensationInformation> compensationActivities = new ArrayList<>();
2828

2929
/**
3030
* Build up a Saga with its options.
@@ -59,7 +59,7 @@ public void registerCompensation(String activityClassName, Object activityInput,
5959
if (activityClassName == null || activityClassName.isEmpty()) {
6060
throw new IllegalArgumentException("activityClassName is required and should not be null or empty.");
6161
}
62-
this.compensationActivities.add(new CompensatationInformation(activityClassName, activityInput, taskOptions));
62+
this.compensationActivities.add(new CompensationInformation(activityClassName, activityInput, taskOptions));
6363
}
6464

6565
/**
@@ -69,7 +69,7 @@ public void registerCompensation(String activityClassName, Object activityInput,
6969
*/
7070
public void compensate(WorkflowContext ctx) {
7171
// Check if parallel compensation is enabled
72-
// Specical case: when parallel compensation is enabled and there is only one
72+
// Special case: when parallel compensation is enabled and there is only one
7373
// compensation, we still
7474
// compensate sequentially.
7575
if (option.isParallelCompensation() && compensationActivities.size() > 1) {
@@ -81,7 +81,7 @@ public void compensate(WorkflowContext ctx) {
8181

8282
private void compensateInParallel(WorkflowContext ctx) {
8383
List<Task<Void>> tasks = new ArrayList<>(compensationActivities.size());
84-
for (CompensatationInformation compensationActivity : compensationActivities) {
84+
for (CompensationInformation compensationActivity : compensationActivities) {
8585
Task<Void> task = executeCompensateActivity(ctx, compensationActivity);
8686
tasks.add(task);
8787
}
@@ -96,7 +96,7 @@ private void compensateInParallel(WorkflowContext ctx) {
9696
private void compensateSequentially(WorkflowContext ctx) {
9797
SagaCompensationException sagaException = null;
9898
for (int i = compensationActivities.size() - 1; i >= 0; i--) {
99-
String activityClassName = compensationActivities.get(i).getCompensatationActivityClassName();
99+
String activityClassName = compensationActivities.get(i).getCompensationActivityClassName();
100100
try {
101101
executeCompensateActivity(ctx, compensationActivities.get(i)).await();
102102
} catch (OrchestratorBlockedException | ContinueAsNewInterruption e) {
@@ -105,7 +105,6 @@ private void compensateSequentially(WorkflowContext ctx) {
105105
if (sagaException == null) {
106106
sagaException = new SagaCompensationException(
107107
"Exception in saga compensatation: activity=" + activityClassName, e);
108-
;
109108
} else {
110109
sagaException.addSuppressed(e);
111110
}
@@ -121,10 +120,10 @@ private void compensateSequentially(WorkflowContext ctx) {
121120
}
122121
}
123122

124-
private Task<Void> executeCompensateActivity(WorkflowContext ctx, CompensatationInformation info)
123+
private Task<Void> executeCompensateActivity(WorkflowContext ctx, CompensationInformation info)
125124
throws SagaCompensationException {
126-
String activityClassName = info.getCompensatationActivityClassName();
127-
return ctx.callActivity(activityClassName, info.getCompensatationActivityInput(),
125+
String activityClassName = info.getCompensationActivityClassName();
126+
return ctx.callActivity(activityClassName, info.getCompensationActivityInput(),
128127
info.getTaskOptions());
129128
}
130129
}

sdk-workflows/src/main/java/io/dapr/workflows/saga/SagaOption.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ public Builder setContinueWithError(boolean continueWithError) {
9292
}
9393

9494
/**
95-
* Build Saga optiion.
96-
* @return Saga optiion
95+
* Build Saga option.
96+
* @return Saga option
9797
*/
9898
public SagaOption build() {
9999
return new SagaOption(this.parallelCompensation, this.maxParallelThread, this.continueWithError);

sdk-workflows/src/test/java/io/dapr/workflows/saga/DaprSagaContextImplTest.java renamed to sdk-workflows/src/test/java/io/dapr/workflows/saga/DaprSagaContextTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,32 @@
66
import static org.mockito.Mockito.times;
77
import static org.mockito.Mockito.verify;
88

9+
import io.dapr.workflows.runtime.saga.DaprSagaContext;
910
import org.junit.Test;
1011

1112
import io.dapr.workflows.WorkflowContext;
1213

13-
public class DaprSagaContextImplTest {
14+
public class DaprSagaContextTest {
1415

1516
@Test
1617
public void testDaprSagaContextImpl_IllegalArgumentException() {
1718
Saga saga = mock(Saga.class);
1819
WorkflowContext workflowContext = mock(WorkflowContext.class);
1920

2021
assertThrows(IllegalArgumentException.class, () -> {
21-
new DaprSagaContextImpl(saga, null);
22+
new DaprSagaContext(saga, null);
2223
});
2324

2425
assertThrows(IllegalArgumentException.class, () -> {
25-
new DaprSagaContextImpl(null, workflowContext);
26+
new DaprSagaContext(null, workflowContext);
2627
});
2728
}
2829

2930
@Test
3031
public void test_registerCompensation() {
3132
Saga saga = mock(Saga.class);
3233
WorkflowContext workflowContext = mock(WorkflowContext.class);
33-
DaprSagaContextImpl ctx = new DaprSagaContextImpl(saga, workflowContext);
34+
DaprSagaContext ctx = new DaprSagaContext(saga, workflowContext);
3435

3536
String activityClassName = "name1";
3637
Object activityInput = new Object();
@@ -44,7 +45,7 @@ public void test_registerCompensation() {
4445
public void test_compensate() {
4546
Saga saga = mock(Saga.class);
4647
WorkflowContext workflowContext = mock(WorkflowContext.class);
47-
DaprSagaContextImpl ctx = new DaprSagaContextImpl(saga, workflowContext);
48+
DaprSagaContext ctx = new DaprSagaContext(saga, workflowContext);
4849

4950
doNothing().when(saga).compensate(workflowContext);
5051

0 commit comments

Comments
 (0)