Skip to content

Commit 1707a29

Browse files
committed
updating tests to cover multiple apps
Signed-off-by: salaboy <[email protected]>
1 parent 4b89187 commit 1707a29

File tree

6 files changed

+118
-9
lines changed

6 files changed

+118
-9
lines changed

spring-boot-examples/workflows/remote-activities/orchestrator/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@
5353
<plugin>
5454
<groupId>org.springframework.boot</groupId>
5555
<artifactId>spring-boot-maven-plugin</artifactId>
56+
<executions>
57+
<execution>
58+
<goals>
59+
<goal>repackage</goal>
60+
</goals>
61+
</execution>
62+
</executions>
5663
</plugin>
5764
<plugin>
5865
<groupId>org.apache.maven.plugins</groupId>

spring-boot-examples/workflows/remote-activities/orchestrator/src/test/java/io/dapr/springboot/examples/orchestrator/DaprTestContainersConfig.java

Lines changed: 88 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@
1818
import io.dapr.testcontainers.DaprContainer;
1919
import org.junit.runner.Description;
2020
import org.junit.runners.model.Statement;
21+
import org.springframework.beans.factory.annotation.Qualifier;
22+
import org.springframework.boot.test.context.SpringBootTest;
2123
import org.springframework.boot.test.context.TestConfiguration;
2224
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
2325
import org.springframework.context.annotation.Bean;
2426
import org.springframework.core.env.Environment;
2527
import org.testcontainers.DockerClientFactory;
28+
import org.testcontainers.containers.GenericContainer;
2629
import org.testcontainers.containers.Network;
30+
import org.testcontainers.containers.wait.strategy.Wait;
31+
import org.testcontainers.utility.MountableFile;
2732

2833
import java.util.HashMap;
2934
import java.util.List;
@@ -68,6 +73,86 @@ public Statement apply(Statement base, Description description) {
6873
}
6974
}
7075

76+
private Map<String, String> getRedisProps(){
77+
Map<String, String> redisProps = new HashMap<>();
78+
redisProps.put("redisHost", "redis:6379");
79+
redisProps.put("redisPassword", "");
80+
redisProps.put("actorStateStore", String.valueOf(true));
81+
return redisProps;
82+
}
83+
84+
@Bean("workerOneDapr")
85+
public DaprContainer workerOneDapr(Network daprNetwork, RedisContainer redisContainer, Environment env,
86+
@Qualifier("daprContainer") DaprContainer orchestratorDaprContainer) {
87+
boolean reuse = env.getProperty("reuse", Boolean.class, false);
88+
89+
return new DaprContainer(DAPR_RUNTIME_IMAGE_TAG)
90+
.withAppName("worker-one")
91+
.withNetworkAliases("worker-one-dapr")
92+
.withNetwork(daprNetwork)
93+
.withReusablePlacement(reuse)
94+
.withReusableScheduler(reuse)
95+
.withComponent(new Component("kvstore", "state.redis", "v1", getRedisProps()))
96+
// .withDaprLogLevel(DaprLogLevel.DEBUG)
97+
// .withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
98+
.withAppPort(8081)
99+
.withAppHealthCheckPath("/actuator/health")
100+
.withAppChannelAddress("host.testcontainers.internal")
101+
.dependsOn(orchestratorDaprContainer)
102+
.dependsOn(redisContainer);
103+
}
104+
@Bean
105+
public GenericContainer<?> workerOneContainer(Network daprNetwork, @Qualifier("workerOneDapr") DaprContainer workerOneDapr){
106+
return new GenericContainer<>("openjdk:17-jdk-slim")
107+
.withCopyFileToContainer(MountableFile.forHostPath("../worker-one/target"), "/app")
108+
.withWorkingDirectory("/app")
109+
.withCommand("java",
110+
"-Ddapr.grpc.endpoint=worker-one-dapr:50001",
111+
"-Ddapr.http.endpoint=worker-one-dapr:3500",
112+
"-jar",
113+
"worker-one-1.17.0-SNAPSHOT.jar")
114+
.withNetwork(daprNetwork)
115+
.dependsOn(workerOneDapr)
116+
.waitingFor(Wait.forLogMessage(".*Started WorkerOneApplication.*", 1))
117+
.withLogConsumer(outputFrame -> System.out.println("WorkerOneApplication: " + outputFrame.getUtf8String()));
118+
}
119+
120+
@Bean("workerTwoDapr")
121+
public DaprContainer workerTwoDapr(Network daprNetwork, RedisContainer redisContainer, Environment env,
122+
@Qualifier("daprContainer") DaprContainer orchestratorDaprContainer) {
123+
boolean reuse = env.getProperty("reuse", Boolean.class, false);
124+
125+
return new DaprContainer(DAPR_RUNTIME_IMAGE_TAG)
126+
.withAppName("worker-two")
127+
.withNetworkAliases("worker-two-dapr")
128+
.withNetwork(daprNetwork)
129+
.withReusablePlacement(reuse)
130+
.withReusableScheduler(reuse)
131+
.withComponent(new Component("kvstore", "state.redis", "v1", getRedisProps()))
132+
// .withDaprLogLevel(DaprLogLevel.DEBUG)
133+
// .withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
134+
.withAppPort(8082)
135+
.withAppHealthCheckPath("/actuator/health")
136+
.withAppChannelAddress("host.testcontainers.internal")
137+
.dependsOn(orchestratorDaprContainer)
138+
.dependsOn(redisContainer);
139+
}
140+
@Bean
141+
public GenericContainer<?> workerTwoContainer(Network daprNetwork, @Qualifier("workerTwoDapr") DaprContainer workerTwoDapr){
142+
return new GenericContainer<>("openjdk:17-jdk-slim")
143+
.withCopyFileToContainer(MountableFile.forHostPath("../worker-two/target"), "/app")
144+
.withWorkingDirectory("/app")
145+
.withCommand("java",
146+
"-Ddapr.grpc.endpoint=worker-two-dapr:50001",
147+
"-Ddapr.http.endpoint=worker-two-dapr:3500",
148+
"-jar",
149+
"worker-two-1.17.0-SNAPSHOT.jar")
150+
.withNetwork(daprNetwork)
151+
.dependsOn(workerTwoDapr)
152+
.waitingFor(Wait.forLogMessage(".*Started WorkerTwoApplication.*", 1))
153+
.withLogConsumer(outputFrame -> System.out.println("WorkerTwoApplication: " + outputFrame.getUtf8String()));
154+
}
155+
71156

