Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public class DaprContainer extends GenericContainer<DaprContainer> {
private static final YamlConverter<Subscription> SUBSCRIPTION_CONVERTER = new SubscriptionYamlConverter(YAML_MAPPER);
private static final YamlConverter<HttpEndpoint> HTTPENDPOINT_CONVERTER = new HttpEndpointYamlConverter(YAML_MAPPER);
private static final YamlConverter<Configuration> CONFIGURATION_CONVERTER = new ConfigurationYamlConverter(
YAML_MAPPER);
YAML_MAPPER);
private static final WaitStrategy WAIT_STRATEGY = Wait.forHttp("/v1.0/healthz/outbound")
.forPort(DAPRD_DEFAULT_HTTP_PORT)
.forStatusCodeMatching(statusCode -> statusCode >= 200 && statusCode <= 399);
.forPort(DAPRD_DEFAULT_HTTP_PORT)
.forStatusCodeMatching(statusCode -> statusCode >= 200 && statusCode <= 399);

private final Set<Component> components = new HashSet<>();
private final Set<Subscription> subscriptions = new HashSet<>();
Expand All @@ -68,8 +68,8 @@ public class DaprContainer extends GenericContainer<DaprContainer> {
private String appChannelAddress = "localhost";
private String placementService = "placement";
private String schedulerService = "scheduler";
private String placementDockerImageName = DAPR_PLACEMENT_IMAGE_TAG;
private String schedulerDockerImageName = DAPR_SCHEDULER_IMAGE_TAG;
private DockerImageName placementDockerImageName = DockerImageName.parse(DAPR_PLACEMENT_IMAGE_TAG);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a reason for changing away from the String type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cicoyle yes, this is needed to be able to provide compatible image names. By using the DockerImageName class we now support flexible image names, that are compatible with the default one that we provide.

private DockerImageName schedulerDockerImageName = DockerImageName.parse(DAPR_SCHEDULER_IMAGE_TAG);

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

/**
* Creates a new Dapr container.
*
* @param dockerImageName Docker image name.
*/
public DaprContainer(DockerImageName dockerImageName) {
Expand All @@ -94,6 +95,7 @@ public DaprContainer(DockerImageName dockerImageName) {

/**
* Creates a new Dapr container.
*
* @param image Docker image name.
*/
public DaprContainer(String image) {
Expand Down Expand Up @@ -166,16 +168,26 @@ public DaprContainer withHttpEndpoint(HttpEndpoint httpEndpoint) {
return this;
}

public DaprContainer withPlacementImage(String placementDockerImageName) {
public DaprContainer withPlacementImage(DockerImageName placementDockerImageName) {
this.placementDockerImageName = placementDockerImageName;
return this;
}

public DaprContainer withSchedulerImage(String schedulerDockerImageName) {
public DaprContainer withPlacementImage(String placementDockerImageName) {
this.placementDockerImageName = DockerImageName.parse(placementDockerImageName);
return this;
}

public DaprContainer withSchedulerImage(DockerImageName schedulerDockerImageName) {
this.schedulerDockerImageName = schedulerDockerImageName;
return this;
}

public DaprContainer withSchedulerImage(String schedulerDockerImageName) {
this.schedulerDockerImageName = DockerImageName.parse(schedulerDockerImageName);
return this;
}

public DaprContainer withReusablePlacement(boolean shouldReusePlacement) {
this.shouldReusePlacement = shouldReusePlacement;
return this;
Expand Down Expand Up @@ -203,6 +215,7 @@ public DaprContainer withComponent(Component component) {

/**
* Adds a Dapr component from a YAML file.
*
* @param path Path to the YAML file.
* @return This container.
*/
Expand All @@ -217,7 +230,7 @@ public DaprContainer withComponent(Path path) {
String type = (String) spec.get("type");
String version = (String) spec.get("version");
List<Map<String, String>> specMetadata =
(List<Map<String, String>>) spec.getOrDefault("metadata", Collections.emptyList());
(List<Map<String, String>>) spec.getOrDefault("metadata", Collections.emptyList());

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

Expand Down Expand Up @@ -258,17 +271,17 @@ protected void configure() {

if (this.placementContainer == null) {
this.placementContainer = new DaprPlacementContainer(this.placementDockerImageName)
.withNetwork(getNetwork())
.withNetworkAliases(placementService)
.withReuse(this.shouldReusePlacement);
.withNetwork(getNetwork())
.withNetworkAliases(placementService)
.withReuse(this.shouldReusePlacement);
this.placementContainer.start();
}

if (this.schedulerContainer == null) {
this.schedulerContainer = new DaprSchedulerContainer(this.schedulerDockerImageName)
.withNetwork(getNetwork())
.withNetworkAliases(schedulerService)
.withReuse(this.shouldReuseScheduler);
.withNetwork(getNetwork())
.withNetworkAliases(schedulerService)
.withReuse(this.shouldReuseScheduler);
this.schedulerContainer.start();
}

Expand Down Expand Up @@ -384,6 +397,14 @@ public static DockerImageName getDefaultImageName() {
return DEFAULT_IMAGE_NAME;
}

public DockerImageName getPlacementDockerImageName() {
return placementDockerImageName;
}

public DockerImageName getSchedulerDockerImageName() {
return schedulerDockerImageName;
}

// Required by spotbugs plugin
@Override
public boolean equals(Object o) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.dapr.testcontainers;

import org.junit.jupiter.api.Test;
import org.testcontainers.utility.DockerImageName;

import static io.dapr.testcontainers.DaprContainerConstants.DAPR_RUNTIME_IMAGE_TAG;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class DaprContainerTest {

@Test
public void schedulerAndPlacementCustomImagesTest() {

DaprContainer dapr = new DaprContainer(DAPR_RUNTIME_IMAGE_TAG)
.withAppName("dapr-app")
.withSchedulerImage(DockerImageName.parse("custom/scheduler:1.15.4")
.asCompatibleSubstituteFor("daprio/scheduler:1.15.4"))
.withPlacementImage(DockerImageName.parse("custom/placement:1.15.4")
.asCompatibleSubstituteFor("daprio/placement:1.15.4"))
.withAppPort(8081)
.withDaprLogLevel(DaprLogLevel.DEBUG)
.withAppChannelAddress("host.testcontainers.internal");


assertEquals("custom/placement:1.15.4", dapr.getPlacementDockerImageName().asCanonicalNameString());
assertEquals("custom/scheduler:1.15.4", dapr.getSchedulerDockerImageName().asCanonicalNameString());

}

@Test
public void schedulerAndPlacementCustomImagesStringTest() {

DaprContainer dapr = new DaprContainer(DAPR_RUNTIME_IMAGE_TAG)
.withAppName("dapr-app")
.withSchedulerImage("daprio/scheduler:1.15.4")
.withPlacementImage("daprio/placement:1.15.4")
.withAppPort(8081)
.withDaprLogLevel(DaprLogLevel.DEBUG)
.withAppChannelAddress("host.testcontainers.internal");


assertEquals("daprio/placement:1.15.4", dapr.getPlacementDockerImageName().asCanonicalNameString());
assertEquals("daprio/scheduler:1.15.4", dapr.getSchedulerDockerImageName().asCanonicalNameString());

}
}
Loading