diff --git a/pom.xml b/pom.xml index 17637aa..e89b14f 100644 --- a/pom.xml +++ b/pom.xml @@ -78,6 +78,12 @@ ${wiremock.version} test + + io.rest-assured + rest-assured + 5.4.0 + test + diff --git a/src/main/java/io/diagrid/dapr/DaprContainer.java b/src/main/java/io/diagrid/dapr/DaprContainer.java index 3695502..6186b32 100644 --- a/src/main/java/io/diagrid/dapr/DaprContainer.java +++ b/src/main/java/io/diagrid/dapr/DaprContainer.java @@ -13,7 +13,9 @@ import java.util.Objects; import java.util.Set; +import org.jetbrains.annotations.Nullable; import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.Network; import org.testcontainers.images.builder.Transferable; import org.testcontainers.utility.DockerImageName; import org.yaml.snakeyaml.DumperOptions; @@ -23,7 +25,7 @@ public class DaprContainer extends GenericContainer { - public static enum DaprLogLevel { + public enum DaprLogLevel { error, warn, info, debug } @@ -119,6 +121,9 @@ public List getMetadata() { private String placementService = "placement:50006"; private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("daprio/daprd"); private Yaml yaml; + private DaprPlacementContainer placementContainer; + private String placementDockerImageName = "daprio/placement"; + private boolean shouldReusePlacement = false; public DaprContainer(DockerImageName dockerImageName) { super(dockerImageName); @@ -275,6 +280,17 @@ public Map subscriptionToMap(Subscription subscription) { @Override protected void configure() { super.configure(); + + if (this.placementContainer == null) { + Network daprNetwork = Network.newNetwork(); + this.placementContainer = new DaprPlacementContainer(this.placementDockerImageName) + .withNetwork(daprNetwork) + .withNetworkAliases("placement") + .withReuse(this.shouldReusePlacement); + dependsOn(this.placementContainer); + withNetwork(daprNetwork); + } + withCommand( "./daprd", "-app-id", appName, @@ -339,4 +355,20 @@ public String getPlacementService() { public static DockerImageName getDefaultImageName() { return DEFAULT_IMAGE_NAME; } + + public DaprContainer withPlacementImage(String placementDockerImageName) { + this.placementDockerImageName = placementDockerImageName; + return this; + } + + public DaprContainer withReusablePlacement(boolean reuse) { + this.shouldReusePlacement = shouldReusePlacement; + return this; + } + + public DaprContainer withPlacementContainer(DaprPlacementContainer placementContainer) { + this.placementContainer = placementContainer; + return this; + } + } \ No newline at end of file diff --git a/src/test/java/io/diagrid/dapr/DaprContainerTest.java b/src/test/java/io/diagrid/dapr/DaprContainerTest.java index bc8e63d..f5b6f0e 100644 --- a/src/test/java/io/diagrid/dapr/DaprContainerTest.java +++ b/src/test/java/io/diagrid/dapr/DaprContainerTest.java @@ -2,6 +2,7 @@ import io.dapr.client.domain.State; +import io.restassured.RestAssured; import org.junit.BeforeClass; import org.junit.ClassRule; import org.junit.Test; @@ -16,13 +17,14 @@ import static java.util.Collections.singletonMap; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static org.junit.Assert.assertTrue; public class DaprContainerTest { - @ClassRule() + @ClassRule public static WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(8081)); - @ClassRule() + @ClassRule public static DaprContainer daprContainer = new DaprContainer("daprio/daprd") .withAppName("dapr-app") .withAppPort(8081) @@ -72,6 +74,17 @@ public void testStateStoreAPIs() throws Exception { } + @Test + public void testPlacement() throws Exception { + RestAssured.baseURI = "http://" + daprContainer.getHost() + ":" + daprContainer.getMappedPort(3500); + boolean isPlacementConnected = RestAssured.given() + .get("/v1.0/metadata") + .jsonPath() + .getString("actorRuntime.placement") + .contentEquals("placement: connected"); + assertTrue(isPlacementConnected); + } + @Test public void testPubSubAPIs() throws Exception {