Skip to content

Commit 8b69e6a

Browse files
Improve CI runs (dapr#1527)
* chore: Wait for dapr script When running mechanical markdown examples wait for dapr to be running Signed-off-by: Javier Aliaga <[email protected]> * chore: Fix build ci Signed-off-by: Javier Aliaga <[email protected]> * chore: Fix build ci Signed-off-by: Javier Aliaga <[email protected]> --------- Signed-off-by: Javier Aliaga <[email protected]> Co-authored-by: salaboy <[email protected]> Signed-off-by: Javier Aliaga <[email protected]>
1 parent 7246eed commit 8b69e6a

File tree

10 files changed

+96
-52
lines changed

10 files changed

+96
-52
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,14 @@ jobs:
112112
wget -q ${{ env.TOXIPROXY_URL }} -O /home/runner/.local/bin/toxiproxy-server
113113
chmod +x /home/runner/.local/bin/toxiproxy-server
114114
/home/runner/.local/bin/toxiproxy-server --version
115-
- name: Clean up files
116-
run: ./mvnw clean -B
117-
- name: Build sdk
118-
run: ./mvnw compile -B -q
115+
- name: Clean up and install sdk
116+
run: ./mvnw clean install -B -q -DskipTests
119117
- name: Unit tests
120118
run: ./mvnw test # making it temporarily verbose.
121119
env:
122120
DOCKER_HOST: ${{steps.setup_docker.outputs.sock}}
123121
- name: Codecov
124122
uses: codecov/[email protected]
125-
- name: Install jars
126-
run: ./mvnw install -q -B -DskipTests
127123
- name: Integration tests using spring boot version ${{ matrix.spring-boot-version }}
128124
id: integration_tests
129125
run: PRODUCT_SPRING_BOOT_VERSION=${{ matrix.spring-boot-version }} ./mvnw -B -Pintegration-tests verify

examples/src/main/java/io/dapr/examples/workflows/README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ background: true
147147
-->
148148
Execute the following script in order to run DemoChainWorker:
149149
```sh
150-
dapr run --app-id demoworkflowworker --resources-path ./components/workflows --dapr-grpc-port 50001 -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.workflows.chain.DemoChainWorker 50001
150+
dapr run --app-id chainingworker --resources-path ./components/workflows --dapr-grpc-port 50001 -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.workflows.chain.DemoChainWorker 50001
151151
```
152152

153153
Once running, the logs will start displaying the different steps: First, you can see workflow is starting:
@@ -169,7 +169,8 @@ timeout_seconds: 20
169169
-->
170170
Then, execute the following script in order to run DemoChainClient:
171171
```sh
172-
sleep 10 && java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.workflows.chain.DemoChainClient 50001
172+
java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.workflows.chain.DemoChainClient 50001
173+
dapr stop --app-id chainingworker
173174
```
174175
<!-- END_STEP -->
175176

@@ -266,7 +267,7 @@ background: true
266267

267268
Execute the following script in order to run DemoFanInOutWorker:
268269
```sh
269-
dapr run --app-id demoworkflowworker --resources-path ./components/workflows --dapr-grpc-port 50002 -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.workflows.faninout.DemoFanInOutWorker 50002
270+
dapr run --app-id faninoutworker --resources-path ./components/workflows --dapr-grpc-port 50002 -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.workflows.faninout.DemoFanInOutWorker 50002
270271
```
271272

272273
<!-- END_STEP -->
@@ -282,7 +283,8 @@ timeout_seconds: 20
282283
Execute the following script in order to run DemoFanInOutClient:
283284

284285
```sh
285-
sleep 10 && java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.workflows.faninout.DemoFanInOutClient 50002
286+
java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.workflows.faninout.DemoFanInOutClient 50002
287+
dapr stop --app-id faninoutworker
286288
```
287289
<!-- END_STEP -->
288290

@@ -660,7 +662,8 @@ timeout_seconds: 30
660662
-->
661663
Once running, execute the following script to run the BookTripClient:
662664
```sh
663-
sleep 15 && java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.workflows.compensation.BookTripClient 50003
665+
java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.workflows.compensation.BookTripClient 50003
666+
dapr stop --app-id book-trip-worker
664667
```
665668
<!-- END_STEP -->
666669

@@ -702,7 +705,7 @@ timeout_seconds: 30
702705
-->
703706

704707
```sh
705-
dapr run --app-id demoworkflowworker --resources-path ./components/workflows --dapr-grpc-port 50004 -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.workflows.suspendresume.DemoSuspendResumeWorker 50004
708+
dapr run --app-id suspendresumeworker --resources-path ./components/workflows --dapr-grpc-port 50004 -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.workflows.suspendresume.DemoSuspendResumeWorker 50004
706709
```
707710

708711
<!-- END_STEP -->
@@ -720,7 +723,8 @@ expected_stdout_lines:
720723
timeout_seconds: 30
721724
-->
722725
```sh
723-
sleep 15 && java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.workflows.suspendresume.DemoSuspendResumeClient 50004
726+
java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.workflows.suspendresume.DemoSuspendResumeClient 50004
727+
dapr stop --app-id suspendresumeworker
724728
```
725729

726730
<!-- END_STEP -->

examples/src/main/java/io/dapr/examples/workflows/chain/DemoChainClient.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
package io.dapr.examples.workflows.chain;
1515

1616
import io.dapr.examples.workflows.utils.PropertyUtils;
17+
import io.dapr.examples.workflows.utils.RetryUtils;
1718
import io.dapr.workflows.client.DaprWorkflowClient;
1819
import io.dapr.workflows.client.WorkflowInstanceStatus;
1920

21+
import java.time.Duration;
2022
import java.util.concurrent.TimeoutException;
2123

2224
public class DemoChainClient {
@@ -28,15 +30,15 @@ public class DemoChainClient {
2830
*/
2931
public static void main(String[] args) {
3032
try (DaprWorkflowClient client = new DaprWorkflowClient(PropertyUtils.getProperties(args))) {
31-
String instanceId = client.scheduleNewWorkflow(DemoChainWorkflow.class);
33+
String instanceId = RetryUtils.callWithRetry(() -> client.scheduleNewWorkflow(DemoChainWorkflow.class),
34+
Duration.ofSeconds(60));
35+
3236
System.out.printf("Started a new chaining model workflow with instance ID: %s%n", instanceId);
3337
WorkflowInstanceStatus workflowInstanceStatus =
3438
client.waitForInstanceCompletion(instanceId, null, true);
3539

3640
String result = workflowInstanceStatus.readOutputAs(String.class);
3741
System.out.printf("workflow instance with ID: %s completed with result: %s%n", instanceId, result);
38-
39-
4042
} catch (TimeoutException | InterruptedException e) {
4143
throw new RuntimeException(e);
4244
}

examples/src/main/java/io/dapr/examples/workflows/compensation/BookTripClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package io.dapr.examples.workflows.compensation;
1515

1616
import io.dapr.examples.workflows.utils.PropertyUtils;
17+
import io.dapr.examples.workflows.utils.RetryUtils;
1718
import io.dapr.workflows.client.DaprWorkflowClient;
1819
import io.dapr.workflows.client.WorkflowInstanceStatus;
1920

@@ -23,7 +24,7 @@
2324
public class BookTripClient {
2425
public static void main(String[] args) {
2526
try (DaprWorkflowClient client = new DaprWorkflowClient(PropertyUtils.getProperties(args))) {
26-
String instanceId = client.scheduleNewWorkflow(BookTripWorkflow.class);
27+
String instanceId = RetryUtils.callWithRetry(() -> client.scheduleNewWorkflow(BookTripWorkflow.class), Duration.ofSeconds(60));
2728
System.out.printf("Started a new trip booking workflow with instance ID: %s%n", instanceId);
2829

2930
WorkflowInstanceStatus status = client.waitForInstanceCompletion(instanceId, Duration.ofMinutes(30), true);

examples/src/main/java/io/dapr/examples/workflows/faninout/DemoFanInOutClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package io.dapr.examples.workflows.faninout;
1515

1616
import io.dapr.examples.workflows.utils.PropertyUtils;
17+
import io.dapr.examples.workflows.utils.RetryUtils;
1718
import io.dapr.workflows.client.DaprWorkflowClient;
1819
import io.dapr.workflows.client.WorkflowInstanceStatus;
1920

@@ -40,9 +41,10 @@ public static void main(String[] args) throws InterruptedException {
4041
"Always remember that you are absolutely unique. Just like everyone else.");
4142

4243
// Schedule an orchestration which will reliably count the number of words in all the given sentences.
43-
String instanceId = client.scheduleNewWorkflow(
44+
String instanceId = RetryUtils.callWithRetry(() -> client.scheduleNewWorkflow(
4445
DemoFanInOutWorkflow.class,
45-
listOfStrings);
46+
listOfStrings), Duration.ofSeconds(60));
47+
4648
System.out.printf("Started a new fan out/fan in model workflow with instance ID: %s%n", instanceId);
4749

4850
// Block until the orchestration completes. Then print the final status, which includes the output.

examples/src/main/java/io/dapr/examples/workflows/suspendresume/DemoSuspendResumeClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515

1616
import io.dapr.examples.workflows.externalevent.DemoExternalEventWorkflow;
1717
import io.dapr.examples.workflows.utils.PropertyUtils;
18+
import io.dapr.examples.workflows.utils.RetryUtils;
1819
import io.dapr.workflows.client.DaprWorkflowClient;
1920
import io.dapr.workflows.client.WorkflowInstanceStatus;
2021

22+
import java.time.Duration;
2123
import java.util.concurrent.TimeoutException;
2224

2325
public class DemoSuspendResumeClient {
@@ -29,7 +31,7 @@ public class DemoSuspendResumeClient {
2931
*/
3032
public static void main(String[] args) {
3133
try (DaprWorkflowClient client = new DaprWorkflowClient(PropertyUtils.getProperties(args))) {
32-
String instanceId = client.scheduleNewWorkflow(DemoExternalEventWorkflow.class);
34+
String instanceId = RetryUtils.callWithRetry(() -> client.scheduleNewWorkflow(DemoExternalEventWorkflow.class), Duration.ofSeconds(60));
3335
System.out.printf("Started a new external-event workflow with instance ID: %s%n", instanceId);
3436

3537

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2025 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.examples.workflows.utils;
15+
16+
import java.time.Duration;
17+
import java.util.concurrent.Callable;
18+
19+
public class RetryUtils {
20+
private static final long RETRY_WAIT_MILLISECONDS = 1000;
21+
22+
public static String callWithRetry(Callable<String> function, Duration retryTimeout) throws InterruptedException {
23+
var retryTimeoutMilliseconds = retryTimeout.toMillis();
24+
long started = System.currentTimeMillis();
25+
while (true) {
26+
Throwable exception;
27+
try {
28+
return function.call();
29+
} catch (Exception | AssertionError e) {
30+
exception = e;
31+
}
32+
33+
long elapsed = System.currentTimeMillis() - started;
34+
if (elapsed >= retryTimeoutMilliseconds) {
35+
if (exception instanceof RuntimeException) {
36+
throw (RuntimeException) exception;
37+
}
38+
39+
throw new RuntimeException(exception);
40+
}
41+
42+
long remaining = retryTimeoutMilliseconds - elapsed;
43+
Thread.sleep(Math.min(remaining, RETRY_WAIT_MILLISECONDS));
44+
}
45+
}
46+
47+
}

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,18 @@
658658
<modules>
659659
<module>sdk-tests</module>
660660
</modules>
661+
<build>
662+
<plugins>
663+
<plugin>
664+
<groupId>org.apache.maven.plugins</groupId>
665+
<artifactId>maven-surefire-plugin</artifactId>
666+
<configuration>
667+
<skipTests>true</skipTests>
668+
</configuration>
669+
</plugin>
670+
</plugins>
671+
</build>
672+
661673
</profile>
662674
</profiles>
663675

sdk-tests/pom.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -315,18 +315,6 @@
315315
<groupId>org.apache.maven.plugins</groupId>
316316
<artifactId>maven-failsafe-plugin</artifactId>
317317
<version>3.2.2</version>
318-
<executions>
319-
<execution>
320-
<goals>
321-
<goal>integration-test</goal>
322-
<goal>verify</goal>
323-
</goals>
324-
<configuration>
325-
<!--suppress UnresolvedMavenProperty -->
326-
<skip>${skipITs}</skip>
327-
</configuration>
328-
</execution>
329-
</executions>
330318
</plugin>
331319
</plugins>
332320
</build>

0 commit comments

Comments
 (0)