Skip to content

Commit 6a6957a

Browse files
salaboydependabot[bot]artur-ciocanumarcduikercicoyle
authored
Supporting placement and scheduler custom images (#1450)
* supporting placement and scheduler custom images Signed-off-by: salaboy <[email protected]> * Bump org.apache.commons:commons-lang3 from 3.9 to 3.18.0 (#1446) Bumps org.apache.commons:commons-lang3 from 3.9 to 3.18.0. --- updated-dependencies: - dependency-name: org.apache.commons:commons-lang3 dependency-version: 3.18.0 dependency-type: direct:development ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: artur-ciocanu <[email protected]> Signed-off-by: salaboy <[email protected]> * Update dapr docs for Hugo upgrade (#1443) Signed-off-by: Marc Duiker <[email protected]> Co-authored-by: Cassie Coyle <[email protected]> Signed-off-by: salaboy <[email protected]> * Adds note about workflow start time (#1444) Signed-off-by: joshvanl <[email protected]> Co-authored-by: Dapr Bot <[email protected]> Co-authored-by: artur-ciocanu <[email protected]> Signed-off-by: salaboy <[email protected]> * adding test to validate canonical names with substitutes Signed-off-by: salaboy <[email protected]> * Migrate PubSub removing flaky test (#1407) * Migrate PubSub removing flaky test Signed-off-by: Matheus Cruz <[email protected]> * Adjust assertion Signed-off-by: Matheus Cruz <[email protected]> * Change assert Signed-off-by: Matheus Cruz <[email protected]> * Apply pull request suggestions Signed-off-by: Matheus Cruz <[email protected]> * Use custom ObjectSerializer Signed-off-by: Matheus Cruz <[email protected]> --------- Signed-off-by: Matheus Cruz <[email protected]> Co-authored-by: artur-ciocanu <[email protected]> Signed-off-by: salaboy <[email protected]> * adding tests for coverage Signed-off-by: salaboy <[email protected]> --------- Signed-off-by: salaboy <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Marc Duiker <[email protected]> Signed-off-by: joshvanl <[email protected]> Signed-off-by: Matheus Cruz <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: artur-ciocanu <[email protected]> Co-authored-by: Marc Duiker <[email protected]> Co-authored-by: Cassie Coyle <[email protected]> Co-authored-by: Josh van Leeuwen <[email protected]> Co-authored-by: Dapr Bot <[email protected]> Co-authored-by: Matheus Cruz <[email protected]>
1 parent 779a4da commit 6a6957a

File tree

2 files changed

+81
-14
lines changed

2 files changed

+81
-14
lines changed

testcontainers-dapr/src/main/java/io/dapr/testcontainers/DaprContainer.java

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ public class DaprContainer extends GenericContainer<DaprContainer> {
5656
private static final YamlConverter<Subscription> SUBSCRIPTION_CONVERTER = new SubscriptionYamlConverter(YAML_MAPPER);
5757
private static final YamlConverter<HttpEndpoint> HTTPENDPOINT_CONVERTER = new HttpEndpointYamlConverter(YAML_MAPPER);
5858
private static final YamlConverter<Configuration> CONFIGURATION_CONVERTER = new ConfigurationYamlConverter(
59-
YAML_MAPPER);
59+
YAML_MAPPER);
6060
private static final WaitStrategy WAIT_STRATEGY = Wait.forHttp("/v1.0/healthz/outbound")
61-
.forPort(DAPRD_DEFAULT_HTTP_PORT)
62-
.forStatusCodeMatching(statusCode -> statusCode >= 200 && statusCode <= 399);
61+
.forPort(DAPRD_DEFAULT_HTTP_PORT)
62+
.forStatusCodeMatching(statusCode -> statusCode >= 200 && statusCode <= 399);
6363

6464
private final Set<Component> components = new HashSet<>();
6565
private final Set<Subscription> subscriptions = new HashSet<>();
@@ -68,8 +68,8 @@ public class DaprContainer extends GenericContainer<DaprContainer> {
6868
private String appChannelAddress = "localhost";
6969
private String placementService = "placement";
7070
private String schedulerService = "scheduler";
71-
private String placementDockerImageName = DAPR_PLACEMENT_IMAGE_TAG;
72-
private String schedulerDockerImageName = DAPR_SCHEDULER_IMAGE_TAG;
71+
private DockerImageName placementDockerImageName = DockerImageName.parse(DAPR_PLACEMENT_IMAGE_TAG);
72+
private DockerImageName schedulerDockerImageName = DockerImageName.parse(DAPR_SCHEDULER_IMAGE_TAG);
7373

7474
private Configuration configuration;
7575
private DaprPlacementContainer placementContainer;
@@ -82,6 +82,7 @@ public class DaprContainer extends GenericContainer<DaprContainer> {
8282

8383
/**
8484
* Creates a new Dapr container.
85+
*
8586
* @param dockerImageName Docker image name.
8687
*/
8788
public DaprContainer(DockerImageName dockerImageName) {
@@ -94,6 +95,7 @@ public DaprContainer(DockerImageName dockerImageName) {
9495

9596
/**
9697
* Creates a new Dapr container.
98+
*
9799
* @param image Docker image name.
98100
*/
99101
public DaprContainer(String image) {
@@ -166,16 +168,26 @@ public DaprContainer withHttpEndpoint(HttpEndpoint httpEndpoint) {
166168
return this;
167169
}
168170

169-
public DaprContainer withPlacementImage(String placementDockerImageName) {
171+
public DaprContainer withPlacementImage(DockerImageName placementDockerImageName) {
170172
this.placementDockerImageName = placementDockerImageName;
171173
return this;
172174
}
173175

174-
public DaprContainer withSchedulerImage(String schedulerDockerImageName) {
176+
public DaprContainer withPlacementImage(String placementDockerImageName) {
177+
this.placementDockerImageName = DockerImageName.parse(placementDockerImageName);
178+
return this;
179+
}
180+
181+
public DaprContainer withSchedulerImage(DockerImageName schedulerDockerImageName) {
175182
this.schedulerDockerImageName = schedulerDockerImageName;
176183
return this;
177184
}
178185

186+
public DaprContainer withSchedulerImage(String schedulerDockerImageName) {
187+
this.schedulerDockerImageName = DockerImageName.parse(schedulerDockerImageName);
188+
return this;
189+
}
190+
179191
public DaprContainer withReusablePlacement(boolean shouldReusePlacement) {
180192
this.shouldReusePlacement = shouldReusePlacement;
181193
return this;
@@ -203,6 +215,7 @@ public DaprContainer withComponent(Component component) {
203215

204216
/**
205217
* Adds a Dapr component from a YAML file.
218+
*
206219
* @param path Path to the YAML file.
207220
* @return This container.
208221
*/
@@ -217,7 +230,7 @@ public DaprContainer withComponent(Path path) {
217230
String type = (String) spec.get("type");
218231
String version = (String) spec.get("version");
219232
List<Map<String, String>> specMetadata =
220-
(List<Map<String, String>>) spec.getOrDefault("metadata", Collections.emptyList());
233+
(List<Map<String, String>>) spec.getOrDefault("metadata", Collections.emptyList());
221234

222235
ArrayList<MetadataEntry> metadataEntries = new ArrayList<>();
223236

@@ -258,17 +271,17 @@ protected void configure() {
258271

259272
if (this.placementContainer == null) {
260273
this.placementContainer = new DaprPlacementContainer(this.placementDockerImageName)
261-
.withNetwork(getNetwork())
262-
.withNetworkAliases(placementService)
263-
.withReuse(this.shouldReusePlacement);
274+
.withNetwork(getNetwork())
275+
.withNetworkAliases(placementService)
276+
.withReuse(this.shouldReusePlacement);
264277
this.placementContainer.start();
265278
}
266279

267280
if (this.schedulerContainer == null) {
268281
this.schedulerContainer = new DaprSchedulerContainer(this.schedulerDockerImageName)
269-
.withNetwork(getNetwork())
270-
.withNetworkAliases(schedulerService)
271-
.withReuse(this.shouldReuseScheduler);
282+
.withNetwork(getNetwork())
283+
.withNetworkAliases(schedulerService)
284+
.withReuse(this.shouldReuseScheduler);
272285
this.schedulerContainer.start();
273286
}
274287

@@ -384,6 +397,14 @@ public static DockerImageName getDefaultImageName() {
384397
return DEFAULT_IMAGE_NAME;
385398
}
386399

400+
public DockerImageName getPlacementDockerImageName() {
401+
return placementDockerImageName;
402+
}
403+
404+
public DockerImageName getSchedulerDockerImageName() {
405+
return schedulerDockerImageName;
406+
}
407+
387408
// Required by spotbugs plugin
388409
@Override
389410
public boolean equals(Object o) {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package io.dapr.testcontainers;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.testcontainers.utility.DockerImageName;
5+
6+
import static io.dapr.testcontainers.DaprContainerConstants.DAPR_RUNTIME_IMAGE_TAG;
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
public class DaprContainerTest {
10+
11+
@Test
12+
public void schedulerAndPlacementCustomImagesTest() {
13+
14+
DaprContainer dapr = new DaprContainer(DAPR_RUNTIME_IMAGE_TAG)
15+
.withAppName("dapr-app")
16+
.withSchedulerImage(DockerImageName.parse("custom/scheduler:1.15.4")
17+
.asCompatibleSubstituteFor("daprio/scheduler:1.15.4"))
18+
.withPlacementImage(DockerImageName.parse("custom/placement:1.15.4")
19+
.asCompatibleSubstituteFor("daprio/placement:1.15.4"))
20+
.withAppPort(8081)
21+
.withDaprLogLevel(DaprLogLevel.DEBUG)
22+
.withAppChannelAddress("host.testcontainers.internal");
23+
24+
25+
assertEquals("custom/placement:1.15.4", dapr.getPlacementDockerImageName().asCanonicalNameString());
26+
assertEquals("custom/scheduler:1.15.4", dapr.getSchedulerDockerImageName().asCanonicalNameString());
27+
28+
}
29+
30+
@Test
31+
public void schedulerAndPlacementCustomImagesStringTest() {
32+
33+
DaprContainer dapr = new DaprContainer(DAPR_RUNTIME_IMAGE_TAG)
34+
.withAppName("dapr-app")
35+
.withSchedulerImage("daprio/scheduler:1.15.4")
36+
.withPlacementImage("daprio/placement:1.15.4")
37+
.withAppPort(8081)
38+
.withDaprLogLevel(DaprLogLevel.DEBUG)
39+
.withAppChannelAddress("host.testcontainers.internal");
40+
41+
42+
assertEquals("daprio/placement:1.15.4", dapr.getPlacementDockerImageName().asCanonicalNameString());
43+
assertEquals("daprio/scheduler:1.15.4", dapr.getSchedulerDockerImageName().asCanonicalNameString());
44+
45+
}
46+
}

0 commit comments

Comments
 (0)