From 4f5d9c68fad230e73b2cd861a7338b441f07b2ab Mon Sep 17 00:00:00 2001 From: Artur Ciocanu Date: Fri, 20 Nov 2026 15:16:54 -0800 Subject: [PATCH] test: migrating API and secrets ITs to Testcontainers v2 Signed-off-by: Artur Ciocanu --- sdk-tests/pom.xml | 6 + .../src/test/java/io/dapr/it/api/ApiIT.java | 57 ------- .../io/dapr/it/testcontainers/api/ApiIT.java | 56 +++++++ .../testcontainers/secrets/DaprSecretsIT.java | 148 ------------------ .../secrets/SecretsClientIT.java | 52 +++--- .../support/DaprTestEnvironment.java | 85 ++++++++-- 6 files changed, 167 insertions(+), 237 deletions(-) delete mode 100644 sdk-tests/src/test/java/io/dapr/it/api/ApiIT.java create mode 100644 sdk-tests/src/test/java/io/dapr/it/testcontainers/api/ApiIT.java delete mode 100644 sdk-tests/src/test/java/io/dapr/it/testcontainers/secrets/DaprSecretsIT.java rename sdk-tests/src/test/java/io/dapr/it/{ => testcontainers}/secrets/SecretsClientIT.java (69%) diff --git a/sdk-tests/pom.xml b/sdk-tests/pom.xml index 132f8b0283..06e401c9a1 100644 --- a/sdk-tests/pom.xml +++ b/sdk-tests/pom.xml @@ -266,6 +266,12 @@ + + + + + + diff --git a/sdk-tests/src/test/java/io/dapr/it/api/ApiIT.java b/sdk-tests/src/test/java/io/dapr/it/api/ApiIT.java deleted file mode 100644 index 24d7bae1ee..0000000000 --- a/sdk-tests/src/test/java/io/dapr/it/api/ApiIT.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2025 The Dapr Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and -limitations under the License. -*/ - -package io.dapr.it.api; - -import io.dapr.client.DaprClient; -import io.dapr.it.containers.BaseContainerIT; -import io.dapr.testcontainers.DaprContainer; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.junit.jupiter.api.Assertions.assertFalse; - -public class ApiIT extends BaseContainerIT { - - private static final Logger logger = LoggerFactory.getLogger(ApiIT.class); - private static final long SHUTDOWN_TIMEOUT_MS = 60_000; - private static final long SIDECAR_WARMUP_MS = 3_000; - - private static DaprContainer dapr; - - @BeforeAll - public static void init() throws Exception { - dapr = daprBuilder("api-it"); - dapr.start(); - deferStop(dapr); - } - - @Test - public void testShutdownAPI() throws Exception { - // TODO(artursouza): change this to wait for the sidecar to be healthy (new method needed in DaprClient). - Thread.sleep(SIDECAR_WARMUP_MS); - try (DaprClient client = newDaprClient(dapr)) { - logger.info("Sending shutdown request."); - client.shutdown().block(); - - logger.info("Ensuring dapr has stopped."); - long deadline = System.currentTimeMillis() + SHUTDOWN_TIMEOUT_MS; - while (dapr.isRunning() && System.currentTimeMillis() < deadline) { - Thread.sleep(100); - } - assertFalse(dapr.isRunning(), "Dapr container should have exited after client.shutdown()"); - } - } -} diff --git a/sdk-tests/src/test/java/io/dapr/it/testcontainers/api/ApiIT.java b/sdk-tests/src/test/java/io/dapr/it/testcontainers/api/ApiIT.java new file mode 100644 index 0000000000..4a0213452b --- /dev/null +++ b/sdk-tests/src/test/java/io/dapr/it/testcontainers/api/ApiIT.java @@ -0,0 +1,56 @@ +/* + * Copyright 2026 The Dapr Authors + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.dapr.it.testcontainers.api; + +import io.dapr.client.DaprClient; +import io.dapr.it.testcontainers.support.DaprTestEnvironment; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import java.time.Duration; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +/** Integration tests for the sidecar-only Dapr API. */ +@Tag("testcontainers") +public class ApiIT { + + private static final Duration SHUTDOWN_TIMEOUT = Duration.ofSeconds(60); + private static final DaprTestEnvironment ENVIRONMENT = DaprTestEnvironment.withoutApplication("api-it"); + + @BeforeAll + public static void init() { + ENVIRONMENT.start(); + } + + @AfterAll + public static void tearDown() { + ENVIRONMENT.stop(); + } + + @Test + public void testShutdownAPI() throws Exception { + try (DaprClient client = ENVIRONMENT.clientBuilder().build()) { + client.shutdown().block(SHUTDOWN_TIMEOUT); + + long deadline = System.nanoTime() + SHUTDOWN_TIMEOUT.toNanos(); + while (ENVIRONMENT.isSidecarRunning() && System.nanoTime() < deadline) { + Thread.sleep(100); + } + assertFalse(ENVIRONMENT.isSidecarRunning(), "Dapr container should have exited after client.shutdown()"); + } + } +} diff --git a/sdk-tests/src/test/java/io/dapr/it/testcontainers/secrets/DaprSecretsIT.java b/sdk-tests/src/test/java/io/dapr/it/testcontainers/secrets/DaprSecretsIT.java deleted file mode 100644 index 3f71938286..0000000000 --- a/sdk-tests/src/test/java/io/dapr/it/testcontainers/secrets/DaprSecretsIT.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2024 The Dapr Authors - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.dapr.it.testcontainers.secrets; - -import com.fasterxml.jackson.databind.ObjectMapper; -import io.dapr.client.DaprClient; -import io.dapr.client.DaprClientBuilder; -import io.dapr.config.Properties; -import io.dapr.testcontainers.Component; -import io.dapr.testcontainers.DaprContainer; -import io.dapr.testcontainers.DaprLogLevel; -import io.dapr.testcontainers.MetadataEntry; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.testcontainers.containers.Network; -import org.testcontainers.images.builder.Transferable; -import org.testcontainers.junit.jupiter.Container; -import org.testcontainers.junit.jupiter.Testcontainers; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static io.dapr.it.testcontainers.ContainerConstants.DAPR_RUNTIME_IMAGE_TAG; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; - -/** - * Integration tests for the Dapr Secrets API using testcontainers. - */ -@Disabled("Needs investigation: DaprContainer file mounting with secretstores.local.file") -@Testcontainers -@Tag("testcontainers") -public class DaprSecretsIT { - - private static final String SECRETS_STORE_NAME = "localSecretStore"; - private static final String CONTAINER_SECRETS_PATH = "/tmp/secrets.json"; - private static final ObjectMapper JSON_SERIALIZER = new ObjectMapper(); - - private static final String KEY1 = "movie"; - private static final String KEY2 = "person"; - - private static final Network DAPR_NETWORK = Network.newNetwork(); - - private static DaprClient daprClient; - - private static final String SECRETS_JSON = createSecretsJson(); - - @Container - private static final DaprContainer DAPR_CONTAINER = new DaprContainer(DAPR_RUNTIME_IMAGE_TAG) - .withAppName("secrets-test-app") - .withNetwork(DAPR_NETWORK) - .withDaprLogLevel(DaprLogLevel.DEBUG) - .withComponent(new Component( - SECRETS_STORE_NAME, - "secretstores.local.file", - "v1", - List.of(new MetadataEntry("secretsFile", CONTAINER_SECRETS_PATH)) - )) - .withCopyToContainer(Transferable.of(SECRETS_JSON), CONTAINER_SECRETS_PATH) - .withLogConsumer(outputFrame -> System.out.println(outputFrame.getUtf8String())); - - private static String createSecretsJson() { - try { - Map secrets = new HashMap<>(); - Map movieSecret = new HashMap<>(); - movieSecret.put("title", "The Metrics IV"); - movieSecret.put("year", "2020"); - secrets.put(KEY1, movieSecret); - - Map personSecret = new HashMap<>(); - personSecret.put("name", "Jon Doe"); - secrets.put(KEY2, personSecret); - - return JSON_SERIALIZER.writeValueAsString(secrets); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - @BeforeAll - static void setUp() { - daprClient = new DaprClientBuilder() - .withPropertyOverride(Properties.HTTP_ENDPOINT, DAPR_CONTAINER.getHttpEndpoint()) - .withPropertyOverride(Properties.GRPC_ENDPOINT, DAPR_CONTAINER.getGrpcEndpoint()) - .build(); - } - - @AfterAll - static void tearDown() throws Exception { - if (daprClient != null) { - daprClient.close(); - } - } - - @Test - public void testGetSecret() { - Map data = daprClient.getSecret(SECRETS_STORE_NAME, KEY1).block(); - - assertNotNull(data); - assertEquals(2, data.size()); - assertEquals("The Metrics IV", data.get("title")); - assertEquals("2020", data.get("year")); - } - - @Test - public void testGetBulkSecret() { - Map> data = daprClient.getBulkSecret(SECRETS_STORE_NAME).block(); - - assertNotNull(data); - assertTrue(data.size() >= 2); - assertEquals(2, data.get(KEY1).size()); - assertEquals("The Metrics IV", data.get(KEY1).get("title")); - assertEquals("2020", data.get(KEY1).get("year")); - assertEquals(1, data.get(KEY2).size()); - assertEquals("Jon Doe", data.get(KEY2).get("name")); - } - - @Test - public void testGetSecretKeyNotFound() { - assertThrows(RuntimeException.class, () -> - daprClient.getSecret(SECRETS_STORE_NAME, "unknownKey").block() - ); - } - - @Test - public void testGetSecretStoreNotFound() { - assertThrows(RuntimeException.class, () -> - daprClient.getSecret("unknownStore", "unknownKey").block() - ); - } -} diff --git a/sdk-tests/src/test/java/io/dapr/it/secrets/SecretsClientIT.java b/sdk-tests/src/test/java/io/dapr/it/testcontainers/secrets/SecretsClientIT.java similarity index 69% rename from sdk-tests/src/test/java/io/dapr/it/secrets/SecretsClientIT.java rename to sdk-tests/src/test/java/io/dapr/it/testcontainers/secrets/SecretsClientIT.java index 202d7b9499..5f35ab5434 100644 --- a/sdk-tests/src/test/java/io/dapr/it/secrets/SecretsClientIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/testcontainers/secrets/SecretsClientIT.java @@ -1,5 +1,5 @@ /* - * Copyright 2025 The Dapr Authors + * Copyright 2026 The Dapr Authors * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -8,68 +8,79 @@ * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and -limitations under the License. -*/ + * limitations under the License. + */ -package io.dapr.it.secrets; +package io.dapr.it.testcontainers.secrets; import com.fasterxml.jackson.databind.ObjectMapper; import io.dapr.client.DaprClient; -import io.dapr.it.containers.BaseContainerIT; +import io.dapr.it.testcontainers.support.DaprTestEnvironment; import io.dapr.testcontainers.Component; -import io.dapr.testcontainers.DaprContainer; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.testcontainers.images.builder.Transferable; +import java.util.List; import java.util.Map; import java.util.UUID; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -public class SecretsClientIT extends BaseContainerIT { +/** Integration tests for the local-file Dapr secret store without an application. */ +@Tag("testcontainers") +public class SecretsClientIT { private static final ObjectMapper JSON_SERIALIZER = new ObjectMapper(); private static final String SECRETS_STORE_NAME = "localSecretStore"; private static final String CONTAINER_SECRET_PATH = "/dapr-secret.json"; private static final String KEY1 = UUID.randomUUID().toString(); - private static final String KYE2 = UUID.randomUUID().toString(); + private static final String KEY2 = UUID.randomUUID().toString(); - private static DaprContainer dapr; + private static final DaprTestEnvironment ENVIRONMENT = DaprTestEnvironment.withoutApplication("secrets-it"); private DaprClient daprClient; @BeforeAll public static void init() throws Exception { byte[] secretJson = JSON_SERIALIZER.writeValueAsBytes(buildSecretPayload()); - dapr = daprBuilder("secrets-it") - .withComponent(new Component(SECRETS_STORE_NAME, "secretstores.local.file", "v1", Map.of( + ENVIRONMENT.withComponents(List.of(new Component(SECRETS_STORE_NAME, "secretstores.local.file", "v1", Map.of( "secretsFile", CONTAINER_SECRET_PATH, "nestedSeparator", ":", "multiValued", "true" - ))) - .withCopyToContainer(Transferable.of(secretJson), CONTAINER_SECRET_PATH); - dapr.start(); - deferStop(dapr); + )))) + .withResource(Transferable.of(secretJson), CONTAINER_SECRET_PATH); + ENVIRONMENT.start(); + } + + @AfterAll + public static void stopEnvironment() { + ENVIRONMENT.stop(); } @BeforeEach public void setup() { - this.daprClient = newDaprClient(dapr); + this.daprClient = ENVIRONMENT.clientBuilder().build(); } @AfterEach public void tearDown() throws Exception { - daprClient.close(); + if (daprClient != null) { + daprClient.close(); + } } @Test public void getSecret() { Map data = daprClient.getSecret(SECRETS_STORE_NAME, KEY1).block(); + assertNotNull(data); assertEquals(2, data.size()); assertEquals("The Metrics IV", data.get("title")); assertEquals("2020", data.get("year")); @@ -78,12 +89,13 @@ public void getSecret() { @Test public void getBulkSecret() { Map> data = daprClient.getBulkSecret(SECRETS_STORE_NAME).block(); + assertNotNull(data); assertTrue(data.size() >= 2); assertEquals(2, data.get(KEY1).size()); assertEquals("The Metrics IV", data.get(KEY1).get("title")); assertEquals("2020", data.get(KEY1).get("year")); - assertEquals(1, data.get(KYE2).size()); - assertEquals("Jon Doe", data.get(KYE2).get("name")); + assertEquals(1, data.get(KEY2).size()); + assertEquals("Jon Doe", data.get(KEY2).get("name")); } @Test @@ -99,7 +111,7 @@ public void getSecretStoreNotFound() { private static Map> buildSecretPayload() { return Map.of( KEY1, Map.of("title", "The Metrics IV", "year", "2020"), - KYE2, Map.of("name", "Jon Doe") + KEY2, Map.of("name", "Jon Doe") ); } } diff --git a/sdk-tests/src/test/java/io/dapr/it/testcontainers/support/DaprTestEnvironment.java b/sdk-tests/src/test/java/io/dapr/it/testcontainers/support/DaprTestEnvironment.java index 985017b1c5..d154b0c4fa 100644 --- a/sdk-tests/src/test/java/io/dapr/it/testcontainers/support/DaprTestEnvironment.java +++ b/sdk-tests/src/test/java/io/dapr/it/testcontainers/support/DaprTestEnvironment.java @@ -26,6 +26,7 @@ import org.testcontainers.containers.Network; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.containers.wait.strategy.WaitStrategy; +import org.testcontainers.images.builder.Transferable; import org.testcontainers.lifecycle.Startable; import reactor.util.retry.Retry; @@ -41,7 +42,7 @@ import static io.dapr.it.testcontainers.ContainerConstants.JDK_17_TEMURIN_JAMMY; -/** Owns one application, its sidecar, control plane and private network. */ +/** Owns an optional application, its sidecar, control plane and private network. */ public final class DaprTestEnvironment implements Startable { private static final int APP_PORT = 8080; private static final String APP_RUNTIME = "/it-runtime"; @@ -75,6 +76,45 @@ public DaprTestEnvironment(String appId, Class mainClass, DaprProtocol protoc this(appId, mainClass.getName(), protocol, Duration.ofMinutes(2)); } + /** + * Defines an isolated sidecar without an application or callback channel. + * @param appId Dapr application ID. + * @return Unstarted environment owning its control plane and private network. + */ + public static DaprTestEnvironment withoutApplication(String appId) { + return new DaprTestEnvironment(appId, (String) null, DaprProtocol.HTTP, Duration.ofMinutes(2)); + } + + /** + * Adds explicit sidecar components before startup, without requiring a backing service. + * @param components Components using container-local or private network addresses. + * @return this environment. + */ + public DaprTestEnvironment withComponents(List components) { + if (started) { + throw new IllegalStateException("Environment already started"); + } + components.forEach(dapr::withComponent); + return this; + } + + /** + * Copies a resource into the sidecar before startup using Testcontainers transfer APIs. + * @param resource Resource content to transfer. + * @param containerPath Absolute destination path inside daprd. + * @return this environment. + */ + public DaprTestEnvironment withResource(Transferable resource, String containerPath) { + if (started) { + throw new IllegalStateException("Environment already started"); + } + if (containerPath == null || !containerPath.startsWith("/")) { + throw new IllegalArgumentException("Resource destination must be an absolute container path"); + } + dapr.withCopyToContainer(resource, containerPath); + return this; + } + /** * Adds one unstarted backing service and explicit sidecar components before startup. * @param container Backing service owned by this environment. @@ -93,7 +133,7 @@ public DaprTestEnvironment withPrerequisite(GenericContainer container, Strin .withLabels(Map.of("io.dapr.it.environment", identity)); prerequisiteAlias = alias; attachLogs(prerequisite, alias); - components.forEach(dapr::withComponent); + withComponents(components); return this; } @@ -131,10 +171,10 @@ public DaprTestEnvironment withConfiguration(Configuration configuration) { scheduler = new DaprSchedulerContainer(DaprContainerConstants.DAPR_SCHEDULER_IMAGE_TAG) .withNetwork(network).withNetworkAliases("scheduler").withLabels(labels) .waitingFor(Wait.forListeningPort().withStartupTimeout(Duration.ofMinutes(2))); - WaitStrategy appWait = protocol == DaprProtocol.GRPC + WaitStrategy appWait = mainClass == null ? null : protocol == DaprProtocol.GRPC ? new GrpcCallbackWaitStrategy(APP_PORT).withStartupTimeout(appReadinessTimeout) : Wait.forHttp("/health").forPort(APP_PORT).forStatusCode(200).withStartupTimeout(appReadinessTimeout); - app = new GenericContainer<>(JDK_17_TEMURIN_JAMMY) + app = mainClass == null ? null : new GenericContainer<>(JDK_17_TEMURIN_JAMMY) .withNetwork(network).withNetworkAliases("app").withLabels(labels) .withExposedPorts(APP_PORT) .waitingFor(appWait) @@ -146,14 +186,19 @@ public DaprTestEnvironment withConfiguration(Configuration configuration) { dapr = new DaprContainer(DaprContainerConstants.DAPR_RUNTIME_IMAGE_TAG) .withNetwork(network).withNetworkAliases("dapr").withLabels(labels) .withAccessToHost(false) - .withAppName(appId).withAppPort(APP_PORT).withAppChannelAddress("app").withAppProtocol(protocol) + .withAppName(appId) .withPlacementContainer(placement).withSchedulerContainer(scheduler) .waitingFor(Wait.forHttp("/v1.0/healthz/outbound").forPort(3500) .forStatusCodeMatching(status -> status >= 200 && status <= 399) .withStartupTimeout(Duration.ofMinutes(2))); + if (app == null) { + dapr.withAppChannelAddress(null).withAppProtocol(null); + } else { + dapr.withAppPort(APP_PORT).withAppChannelAddress("app").withAppProtocol(protocol); + attachLogs(app, "app"); + } attachLogs(placement, "placement"); attachLogs(scheduler, "scheduler"); - attachLogs(app, "app"); attachLogs(dapr, "dapr"); } @@ -208,10 +253,12 @@ public void start() { System.out.printf("[%s] placement id=%s%n", identity, placement.getContainerId()); resources.start(scheduler); System.out.printf("[%s] scheduler id=%s%n", identity, scheduler.getContainerId()); - configureApplication(); - resources.start(app); - System.out.printf("[%s] app id=%s image=%s protocol=%s address=%s%n", identity, app.getContainerId(), - JDK_17_TEMURIN_JAMMY, protocol, appAddress()); + if (app != null) { + configureApplication(); + resources.start(app); + System.out.printf("[%s] app id=%s image=%s protocol=%s address=%s%n", identity, app.getContainerId(), + JDK_17_TEMURIN_JAMMY, protocol, appAddress()); + } resources.start(dapr); System.out.printf("[%s] dapr id=%s endpoint=%s grpc=%s:%d%n", identity, dapr.getContainerId(), Endpoints.http(dapr.getHost(), dapr.getHttpPort()), dapr.getHost(), dapr.getGrpcPort()); @@ -224,7 +271,8 @@ public void start() { } System.out.printf("[%s] app=%s (%s, %s), dapr=%s (%s), placement=%s, scheduler=%s%n", identity, - appAddress(), protocol, app.getContainerId(), Endpoints.http(dapr.getHost(), dapr.getHttpPort()), + app == null ? "none" : appAddress(), protocol, appContainerId(), + Endpoints.http(dapr.getHost(), dapr.getHttpPort()), dapr.getContainerId(), placement.getContainerId(), scheduler.getContainerId()); } catch (RuntimeException | Error failure) { diagnosticLogs(prerequisite, prerequisiteAlias); @@ -261,6 +309,7 @@ public void stop() { /** Returns the HTTP application endpoint reachable by the test JVM. */ public URI appEndpoint() { + requireApplication(); if (protocol != DaprProtocol.HTTP) { throw new IllegalStateException("Application is not HTTP: " + protocol); } @@ -273,9 +322,21 @@ public URI appEndpoint() { * @return Application authority reachable by the test JVM. */ public String appAddress() { + requireApplication(); return Endpoints.http(app.getHost(), app.getMappedPort(APP_PORT)).getRawAuthority(); } + private void requireApplication() { + if (app == null) { + throw new IllegalStateException("Environment has no application"); + } + } + + /** Returns whether the owned daprd process is still running, including after SDK shutdown. */ + public boolean isSidecarRunning() { + return dapr.isRunning(); + } + /** Returns a client builder configured for the mapped sidecar ports. */ public DaprClientBuilder clientBuilder() { return Endpoints.client(dapr.getHost(), dapr.getHttpPort(), dapr.getGrpcPort()); @@ -299,6 +360,6 @@ DaprProtocol appProtocol() { } String appContainerId() { - return app.getContainerId(); + return app == null ? null : app.getContainerId(); } }