diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 070f163dc..e4964523b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,9 +38,9 @@ jobs: GOARCH: amd64 GOPROXY: https://proxy.golang.org JDK_VER: ${{ matrix.java }} - DAPR_CLI_VER: 1.14.0-rc.6 - DAPR_RUNTIME_VER: 1.14.0-rc.6 - DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/v1.14.0-rc.4/install/install.sh + DAPR_CLI_VER: 1.14.0 + DAPR_RUNTIME_VER: 1.14.4 + DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/v1.14.0/install/install.sh DAPR_CLI_REF: DAPR_REF: TOXIPROXY_URL: https://github.com/Shopify/toxiproxy/releases/download/v2.5.0/toxiproxy-server-linux-amd64 diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index ef6bc85b0..58ea173f9 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -37,9 +37,9 @@ jobs: GOARCH: amd64 GOPROXY: https://proxy.golang.org JDK_VER: ${{ matrix.java }} - DAPR_CLI_VER: 1.14.0-rc.6 - DAPR_RUNTIME_VER: 1.14.0-rc.6 - DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/v1.14.0-rc.3/install/install.sh + DAPR_CLI_VER: 1.14.0 + DAPR_RUNTIME_VER: 1.14.4 + DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/v1.14.0/install/install.sh DAPR_CLI_REF: DAPR_REF: steps: diff --git a/dapr-spring/dapr-spring-boot-autoconfigure/src/main/java/io/dapr/spring/boot/autoconfigure/client/DaprClientAutoConfiguration.java b/dapr-spring/dapr-spring-boot-autoconfigure/src/main/java/io/dapr/spring/boot/autoconfigure/client/DaprClientAutoConfiguration.java index 3aa422cf1..f77683424 100644 --- a/dapr-spring/dapr-spring-boot-autoconfigure/src/main/java/io/dapr/spring/boot/autoconfigure/client/DaprClientAutoConfiguration.java +++ b/dapr-spring/dapr-spring-boot-autoconfigure/src/main/java/io/dapr/spring/boot/autoconfigure/client/DaprClientAutoConfiguration.java @@ -37,10 +37,18 @@ DaprConnectionDetails daprConnectionDetails(DaprClientProperties properties) { @ConditionalOnMissingBean DaprClientBuilder daprClientBuilder(DaprConnectionDetails daprConnectionDetails) { DaprClientBuilder builder = new DaprClientBuilder(); - builder.withPropertyOverride(Properties.HTTP_ENDPOINT, daprConnectionDetails.httpEndpoint()); - builder.withPropertyOverride(Properties.GRPC_ENDPOINT, daprConnectionDetails.grpcEndpoint()); - builder.withPropertyOverride(Properties.HTTP_PORT, String.valueOf(daprConnectionDetails.httpPort())); - builder.withPropertyOverride(Properties.GRPC_PORT, String.valueOf(daprConnectionDetails.grpcPort())); + if (daprConnectionDetails.httpEndpoint() != null) { + builder.withPropertyOverride(Properties.HTTP_ENDPOINT, daprConnectionDetails.httpEndpoint()); + } + if (daprConnectionDetails.grpcEndpoint() != null) { + builder.withPropertyOverride(Properties.GRPC_ENDPOINT, daprConnectionDetails.grpcEndpoint()); + } + if (daprConnectionDetails.httpPort() != null) { + builder.withPropertyOverride(Properties.HTTP_PORT, String.valueOf(daprConnectionDetails.httpPort())); + } + if (daprConnectionDetails.grpcPort() != null) { + builder.withPropertyOverride(Properties.GRPC_PORT, String.valueOf(daprConnectionDetails.grpcPort())); + } return builder; } diff --git a/sdk-actors/src/main/java/io/dapr/actors/client/ActorClient.java b/sdk-actors/src/main/java/io/dapr/actors/client/ActorClient.java index 6befd413f..c2d7a4444 100644 --- a/sdk-actors/src/main/java/io/dapr/actors/client/ActorClient.java +++ b/sdk-actors/src/main/java/io/dapr/actors/client/ActorClient.java @@ -20,8 +20,6 @@ import io.grpc.Channel; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import reactor.core.publisher.Mono; /** @@ -29,8 +27,6 @@ */ public class ActorClient implements AutoCloseable { - private static final Logger LOGGER = LoggerFactory.getLogger(ActorClient.class); - /** * gRPC channel for communication with Dapr sidecar. */ @@ -45,7 +41,7 @@ public class ActorClient implements AutoCloseable { * Instantiates a new channel for Dapr sidecar communication. */ public ActorClient() { - this(null); + this(new Properties(), null); } /** @@ -53,8 +49,27 @@ public ActorClient() { * * @param resiliencyOptions Client resiliency options. */ - private ActorClient(ResiliencyOptions resiliencyOptions) { - this(buildManagedChannel(), resiliencyOptions); + public ActorClient(ResiliencyOptions resiliencyOptions) { + this(new Properties(), resiliencyOptions); + } + + /** + * Instantiates a new channel for Dapr sidecar communication. + * + * @param overrideProperties Override properties. + */ + public ActorClient(Properties overrideProperties) { + this(buildManagedChannel(overrideProperties), null); + } + + /** + * Instantiates a new channel for Dapr sidecar communication. + * + * @param overrideProperties Override properties. + * @param resiliencyOptions Client resiliency options. + */ + public ActorClient(Properties overrideProperties, ResiliencyOptions resiliencyOptions) { + this(buildManagedChannel(overrideProperties), resiliencyOptions); } /** @@ -96,15 +111,18 @@ public void close() { /** * Creates a GRPC managed channel (or null, if not applicable). * + * @param overrideProperties Overrides * @return GRPC managed channel or null. */ - private static ManagedChannel buildManagedChannel() { - int port = Properties.GRPC_PORT.get(); + private static ManagedChannel buildManagedChannel(Properties overrideProperties) { + int port = overrideProperties.getValue(Properties.GRPC_PORT); if (port <= 0) { throw new IllegalArgumentException("Invalid port."); } - return ManagedChannelBuilder.forAddress(Properties.SIDECAR_IP.get(), port) + var sidecarHost = overrideProperties.getValue(Properties.SIDECAR_IP); + + return ManagedChannelBuilder.forAddress(sidecarHost, port) .usePlaintext() .userAgent(Version.getSdkVersion()) .build(); diff --git a/sdk-tests/src/test/java/io/dapr/it/BaseIT.java b/sdk-tests/src/test/java/io/dapr/it/BaseIT.java index abef394b7..f50025e21 100644 --- a/sdk-tests/src/test/java/io/dapr/it/BaseIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/BaseIT.java @@ -15,6 +15,7 @@ import io.dapr.actors.client.ActorClient; import io.dapr.client.resiliency.ResiliencyOptions; +import io.dapr.config.Properties; import org.apache.commons.lang3.tuple.ImmutablePair; import org.junit.jupiter.api.AfterAll; @@ -46,7 +47,7 @@ protected static DaprRun startDaprApp( Class serviceClass, Boolean useAppPort, int maxWaitMilliseconds) throws Exception { - return startDaprApp(testName, successMessage, serviceClass, useAppPort, maxWaitMilliseconds, GRPC); + return startDaprApp(testName, successMessage, serviceClass, useAppPort, maxWaitMilliseconds, HTTP); } protected static DaprRun startDaprApp( @@ -55,7 +56,7 @@ protected static DaprRun startDaprApp( Class serviceClass, AppRun.AppProtocol appProtocol, int maxWaitMilliseconds) throws Exception { - return startDaprApp(testName, successMessage, serviceClass, true, maxWaitMilliseconds, GRPC, appProtocol); + return startDaprApp(testName, successMessage, serviceClass, true, maxWaitMilliseconds, appProtocol); } protected static DaprRun startDaprApp( @@ -64,25 +65,6 @@ protected static DaprRun startDaprApp( Class serviceClass, Boolean useAppPort, int maxWaitMilliseconds, - AppRun.AppProtocol protocol) throws Exception { - return startDaprApp( - testName, - successMessage, - serviceClass, - useAppPort, - true, - maxWaitMilliseconds, - protocol, - HTTP); - } - - protected static DaprRun startDaprApp( - String testName, - String successMessage, - Class serviceClass, - Boolean useAppPort, - int maxWaitMilliseconds, - AppRun.AppProtocol protocol, AppRun.AppProtocol appProtocol) throws Exception { return startDaprApp( testName, @@ -91,7 +73,6 @@ protected static DaprRun startDaprApp( useAppPort, true, maxWaitMilliseconds, - protocol, appProtocol); } @@ -105,7 +86,6 @@ protected static DaprRun startDaprApp( false, true, maxWaitMilliseconds, - GRPC, HTTP); } @@ -116,7 +96,6 @@ protected static DaprRun startDaprApp( Boolean useAppPort, Boolean useDaprPorts, int maxWaitMilliseconds, - AppRun.AppProtocol protocol, AppRun.AppProtocol appProtocol) throws Exception { DaprRun.Builder builder = new DaprRun.Builder( testName, @@ -128,7 +107,6 @@ protected static DaprRun startDaprApp( TO_BE_STOPPED.add(run); DAPR_RUN_BUILDERS.put(run.getAppName(), builder); run.start(); - run.use(); return run; } @@ -138,24 +116,12 @@ protected static ImmutablePair startSplitDaprAndApp( Class serviceClass, Boolean useAppPort, int maxWaitMilliseconds) throws Exception { - return startSplitDaprAndApp( - testName, successMessage, serviceClass, useAppPort, maxWaitMilliseconds, AppRun.AppProtocol.GRPC); - } - - protected static ImmutablePair startSplitDaprAndApp( - String testName, - String successMessage, - Class serviceClass, - Boolean useAppPort, - int maxWaitMilliseconds, - AppRun.AppProtocol protocol) throws Exception { return startSplitDaprAndApp( testName, successMessage, serviceClass, useAppPort, maxWaitMilliseconds, - protocol, HTTP); } @@ -165,7 +131,6 @@ protected static ImmutablePair startSplitDaprAndApp( Class serviceClass, Boolean useAppPort, int maxWaitMilliseconds, - AppRun.AppProtocol protocol, AppRun.AppProtocol appProtocol) throws Exception { DaprRun.Builder builder = new DaprRun.Builder( testName, @@ -179,10 +144,14 @@ protected static ImmutablePair startSplitDaprAndApp( DAPR_RUN_BUILDERS.put(runs.right.getAppName(), builder); runs.left.start(); runs.right.start(); - runs.right.use(); return runs; } + protected static T deferClose(T object) { + TO_BE_CLOSED.add(object); + return object; + } + @AfterAll public static void cleanUp() throws Exception { while (!TO_BE_CLOSED.isEmpty()) { @@ -194,8 +163,8 @@ public static void cleanUp() throws Exception { } } - protected static ActorClient newActorClient() { - return newActorClient(null); + protected static ActorClient newActorClient(Properties properties) { + return new ActorClient(properties, null); } protected static ActorClient newActorClient(ResiliencyOptions resiliencyOptions) throws RuntimeException { diff --git a/sdk-tests/src/test/java/io/dapr/it/DaprPorts.java b/sdk-tests/src/test/java/io/dapr/it/DaprPorts.java index aaf186e87..b56dd7a25 100644 --- a/sdk-tests/src/test/java/io/dapr/it/DaprPorts.java +++ b/sdk-tests/src/test/java/io/dapr/it/DaprPorts.java @@ -14,12 +14,16 @@ package io.dapr.it; import io.dapr.config.Properties; +import io.dapr.config.Property; import java.io.IOException; import java.net.ServerSocket; import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; public class DaprPorts { @@ -30,10 +34,18 @@ public class DaprPorts { private final Integer appPort; + private final Map, String> overrides; + private DaprPorts(Integer appPort, Integer httpPort, Integer grpcPort) { this.grpcPort = grpcPort; this.httpPort = httpPort; this.appPort = appPort; + this.overrides = Collections.unmodifiableMap(new HashMap<>(){{ + put(Properties.GRPC_PORT, grpcPort.toString()); + put(Properties.HTTP_PORT, httpPort.toString()); + put(Properties.HTTP_ENDPOINT, "http://127.0.0.1:" + httpPort); + put(Properties.GRPC_ENDPOINT, "127.0.0.1:" + grpcPort); + }}); } public static DaprPorts build(boolean appPort, boolean httpPort, boolean grpcPort) { @@ -48,20 +60,6 @@ public static DaprPorts build(boolean appPort, boolean httpPort, boolean grpcPor } } - public void use() { - if (this.httpPort != null) { - System.getProperties().setProperty(Properties.HTTP_PORT.getName(), String.valueOf(this.httpPort)); - System.getProperties().setProperty( - Properties.HTTP_ENDPOINT.getName(), "http://127.0.0.1:" + this.httpPort); - } - - if (this.grpcPort != null) { - System.getProperties().setProperty(Properties.GRPC_PORT.getName(), String.valueOf(this.grpcPort)); - System.getProperties().setProperty( - Properties.GRPC_ENDPOINT.getName(), "127.0.0.1:" + this.grpcPort); - } - } - public Integer getGrpcPort() { return grpcPort; } @@ -74,6 +72,10 @@ public Integer getAppPort() { return appPort; } + public Map, String> getPropertyOverrides() { + return this.overrides; + } + private static Set findFreePorts(int n) throws IOException { Set output = new HashSet<>(); for (int i = 0; i < n;) { diff --git a/sdk-tests/src/test/java/io/dapr/it/DaprRun.java b/sdk-tests/src/test/java/io/dapr/it/DaprRun.java index 9a7533a27..fce5ac976 100644 --- a/sdk-tests/src/test/java/io/dapr/it/DaprRun.java +++ b/sdk-tests/src/test/java/io/dapr/it/DaprRun.java @@ -14,7 +14,11 @@ package io.dapr.it; import com.google.protobuf.Empty; +import io.dapr.actors.client.ActorClient; +import io.dapr.client.DaprClientBuilder; +import io.dapr.client.resiliency.ResiliencyOptions; import io.dapr.config.Properties; +import io.dapr.config.Property; import io.dapr.v1.AppCallbackHealthCheckGrpc; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; @@ -24,6 +28,7 @@ import org.apache.commons.lang3.tuple.ImmutablePair; import java.io.IOException; +import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Supplier; @@ -141,8 +146,20 @@ public void stop() throws InterruptedException, IOException { } } - public void use() { - this.ports.use(); + public Map, String> getPropertyOverrides() { + return this.ports.getPropertyOverrides(); + } + + public DaprClientBuilder newDaprClientBuilder() { + return new DaprClientBuilder().withPropertyOverrides(this.getPropertyOverrides()); + } + + public ActorClient newActorClient() { + return this.newActorClient(null); + } + + public ActorClient newActorClient(ResiliencyOptions resiliencyOptions) { + return new ActorClient(new Properties(this.getPropertyOverrides()), resiliencyOptions); } public void waitForAppHealth(int maxWaitMilliseconds) throws InterruptedException { diff --git a/sdk-tests/src/test/java/io/dapr/it/ToxiProxyRun.java b/sdk-tests/src/test/java/io/dapr/it/ToxiProxyRun.java index 1f592fd61..ad248ec4b 100644 --- a/sdk-tests/src/test/java/io/dapr/it/ToxiProxyRun.java +++ b/sdk-tests/src/test/java/io/dapr/it/ToxiProxyRun.java @@ -16,10 +16,16 @@ import eu.rekawek.toxiproxy.Proxy; import eu.rekawek.toxiproxy.ToxiproxyClient; import eu.rekawek.toxiproxy.model.ToxicDirection; +import io.dapr.actors.client.ActorClient; +import io.dapr.client.DaprClientBuilder; +import io.dapr.client.resiliency.ResiliencyOptions; +import io.dapr.config.Properties; +import io.dapr.config.Property; import io.dapr.utils.NetworkUtils; import java.io.IOException; import java.time.Duration; +import java.util.Map; public class ToxiProxyRun implements Stoppable { @@ -30,7 +36,9 @@ public class ToxiProxyRun implements Stoppable { private final Duration jitter; - private Command toxiProxyServer; + private final Command toxiProxyServer; + + private final DaprPorts toxiProxyPorts; private ToxiproxyClient toxiproxyClient; @@ -38,8 +46,6 @@ public class ToxiProxyRun implements Stoppable { private Proxy httpProxy; - private DaprPorts toxiProxyPorts; - public ToxiProxyRun(DaprRun run, Duration latency, Duration jitter) { this.daprRun = run; this.latency = latency; @@ -78,8 +84,20 @@ public void start() throws IOException, InterruptedException { } } - public void use() { - this.toxiProxyPorts.use(); + public Map, String> getPropertyOverrides() { + return this.toxiProxyPorts.getPropertyOverrides(); + } + + public DaprClientBuilder newDaprClientBuilder() { + return this.daprRun.newDaprClientBuilder().withPropertyOverrides(this.getPropertyOverrides()); + } + + public ActorClient newActorClient() { + return this.newActorClient(null); + } + + public ActorClient newActorClient(ResiliencyOptions resiliencyOptions) { + return new ActorClient(new Properties(this.getPropertyOverrides()), resiliencyOptions); } @Override diff --git a/sdk-tests/src/test/java/io/dapr/it/actors/ActivationDeactivationIT.java b/sdk-tests/src/test/java/io/dapr/it/actors/ActivationDeactivationIT.java index f57ce0905..369d02945 100644 --- a/sdk-tests/src/test/java/io/dapr/it/actors/ActivationDeactivationIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/actors/ActivationDeactivationIT.java @@ -37,7 +37,7 @@ public class ActivationDeactivationIT extends BaseIT { @Test public void activateInvokeDeactivate() throws Exception { // The call below will fail if service cannot start successfully. - startDaprApp( + var run = startDaprApp( ActivationDeactivationIT.class.getSimpleName(), DemoActorService.SUCCESS_MESSAGE, DemoActorService.class, @@ -46,7 +46,8 @@ public void activateInvokeDeactivate() throws Exception { final AtomicInteger atomicInteger = new AtomicInteger(1); logger.debug("Creating proxy builder"); - ActorProxyBuilder proxyBuilder = new ActorProxyBuilder(DemoActor.class, newActorClient()); + ActorProxyBuilder proxyBuilder + = new ActorProxyBuilder(DemoActor.class, deferClose(run.newActorClient())); logger.debug("Creating actorId"); ActorId actorId1 = new ActorId(Integer.toString(atomicInteger.getAndIncrement())); logger.debug("Building proxy"); diff --git a/sdk-tests/src/test/java/io/dapr/it/actors/ActorExceptionIT.java b/sdk-tests/src/test/java/io/dapr/it/actors/ActorExceptionIT.java index e8e1cd0c3..3b97084cb 100644 --- a/sdk-tests/src/test/java/io/dapr/it/actors/ActorExceptionIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/actors/ActorExceptionIT.java @@ -33,7 +33,7 @@ public class ActorExceptionIT extends BaseIT { @Test public void exceptionTest() throws Exception { // The call below will fail if service cannot start successfully. - startDaprApp( + var run = startDaprApp( ActorExceptionIT.class.getSimpleName(), MyActorService.SUCCESS_MESSAGE, MyActorService.class, @@ -42,7 +42,7 @@ public void exceptionTest() throws Exception { logger.debug("Creating proxy builder"); ActorProxyBuilder proxyBuilder = - new ActorProxyBuilder("MyActorTest", MyActor.class, newActorClient()); + new ActorProxyBuilder("MyActorTest", MyActor.class, deferClose(run.newActorClient())); logger.debug("Creating actorId"); ActorId actorId1 = new ActorId("1"); logger.debug("Building proxy"); diff --git a/sdk-tests/src/test/java/io/dapr/it/actors/ActorMethodNameIT.java b/sdk-tests/src/test/java/io/dapr/it/actors/ActorMethodNameIT.java index 65c6232c8..bf9a2eb74 100644 --- a/sdk-tests/src/test/java/io/dapr/it/actors/ActorMethodNameIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/actors/ActorMethodNameIT.java @@ -33,7 +33,7 @@ public class ActorMethodNameIT extends BaseIT { @Test public void actorMethodNameChange() throws Exception { // The call below will fail if service cannot start successfully. - startDaprApp( + var run = startDaprApp( ActorMethodNameIT.class.getSimpleName(), MyActorService.SUCCESS_MESSAGE, MyActorService.class, @@ -42,7 +42,7 @@ public void actorMethodNameChange() throws Exception { logger.debug("Creating proxy builder"); ActorProxyBuilder proxyBuilder = - new ActorProxyBuilder("MyActorTest", MyActor.class, newActorClient()); + new ActorProxyBuilder("MyActorTest", MyActor.class, deferClose(run.newActorClient())); logger.debug("Creating actorId"); ActorId actorId1 = new ActorId("1"); logger.debug("Building proxy"); @@ -57,7 +57,7 @@ public void actorMethodNameChange() throws Exception { logger.debug("Creating proxy builder 2"); ActorProxyBuilder proxyBuilder2 = - new ActorProxyBuilder("MyActorTest", ActorProxy.class, newActorClient()); + new ActorProxyBuilder("MyActorTest", ActorProxy.class, deferClose(run.newActorClient())); logger.debug("Building proxy 2"); ActorProxy proxy2 = proxyBuilder2.build(actorId1); diff --git a/sdk-tests/src/test/java/io/dapr/it/actors/ActorReminderFailoverIT.java b/sdk-tests/src/test/java/io/dapr/it/actors/ActorReminderFailoverIT.java index efd9aebac..8e7b64c93 100644 --- a/sdk-tests/src/test/java/io/dapr/it/actors/ActorReminderFailoverIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/actors/ActorReminderFailoverIT.java @@ -14,8 +14,10 @@ package io.dapr.it.actors; import io.dapr.actors.ActorId; +import io.dapr.actors.client.ActorClient; import io.dapr.actors.client.ActorProxy; import io.dapr.actors.client.ActorProxyBuilder; +import io.dapr.config.Properties; import io.dapr.it.BaseIT; import io.dapr.it.DaprRun; import io.dapr.it.actors.app.MyActorService; @@ -72,7 +74,7 @@ public void init() throws Exception { logger.debug("Creating proxy builder"); ActorProxyBuilder proxyBuilder = - new ActorProxyBuilder(actorType, ActorProxy.class, newActorClient()); + new ActorProxyBuilder(actorType, ActorProxy.class, deferClose(clientAppRun.newActorClient())); logger.debug("Creating actorId"); logger.debug("Building proxy"); proxy = proxyBuilder.build(actorId); @@ -91,8 +93,6 @@ public void tearDown() { */ @Test public void reminderRecoveryTest() throws Exception { - clientAppRun.use(); - logger.debug("Invoking actor method 'startReminder' which will register a reminder"); proxy.invokeMethod("startReminder", "myReminder").block(); diff --git a/sdk-tests/src/test/java/io/dapr/it/actors/ActorReminderRecoveryIT.java b/sdk-tests/src/test/java/io/dapr/it/actors/ActorReminderRecoveryIT.java index 73f0eb382..c388a906a 100644 --- a/sdk-tests/src/test/java/io/dapr/it/actors/ActorReminderRecoveryIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/actors/ActorReminderRecoveryIT.java @@ -96,7 +96,6 @@ public void setup(String actorType) throws Exception { // Run that will stay up for integration tests. // appId must not contain the appId from the other run, otherwise ITs will not run properly. clientRun = startDaprApp("ActorReminderRecoveryTestClient", 5000); - clientRun.use(); Thread.sleep(3000); @@ -104,7 +103,7 @@ public void setup(String actorType) throws Exception { logger.debug("Creating proxy builder"); ActorProxyBuilder proxyBuilder = - new ActorProxyBuilder(actorType, ActorProxy.class, newActorClient()); + new ActorProxyBuilder(actorType, ActorProxy.class, deferClose(clientRun.newActorClient())); logger.debug("Creating actorId"); logger.debug("Building proxy"); proxy = proxyBuilder.build(actorId); diff --git a/sdk-tests/src/test/java/io/dapr/it/actors/ActorSdkResiliencyIT.java b/sdk-tests/src/test/java/io/dapr/it/actors/ActorSdkResiliencyIT.java index e8140d68c..c9b7f27b7 100644 --- a/sdk-tests/src/test/java/io/dapr/it/actors/ActorSdkResiliencyIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/actors/ActorSdkResiliencyIT.java @@ -14,9 +14,9 @@ package io.dapr.it.actors; import io.dapr.actors.ActorId; +import io.dapr.actors.client.ActorClient; import io.dapr.actors.client.ActorProxyBuilder; import io.dapr.client.DaprClient; -import io.dapr.client.DaprClientBuilder; import io.dapr.client.resiliency.ResiliencyOptions; import io.dapr.it.BaseIT; import io.dapr.it.DaprRun; @@ -75,22 +75,22 @@ public static void init() throws Exception { true, 60000); - demoActor = buildDemoActorProxy(null); - daprClient = new DaprClientBuilder().build(); + demoActor = buildDemoActorProxy(deferClose(daprRun.newActorClient())); + daprClient = daprRun.newDaprClientBuilder().build(); toxiProxyRun = new ToxiProxyRun(daprRun, LATENCY, JITTER); toxiProxyRun.start(); - toxiProxyRun.use(); - toxiDemoActor = buildDemoActorProxy(new ResiliencyOptions().setTimeout(TIMEOUT)); + + toxiDemoActor = buildDemoActorProxy( + toxiProxyRun.newActorClient(new ResiliencyOptions().setTimeout(TIMEOUT))); resilientDemoActor = buildDemoActorProxy( - new ResiliencyOptions().setTimeout(TIMEOUT).setMaxRetries(MAX_RETRIES)); + toxiProxyRun.newActorClient(new ResiliencyOptions().setTimeout(TIMEOUT).setMaxRetries(MAX_RETRIES))); oneRetryDemoActor = buildDemoActorProxy( - new ResiliencyOptions().setTimeout(TIMEOUT).setMaxRetries(1)); + toxiProxyRun.newActorClient(new ResiliencyOptions().setTimeout(TIMEOUT).setMaxRetries(1))); } - private static DemoActor buildDemoActorProxy(ResiliencyOptions resiliencyOptions) { - ActorProxyBuilder builder = - new ActorProxyBuilder(DemoActor.class, newActorClient(resiliencyOptions)); + private static DemoActor buildDemoActorProxy(ActorClient actorClient) { + ActorProxyBuilder builder = new ActorProxyBuilder(DemoActor.class, actorClient); return builder.build(ACTOR_ID); } diff --git a/sdk-tests/src/test/java/io/dapr/it/actors/ActorStateIT.java b/sdk-tests/src/test/java/io/dapr/it/actors/ActorStateIT.java index 534fd481d..67d6b9659 100644 --- a/sdk-tests/src/test/java/io/dapr/it/actors/ActorStateIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/actors/ActorStateIT.java @@ -16,19 +16,14 @@ import io.dapr.actors.ActorId; import io.dapr.actors.client.ActorProxy; import io.dapr.actors.client.ActorProxyBuilder; -import io.dapr.it.AppRun; import io.dapr.it.BaseIT; import io.dapr.it.DaprRun; import io.dapr.it.actors.services.springboot.StatefulActor; import io.dapr.it.actors.services.springboot.StatefulActorService; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.stream.Stream; - import static io.dapr.it.Retry.callWithRetry; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -38,51 +33,37 @@ public class ActorStateIT extends BaseIT { private static Logger logger = LoggerFactory.getLogger(ActorStateIT.class); - /** - * Parameters for this test. - * Param #1: useGrpc. - * @return Collection of parameter tuples. - */ - public static Stream data() { - return Stream.of( - Arguments.of(AppRun.AppProtocol.HTTP ), - Arguments.of(AppRun.AppProtocol.GRPC ) - ); - } - - @ParameterizedTest - @MethodSource("data") - public void writeReadState(AppRun.AppProtocol serviceAppProtocol) throws Exception { + @Test + public void writeReadState() throws Exception { logger.debug("Starting actor runtime ..."); // The call below will fail if service cannot start successfully. - DaprRun runtime = startDaprApp( + DaprRun run = startDaprApp( this.getClass().getSimpleName(), StatefulActorService.SUCCESS_MESSAGE, StatefulActorService.class, true, - 60000, - serviceAppProtocol); + 60000); String message = "This is a message to be saved and retrieved."; String name = "Jon Doe"; byte[] bytes = new byte[] { 0x1 }; ActorId actorId = new ActorId( - String.format("%d-%b", System.currentTimeMillis(), serviceAppProtocol)); + String.format("%d", System.currentTimeMillis())); String actorType = "StatefulActorTest"; logger.debug("Building proxy ..."); ActorProxyBuilder proxyBuilder = - new ActorProxyBuilder(actorType, ActorProxy.class, newActorClient()); + new ActorProxyBuilder(actorType, ActorProxy.class, deferClose(run.newActorClient())); ActorProxy proxy = proxyBuilder.build(actorId); // wating for actor to be activated - Thread.sleep(2000); + Thread.sleep(5000); // Validate conditional read works. callWithRetry(() -> { logger.debug("Invoking readMessage where data is not present yet ... "); String result = proxy.invokeMethod("readMessage", String.class).block(); assertNull(result); - }, 5000); + }, 10000); callWithRetry(() -> { logger.debug("Invoking writeMessage ... "); @@ -146,7 +127,7 @@ public void writeReadState(AppRun.AppProtocol serviceAppProtocol) throws Excepti Thread.sleep(10000); logger.debug("Stopping service ..."); - runtime.stop(); + run.stop(); logger.debug("Starting service ..."); DaprRun run2 = startDaprApp( @@ -154,11 +135,10 @@ public void writeReadState(AppRun.AppProtocol serviceAppProtocol) throws Excepti StatefulActorService.SUCCESS_MESSAGE, StatefulActorService.class, true, - 60000, - serviceAppProtocol); + 60000); // Need new proxy builder because the proxy builder holds the channel. - proxyBuilder = new ActorProxyBuilder(actorType, ActorProxy.class, newActorClient()); + proxyBuilder = new ActorProxyBuilder(actorType, ActorProxy.class, deferClose(run2.newActorClient())); ActorProxy newProxy = proxyBuilder.build(actorId); // wating for actor to be activated diff --git a/sdk-tests/src/test/java/io/dapr/it/actors/ActorTimerRecoveryIT.java b/sdk-tests/src/test/java/io/dapr/it/actors/ActorTimerRecoveryIT.java index 796aa4e66..809cd21a9 100644 --- a/sdk-tests/src/test/java/io/dapr/it/actors/ActorTimerRecoveryIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/actors/ActorTimerRecoveryIT.java @@ -59,7 +59,7 @@ public void timerRecoveryTest() throws Exception { logger.debug("Creating proxy builder"); ActorProxyBuilder proxyBuilder = - new ActorProxyBuilder(actorType, ActorProxy.class, newActorClient()); + new ActorProxyBuilder(actorType, ActorProxy.class, deferClose(runs.right.newActorClient())); logger.debug("Creating actorId"); ActorId actorId = new ActorId(UUID.randomUUID().toString()); logger.debug("Building proxy"); diff --git a/sdk-tests/src/test/java/io/dapr/it/actors/ActorTurnBasedConcurrencyIT.java b/sdk-tests/src/test/java/io/dapr/it/actors/ActorTurnBasedConcurrencyIT.java index adc7b36c3..dd021d98b 100644 --- a/sdk-tests/src/test/java/io/dapr/it/actors/ActorTurnBasedConcurrencyIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/actors/ActorTurnBasedConcurrencyIT.java @@ -80,7 +80,7 @@ public void cleanUpTestCase() { public void invokeOneActorMethodReminderAndTimer() throws Exception { System.out.println("Starting test 'actorTest1'"); - startDaprApp( + var run = startDaprApp( ActorTurnBasedConcurrencyIT.class.getSimpleName(), MyActorService.SUCCESS_MESSAGE, MyActorService.class, @@ -92,7 +92,7 @@ public void invokeOneActorMethodReminderAndTimer() throws Exception { logger.debug("Creating proxy builder"); ActorProxyBuilder proxyBuilder = - new ActorProxyBuilder(actorType, ActorProxy.class, newActorClient()); + new ActorProxyBuilder(actorType, ActorProxy.class, deferClose(run.newActorClient())); logger.debug("Creating actorId"); ActorId actorId1 = new ActorId(ACTOR_ID); logger.debug("Building proxy"); 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 index 462d22927..8b37c5ad3 100644 --- a/sdk-tests/src/test/java/io/dapr/it/api/ApiIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/api/ApiIT.java @@ -19,7 +19,7 @@ public void testShutdownAPI() throws Exception { // TODO(artursouza): change this to wait for the sidecar to be healthy (new method needed in DaprClient). Thread.sleep(3000); - try (DaprClient client = new DaprClientBuilder().build()) { + try (DaprClient client = run.newDaprClientBuilder().build()) { logger.info("Sending shutdown request."); client.shutdown().block(); diff --git a/sdk-tests/src/test/java/io/dapr/it/binding/http/BindingIT.java b/sdk-tests/src/test/java/io/dapr/it/binding/http/BindingIT.java index 610a55820..a22eb731b 100644 --- a/sdk-tests/src/test/java/io/dapr/it/binding/http/BindingIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/binding/http/BindingIT.java @@ -37,10 +37,10 @@ public class BindingIT extends BaseIT { @Test public void httpOutputBindingError() throws Exception { - startDaprApp( + var run = startDaprApp( this.getClass().getSimpleName() + "-httpoutputbinding-exception", 60000); - try(DaprClient client = new DaprClientBuilder().build()) { + try(DaprClient client = run.newDaprClientBuilder().build()) { // Validate error message callWithRetry(() -> { System.out.println("Checking exception handling for output binding ..."); @@ -60,10 +60,10 @@ public void httpOutputBindingError() throws Exception { @Test public void httpOutputBindingErrorIgnoredByComponent() throws Exception { - startDaprApp( + var run = startDaprApp( this.getClass().getSimpleName() + "-httpoutputbinding-ignore-error", 60000); - try(DaprClient client = new DaprClientBuilder().build()) { + try(DaprClient client = run.newDaprClientBuilder().build()) { // Validate error message callWithRetry(() -> { System.out.println("Checking exception handling for output binding ..."); @@ -92,7 +92,7 @@ public void inputOutputBinding() throws Exception { var bidingName = "sample123"; - try(DaprClient client = new DaprClientBuilder().build()) { + try(DaprClient client = daprRun.newDaprClientBuilder().build()) { callWithRetry(() -> { System.out.println("Checking if input binding is up before publishing events ..."); client.invokeBinding( diff --git a/sdk-tests/src/test/java/io/dapr/it/configuration/ConfigurationClientIT.java b/sdk-tests/src/test/java/io/dapr/it/configuration/ConfigurationClientIT.java index 02c5798de..ee1343467 100644 --- a/sdk-tests/src/test/java/io/dapr/it/configuration/ConfigurationClientIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/configuration/ConfigurationClientIT.java @@ -68,7 +68,7 @@ public class ConfigurationClientIT extends BaseIT { @BeforeAll public static void init() throws Exception { daprRun = startDaprApp(ConfigurationClientIT.class.getSimpleName(), 5000); - daprClient = new DaprClientBuilder().build(); + daprClient = daprRun.newDaprClientBuilder().build(); } @AfterAll diff --git a/sdk-tests/src/test/java/io/dapr/it/methodinvoke/grpc/MethodInvokeIT.java b/sdk-tests/src/test/java/io/dapr/it/methodinvoke/grpc/MethodInvokeIT.java index ed9609cc9..ea94d2136 100644 --- a/sdk-tests/src/test/java/io/dapr/it/methodinvoke/grpc/MethodInvokeIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/methodinvoke/grpc/MethodInvokeIT.java @@ -49,7 +49,7 @@ public void init() throws Exception { @Test public void testInvoke() throws Exception { - try (DaprClient client = new DaprClientBuilder().build()) { + try (DaprClient client = daprRun.newDaprClientBuilder().build()) { client.waitForSidecar(10000).block(); daprRun.waitForAppHealth(10000); @@ -81,7 +81,7 @@ public void testInvoke() throws Exception { @Test public void testInvokeTimeout() throws Exception { - try (DaprClient client = new DaprClientBuilder().withResiliencyOptions(RESILIENCY_OPTIONS).build()) { + try (DaprClient client = daprRun.newDaprClientBuilder().withResiliencyOptions(RESILIENCY_OPTIONS).build()) { client.waitForSidecar(10000).block(); daprRun.waitForAppHealth(10000); @@ -99,7 +99,7 @@ public void testInvokeTimeout() throws Exception { @Test public void testInvokeException() throws Exception { - try (DaprClient client = new DaprClientBuilder().build()) { + try (DaprClient client = daprRun.newDaprClientBuilder().build()) { client.waitForSidecar(10000).block(); daprRun.waitForAppHealth(10000); diff --git a/sdk-tests/src/test/java/io/dapr/it/methodinvoke/http/MethodInvokeIT.java b/sdk-tests/src/test/java/io/dapr/it/methodinvoke/http/MethodInvokeIT.java index 1b5ab7577..ba7b485ca 100644 --- a/sdk-tests/src/test/java/io/dapr/it/methodinvoke/http/MethodInvokeIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/methodinvoke/http/MethodInvokeIT.java @@ -48,7 +48,7 @@ public void testInvoke() throws Exception { // At this point, it is guaranteed that the service above is running and all ports being listened to. - try (DaprClient client = new DaprClientBuilder().build()) { + try (DaprClient client = daprRun.newDaprClientBuilder().build()) { client.waitForSidecar(10000).block(); for (int i = 0; i < NUM_MESSAGES; i++) { String message = String.format("This is message #%d", i); @@ -74,7 +74,7 @@ public void testInvoke() throws Exception { @Test public void testInvokeWithObjects() throws Exception { - try (DaprClient client = new DaprClientBuilder().build()) { + try (DaprClient client = daprRun.newDaprClientBuilder().build()) { client.waitForSidecar(10000).block(); for (int i = 0; i < NUM_MESSAGES; i++) { Person person = new Person(); @@ -110,7 +110,7 @@ public void testInvokeWithObjects() throws Exception { @Test public void testInvokeTimeout() throws Exception { - try (DaprClient client = new DaprClientBuilder().build()) { + try (DaprClient client = daprRun.newDaprClientBuilder().build()) { client.waitForSidecar(10000).block(); long started = System.currentTimeMillis(); String message = assertThrows(IllegalStateException.class, () -> { @@ -127,7 +127,7 @@ public void testInvokeTimeout() throws Exception { @Test public void testInvokeException() throws Exception { - try (DaprClient client = new DaprClientBuilder().build()) { + try (DaprClient client = daprRun.newDaprClientBuilder().build()) { client.waitForSidecar(10000).block(); MethodInvokeServiceProtos.SleepRequest req = MethodInvokeServiceProtos.SleepRequest.newBuilder().setSeconds(-9).build(); DaprException exception = assertThrows(DaprException.class, () -> diff --git a/sdk-tests/src/test/java/io/dapr/it/pubsub/http/PubSubIT.java b/sdk-tests/src/test/java/io/dapr/it/pubsub/http/PubSubIT.java index 347bd64de..f34eed33f 100644 --- a/sdk-tests/src/test/java/io/dapr/it/pubsub/http/PubSubIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/pubsub/http/PubSubIT.java @@ -104,7 +104,7 @@ public void publishPubSubNotFound() throws Exception { this.getClass().getSimpleName(), 60000)); - try (DaprClient client = new DaprClientBuilder().build()) { + try (DaprClient client = daprRun.newDaprClientBuilder().build()) { assertThrowsDaprExceptionWithReason( "INVALID_ARGUMENT", "INVALID_ARGUMENT: pubsub unknown pubsub is not found", @@ -119,7 +119,7 @@ public void testBulkPublishPubSubNotFound() throws Exception { this.getClass().getSimpleName(), 60000)); - try (DaprPreviewClient client = new DaprClientBuilder().buildPreviewClient()) { + try (DaprPreviewClient client = daprRun.newDaprClientBuilder().buildPreviewClient()) { assertThrowsDaprException( "INVALID_ARGUMENT", "INVALID_ARGUMENT: pubsub unknown pubsub is not found", @@ -151,8 +151,8 @@ public String getContentType() { return "application/json"; } }; - try (DaprClient client = new DaprClientBuilder().withObjectSerializer(serializer).build(); - DaprPreviewClient previewClient = new DaprClientBuilder().withObjectSerializer(serializer).buildPreviewClient()) { + try (DaprClient client = daprRun.newDaprClientBuilder().withObjectSerializer(serializer).build(); + DaprPreviewClient previewClient = daprRun.newDaprClientBuilder().withObjectSerializer(serializer).buildPreviewClient()) { // Only for the gRPC test // Send a multiple messages on one topic in messagebus pubsub via publishEvents API. List messages = new ArrayList<>(); @@ -282,7 +282,7 @@ public String getContentType() { }; // Send a batch of messages on one topic - try (DaprClient client = new DaprClientBuilder().withObjectSerializer(serializer).build()) { + try (DaprClient client = daprRun.newDaprClientBuilder().withObjectSerializer(serializer).build()) { for (int i = 0; i < NUM_MESSAGES; i++) { String message = String.format("This is message #%d on topic %s", i, TOPIC_NAME); //Publishing messages @@ -494,7 +494,7 @@ public String getContentType() { return "application/octet-stream"; } }; - try (DaprClient client = new DaprClientBuilder().withObjectSerializer(serializer).build()) { + try (DaprClient client = daprRun.newDaprClientBuilder().withObjectSerializer(serializer).build()) { client.publishEvent( PUBSUB_NAME, BINARY_TOPIC_NAME, @@ -504,7 +504,7 @@ public String getContentType() { Thread.sleep(3000); - try (DaprClient client = new DaprClientBuilder().build()) { + try (DaprClient client = daprRun.newDaprClientBuilder().build()) { callWithRetry(() -> { System.out.println("Checking results for topic " + BINARY_TOPIC_NAME); final List messages = client.invokeMethod( @@ -526,7 +526,7 @@ public void testPubSubTTLMetadata() throws Exception { 60000)); // Send a batch of messages on one topic, all to be expired in 1 second. - try (DaprClient client = new DaprClientBuilder().build()) { + try (DaprClient client = daprRun.newDaprClientBuilder().build()) { for (int i = 0; i < NUM_MESSAGES; i++) { String message = String.format("This is message #%d on topic %s", i, TTL_TOPIC_NAME); //Publishing messages @@ -555,7 +555,7 @@ public void testPubSubTTLMetadata() throws Exception { Thread.sleep(5000); final String appId = daprRun.getAppName(); - try (DaprClient client = new DaprClientBuilder().build()) { + try (DaprClient client = daprRun.newDaprClientBuilder().build()) { callWithRetry(() -> { System.out.println("Checking results for topic " + TTL_TOPIC_NAME); final List messages = client.invokeMethod(appId, "messages/" + TTL_TOPIC_NAME, null, HttpExtension.GET, List.class).block(); @@ -576,7 +576,7 @@ public void testPubSubBulkSubscribe() throws Exception { 60000)); // Send a batch of messages on one topic. - try (DaprClient client = new DaprClientBuilder().build()) { + try (DaprClient client = daprRun.newDaprClientBuilder().build()) { for (int i = 0; i < NUM_MESSAGES; i++) { String message = String.format("This is message #%d on topic %s", i, BULK_SUB_TOPIC_NAME); // Publishing messages @@ -590,7 +590,7 @@ public void testPubSubBulkSubscribe() throws Exception { Thread.sleep(5000); final String appId = daprRun.getAppName(); - try (DaprClient client = new DaprClientBuilder().build()) { + try (DaprClient client = daprRun.newDaprClientBuilder().build()) { callWithRetry(() -> { System.out.println("Checking results for topic " + BULK_SUB_TOPIC_NAME); @@ -643,7 +643,7 @@ public void testLongValues() throws Exception { values.add(val); } Iterator valuesIt = values.iterator(); - try (DaprClient client = new DaprClientBuilder().build()) { + try (DaprClient client = daprRun.newDaprClientBuilder().build()) { for (int i = 0; i < NUM_MESSAGES; i++) { ConvertToLong value = valuesIt.next(); System.out.println("The long value sent " + value.getValue()); @@ -665,7 +665,7 @@ public void testLongValues() throws Exception { } Set actual = new HashSet<>(); - try (DaprClient client = new DaprClientBuilder().build()) { + try (DaprClient client = daprRun.newDaprClientBuilder().build()) { callWithRetry(() -> { System.out.println("Checking results for topic " + LONG_TOPIC_NAME); final List> messages = client.invokeMethod( diff --git a/sdk-tests/src/test/java/io/dapr/it/resiliency/SdkResiliencyIT.java b/sdk-tests/src/test/java/io/dapr/it/resiliency/SdkResiliencyIT.java index c3bdc7195..723e40b2a 100644 --- a/sdk-tests/src/test/java/io/dapr/it/resiliency/SdkResiliencyIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/resiliency/SdkResiliencyIT.java @@ -63,22 +63,21 @@ public class SdkResiliencyIT extends BaseIT { @BeforeAll public static void init() throws Exception { DaprRun daprRun = startDaprApp(SdkResiliencyIT.class.getSimpleName(), 5000); - daprClient = new DaprClientBuilder().build(); + daprClient = daprRun.newDaprClientBuilder().build(); daprClient.waitForSidecar(8000).block(); toxiProxyRun = new ToxiProxyRun(daprRun, LATENCY, JITTER); toxiProxyRun.start(); - toxiProxyRun.use(); - daprToxiClient = new DaprClientBuilder() + daprToxiClient = toxiProxyRun.newDaprClientBuilder() .withResiliencyOptions( new ResiliencyOptions().setTimeout(TIMEOUT)) .build(); - daprResilientClient = new DaprClientBuilder() + daprResilientClient = toxiProxyRun.newDaprClientBuilder() .withResiliencyOptions( new ResiliencyOptions().setTimeout(TIMEOUT).setMaxRetries(MAX_RETRIES)) .build(); - daprRetriesOnceClient = new DaprClientBuilder() + daprRetriesOnceClient = toxiProxyRun.newDaprClientBuilder() .withResiliencyOptions( new ResiliencyOptions().setTimeout(TIMEOUT).setMaxRetries(1)) .build(); diff --git a/sdk-tests/src/test/java/io/dapr/it/secrets/SecretsClientIT.java b/sdk-tests/src/test/java/io/dapr/it/secrets/SecretsClientIT.java index fc6260a68..23f05957b 100644 --- a/sdk-tests/src/test/java/io/dapr/it/secrets/SecretsClientIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/secrets/SecretsClientIT.java @@ -75,7 +75,7 @@ public static void init() throws Exception { @BeforeEach public void setup() { - this.daprClient = new DaprClientBuilder().build(); + this.daprClient = daprRun.newDaprClientBuilder().build(); } @AfterEach diff --git a/sdk-tests/src/test/java/io/dapr/it/state/GRPCStateClientIT.java b/sdk-tests/src/test/java/io/dapr/it/state/GRPCStateClientIT.java index 1c77d93d2..5254e0b06 100644 --- a/sdk-tests/src/test/java/io/dapr/it/state/GRPCStateClientIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/state/GRPCStateClientIT.java @@ -37,7 +37,7 @@ public class GRPCStateClientIT extends AbstractStateClientIT { @BeforeAll public static void init() throws Exception { daprRun = startDaprApp(GRPCStateClientIT.class.getSimpleName(), 5000); - daprClient = new DaprClientBuilder().build(); + daprClient = daprRun.newDaprClientBuilder().build(); } @AfterAll diff --git a/sdk-tests/src/test/java/io/dapr/it/tracing/grpc/TracingIT.java b/sdk-tests/src/test/java/io/dapr/it/tracing/grpc/TracingIT.java index 76df40044..256347398 100644 --- a/sdk-tests/src/test/java/io/dapr/it/tracing/grpc/TracingIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/tracing/grpc/TracingIT.java @@ -47,7 +47,7 @@ public void testInvoke() throws Exception { String spanName = UUID.randomUUID().toString(); Span span = tracer.spanBuilder(spanName).setSpanKind(SpanKind.CLIENT).startSpan(); - try (DaprClient client = new DaprClientBuilder().build()) { + try (DaprClient client = daprRun.newDaprClientBuilder().build()) { client.waitForSidecar(10000).block(); try (Scope scope = span.makeCurrent()) { SleepRequest req = SleepRequest.newBuilder().setSeconds(1).build(); diff --git a/sdk-tests/src/test/java/io/dapr/it/tracing/http/TracingIT.java b/sdk-tests/src/test/java/io/dapr/it/tracing/http/TracingIT.java index a4c75d140..3285d2ca8 100644 --- a/sdk-tests/src/test/java/io/dapr/it/tracing/http/TracingIT.java +++ b/sdk-tests/src/test/java/io/dapr/it/tracing/http/TracingIT.java @@ -46,7 +46,7 @@ public void testInvoke() throws Exception { String spanName = UUID.randomUUID().toString(); Span span = tracer.spanBuilder(spanName).setSpanKind(SpanKind.CLIENT).startSpan(); - try (DaprClient client = new DaprClientBuilder().build()) { + try (DaprClient client = daprRun.newDaprClientBuilder().build()) { client.waitForSidecar(10000).block(); try (Scope scope = span.makeCurrent()) { client.invokeMethod(daprRun.getAppName(), "sleep", 1, HttpExtension.POST) diff --git a/sdk/src/main/java/io/dapr/client/DaprClientBuilder.java b/sdk/src/main/java/io/dapr/client/DaprClientBuilder.java index a31276b9d..ad67eed8c 100644 --- a/sdk/src/main/java/io/dapr/client/DaprClientBuilder.java +++ b/sdk/src/main/java/io/dapr/client/DaprClientBuilder.java @@ -117,12 +117,24 @@ public DaprClientBuilder withResiliencyOptions(ResiliencyOptions options) { * @param property that we want to override * @param value the value of such property * @return an instance of the setup Client - */ + */ public DaprClientBuilder withPropertyOverride(Property property, String value) { this.propertyOverrides.put(property.getName(), value); return this; } + /** + * Allow to set up properties override for static properties. + * @param overrides properties to override + * @return an instance of the setup Client + */ + public DaprClientBuilder withPropertyOverrides(Map, String> overrides) { + for (final Map.Entry, String> override : overrides.entrySet()) { + this.propertyOverrides.put(override.getKey().getName(), override.getValue()); + } + return this; + } + /** * Build an instance of the Client based on the provided setup. * diff --git a/sdk/src/main/java/io/dapr/client/DaprTracingInterceptor.java b/sdk/src/main/java/io/dapr/client/DaprTracingInterceptor.java deleted file mode 100644 index 20f6d1c06..000000000 --- a/sdk/src/main/java/io/dapr/client/DaprTracingInterceptor.java +++ /dev/null @@ -1,48 +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.client; - -import io.grpc.CallOptions; -import io.grpc.Channel; -import io.grpc.ClientCall; -import io.grpc.ClientInterceptor; -import io.grpc.MethodDescriptor; -import reactor.util.context.ContextView; - -/** - * Injects tracing headers to gRPC metadata. - */ -public class DaprTracingInterceptor implements ClientInterceptor { - - private final io.dapr.internal.grpc.interceptors.DaprTracingInterceptor delegate; - - /** - * Creates an instance of the injector for gRPC context from Reactor's context. - * @param context Reactor's context - */ - public DaprTracingInterceptor(ContextView context) { - this.delegate = new io.dapr.internal.grpc.interceptors.DaprTracingInterceptor(context); - } - - /** - * {@inheritDoc} - */ - @Override - public ClientCall interceptCall( - MethodDescriptor methodDescriptor, - CallOptions callOptions, - Channel channel) { - return this.delegate.interceptCall(methodDescriptor, callOptions, channel); - } -} diff --git a/sdk/src/main/java/io/dapr/config/Properties.java b/sdk/src/main/java/io/dapr/config/Properties.java index 38a88b767..445ae716b 100644 --- a/sdk/src/main/java/io/dapr/config/Properties.java +++ b/sdk/src/main/java/io/dapr/config/Properties.java @@ -18,8 +18,10 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.time.Duration; +import java.util.Arrays; import java.util.Collections; import java.util.Map; +import java.util.stream.Collectors; /** * Global properties for Dapr's SDK, using Supplier so they are dynamically resolved. @@ -189,10 +191,17 @@ public Properties() { /** * Creates a new instance to handle Properties per instance. - * @param overrides to override static properties - */ - public Properties(Map overrides) { - this.overrides = Collections.unmodifiableMap(overrides); + * @param overridesInput to override static properties + */ + public Properties(Map overridesInput) { + this.overrides = overridesInput == null ? Collections.emptyMap() : + Collections.unmodifiableMap(overridesInput.entrySet().stream() + .filter(e -> e.getKey() != null) + .filter(e -> e.getValue() != null) + .collect(Collectors.toMap( + entry -> entry.getKey().toString(), + entry -> entry.getValue() + ))); } /** diff --git a/sdk/src/main/java/io/dapr/config/Property.java b/sdk/src/main/java/io/dapr/config/Property.java index f0e54f2e7..c24ab5384 100644 --- a/sdk/src/main/java/io/dapr/config/Property.java +++ b/sdk/src/main/java/io/dapr/config/Property.java @@ -58,6 +58,14 @@ public String getName() { return this.name; } + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return this.name; + } + /** * Gets the environment variable's name. * @return Name. diff --git a/sdk/src/test/java/io/dapr/client/DaprClientBuilderTest.java b/sdk/src/test/java/io/dapr/client/DaprClientBuilderTest.java index 4a972a019..dbc8ffae1 100644 --- a/sdk/src/test/java/io/dapr/client/DaprClientBuilderTest.java +++ b/sdk/src/test/java/io/dapr/client/DaprClientBuilderTest.java @@ -41,7 +41,6 @@ public void build() { @Test public void buildWithOverrideSidecarIP() { - DaprClientBuilder daprClientBuilder = new DaprClientBuilder(); daprClientBuilder.withPropertyOverride(Properties.SIDECAR_IP, "unknown-host"); DaprClient daprClient = daprClientBuilder.build(); diff --git a/sdk/src/test/java/io/dapr/client/DaprClientHttpTest.java b/sdk/src/test/java/io/dapr/client/DaprClientHttpTest.java index fae617c69..c09a00124 100644 --- a/sdk/src/test/java/io/dapr/client/DaprClientHttpTest.java +++ b/sdk/src/test/java/io/dapr/client/DaprClientHttpTest.java @@ -124,7 +124,6 @@ public void waitForSidecarTimeOutHealthCheck() throws Exception { @Test public void waitForSidecarBadHealthCheck() throws Exception { int port = findFreePort(); - System.setProperty(Properties.HTTP_PORT.getName(), Integer.toString(port)); daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), port, daprApiToken, okHttpClient); DaprClient daprClientHttp = buildDaprClient(daprHttp); @@ -149,7 +148,6 @@ public void waitForSidecarBadHealthCheck() throws Exception { @Test public void waitForSidecarSlowSuccessfulHealthCheck() throws Exception { int port = findFreePort(); - System.setProperty(Properties.HTTP_PORT.getName(), Integer.toString(port)); daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), port, daprApiToken, okHttpClient); DaprClient daprClientHttp = buildDaprClient(daprHttp); @@ -178,7 +176,6 @@ public void waitForSidecarSlowSuccessfulHealthCheck() throws Exception { @Test public void waitForSidecarOK() throws Exception { int port = findFreePort(); - System.setProperty(Properties.HTTP_PORT.getName(), Integer.toString(port)); daprHttp = new DaprHttp(sidecarIp, port, daprApiToken, okHttpClient); DaprClient daprClientHttp = buildDaprClient(daprHttp); @@ -201,7 +198,6 @@ public void waitForSidecarTimeoutOK() throws Exception { .respond(204); try (ServerSocket serverSocket = new ServerSocket(0)) { final int port = serverSocket.getLocalPort(); - System.setProperty(Properties.HTTP_PORT.getName(), Integer.toString(port)); Thread t = new Thread(() -> { try { try (Socket socket = serverSocket.accept()) { diff --git a/sdk/src/test/java/io/dapr/client/DaprHttpTest.java b/sdk/src/test/java/io/dapr/client/DaprHttpTest.java index b65270ba5..bf21e6419 100644 --- a/sdk/src/test/java/io/dapr/client/DaprHttpTest.java +++ b/sdk/src/test/java/io/dapr/client/DaprHttpTest.java @@ -122,9 +122,7 @@ public void invokeMethod() throws IOException { @Test public void invokeMethodIPv6() throws IOException { - String prevSidecarIp = sidecarIp; - System.setProperty(Properties.SIDECAR_IP.getName(), "2001:db8:3333:4444:5555:6666:7777:8888"); - sidecarIp = formatIpAddress(Properties.SIDECAR_IP.get()); + sidecarIp = formatIpAddress("2001:db8:3333:4444:5555:6666:7777:8888"); Map headers = new HashMap<>(); headers.put("content-type", "text/html"); headers.put("header1", "value1"); @@ -132,7 +130,6 @@ public void invokeMethodIPv6() throws IOException { .post("http://" + sidecarIp + ":3500/v1.0/state") .respond(serializer.serialize(EXPECTED_RESULT)); DaprHttp daprHttp = new DaprHttp(sidecarIp, 3500, daprTokenApi, okHttpClient); - System.setProperty(Properties.SIDECAR_IP.getName(), prevSidecarIp); Mono mono = daprHttp.invokeApi("POST", "v1.0/state".split("/"), null, (byte[]) null, headers, Context.empty()); DaprHttp.Response response = mono.block(); diff --git a/sdk/src/test/java/io/dapr/utils/NetworkUtilsTest.java b/sdk/src/test/java/io/dapr/utils/NetworkUtilsTest.java index 878d249f6..4d0097ce5 100644 --- a/sdk/src/test/java/io/dapr/utils/NetworkUtilsTest.java +++ b/sdk/src/test/java/io/dapr/utils/NetworkUtilsTest.java @@ -8,19 +8,25 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + public class NetworkUtilsTest { private final int defaultGrpcPort = 4000; private final String defaultSidecarIP = "127.0.0.1"; private ManagedChannel channel; - private Properties properties = new Properties(); + private Map propertiesOverride; @BeforeEach public void setUp() { - System.setProperty(Properties.GRPC_PORT.getName(), Integer.toString(defaultGrpcPort)); - System.setProperty(Properties.SIDECAR_IP.getName(), defaultSidecarIP); - System.setProperty(Properties.GRPC_ENDPOINT.getName(), ""); + propertiesOverride = new HashMap<>(){{ + put(Properties.GRPC_PORT.getName(), Integer.toString(defaultGrpcPort)); + put(Properties.SIDECAR_IP.getName(), defaultSidecarIP); + put(Properties.GRPC_ENDPOINT.getName(), ""); + }}; } @AfterEach @@ -32,7 +38,7 @@ public void tearDown() { @Test public void testBuildGrpcManagedChannel() { - channel = NetworkUtils.buildGrpcManagedChannel(properties); + channel = NetworkUtils.buildGrpcManagedChannel(new Properties(propertiesOverride)); String expectedAuthority = String.format("%s:%s", defaultSidecarIP, defaultGrpcPort); Assertions.assertEquals(expectedAuthority, channel.authority()); @@ -40,8 +46,8 @@ public void testBuildGrpcManagedChannel() { @Test public void testBuildGrpcManagedChannel_httpEndpointNoPort() { - System.setProperty(Properties.GRPC_ENDPOINT.getName(), "http://example.com"); - channel = NetworkUtils.buildGrpcManagedChannel(properties); + propertiesOverride.put(Properties.GRPC_ENDPOINT.getName(), "http://example.com"); + channel = NetworkUtils.buildGrpcManagedChannel(new Properties(propertiesOverride)); String expectedAuthority = "example.com:80"; Assertions.assertEquals(expectedAuthority, channel.authority()); @@ -49,8 +55,8 @@ public void testBuildGrpcManagedChannel_httpEndpointNoPort() { @Test public void testBuildGrpcManagedChannel_httpEndpointWithPort() { - System.setProperty(Properties.GRPC_ENDPOINT.getName(), "http://example.com:3000"); - channel = NetworkUtils.buildGrpcManagedChannel(properties); + propertiesOverride.put(Properties.GRPC_ENDPOINT.getName(), "http://example.com:3000"); + channel = NetworkUtils.buildGrpcManagedChannel(new Properties(propertiesOverride)); String expectedAuthority = "example.com:3000"; Assertions.assertEquals(expectedAuthority, channel.authority()); @@ -58,8 +64,8 @@ public void testBuildGrpcManagedChannel_httpEndpointWithPort() { @Test public void testBuildGrpcManagedChannel_httpsEndpointNoPort() { - System.setProperty(Properties.GRPC_ENDPOINT.getName(), "https://example.com"); - channel = NetworkUtils.buildGrpcManagedChannel(properties); + propertiesOverride.put(Properties.GRPC_ENDPOINT.getName(), "https://example.com"); + channel = NetworkUtils.buildGrpcManagedChannel(new Properties(propertiesOverride)); String expectedAuthority = "example.com:443"; Assertions.assertEquals(expectedAuthority, channel.authority()); @@ -67,8 +73,8 @@ public void testBuildGrpcManagedChannel_httpsEndpointNoPort() { @Test public void testBuildGrpcManagedChannel_httpsEndpointWithPort() { - System.setProperty(Properties.GRPC_ENDPOINT.getName(), "https://example.com:3000"); - channel = NetworkUtils.buildGrpcManagedChannel(properties); + propertiesOverride.put(Properties.GRPC_ENDPOINT.getName(), "https://example.com:3000"); + channel = NetworkUtils.buildGrpcManagedChannel(new Properties(propertiesOverride)); String expectedAuthority = "example.com:3000"; Assertions.assertEquals(expectedAuthority, channel.authority()); @@ -138,8 +144,8 @@ private static void testGrpcEndpointParsingScenario( String expectedEndpoint, boolean expectSecure ) { - System.setProperty(Properties.GRPC_ENDPOINT.getName(), grpcEndpointEnvValue); - var settings = NetworkUtils.GrpcEndpointSettings.parse(new Properties()); + var override = Collections.singletonMap(Properties.GRPC_ENDPOINT.getName(), grpcEndpointEnvValue); + var settings = NetworkUtils.GrpcEndpointSettings.parse(new Properties(override)); Assertions.assertEquals(expectedEndpoint, settings.endpoint); Assertions.assertEquals(expectSecure, settings.secure); @@ -147,8 +153,8 @@ private static void testGrpcEndpointParsingScenario( private static void testGrpcEndpointParsingErrorScenario(String grpcEndpointEnvValue) { try { - System.setProperty(Properties.GRPC_ENDPOINT.getName(), grpcEndpointEnvValue); - NetworkUtils.GrpcEndpointSettings.parse(new Properties()); + var override = Collections.singletonMap(Properties.GRPC_ENDPOINT.getName(), grpcEndpointEnvValue); + NetworkUtils.GrpcEndpointSettings.parse(new Properties(override)); Assert.fail(); } catch (IllegalArgumentException e) { // Expected