Skip to content

Commit 3574e56

Browse files
committed
chore: fix CI by removing examples module; remove *.db files from tests module
Signed-off-by: Ricardo Zanini <[email protected]>
1 parent cbbd717 commit 3574e56

File tree

6 files changed

+163
-37
lines changed

6 files changed

+163
-37
lines changed

impl/test/src/test/java/io/serverlessworkflow/impl/test/DBGenerator.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,26 @@
1616
package io.serverlessworkflow.impl.test;
1717

1818
import static io.serverlessworkflow.api.WorkflowReader.readWorkflowFromClasspath;
19+
import static org.awaitility.Awaitility.await;
1920

2021
import io.serverlessworkflow.impl.WorkflowApplication;
2122
import io.serverlessworkflow.impl.WorkflowDefinition;
2223
import io.serverlessworkflow.impl.WorkflowInstance;
24+
import io.serverlessworkflow.impl.WorkflowStatus;
2325
import io.serverlessworkflow.impl.persistence.PersistenceApplicationBuilder;
2426
import io.serverlessworkflow.impl.persistence.PersistenceInstanceHandlers;
2527
import io.serverlessworkflow.impl.persistence.bigmap.BytesMapPersistenceInstanceHandlers;
2628
import io.serverlessworkflow.impl.persistence.mvstore.MVStorePersistenceStore;
2729
import java.io.IOException;
2830
import java.nio.file.Files;
2931
import java.nio.file.Path;
32+
import java.time.Duration;
3033
import java.util.Map;
3134