72157
@Bean
73158
public RedisContainer redisContainer(Network daprNetwork, Environment env){
@@ -82,17 +167,13 @@ public RedisContainer redisContainer(Network daprNetwork, Environment env){
82167
@ServiceConnection
83168
public DaprContainer daprContainer(Network daprNetwork, RedisContainer redisContainer, Environment env) {
84169
boolean reuse = env.getProperty("reuse", Boolean.class, false);
85-
Map<String, String> redisProps = new HashMap<>();
86-
redisProps.put("redisHost", "redis:6379");
87-
redisProps.put("redisPassword", "");
88-
redisProps.put("actorStateStore", String.valueOf(true));
89170

90171
return new DaprContainer(DAPR_RUNTIME_IMAGE_TAG)
91172
.withAppName("orchestrator")
92173
.withNetwork(daprNetwork)
93-
.withReusablePlacement(reuse)
94-
.withReusableScheduler(reuse)
95-
.withComponent(new Component("kvstore", "state.redis", "v1", redisProps))
174+
// .withReusablePlacement(reuse)
175+
// .withReusableScheduler(reuse)
176+
.withComponent(new Component("kvstore", "state.redis", "v1", getRedisProps()))
96177
// .withDaprLogLevel(DaprLogLevel.DEBUG)
97178
// .withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String()))
98179
.withAppPort(8080)

spring-boot-examples/workflows/remote-activities/orchestrator/src/test/java/io/dapr/springboot/examples/orchestrator/OrchestratorAppTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.junit.jupiter.api.Test;
2222
import org.springframework.beans.factory.annotation.Autowired;
2323
import org.springframework.boot.test.context.SpringBootTest;
24+
import org.springframework.test.context.TestPropertySource;
2425

2526
import java.io.IOException;
2627

@@ -30,7 +31,7 @@
3031
import static org.junit.jupiter.api.Assertions.assertEquals;
3132

3233
@SpringBootTest(classes = {TestOrchestratorApplication.class, DaprTestContainersConfig.class},
33-
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
34+
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, properties = {"reuse=true"})
3435
class OrchestratorAppTests {
3536

3637

@@ -65,7 +66,7 @@ void testCustomersWorkflows() throws InterruptedException, IOException {
6566
// io.dapr.springboot.examples.orchestrator.Customer customer = customerStore.getCustomer("salaboy");
6667
// assertEquals(true, customer.isInCustomerDB());
6768
// String workflowId = customer.getWorkflowId();
68-
// given().contentType(ContentType.JSON)
69+
// given().contentType(ContentType.JSON)
6970
// .body("{ \"workflowId\": \"" + workflowId + "\",\"customerName\": \"salaboy\" }")
7071
// .when()
7172
// .post("/customers/followup")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<FindBugsFilter>
2+
<!--Ignoring checking for examples-->
3+
<Match>
4+
<Package name="~io\.dapr\.springboot.examples.*"/>
5+
</Match>
6+
</FindBugsFilter>

spring-boot-examples/workflows/remote-activities/worker-one/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@
5353
<plugin>
5454
<groupId>org.springframework.boot</groupId>
5555
<artifactId>spring-boot-maven-plugin</artifactId>
56+
<executions>
57+
<execution>
58+
<goals>
59+
<goal>repackage</goal>
60+
</goals>
61+
</execution>
62+
</executions>
5663
</plugin>
5764
<plugin>
5865
<groupId>org.apache.maven.plugins</groupId>

spring-boot-examples/workflows/remote-activities/worker-two/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@
5353
<plugin>
5454
<groupId>org.springframework.boot</groupId>
5555
<artifactId>spring-boot-maven-plugin</artifactId>
56+
<executions>
57+
<execution>
58+
<goals>
59+
<goal>repackage</goal>
60+
</goals>
61+
</execution>
62+
</executions>
5663
</plugin>
5764
<plugin>
5865
<groupId>org.apache.maven.plugins</groupId>

0 commit comments

Comments
 (0)