32-
public class DBGenerator {
35+
public final class DBGenerator {
3336

34-
public static void main(String[] args) throws IOException {
35-
runInstance("db-samples/running_v1.db", false);
36-
runInstance("db-samples/suspended_v1.db", true);
37-
}
38-
39-
private static void runInstance(String dbName, boolean suspend) throws IOException {
37+
public static void generate(String dbName, boolean suspend)
38+
throws IOException, InterruptedException {
4039
Files.deleteIfExists(Path.of(dbName));
4140
try (PersistenceInstanceHandlers factories =
4241
BytesMapPersistenceInstanceHandlers.builder(new MVStorePersistenceStore(dbName))
@@ -51,8 +50,16 @@ private static void runInstance(String dbName, boolean suspend) throws IOExcepti
5150
readWorkflowFromClasspath("workflows-samples/set-listen-to-any.yaml"));
5251
WorkflowInstance instance = definition.instance(Map.of());
5352
instance.start();
53+
54+
await()
55+
.atMost(Duration.ofSeconds(5))
56+
.until(() -> instance.status() == WorkflowStatus.WAITING);
57+
5458
if (suspend) {
5559
instance.suspend();
60+
await()
61+
.atMost(Duration.ofSeconds(5))
62+
.until(() -> instance.status() == WorkflowStatus.SUSPENDED);
5663
}
5764
}
5865
}
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package io.serverlessworkflow.impl.test;
217

3-
public class DBGeneratorCli {
18+
public final class DBGeneratorCli {
19+
public static void main(String[] args) throws Exception {
20+
if (args.length < 2) {
21+
System.err.println("Usage: DBGeneratorCli <dbPath> <suspend:true|false>");
22+
System.exit(2);
23+
}
24+
DBGenerator.generate(args[0], Boolean.parseBoolean(args[1]));
25+
}
426
}
Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,54 @@
1+
/*
2+
* Copyright 2020-Present The Serverless Workflow Specification Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package io.serverlessworkflow.impl.test;
217

3-
public class ForkedDbGen {
18+
import java.io.*;
19+
import java.nio.file.*;
20+
import java.util.Optional;
21+
22+
final class ForkedDbGen {
23+
private static String detectJavaCmd() {
24+
Optional<String> cmd = ProcessHandle.current().info().command();
25+
if (cmd.isPresent() && Files.isRegularFile(Path.of(cmd.get()))) return cmd.get();
26+
String home = System.getProperty("java.home");
27+
String exe = System.getProperty("os.name").toLowerCase().contains("win") ? "java.exe" : "java";
28+
Path p = Path.of(home, "bin", exe);
29+
return Files.isRegularFile(p) ? p.toString() : "java";
30+
}
31+
32+
static void run(Path db, boolean suspend) throws IOException, InterruptedException {
33+
Files.createDirectories(db.getParent());
34+
String javaCmd = detectJavaCmd();
35+
String cp = System.getProperty("java.class.path");
36+
37+
ProcessBuilder pb =
38+
new ProcessBuilder(
39+
javaCmd,
40+
"-cp",
41+
cp,
42+
DBGeneratorCli.class.getCanonicalName(),
43+
db.toString(),
44+
String.valueOf(suspend));
45+
pb.redirectErrorStream(true);
46+
47+
Process p = pb.start();
48+
try (BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()))) {
49+
for (String line; (line = r.readLine()) != null; ) System.out.println("[dbgen] " + line);
50+
}
51+
int code = p.waitFor();
52+
if (code != 0) throw new IllegalStateException("DB gen failed (" + code + ") for " + db);
53+
}
454
}

impl/test/src/test/java/io/serverlessworkflow/impl/test/MvStorePersistenceTest.java

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,59 @@
2727
import io.serverlessworkflow.impl.persistence.bigmap.BytesMapPersistenceInstanceHandlers;
2828
import io.serverlessworkflow.impl.persistence.mvstore.MVStorePersistenceStore;
2929
import java.io.IOException;
30-
import java.nio.file.Files;
3130
import java.nio.file.Path;
3231
import java.util.Collection;
3332
import java.util.Map;
33+
import java.util.stream.Stream;
34+
import org.junit.jupiter.api.BeforeAll;
3435
import org.junit.jupiter.api.Test;
36+
import org.junit.jupiter.api.io.TempDir;
37+
import org.junit.jupiter.api.parallel.Execution;
38+
import org.junit.jupiter.api.parallel.ExecutionMode;
39+
import org.junit.jupiter.params.ParameterizedTest;
40+
import org.junit.jupiter.params.provider.Arguments;
41+
import org.junit.jupiter.params.provider.MethodSource;
3542

36-
public class MvStorePersistenceTest {
43+
@Execution(ExecutionMode.SAME_THREAD)
44+
class MvStorePersistenceTest {
45+
46+
@TempDir static Path tmp;
47+
48+
static Path runningV1, suspendedV1, runningV0, suspendedV0;
49+
50+
@BeforeAll
51+
static void prepareDbSamples() throws IOException, InterruptedException {
52+
runningV1 = tmp.resolve("running_v1.db");
53+
suspendedV1 = tmp.resolve("suspended_v1.db");
54+
runningV0 = tmp.resolve("running.db");
55+
suspendedV0 = tmp.resolve("suspended.db");
56+
57+
ForkedDbGen.run(runningV1, false);
58+
ForkedDbGen.run(suspendedV1, true);
59+
ForkedDbGen.run(runningV0, false);
60+
ForkedDbGen.run(suspendedV0, true);
61+
}
3762

3863
@Test
3964
void testSimpleRun() throws IOException {
40-
final String dbName = "db-samples/simple.db";
65+
final Path dbPath = tmp.resolve("simple.db");
4166
try (PersistenceInstanceHandlers handlers =
42-
BytesMapPersistenceInstanceHandlers.builder(new MVStorePersistenceStore(dbName))
67+
BytesMapPersistenceInstanceHandlers.builder(
68+
new MVStorePersistenceStore(dbPath.toString()))
4369
.build();
4470
WorkflowApplication application =
4571
PersistenceApplicationBuilder.builder(WorkflowApplication.builder(), handlers.writer())
46-
.build(); ) {
72+
.build()) {
73+
4774
WorkflowDefinition definition =
4875
application.workflowDefinition(
4976
readWorkflowFromClasspath("workflows-samples/simple-expression.yaml"));
77+
5078
assertThat(handlers.reader().readAll(definition).values()).isEmpty();
79+
5180
definition.instance(Map.of()).start().join();
81+
5282
assertThat(handlers.reader().readAll(definition).values()).isEmpty();
53-
} finally {
54-
Files.delete(Path.of(dbName));
5583
}
5684
}
5785

@@ -60,54 +88,57 @@ void testWaitingInstance() throws IOException {
6088
TaskCounterPerInstanceListener taskCounter = new TaskCounterPerInstanceListener();
6189
try (WorkflowApplication application =
6290
WorkflowApplication.builder().withListener(taskCounter).build()) {
91+
6392
WorkflowDefinition definition =
6493
application.workflowDefinition(
6594
readWorkflowFromClasspath("workflows-samples/set-listen-to-any.yaml"));
6695

6796
WorkflowInstance instance = definition.instance(Map.of());
6897
instance.start();
98+
6999
assertThat(taskCounter.taskCounter(instance.id()).completed()).isEqualTo(1);
70100
}
71101
}
72102

73-
@Test
74-
void testRestoreWaitingInstanceV0() throws IOException {
75-
runIt("db-samples/running.db", WorkflowStatus.WAITING);
103+
@ParameterizedTest(name = "{index} ⇒ {0} should restore as {1}")
104+
@MethodSource("dbSamples")
105+
void testRestoreInstances(Path dbFile, WorkflowStatus expectedStatus) throws IOException {
106+
runIt(dbFile, expectedStatus);
76107
}
77108

78-
@Test
79-
void testRestoreSuspendedInstanceV0() throws IOException {
80-
runIt("db-samples/suspended.db", WorkflowStatus.SUSPENDED);
109+
private static Stream<Arguments> dbSamples() {
110+
return Stream.of(
111+
Arguments.of(runningV0, WorkflowStatus.WAITING),
112+
Arguments.of(suspendedV0, WorkflowStatus.SUSPENDED),
113+
Arguments.of(runningV1, WorkflowStatus.WAITING),
114+
Arguments.of(suspendedV1, WorkflowStatus.SUSPENDED));
81115
}
82116

83-
@Test
84-
void testRestoreWaitingInstanceV1() throws IOException {
85-
runIt("db-samples/running_v1.db", WorkflowStatus.WAITING);
86-
}
87-
88-
@Test
89-
void testRestoreSuspendedInstanceV1() throws IOException {
90-
runIt("db-samples/suspended_v1.db", WorkflowStatus.SUSPENDED);
91-
}
92-
93-
private void runIt(String dbName, WorkflowStatus expectedStatus) throws IOException {
117+
private void runIt(Path dbFile, WorkflowStatus expectedStatus) throws IOException {
94118
TaskCounterPerInstanceListener taskCounter = new TaskCounterPerInstanceListener();
119+
95120
try (PersistenceInstanceHandlers handlers =
96-
BytesMapPersistenceInstanceHandlers.builder(new MVStorePersistenceStore(dbName))
121+
BytesMapPersistenceInstanceHandlers.builder(
122+
new MVStorePersistenceStore(dbFile.toString()))
97123
.build();
98124
WorkflowApplication application =
99125
PersistenceApplicationBuilder.builder(
100126
WorkflowApplication.builder()
101127
.withListener(taskCounter)
102128
.withListener(new TraceExecutionListener()),
103129
handlers.writer())
104-
.build(); ) {
130+
.build()) {
131+
105132
WorkflowDefinition definition =
106133
application.workflowDefinition(
107134
readWorkflowFromClasspath("workflows-samples/set-listen-to-any.yaml"));
135+
108136
Collection<WorkflowInstance> instances = handlers.reader().readAll(definition).values();
137+
109138
assertThat(instances).hasSize(1);
139+
110140
instances.forEach(WorkflowInstance::start);
141+
111142
assertThat(instances)
112143
.singleElement()
113144
.satisfies(

impl/test/src/test/resources/workflows-samples/set-listen-to-any.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ do:
1010
- callDoctor:
1111
listen:
1212
to:
13-
any: []
13+
any:
14+
- with:
15+
type: com.acme.any

pom.xml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
<module>annotations</module>
4444
<module>generators</module>
4545
<module>serialization</module>
46-
<module>examples</module>
4746
<module>experimental</module>
4847
<module>fluent</module>
4948
<module>mermaid</module>
@@ -584,8 +583,23 @@
584583
</pluginRepositories>
585584

586585
<profiles>
586+
<profile>
587+
<id>examples</id>
588+
<activation>
589+
<property>
590+
<name>performRelease</name>
591+
<value>!true</value>
592+
</property>
593+
</activation>
594+
<modules>
595+
<module>examples</module>
596+
</modules>
597+
</profile>
587598
<profile>
588599
<id>release</id>
600+
<properties>
601+
<performRelease>true</performRelease>
602+
</properties>
589603
<build>
590604
<plugins>
591605
<plugin>

0 commit comments

Comments
 (0)