mirror of https://github.com/dapr/java-sdk.git
Refactoring properties and constants. (#333)
This commit is contained in:
parent
7b174d88e8
commit
fe027d0c54
|
@ -6,7 +6,6 @@
|
|||
package io.dapr.actors.client;
|
||||
|
||||
import io.dapr.client.DaprHttp;
|
||||
import io.dapr.utils.Constants;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
|
@ -16,6 +15,16 @@ import reactor.core.publisher.Mono;
|
|||
*/
|
||||
class DaprHttpClient implements DaprClient {
|
||||
|
||||
/**
|
||||
* Base URL for Dapr Actor APIs.
|
||||
*/
|
||||
private static final String ACTORS_BASE_URL = DaprHttp.API_VERSION + "/" + "actors";
|
||||
|
||||
/**
|
||||
* String format for Actors method invocation relative url.
|
||||
*/
|
||||
private static final String ACTOR_METHOD_RELATIVE_URL_FORMAT = ACTORS_BASE_URL + "/%s/%s/method/%s";
|
||||
|
||||
/**
|
||||
* The HTTP client to be used.
|
||||
*
|
||||
|
@ -37,7 +46,7 @@ class DaprHttpClient implements DaprClient {
|
|||
*/
|
||||
@Override
|
||||
public Mono<byte[]> invokeActorMethod(String actorType, String actorId, String methodName, byte[] jsonPayload) {
|
||||
String url = String.format(Constants.ACTOR_METHOD_RELATIVE_URL_FORMAT, actorType, actorId, methodName);
|
||||
String url = String.format(ACTOR_METHOD_RELATIVE_URL_FORMAT, actorType, actorId, methodName);
|
||||
Mono<DaprHttp.Response> responseMono =
|
||||
this.client.invokeApi(DaprHttp.HttpMethods.POST.name(), url, null, jsonPayload, null, null);
|
||||
return responseMono.map(r -> r.getBody());
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
package io.dapr.actors.runtime;
|
||||
|
||||
import io.dapr.client.DaprHttp;
|
||||
import io.dapr.utils.Constants;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
|
@ -14,6 +13,31 @@ import reactor.core.publisher.Mono;
|
|||
*/
|
||||
class DaprHttpClient implements DaprClient {
|
||||
|
||||
/**
|
||||
* Base URL for Dapr Actor APIs.
|
||||
*/
|
||||
private static final String ACTORS_BASE_URL = DaprHttp.API_VERSION + "/" + "actors";
|
||||
|
||||
/**
|
||||
* String format for Actors state management relative url.
|
||||
*/
|
||||
private static final String ACTOR_STATE_KEY_RELATIVE_URL_FORMAT = ACTORS_BASE_URL + "/%s/%s/state/%s";
|
||||
|
||||
/**
|
||||
* String format for Actors state management relative url.
|
||||
*/
|
||||
private static final String ACTOR_STATE_RELATIVE_URL_FORMAT = ACTORS_BASE_URL + "/%s/%s/state";
|
||||
|
||||
/**
|
||||
* String format for Actors reminder registration relative url.
|
||||
*/
|
||||
private static final String ACTOR_REMINDER_RELATIVE_URL_FORMAT = ACTORS_BASE_URL + "/%s/%s/reminders/%s";
|
||||
|
||||
/**
|
||||
* String format for Actors timer registration relative url.
|
||||
*/
|
||||
private static final String ACTOR_TIMER_RELATIVE_URL_FORMAT = ACTORS_BASE_URL + "/%s/%s/timers/%s";
|
||||
|
||||
/**
|
||||
* The HTTP client to be used.
|
||||
*
|
||||
|
@ -35,7 +59,7 @@ class DaprHttpClient implements DaprClient {
|
|||
*/
|
||||
@Override
|
||||
public Mono<byte[]> getActorState(String actorType, String actorId, String keyName) {
|
||||
String url = String.format(Constants.ACTOR_STATE_KEY_RELATIVE_URL_FORMAT, actorType, actorId, keyName);
|
||||
String url = String.format(ACTOR_STATE_KEY_RELATIVE_URL_FORMAT, actorType, actorId, keyName);
|
||||
Mono<DaprHttp.Response> responseMono =
|
||||
this.client.invokeApi(DaprHttp.HttpMethods.GET.name(), url, null, "", null, null);
|
||||
return responseMono.map(r -> {
|
||||
|
@ -52,7 +76,7 @@ class DaprHttpClient implements DaprClient {
|
|||
*/
|
||||
@Override
|
||||
public Mono<Void> saveActorStateTransactionally(String actorType, String actorId, byte[] data) {
|
||||
String url = String.format(Constants.ACTOR_STATE_RELATIVE_URL_FORMAT, actorType, actorId);
|
||||
String url = String.format(ACTOR_STATE_RELATIVE_URL_FORMAT, actorType, actorId);
|
||||
return this.client.invokeApi(DaprHttp.HttpMethods.PUT.name(), url, null, data, null, null).then();
|
||||
}
|
||||
|
||||
|
@ -61,7 +85,7 @@ class DaprHttpClient implements DaprClient {
|
|||
*/
|
||||
@Override
|
||||
public Mono<Void> registerActorReminder(String actorType, String actorId, String reminderName, byte[] data) {
|
||||
String url = String.format(Constants.ACTOR_REMINDER_RELATIVE_URL_FORMAT, actorType, actorId, reminderName);
|
||||
String url = String.format(ACTOR_REMINDER_RELATIVE_URL_FORMAT, actorType, actorId, reminderName);
|
||||
return this.client.invokeApi(DaprHttp.HttpMethods.PUT.name(), url, null, data, null, null).then();
|
||||
}
|
||||
|
||||
|
@ -70,7 +94,7 @@ class DaprHttpClient implements DaprClient {
|
|||
*/
|
||||
@Override
|
||||
public Mono<Void> unregisterActorReminder(String actorType, String actorId, String reminderName) {
|
||||
String url = String.format(Constants.ACTOR_REMINDER_RELATIVE_URL_FORMAT, actorType, actorId, reminderName);
|
||||
String url = String.format(ACTOR_REMINDER_RELATIVE_URL_FORMAT, actorType, actorId, reminderName);
|
||||
return this.client.invokeApi(DaprHttp.HttpMethods.DELETE.name(), url, null, null, null).then();
|
||||
}
|
||||
|
||||
|
@ -79,7 +103,7 @@ class DaprHttpClient implements DaprClient {
|
|||
*/
|
||||
@Override
|
||||
public Mono<Void> registerActorTimer(String actorType, String actorId, String timerName, byte[] data) {
|
||||
String url = String.format(Constants.ACTOR_TIMER_RELATIVE_URL_FORMAT, actorType, actorId, timerName);
|
||||
String url = String.format(ACTOR_TIMER_RELATIVE_URL_FORMAT, actorType, actorId, timerName);
|
||||
return this.client.invokeApi(DaprHttp.HttpMethods.PUT.name(), url, null, data, null, null).then();
|
||||
}
|
||||
|
||||
|
@ -88,7 +112,7 @@ class DaprHttpClient implements DaprClient {
|
|||
*/
|
||||
@Override
|
||||
public Mono<Void> unregisterActorTimer(String actorType, String actorId, String timerName) {
|
||||
String url = String.format(Constants.ACTOR_TIMER_RELATIVE_URL_FORMAT, actorType, actorId, timerName);
|
||||
String url = String.format(ACTOR_TIMER_RELATIVE_URL_FORMAT, actorType, actorId, timerName);
|
||||
return this.client.invokeApi(DaprHttp.HttpMethods.DELETE.name(), url, null, null, null).then();
|
||||
}
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@ package io.dapr.actors.runtime;
|
|||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import io.dapr.actors.ActorId;
|
||||
import io.dapr.config.Properties;
|
||||
import io.dapr.serializer.DaprObjectSerializer;
|
||||
import io.dapr.serializer.DefaultObjectSerializer;
|
||||
import io.dapr.utils.Properties;
|
||||
import io.dapr.utils.TypeRef;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ package io.dapr.actors.client;
|
|||
|
||||
import io.dapr.client.DaprHttp;
|
||||
import io.dapr.client.DaprHttpProxy;
|
||||
import io.dapr.config.Properties;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.mock.Behavior;
|
||||
import okhttp3.mock.MockInterceptor;
|
||||
|
@ -38,7 +39,7 @@ public class DaprHttpClientTest {
|
|||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/actors/DemoActor/1/method/Payment")
|
||||
.respond(EXPECTED_RESULT);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(3000, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
DaprHttpClient = new DaprHttpClient(daprHttp);
|
||||
Mono<byte[]> mono =
|
||||
DaprHttpClient.invokeActorMethod("DemoActor", "1", "Payment", "".getBytes());
|
||||
|
|
|
@ -6,6 +6,7 @@ package io.dapr.actors.runtime;
|
|||
|
||||
import io.dapr.client.DaprHttp;
|
||||
import io.dapr.client.DaprHttpProxy;
|
||||
import io.dapr.config.Properties;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.mock.Behavior;
|
||||
import okhttp3.mock.MockInterceptor;
|
||||
|
@ -37,7 +38,7 @@ public class DaprHttpClientTest {
|
|||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/actors/DemoActor/1/state/order")
|
||||
.respond(EXPECTED_RESULT);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(3000, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
DaprHttpClient = new DaprHttpClient(daprHttp);
|
||||
Mono<byte[]> mono = DaprHttpClient.getActorState("DemoActor", "1", "order");
|
||||
assertEquals(new String(mono.block()), EXPECTED_RESULT);
|
||||
|
@ -49,7 +50,7 @@ public class DaprHttpClientTest {
|
|||
mockInterceptor.addRule()
|
||||
.put("http://127.0.0.1:3000/v1.0/actors/DemoActor/1/state")
|
||||
.respond(EXPECTED_RESULT);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(3000, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
DaprHttpClient = new DaprHttpClient(daprHttp);
|
||||
Mono<Void> mono =
|
||||
DaprHttpClient.saveActorStateTransactionally("DemoActor", "1", "".getBytes());
|
||||
|
@ -61,7 +62,7 @@ public class DaprHttpClientTest {
|
|||
mockInterceptor.addRule()
|
||||
.put("http://127.0.0.1:3000/v1.0/actors/DemoActor/1/reminders/reminder")
|
||||
.respond(EXPECTED_RESULT);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(3000, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
DaprHttpClient = new DaprHttpClient(daprHttp);
|
||||
Mono<Void> mono =
|
||||
DaprHttpClient.registerActorReminder("DemoActor", "1", "reminder", "".getBytes());
|
||||
|
@ -73,7 +74,7 @@ public class DaprHttpClientTest {
|
|||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/actors/DemoActor/1/reminders/reminder")
|
||||
.respond(EXPECTED_RESULT);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(3000, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
DaprHttpClient = new DaprHttpClient(daprHttp);
|
||||
Mono<Void> mono = DaprHttpClient.unregisterActorReminder("DemoActor", "1", "reminder");
|
||||
assertNull(mono.block());
|
||||
|
@ -84,7 +85,7 @@ public class DaprHttpClientTest {
|
|||
mockInterceptor.addRule()
|
||||
.put("http://127.0.0.1:3000/v1.0/actors/DemoActor/1/timers/timer")
|
||||
.respond(EXPECTED_RESULT);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(3000, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
DaprHttpClient = new DaprHttpClient(daprHttp);
|
||||
Mono<Void> mono =
|
||||
DaprHttpClient.registerActorTimer("DemoActor", "1", "timer", "".getBytes());
|
||||
|
@ -96,7 +97,7 @@ public class DaprHttpClientTest {
|
|||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/actors/DemoActor/1/timers/timer")
|
||||
.respond(EXPECTED_RESULT);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(3000, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
DaprHttpClient = new DaprHttpClient(daprHttp);
|
||||
Mono<Void> mono = DaprHttpClient.unregisterActorTimer("DemoActor", "1", "timer");
|
||||
assertNull(mono.block());
|
||||
|
|
|
@ -9,8 +9,8 @@ import okhttp3.OkHttpClient;
|
|||
|
||||
public class DaprHttpProxy extends io.dapr.client.DaprHttp {
|
||||
|
||||
public DaprHttpProxy(int port, OkHttpClient httpClient) {
|
||||
super(port, httpClient);
|
||||
public DaprHttpProxy(String hostname, int port, OkHttpClient httpClient) {
|
||||
super(hostname, port, httpClient);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
package io.dapr.actors.runtime;
|
||||
|
||||
import io.dapr.client.DaprHttp;
|
||||
|
||||
/**
|
||||
* Exposes useful methods for IT in DaprClientHttp.
|
||||
*/
|
||||
public class DaprClientHttpUtils {
|
||||
|
||||
public static void unregisterActorReminder(
|
||||
DaprHttp client,
|
||||
String actorType,
|
||||
String actorId,
|
||||
String reminderName) throws Exception {
|
||||
new DaprHttpClient(client).unregisterActorReminder(actorType, actorId, reminderName).block();
|
||||
}
|
||||
}
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
package io.dapr.it;
|
||||
|
||||
import io.dapr.config.Properties;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Supplier;
|
||||
|
@ -171,8 +173,7 @@ public class DaprRun {
|
|||
private static void assertListeningOnPort(int port) {
|
||||
System.out.printf("Checking port %d ...\n", port);
|
||||
|
||||
java.net.SocketAddress socketAddress = new java.net.InetSocketAddress(io.dapr.utils.Constants.DEFAULT_HOSTNAME,
|
||||
port);
|
||||
java.net.SocketAddress socketAddress = new java.net.InetSocketAddress(Properties.SIDECAR_IP.get(), port);
|
||||
try (java.net.Socket socket = new java.net.Socket()) {
|
||||
socket.connect(socketAddress, 1000);
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -8,11 +8,11 @@ package io.dapr.it.actors;
|
|||
import io.dapr.actors.ActorId;
|
||||
import io.dapr.actors.client.ActorProxy;
|
||||
import io.dapr.actors.client.ActorProxyBuilder;
|
||||
import io.dapr.actors.runtime.DaprClientHttpUtils;
|
||||
import io.dapr.client.DaprHttp;
|
||||
import io.dapr.client.DaprHttpBuilder;
|
||||
import io.dapr.it.BaseIT;
|
||||
import io.dapr.it.actors.app.MyActorService;
|
||||
import io.dapr.utils.Constants;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -23,7 +23,6 @@ import java.util.ArrayList;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.dapr.it.Retry.callWithRetry;
|
||||
|
@ -34,10 +33,6 @@ public class ActorTurnBasedConcurrencyIT extends BaseIT {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(ActorTurnBasedConcurrencyIT.class);
|
||||
|
||||
private static final AtomicInteger atomicInteger = new AtomicInteger(1);
|
||||
|
||||
private final String BASE_URL = "actors/%s/%s";
|
||||
|
||||
private final String ACTOR_TYPE = "MyActorTest";
|
||||
private final String REMINDER_NAME = UUID.randomUUID().toString();
|
||||
private final String ACTOR_ID = "1";
|
||||
|
@ -45,16 +40,12 @@ public class ActorTurnBasedConcurrencyIT extends BaseIT {
|
|||
@After
|
||||
public void cleanUpTestCase() {
|
||||
// Delete the reminder in case the test failed, otherwise it may interfere with future tests since it is persisted.
|
||||
// It'll have this structure with different values: http://127.0.0.1:33997/v1.0/actors/MyActorTest/1/reminders/588e4adc-f902-4596-b12e-3d2955db68b6
|
||||
DaprHttp client = new DaprHttpBuilder().build();
|
||||
String url = String.format(Constants.ACTOR_REMINDER_RELATIVE_URL_FORMAT, ACTOR_TYPE, ACTOR_ID, REMINDER_NAME);
|
||||
|
||||
System.out.println("Invoking during cleanup");
|
||||
try {
|
||||
client.invokeApi(DaprHttp.HttpMethods.DELETE.name(), url, null, null, null).block();
|
||||
DaprClientHttpUtils.unregisterActorReminder(client, ACTOR_TYPE, ACTOR_ID, REMINDER_NAME);
|
||||
} catch(Exception e) {
|
||||
// informational only
|
||||
System.out.println("Caught " + e.toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,10 +5,9 @@
|
|||
|
||||
package io.dapr.client;
|
||||
|
||||
import io.dapr.config.Properties;
|
||||
import io.dapr.serializer.DaprObjectSerializer;
|
||||
import io.dapr.serializer.DefaultObjectSerializer;
|
||||
import io.dapr.utils.Constants;
|
||||
import io.dapr.utils.Properties;
|
||||
import io.dapr.v1.DaprGrpc;
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
|
@ -107,7 +106,8 @@ public class DaprClientBuilder {
|
|||
if (port <= 0) {
|
||||
throw new IllegalStateException("Invalid port.");
|
||||
}
|
||||
ManagedChannel channel = ManagedChannelBuilder.forAddress(Constants.DEFAULT_HOSTNAME, port).usePlaintext().build();
|
||||
ManagedChannel channel = ManagedChannelBuilder.forAddress(
|
||||
Properties.SIDECAR_IP.get(), port).usePlaintext().build();
|
||||
Closeable closeableChannel = () -> {
|
||||
if (channel != null && !channel.isShutdown()) {
|
||||
channel.shutdown();
|
||||
|
@ -128,7 +128,7 @@ public class DaprClientBuilder {
|
|||
throw new IllegalStateException("Invalid port.");
|
||||
}
|
||||
OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
|
||||
DaprHttp daprHttp = new DaprHttp(port, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), port, okHttpClient);
|
||||
return new DaprClientHttp(daprHttp, this.objectSerializer, this.stateSerializer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,9 +20,8 @@ import io.dapr.client.domain.Response;
|
|||
import io.dapr.client.domain.SaveStateRequest;
|
||||
import io.dapr.client.domain.State;
|
||||
import io.dapr.client.domain.StateOptions;
|
||||
import io.dapr.config.Properties;
|
||||
import io.dapr.serializer.DaprObjectSerializer;
|
||||
import io.dapr.utils.Constants;
|
||||
import io.dapr.utils.Properties;
|
||||
import io.dapr.utils.TypeRef;
|
||||
import io.dapr.v1.CommonProtos;
|
||||
import io.dapr.v1.DaprGrpc;
|
||||
|
@ -486,12 +485,12 @@ public class DaprClientGrpc extends AbstractDaprClient {
|
|||
SpanContext opencensusSpanContext = extractOpenCensusSpanContext(context);
|
||||
if (opencensusSpanContext != null) {
|
||||
byte[] grpcTraceBin = OPENCENSUS_BINARY_FORMAT.toByteArray(opencensusSpanContext);
|
||||
headers.put(Key.of("grpc-trace-bin", Metadata.BINARY_BYTE_MARSHALLER), grpcTraceBin);
|
||||
headers.put(Key.of(Headers.GRPC_TRACE_BIN, Metadata.BINARY_BYTE_MARSHALLER), grpcTraceBin);
|
||||
}
|
||||
|
||||
String daprApiToken = Properties.DAPR_API_TOKEN.get();
|
||||
String daprApiToken = Properties.API_TOKEN.get();
|
||||
if (daprApiToken != null) {
|
||||
headers.put(Key.of(Constants.DAPR_API_TOKEN_HEADER, Metadata.ASCII_STRING_MARSHALLER), daprApiToken);
|
||||
headers.put(Key.of(Headers.DAPR_API_TOKEN, Metadata.ASCII_STRING_MARSHALLER), daprApiToken);
|
||||
}
|
||||
|
||||
super.start(responseListener, headers);
|
||||
|
|
|
@ -18,13 +18,11 @@ import io.dapr.client.domain.State;
|
|||
import io.dapr.client.domain.StateOptions;
|
||||
import io.dapr.serializer.DaprObjectSerializer;
|
||||
import io.dapr.serializer.DefaultObjectSerializer;
|
||||
import io.dapr.utils.Constants;
|
||||
import io.dapr.utils.TypeRef;
|
||||
import io.grpc.Context;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -41,11 +39,41 @@ import java.util.Optional;
|
|||
*/
|
||||
public class DaprClientHttp extends AbstractDaprClient {
|
||||
|
||||
/**
|
||||
* Header for the conditional operation.
|
||||
*/
|
||||
private static final String HEADER_HTTP_ETAG_ID = "If-Match";
|
||||
|
||||
/**
|
||||
* Serializer for internal objects.
|
||||
*/
|
||||
private static final ObjectSerializer INTERNAL_SERIALIZER = new ObjectSerializer();
|
||||
|
||||
/**
|
||||
* Base path to invoke methods.
|
||||
*/
|
||||
public static final String INVOKE_PATH = DaprHttp.API_VERSION + "/invoke";
|
||||
|
||||
/**
|
||||
* Invoke Publish Path.
|
||||
*/
|
||||
public static final String PUBLISH_PATH = DaprHttp.API_VERSION + "/publish";
|
||||
|
||||
/**
|
||||
* Invoke Binding Path.
|
||||
*/
|
||||
public static final String BINDING_PATH = DaprHttp.API_VERSION + "/bindings";
|
||||
|
||||
/**
|
||||
* State Path.
|
||||
*/
|
||||
public static final String STATE_PATH = DaprHttp.API_VERSION + "/state";
|
||||
|
||||
/**
|
||||
* Secrets Path.
|
||||
*/
|
||||
public static final String SECRETS_PATH = DaprHttp.API_VERSION + "/secrets";
|
||||
|
||||
/**
|
||||
* The HTTP client to be used.
|
||||
*
|
||||
|
@ -106,7 +134,7 @@ public class DaprClientHttp extends AbstractDaprClient {
|
|||
throw new IllegalArgumentException("Topic name cannot be null or empty.");
|
||||
}
|
||||
|
||||
StringBuilder url = new StringBuilder(Constants.PUBLISH_PATH)
|
||||
StringBuilder url = new StringBuilder(PUBLISH_PATH)
|
||||
.append("/").append(pubsubName)
|
||||
.append("/").append(topic);
|
||||
byte[] serializedEvent = objectSerializer.serialize(data);
|
||||
|
@ -140,7 +168,7 @@ public class DaprClientHttp extends AbstractDaprClient {
|
|||
if (method == null || method.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("Method name cannot be null or empty.");
|
||||
}
|
||||
String path = String.format("%s/%s/method/%s", Constants.INVOKE_PATH, appId, method);
|
||||
String path = String.format("%s/%s/method/%s", INVOKE_PATH, appId, method);
|
||||
byte[] serializedRequestBody = objectSerializer.serialize(request);
|
||||
Mono<DaprHttp.Response> response = this.client.invokeApi(httMethod, path,
|
||||
httpExtension.getQueryString(), serializedRequestBody, metadata, context);
|
||||
|
@ -206,7 +234,7 @@ public class DaprClientHttp extends AbstractDaprClient {
|
|||
}
|
||||
}
|
||||
|
||||
StringBuilder url = new StringBuilder(Constants.BINDING_PATH).append("/").append(name);
|
||||
StringBuilder url = new StringBuilder(BINDING_PATH).append("/").append(name);
|
||||
|
||||
byte[] payload = INTERNAL_SERIALIZER.serialize(jsonMap);
|
||||
String httpMethod = DaprHttp.HttpMethods.POST.name();
|
||||
|
@ -249,10 +277,10 @@ public class DaprClientHttp extends AbstractDaprClient {
|
|||
}
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
if (etag != null && !etag.trim().isEmpty()) {
|
||||
headers.put(Constants.HEADER_HTTP_ETAG_ID, etag);
|
||||
headers.put(HEADER_HTTP_ETAG_ID, etag);
|
||||
}
|
||||
|
||||
StringBuilder url = new StringBuilder(Constants.STATE_PATH)
|
||||
StringBuilder url = new StringBuilder(STATE_PATH)
|
||||
.append("/")
|
||||
.append(stateStoreName)
|
||||
.append("/")
|
||||
|
@ -295,9 +323,9 @@ public class DaprClientHttp extends AbstractDaprClient {
|
|||
final String etag = states.stream().filter(state -> null != state.getEtag() && !state.getEtag().trim().isEmpty())
|
||||
.findFirst().orElse(new State<>(null, null, null, null)).getEtag();
|
||||
if (etag != null && !etag.trim().isEmpty()) {
|
||||
headers.put(Constants.HEADER_HTTP_ETAG_ID, etag);
|
||||
headers.put(HEADER_HTTP_ETAG_ID, etag);
|
||||
}
|
||||
final String url = Constants.STATE_PATH + "/" + stateStoreName;
|
||||
final String url = STATE_PATH + "/" + stateStoreName;
|
||||
List<State<Object>> internalStateObjects = new ArrayList<>(states.size());
|
||||
for (State state : states) {
|
||||
if (state == null) {
|
||||
|
@ -345,9 +373,9 @@ public class DaprClientHttp extends AbstractDaprClient {
|
|||
}
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
if (etag != null && !etag.trim().isEmpty()) {
|
||||
headers.put(Constants.HEADER_HTTP_ETAG_ID, etag);
|
||||
headers.put(HEADER_HTTP_ETAG_ID, etag);
|
||||
}
|
||||
String url = Constants.STATE_PATH + "/" + stateStoreName + "/" + key;
|
||||
String url = STATE_PATH + "/" + stateStoreName + "/" + key;
|
||||
Map<String, String> urlParameters = Optional.ofNullable(options)
|
||||
.map(stateOptions -> stateOptions.getStateOptionsAsMap())
|
||||
.orElse(new HashMap<>());
|
||||
|
@ -402,7 +430,7 @@ public class DaprClientHttp extends AbstractDaprClient {
|
|||
return Mono.error(e);
|
||||
}
|
||||
|
||||
String url = Constants.SECRETS_PATH + "/" + secretStoreName + "/" + key;
|
||||
String url = SECRETS_PATH + "/" + secretStoreName + "/" + key;
|
||||
return this.client
|
||||
.invokeApi(DaprHttp.HttpMethods.GET.name(), url, metadata, (String)null, null, context)
|
||||
.flatMap(response -> {
|
||||
|
|
|
@ -6,10 +6,9 @@
|
|||
package io.dapr.client;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.dapr.config.Properties;
|
||||
import io.dapr.exceptions.DaprError;
|
||||
import io.dapr.exceptions.DaprException;
|
||||
import io.dapr.utils.Constants;
|
||||
import io.dapr.utils.Properties;
|
||||
import io.grpc.Context;
|
||||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.context.propagation.HttpTextFormat;
|
||||
|
@ -33,11 +32,25 @@ import java.util.Optional;
|
|||
import java.util.UUID;
|
||||
|
||||
public class DaprHttp implements Closeable {
|
||||
|
||||
/**
|
||||
* Dapr API used in this client.
|
||||
*/
|
||||
public static final String API_VERSION = "v1.0";
|
||||
|
||||
/**
|
||||
* Header used for request id in Dapr.
|
||||
*/
|
||||
private static final String HEADER_DAPR_REQUEST_ID = "X-DaprRequestId";
|
||||
|
||||
/**
|
||||
* Dapr's http default scheme.
|
||||
*/
|
||||
private static final String DEFAULT_HTTP_SCHEME = "http";
|
||||
|
||||
/**
|
||||
* Sets the headers for OpenTelemetry SDK.
|
||||
*/
|
||||
private static final HttpTextFormat.Setter<Request.Builder> OPENTELEMETRY_SETTER =
|
||||
new HttpTextFormat.Setter<Request.Builder>() {
|
||||
@Override
|
||||
|
@ -114,6 +127,11 @@ public class DaprHttp implements Closeable {
|
|||
*/
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* Hostname used to communicate to Dapr's HTTP endpoint.
|
||||
*/
|
||||
private final String hostname;
|
||||
|
||||
/**
|
||||
* Port used to communicate to Dapr's HTTP endpoint.
|
||||
*/
|
||||
|
@ -127,10 +145,12 @@ public class DaprHttp implements Closeable {
|
|||
/**
|
||||
* Creates a new instance of {@link DaprHttp}.
|
||||
*
|
||||
* @param hostname Hostname for calling Dapr. (e.g. "127.0.0.1")
|
||||
* @param port Port for calling Dapr. (e.g. 3500)
|
||||
* @param httpClient RestClient used for all API calls in this new instance.
|
||||
*/
|
||||
DaprHttp(int port, OkHttpClient httpClient) {
|
||||
DaprHttp(String hostname, int port, OkHttpClient httpClient) {
|
||||
this.hostname = hostname;
|
||||
this.port = port;
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
@ -240,7 +260,7 @@ public class DaprHttp implements Closeable {
|
|||
}
|
||||
HttpUrl.Builder urlBuilder = new HttpUrl.Builder();
|
||||
urlBuilder.scheme(DEFAULT_HTTP_SCHEME)
|
||||
.host(Constants.DEFAULT_HOSTNAME)
|
||||
.host(this.hostname)
|
||||
.port(this.port)
|
||||
.addPathSegments(urlString);
|
||||
Optional.ofNullable(urlParameters).orElse(Collections.emptyMap()).entrySet().stream()
|
||||
|
@ -248,7 +268,7 @@ public class DaprHttp implements Closeable {
|
|||
|
||||
Request.Builder requestBuilder = new Request.Builder()
|
||||
.url(urlBuilder.build())
|
||||
.addHeader(Constants.HEADER_DAPR_REQUEST_ID, requestId);
|
||||
.addHeader(HEADER_DAPR_REQUEST_ID, requestId);
|
||||
if (context != null) {
|
||||
OpenTelemetry.getPropagators().getHttpTextFormat().inject(context, requestBuilder, OPENTELEMETRY_SETTER);
|
||||
}
|
||||
|
@ -260,9 +280,9 @@ public class DaprHttp implements Closeable {
|
|||
requestBuilder.method(method, body);
|
||||
}
|
||||
|
||||
String daprApiToken = Properties.DAPR_API_TOKEN.get();
|
||||
String daprApiToken = Properties.API_TOKEN.get();
|
||||
if (daprApiToken != null) {
|
||||
requestBuilder.addHeader(Constants.DAPR_API_TOKEN_HEADER, daprApiToken);
|
||||
requestBuilder.addHeader(Headers.DAPR_API_TOKEN, daprApiToken);
|
||||
}
|
||||
|
||||
if (headers != null) {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
package io.dapr.client;
|
||||
|
||||
import io.dapr.utils.Properties;
|
||||
import io.dapr.config.Properties;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
import java.time.Duration;
|
||||
|
@ -55,6 +55,6 @@ public class DaprHttpBuilder {
|
|||
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||
builder.readTimeout(this.readTimeout);
|
||||
OkHttpClient okHttpClient = builder.build();
|
||||
return new DaprHttp(Properties.HTTP_PORT.get(), okHttpClient);
|
||||
return new DaprHttp(Properties.SIDECAR_IP.get(), Properties.HTTP_PORT.get(), okHttpClient);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package io.dapr.client;
|
||||
|
||||
/**
|
||||
* Common headers for GRPC and HTTP communication.
|
||||
*/
|
||||
class Headers {
|
||||
|
||||
/**
|
||||
* OpenCensus's metadata for GRPC.
|
||||
*/
|
||||
static final String GRPC_TRACE_BIN = "grpc-trace-bin";
|
||||
|
||||
/**
|
||||
* Token for authentication from Application to Dapr runtime.
|
||||
*/
|
||||
static final String DAPR_API_TOKEN = "dapr-api-token";
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package io.dapr.config;
|
||||
|
||||
/**
|
||||
* Boolean configuration property.
|
||||
*/
|
||||
public class BooleanProperty extends Property<Boolean> {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
BooleanProperty(String name, String envName, Boolean defaultValue) {
|
||||
super(name, envName, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Boolean parse(String value) {
|
||||
return Boolean.valueOf(value);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package io.dapr.config;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Configuration property for any type.
|
||||
*/
|
||||
public class GenericProperty<T> extends Property<T> {
|
||||
|
||||
private final Function<String, T> parser;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
GenericProperty(String name, String envName, T defaultValue, Function<String, T> parser) {
|
||||
super(name, envName, defaultValue);
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected T parse(String value) {
|
||||
return parser.apply(value);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package io.dapr.config;
|
||||
|
||||
/**
|
||||
* Integer configuration property.
|
||||
*/
|
||||
public class IntegerProperty extends Property<Integer> {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
IntegerProperty(String name, String envName, Integer defaultValue) {
|
||||
super(name, envName, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected Integer parse(String value) {
|
||||
return Integer.valueOf(value);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package io.dapr.config;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* Global properties for Dapr's SDK, using Supplier so they are dynamically resolved.
|
||||
*/
|
||||
public class Properties {
|
||||
|
||||
/**
|
||||
* Dapr's default IP for HTTP and GRPC communication.
|
||||
*/
|
||||
private static final String DEFAULT_SIDECAR_IP = "127.0.0.1";
|
||||
|
||||
/**
|
||||
* Dapr's default HTTP port.
|
||||
*/
|
||||
private static final Integer DEFAULT_HTTP_PORT = 3500;
|
||||
|
||||
/**
|
||||
* Dapr's default GRPC port.
|
||||
*/
|
||||
private static final Integer DEFAULT_GRPC_PORT = 50001;
|
||||
|
||||
/**
|
||||
* Dapr's default GRPC port.
|
||||
*/
|
||||
private static final Boolean DEFAULT_GRPC_ENABLED = true;
|
||||
|
||||
/**
|
||||
* Dapr's default String encoding: UTF-8.
|
||||
*/
|
||||
private static final Charset DEFAULT_STRING_CHARSET = StandardCharsets.UTF_8;
|
||||
|
||||
/**
|
||||
* IP for Dapr's sidecar.
|
||||
*/
|
||||
public static final Property<String> SIDECAR_IP = new StringProperty(
|
||||
"dapr.sidecar.ip",
|
||||
"DAPR_SIDECAR_IP",
|
||||
DEFAULT_SIDECAR_IP);
|
||||
|
||||
/**
|
||||
* HTTP port for Dapr after checking system property and environment variable.
|
||||
*/
|
||||
public static final Property<Integer> HTTP_PORT = new IntegerProperty(
|
||||
"dapr.http.port",
|
||||
"DAPR_HTTP_PORT",
|
||||
DEFAULT_HTTP_PORT);
|
||||
|
||||
/**
|
||||
* GRPC port for Dapr after checking system property and environment variable.
|
||||
*/
|
||||
public static final Property<Integer> GRPC_PORT = new IntegerProperty(
|
||||
"dapr.grpc.port",
|
||||
"DAPR_GRPC_PORT",
|
||||
DEFAULT_GRPC_PORT);
|
||||
|
||||
/**
|
||||
* Determines if Dapr client will use GRPC to talk to Dapr's side car.
|
||||
*/
|
||||
public static final Property<Boolean> USE_GRPC = new BooleanProperty(
|
||||
"dapr.grpc.enabled",
|
||||
"DAPR_GRPC_ENABLED",
|
||||
DEFAULT_GRPC_ENABLED);
|
||||
|
||||
/**
|
||||
* API token for authentication between App and Dapr's side car.
|
||||
*/
|
||||
public static final Property<String> API_TOKEN = new StringProperty(
|
||||
"dapr.api.token",
|
||||
"DAPR_API_TOKEN",
|
||||
null);
|
||||
|
||||
/**
|
||||
* Determines which string encoding is used in Dapr's Java SDK.
|
||||
*/
|
||||
public static final Property<Charset> STRING_CHARSET = new GenericProperty<>(
|
||||
"dapr.string.charset",
|
||||
"DAPR_STRING_CHARSET",
|
||||
DEFAULT_STRING_CHARSET,
|
||||
(s) -> Charset.forName(s));
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package io.dapr.config;
|
||||
|
||||
import io.opentelemetry.trace.propagation.HttpTraceContext;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* A configuration property in the Dapr's SDK.
|
||||
*/
|
||||
public abstract class Property<T> {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(Property.class.getName());
|
||||
|
||||
/**
|
||||
* Property's name as a Java Property.
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Property's name as a environment variable.
|
||||
*/
|
||||
private final String envName;
|
||||
|
||||
/**
|
||||
* Default value.
|
||||
*/
|
||||
private final T defaultValue;
|
||||
|
||||
/**
|
||||
* Instantiates a new configuration property.
|
||||
*
|
||||
* @param name Java property name.
|
||||
* @param envName Environment variable name.
|
||||
* @param defaultValue Default value.
|
||||
*/
|
||||
Property(String name, String envName, T defaultValue) {
|
||||
this.name = name;
|
||||
this.envName = envName;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Java property's name.
|
||||
* @return Name.
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the environment variable's name.
|
||||
* @return Name.
|
||||
*/
|
||||
public String getEnvName() {
|
||||
return this.envName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value defined by system property first, then env variable or sticks to default.
|
||||
*
|
||||
* @return Value from system property (1st) or env variable (2nd) or default (last).
|
||||
*/
|
||||
public T get() {
|
||||
String propValue = System.getProperty(this.name);
|
||||
if (propValue != null && !propValue.trim().isEmpty()) {
|
||||
try {
|
||||
return this.parse(propValue);
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOGGER.warning(String.format("Invalid value in property: %s", this.name));
|
||||
// OK, we tried. Falling back to system environment variable.
|
||||
}
|
||||
}
|
||||
|
||||
String envValue = System.getenv(this.envName);
|
||||
if (envValue != null && !envValue.trim().isEmpty()) {
|
||||
try {
|
||||
return this.parse(envValue);
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOGGER.warning(String.format("Invalid value in environment variable: %s", this.envName));
|
||||
// OK, we tried. Falling back to default.
|
||||
}
|
||||
}
|
||||
|
||||
return this.defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the value to the specific type.
|
||||
* @param value String value to be parsed.
|
||||
* @return Value in the specific type.
|
||||
*/
|
||||
protected abstract T parse(String value);
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package io.dapr.config;
|
||||
|
||||
/**
|
||||
* String configuration property.
|
||||
*/
|
||||
public class StringProperty extends Property<String> {
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
StringProperty(String name, String envName, String defaultValue) {
|
||||
super(name, envName, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected String parse(String value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package io.dapr.utils;
|
||||
|
||||
/**
|
||||
* Useful constants for the Dapr's Actor SDK.
|
||||
*/
|
||||
public final class Constants {
|
||||
|
||||
/**
|
||||
* Dapr API used in this client.
|
||||
*/
|
||||
public static final String API_VERSION = "v1.0";
|
||||
|
||||
/**
|
||||
* Dapr's default hostname.
|
||||
*/
|
||||
public static final String DEFAULT_HOSTNAME = "127.0.0.1";
|
||||
|
||||
/**
|
||||
* Header used for request id in Dapr.
|
||||
*/
|
||||
public static final String HEADER_DAPR_REQUEST_ID = "X-DaprRequestId";
|
||||
|
||||
/**
|
||||
* Header for the conditional operation.
|
||||
*/
|
||||
public static final String HEADER_HTTP_ETAG_ID = "If-Match";
|
||||
|
||||
/**
|
||||
* Base URL for Dapr Actor APIs.
|
||||
*/
|
||||
private static final String ACTORS_BASE_URL = API_VERSION + "/" + "actors";
|
||||
|
||||
/**
|
||||
* String format for Actors state management relative url.
|
||||
*/
|
||||
public static final String ACTOR_STATE_KEY_RELATIVE_URL_FORMAT = ACTORS_BASE_URL + "/%s/%s/state/%s";
|
||||
|
||||
/**
|
||||
* String format for Actors state management relative url.
|
||||
*/
|
||||
public static final String ACTOR_STATE_RELATIVE_URL_FORMAT = ACTORS_BASE_URL + "/%s/%s/state";
|
||||
|
||||
/**
|
||||
* String format for Actors method invocation relative url.
|
||||
*/
|
||||
public static final String ACTOR_METHOD_RELATIVE_URL_FORMAT = ACTORS_BASE_URL + "/%s/%s/method/%s";
|
||||
|
||||
/**
|
||||
* String format for Actors reminder registration relative url..
|
||||
*/
|
||||
public static final String ACTOR_REMINDER_RELATIVE_URL_FORMAT = ACTORS_BASE_URL + "/%s/%s/reminders/%s";
|
||||
|
||||
/**
|
||||
* String format for Actors timer registration relative url..
|
||||
*/
|
||||
public static final String ACTOR_TIMER_RELATIVE_URL_FORMAT = ACTORS_BASE_URL + "/%s/%s/timers/%s";
|
||||
|
||||
/**
|
||||
* Environment variable name for dapr api token.
|
||||
*/
|
||||
public static final String DAPR_API_TOKEN = "DAPR_API_TOKEN";
|
||||
|
||||
/**
|
||||
* Header name for the dapr api token environment variable name.
|
||||
*/
|
||||
public static final String DAPR_API_TOKEN_HEADER = "dapr-api-token";
|
||||
|
||||
/**
|
||||
* Base path to invoke methods.
|
||||
*/
|
||||
public static final String INVOKE_PATH = API_VERSION + "/invoke";
|
||||
|
||||
/**
|
||||
* Invoke Publish Path.
|
||||
*/
|
||||
public static final String PUBLISH_PATH = API_VERSION + "/publish";
|
||||
|
||||
/**
|
||||
* Invoke Binding Path.
|
||||
*/
|
||||
public static final String BINDING_PATH = API_VERSION + "/bindings";
|
||||
|
||||
/**
|
||||
* State Path.
|
||||
*/
|
||||
public static final String STATE_PATH = API_VERSION + "/state";
|
||||
|
||||
/**
|
||||
* Secrets Path.
|
||||
*/
|
||||
public static final String SECRETS_PATH = API_VERSION + "/secrets";
|
||||
}
|
|
@ -1,142 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) Microsoft Corporation.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
package io.dapr.utils;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Global properties for Dapr's SDK, using Supplier so they are dynamically resolved.
|
||||
*/
|
||||
public class Properties {
|
||||
|
||||
/**
|
||||
* Dapr's default HTTP port.
|
||||
*/
|
||||
private static final Integer DEFAULT_HTTP_PORT = 3500;
|
||||
|
||||
/**
|
||||
* Dapr's default GRPC port.
|
||||
*/
|
||||
private static final Integer DEFAULT_GRPC_PORT = 50001;
|
||||
|
||||
/**
|
||||
* Dapr's default GRPC port.
|
||||
*/
|
||||
private static final Boolean DEFAULT_GRPC_ENABLED = true;
|
||||
|
||||
/**
|
||||
* Dapr's default String encoding: UTF-8.
|
||||
*/
|
||||
private static final String DEFAULT_STRING_CHARSET = StandardCharsets.UTF_8.name();
|
||||
|
||||
/**
|
||||
* API token for Dapr after checking system property and environment variable.
|
||||
*/
|
||||
public static final Supplier<String> DAPR_API_TOKEN = () -> getStringOrDefault(
|
||||
"dapr.api.token",
|
||||
Constants.DAPR_API_TOKEN, null);
|
||||
|
||||
/**
|
||||
* HTTP port for Dapr after checking system property and environment variable.
|
||||
*/
|
||||
public static final Supplier<Integer> HTTP_PORT = () -> getIntOrDefault(
|
||||
"dapr.http.port",
|
||||
"DAPR_HTTP_PORT", DEFAULT_HTTP_PORT);
|
||||
|
||||
/**
|
||||
* GRPC port for Dapr after checking system property and environment variable.
|
||||
*/
|
||||
public static final Supplier<Integer> GRPC_PORT = () -> getIntOrDefault(
|
||||
"dapr.grpc.port",
|
||||
"DAPR_GRPC_PORT", DEFAULT_GRPC_PORT);
|
||||
|
||||
/**
|
||||
* Determines if Dapr client will use GRPC to talk to Dapr's side car.
|
||||
*/
|
||||
public static final Supplier<Boolean> USE_GRPC = () -> getBooleanOrDefault(
|
||||
"dapr.grpc.enabled",
|
||||
"DAPR_GRPC_ENABLED", DEFAULT_GRPC_ENABLED);
|
||||
|
||||
/**
|
||||
* Determines which string encoding is used in Dapr's Java SDK.
|
||||
*/
|
||||
public static final Supplier<Charset> STRING_CHARSET = () -> Charset.forName(
|
||||
getStringOrDefault("dapr.string.charset", "DAPR_STRING_CHARSET", DEFAULT_STRING_CHARSET));
|
||||
|
||||
/**
|
||||
* Finds an integer defined by system property first, then env variable or sticks to default.
|
||||
* @param propName Name of the JVM's system property to override (1st).
|
||||
* @param envName Name of env variable (2nd).
|
||||
* @param defaultValue Default value if cannot find a valid config (last).
|
||||
*
|
||||
* @return Integer from system property (1st) or env variable (2nd) or default (last).
|
||||
*/
|
||||
private static Integer getIntOrDefault(String propName, String envName, Integer defaultValue) {
|
||||
return getValueOrDefault(propName, envName, defaultValue, s -> Integer.valueOf(s));
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a boolean defined by system property first, then env variable or sticks to default.
|
||||
* @param propName Name of the JVM's system property to override (1st).
|
||||
* @param envName Name of env variable (2nd).
|
||||
* @param defaultValue Default value if cannot find a valid config (last).
|
||||
*
|
||||
* @return Boolean from system property (1st) or env variable (2nd) or default (last).
|
||||
*/
|
||||
private static Boolean getBooleanOrDefault(String propName, String envName, Boolean defaultValue) {
|
||||
return getValueOrDefault(propName, envName, defaultValue, s -> Boolean.valueOf(s));
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a string defined by system property first, then env variable or sticks to default.
|
||||
* @param propName Name of the JVM's system property to override (1st).
|
||||
* @param envName Name of env variable (2nd).
|
||||
* @param defaultValue Default value if cannot find a valid config (last).
|
||||
*
|
||||
* @return String from system property (1st) or env variable (2nd) or default (last).
|
||||
*/
|
||||
private static String getStringOrDefault(String propName, String envName, String defaultValue) {
|
||||
return getValueOrDefault(propName, envName, defaultValue, s -> s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a value defined by system property first, then env variable or sticks to default.
|
||||
* @param propName Name of the JVM's system property to override (1st).
|
||||
* @param envName Name of env variable (2nd).
|
||||
* @param defaultValue Default value if cannot find a valid config (last).
|
||||
*
|
||||
* @return Value from system property (1st) or env variable (2nd) or default (last).
|
||||
*/
|
||||
private static <T> T getValueOrDefault(String propName, String envName, T defaultValue, Function<String, T> parser) {
|
||||
String propValue = System.getProperty(propName);
|
||||
if (propValue != null && !propValue.trim().isEmpty()) {
|
||||
try {
|
||||
return parser.apply(propValue);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// OK, we tried. Falling back to system environment variable.
|
||||
}
|
||||
}
|
||||
|
||||
String envValue = System.getenv(envName);
|
||||
if (envValue == null || envValue.trim().isEmpty()) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
try {
|
||||
return parser.apply(envValue);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// OK, we tried. Falling back to default.
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@ package io.dapr.client;
|
|||
import io.dapr.client.domain.HttpExtension;
|
||||
import io.dapr.client.domain.State;
|
||||
import io.dapr.client.domain.StateOptions;
|
||||
import io.dapr.config.Properties;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.mock.Behavior;
|
||||
import okhttp3.mock.MockInterceptor;
|
||||
|
@ -28,7 +29,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
|||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class DaprClientHttpTest {
|
||||
|
||||
|
||||
private static final String STATE_STORE_NAME = "MyStateStore";
|
||||
|
||||
private static final String SECRET_STORE_NAME = "MySecretStore";
|
||||
|
@ -56,7 +57,7 @@ public class DaprClientHttpTest {
|
|||
.post("http://127.0.0.1:3000/v1.0/publish/mypubsubname/A")
|
||||
.respond(EXPECTED_RESULT);
|
||||
String event = "{ \"message\": \"This is a test\" }";
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
DaprClientHttp daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.publishEvent("mypubsubname", "A", event, null);
|
||||
assertNull(mono.block());
|
||||
|
@ -68,7 +69,7 @@ public class DaprClientHttpTest {
|
|||
.post("http://127.0.0.1:3000/v1.0/publish/mypubsubname/A")
|
||||
.respond(EXPECTED_RESULT);
|
||||
String event = "{ \"message\": \"This is a test\" }";
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.publishEvent("mypubsubname","A", event);
|
||||
assertNull(mono.block());
|
||||
|
@ -80,7 +81,7 @@ public class DaprClientHttpTest {
|
|||
.post("http://127.0.0.1:3000/v1.0/publish/mypubsubname/A")
|
||||
.respond(EXPECTED_RESULT);
|
||||
String event = "{ \"message\": \"This is a test\" }";
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.publishEvent("mypubsubname", "", event);
|
||||
assertNull(mono.block());
|
||||
|
@ -92,7 +93,7 @@ public class DaprClientHttpTest {
|
|||
.post("http://127.0.0.1:3000/v1.0/publish/mypubsubname/A")
|
||||
.respond(EXPECTED_RESULT);
|
||||
String event = "{ \"message\": \"This is a test\" }";
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
daprClientHttp.publishEvent("mypubsubname", "", event);
|
||||
// Should not throw exception because did not call block() on mono above.
|
||||
|
@ -104,7 +105,7 @@ public class DaprClientHttpTest {
|
|||
.post("http://127.0.0.1:3000/v1.0/publish/A")
|
||||
.respond(EXPECTED_RESULT);
|
||||
String event = "{ \"message\": \"This is a test\" }";
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.invokeService(null, "", "", null, null, (Class)null);
|
||||
assertNull(mono.block());
|
||||
|
@ -116,7 +117,7 @@ public class DaprClientHttpTest {
|
|||
.post("http://127.0.0.1:3000/v1.0/publish/A")
|
||||
.respond(EXPECTED_RESULT);
|
||||
String event = "{ \"message\": \"This is a test\" }";
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// null HttpMethod
|
||||
|
@ -151,7 +152,7 @@ public class DaprClientHttpTest {
|
|||
.post("http://127.0.0.1:3000/v1.0/publish/A")
|
||||
.respond(EXPECTED_RESULT);
|
||||
String event = "{ \"message\": \"This is a test\" }";
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.invokeService("1", "", null, HttpExtension.POST, null, (Class)null);
|
||||
assertNull(mono.block());
|
||||
|
@ -162,7 +163,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/invoke/41/method/neworder")
|
||||
.respond("\"hello world\"");
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<String> mono = daprClientHttp.invokeService("41", "neworder", null, HttpExtension.GET, null, String.class);
|
||||
assertEquals("hello world", mono.block());
|
||||
|
@ -174,7 +175,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/invoke/41/method/neworder")
|
||||
.respond(EXPECTED_RESULT);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<byte[]> mono = daprClientHttp.invokeService("41", "neworder", null, HttpExtension.GET, byte[].class);
|
||||
assertEquals(new String(mono.block()), EXPECTED_RESULT);
|
||||
|
@ -186,7 +187,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/invoke/41/method/neworder")
|
||||
.respond(EXPECTED_RESULT);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<byte[]> mono = daprClientHttp.invokeService("41", "neworder", (byte[]) null, HttpExtension.GET, map);
|
||||
String monoString = new String(mono.block());
|
||||
|
@ -199,7 +200,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/invoke/41/method/neworder")
|
||||
.respond(EXPECTED_RESULT);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.invokeService("41", "neworder", HttpExtension.GET, map);
|
||||
assertNull(mono.block());
|
||||
|
@ -211,7 +212,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/invoke/41/method/neworder")
|
||||
.respond(EXPECTED_RESULT);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.invokeService("41", "neworder", "", HttpExtension.GET, map);
|
||||
assertNull(mono.block());
|
||||
|
@ -223,7 +224,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/invoke/41/method/neworder?test=1")
|
||||
.respond(EXPECTED_RESULT);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Map<String, String> queryString = new HashMap<>();
|
||||
queryString.put("test", "1");
|
||||
|
@ -238,7 +239,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/invoke/41/method/neworder")
|
||||
.respond(500);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
daprClientHttp.invokeService("41", "neworder", "", HttpExtension.GET, map);
|
||||
// No exception should be thrown because did not call block() on mono above.
|
||||
|
@ -250,7 +251,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.respond("");
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.invokeBinding("sample-topic", "myoperation", "");
|
||||
assertNull(mono.block());
|
||||
|
@ -262,7 +263,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.respond("\"OK\"");
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<String> mono = daprClientHttp.invokeBinding("sample-topic", "myoperation", "", null, String.class);
|
||||
assertEquals("OK", mono.block());
|
||||
|
@ -274,7 +275,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.respond("1.5");
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Double> mono = daprClientHttp.invokeBinding("sample-topic", "myoperation", "", null, double.class);
|
||||
assertEquals(1.5, mono.block(), 0.0001);
|
||||
|
@ -286,7 +287,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.respond("1.5");
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Float> mono = daprClientHttp.invokeBinding("sample-topic", "myoperation", "", null, float.class);
|
||||
assertEquals(1.5, mono.block(), 0.0001);
|
||||
|
@ -298,7 +299,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.respond("\"a\"");
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Character> mono = daprClientHttp.invokeBinding("sample-topic", "myoperation", "", null, char.class);
|
||||
assertEquals('a', (char)mono.block());
|
||||
|
@ -310,7 +311,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.respond("\"2\"");
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Byte> mono = daprClientHttp.invokeBinding("sample-topic", "myoperation", "", null, byte.class);
|
||||
assertEquals((byte)0x2, (byte)mono.block());
|
||||
|
@ -322,7 +323,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.respond("1");
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Long> mono = daprClientHttp.invokeBinding("sample-topic", "myoperation", "", null, long.class);
|
||||
assertEquals(1, (long)mono.block());
|
||||
|
@ -334,7 +335,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.respond("1");
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Integer> mono = daprClientHttp.invokeBinding("sample-topic", "myoperation", "", null, int.class);
|
||||
assertEquals(1, (int)mono.block());
|
||||
|
@ -346,7 +347,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.respond(EXPECTED_RESULT);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.invokeBinding(null, "myoperation", "");
|
||||
assertNull(mono.block());
|
||||
|
@ -358,7 +359,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.respond(EXPECTED_RESULT);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.invokeBinding("sample-topic", null, "");
|
||||
assertNull(mono.block());
|
||||
|
@ -370,7 +371,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.respond(EXPECTED_RESULT);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
daprClientHttp.invokeBinding(null, "", "");
|
||||
// No exception is thrown because did not call block() on mono above.
|
||||
|
@ -384,7 +385,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.respond("\"" + EXPECTED_RESULT + "\"");
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
daprClientHttp.getState(STATE_STORE_NAME, stateKeyNull, String.class).block();
|
||||
|
@ -399,7 +400,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.respond("\"" + EXPECTED_RESULT + "\"");
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<State<String>> monoEmptyEtag = daprClientHttp.getState(STATE_STORE_NAME, stateEmptyEtag, String.class);
|
||||
assertEquals(monoEmptyEtag.block().getKey(), "key");
|
||||
|
@ -411,7 +412,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.respond("\"" + EXPECTED_RESULT + "\"");
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<State<String>> monoNullEtag = daprClientHttp.getState(STATE_STORE_NAME, stateNullEtag, String.class);
|
||||
assertEquals(monoNullEtag.block().getKey(), "key");
|
||||
|
@ -423,7 +424,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.respond(500);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
daprClientHttp.getState(STATE_STORE_NAME, stateNullEtag, String.class);
|
||||
// No exception should be thrown since did not call block() on mono above.
|
||||
|
@ -436,7 +437,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore")
|
||||
.respond(EXPECTED_RESULT);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.saveStates(STATE_STORE_NAME, stateKeyValueList);
|
||||
assertNull(mono.block());
|
||||
|
@ -444,7 +445,7 @@ public class DaprClientHttpTest {
|
|||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void saveStateNullStateStoreName() {
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.saveStates(null, null);
|
||||
assertNull(mono.block());
|
||||
|
@ -457,7 +458,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore")
|
||||
.respond(EXPECTED_RESULT);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.saveStates(STATE_STORE_NAME, null);
|
||||
assertNull(mono.block());
|
||||
|
@ -472,7 +473,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore")
|
||||
.respond(EXPECTED_RESULT);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.saveStates(STATE_STORE_NAME, stateKeyValueList);
|
||||
assertNull(mono.block());
|
||||
|
@ -485,7 +486,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore")
|
||||
.respond(EXPECTED_RESULT);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.saveStates(STATE_STORE_NAME, stateKeyValueList);
|
||||
assertNull(mono.block());
|
||||
|
@ -497,7 +498,7 @@ public class DaprClientHttpTest {
|
|||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore")
|
||||
.respond(EXPECTED_RESULT);
|
||||
StateOptions stateOptions = mock(StateOptions.class);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.saveState(STATE_STORE_NAME, "key", "etag", "value", stateOptions);
|
||||
assertNull(mono.block());
|
||||
|
@ -509,7 +510,7 @@ public class DaprClientHttpTest {
|
|||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore")
|
||||
.respond(500);
|
||||
StateOptions stateOptions = mock(StateOptions.class);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
daprClientHttp.saveState(STATE_STORE_NAME, "key", "etag", "value", stateOptions);
|
||||
// No exception should be thrown because we did not call block() on the mono above.
|
||||
|
@ -522,7 +523,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.respond(EXPECTED_RESULT);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.deleteState(STATE_STORE_NAME, stateKeyValue.getKey(), stateKeyValue.getEtag(), stateOptions);
|
||||
assertNull(mono.block());
|
||||
|
@ -535,7 +536,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.respond(500);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
daprClientHttp.deleteState(STATE_STORE_NAME, stateKeyValue.getKey(), stateKeyValue.getEtag(), stateOptions);
|
||||
// No exception should be thrown because we did not call block() on the mono above.
|
||||
|
@ -547,7 +548,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.respond(EXPECTED_RESULT);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.deleteState(STATE_STORE_NAME, stateKeyValue.getKey(), stateKeyValue.getEtag(), null);
|
||||
assertNull(mono.block());
|
||||
|
@ -559,7 +560,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.respond(EXPECTED_RESULT);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.deleteState(STATE_STORE_NAME, stateKeyValue.getKey(), stateKeyValue.getEtag(), null);
|
||||
assertNull(mono.block());
|
||||
|
@ -572,7 +573,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.respond(EXPECTED_RESULT);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
daprClientHttp.deleteState(STATE_STORE_NAME, null, null, null).block();
|
||||
|
@ -599,7 +600,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/secrets/MySecretStore/key")
|
||||
.respond("{ \"mysecretkey\": \"mysecretvalue\"}");
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
daprClientHttp.getSecret(SECRET_STORE_NAME, null).block();
|
||||
|
@ -615,7 +616,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/secrets/MySecretStore/key")
|
||||
.respond("");
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
daprClientHttp.getSecret(SECRET_STORE_NAME, null).block();
|
||||
|
@ -630,7 +631,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/secrets/MySecretStore/key")
|
||||
.respond(404);
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
assertThrows(IllegalStateException.class, () -> {
|
||||
daprClientHttp.getSecret(SECRET_STORE_NAME, "key").block();
|
||||
|
@ -639,7 +640,7 @@ public class DaprClientHttpTest {
|
|||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void getSecretsNullStoreName() {
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
daprClientHttp.getSecret(null, "key").block();
|
||||
}
|
||||
|
@ -652,7 +653,7 @@ public class DaprClientHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/secrets/MySecretStore/key?metakey=metavalue")
|
||||
.respond("{ \"mysecretkey2\": \"mysecretvalue2\"}");
|
||||
daprHttp = new DaprHttp(3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
daprClientHttp.getSecret(SECRET_STORE_NAME, null).block();
|
||||
|
|
|
@ -26,7 +26,7 @@ public class DaprHttpStub extends DaprHttp {
|
|||
* Instantiates a stub for DaprHttp
|
||||
*/
|
||||
public DaprHttpStub() {
|
||||
super(3000, null);
|
||||
super(null, 3000, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
*/
|
||||
package io.dapr.client;
|
||||
|
||||
import io.dapr.config.Properties;
|
||||
import io.dapr.exceptions.DaprException;
|
||||
import io.dapr.utils.Constants;
|
||||
import io.dapr.utils.Properties;
|
||||
import io.grpc.Context;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
@ -14,9 +13,9 @@ import okhttp3.ResponseBody;
|
|||
import okhttp3.mock.Behavior;
|
||||
import okhttp3.mock.MockInterceptor;
|
||||
import org.junit.Before;
|
||||
import org.junit.contrib.java.lang.system.EnvironmentVariables;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.contrib.java.lang.system.EnvironmentVariables;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -52,11 +51,11 @@ public class DaprHttpTest {
|
|||
public void invokeApi_daprApiToken_present() throws IOException {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3500/v1.0/state")
|
||||
.hasHeader(Constants.DAPR_API_TOKEN_HEADER)
|
||||
.hasHeader(Headers.DAPR_API_TOKEN)
|
||||
.respond(serializer.serialize(EXPECTED_RESULT));
|
||||
environmentVariables.set(Constants.DAPR_API_TOKEN, "xyz");
|
||||
assertEquals("xyz", Properties.DAPR_API_TOKEN.get());
|
||||
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||
environmentVariables.set(Properties.API_TOKEN.getEnvName(), "xyz");
|
||||
assertEquals("xyz", Properties.API_TOKEN.get());
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono =
|
||||
daprHttp.invokeApi("POST", "v1.0/state", null, (byte[]) null, null, Context.current());
|
||||
DaprHttp.Response response = mono.block();
|
||||
|
@ -69,10 +68,10 @@ public class DaprHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3500/v1.0/state")
|
||||
.not()
|
||||
.hasHeader(Constants.DAPR_API_TOKEN_HEADER)
|
||||
.hasHeader(Headers.DAPR_API_TOKEN)
|
||||
.respond(serializer.serialize(EXPECTED_RESULT));
|
||||
assertNull(Properties.DAPR_API_TOKEN.get());
|
||||
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||
assertNull(Properties.API_TOKEN.get());
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono =
|
||||
daprHttp.invokeApi("POST", "v1.0/state", null, (byte[]) null, null, Context.current());
|
||||
DaprHttp.Response response = mono.block();
|
||||
|
@ -88,7 +87,7 @@ public class DaprHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3500/v1.0/state")
|
||||
.respond(serializer.serialize(EXPECTED_RESULT));
|
||||
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono =
|
||||
daprHttp.invokeApi("POST", "v1.0/state", null, (byte[]) null, headers, Context.current());
|
||||
DaprHttp.Response response = mono.block();
|
||||
|
@ -102,7 +101,7 @@ public class DaprHttpTest {
|
|||
.post("http://127.0.0.1:3500/v1.0/state")
|
||||
.respond(serializer.serialize(EXPECTED_RESULT))
|
||||
.addHeader("Header", "Value");
|
||||
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono =
|
||||
daprHttp.invokeApi("POST", "v1.0/state", null, "", null, Context.current());
|
||||
DaprHttp.Response response = mono.block();
|
||||
|
@ -115,7 +114,7 @@ public class DaprHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3500/v1.0/state")
|
||||
.respond(serializer.serialize(EXPECTED_RESULT));
|
||||
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono =
|
||||
daprHttp.invokeApi("DELETE", "v1.0/state", null, (String) null, null, Context.current());
|
||||
DaprHttp.Response response = mono.block();
|
||||
|
@ -128,7 +127,7 @@ public class DaprHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3500/v1.0/get")
|
||||
.respond(serializer.serialize(EXPECTED_RESULT));
|
||||
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono = daprHttp.invokeApi("GET", "v1.0/get", null, null, Context.current());
|
||||
DaprHttp.Response response = mono.block();
|
||||
String body = serializer.deserialize(response.getBody(), String.class);
|
||||
|
@ -145,7 +144,7 @@ public class DaprHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3500/v1.0/state/order?orderId=41")
|
||||
.respond(serializer.serialize(EXPECTED_RESULT));
|
||||
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono =
|
||||
daprHttp.invokeApi("GET", "v1.0/state/order", urlParameters, headers, Context.current());
|
||||
DaprHttp.Response response = mono.block();
|
||||
|
@ -158,7 +157,7 @@ public class DaprHttpTest {
|
|||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3500/v1.0/state")
|
||||
.respond(500);
|
||||
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono =
|
||||
daprHttp.invokeApi("POST", "v1.0/state", null, null, Context.current());
|
||||
DaprHttp.Response response = mono.block();
|
||||
|
@ -172,7 +171,7 @@ public class DaprHttpTest {
|
|||
.post("http://127.0.0.1:3500/v1.0/state")
|
||||
.respond(500, ResponseBody.create(MediaType.parse("text"),
|
||||
"{\"errorCode\":null,\"message\":null}"));
|
||||
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono = daprHttp.invokeApi("POST", "v1.0/state", null, null, Context.current());
|
||||
DaprHttp.Response response = mono.block();
|
||||
String body = serializer.deserialize(response.getBody(), String.class);
|
||||
|
@ -185,7 +184,7 @@ public class DaprHttpTest {
|
|||
.post("http://127.0.0.1:3500/v1.0/state")
|
||||
.respond(500, ResponseBody.create(MediaType.parse("application/json"),
|
||||
"{\"errorCode\":\"null\",\"message\":\"null\"}"));
|
||||
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono = daprHttp.invokeApi("POST", "v1.0/state", null, null, Context.current());
|
||||
DaprHttp.Response response = mono.block();
|
||||
String body = serializer.deserialize(response.getBody(), String.class);
|
||||
|
@ -215,8 +214,8 @@ public class DaprHttpTest {
|
|||
public void testCallbackCalledAtTheExpectedTimeTest() throws IOException {
|
||||
String deletedStateKey = "deletedKey";
|
||||
String existingState = "existingState";
|
||||
String urlDeleteState = Constants.STATE_PATH + "/" + deletedStateKey;
|
||||
String urlExistingState = Constants.STATE_PATH + "/" + existingState;
|
||||
String urlDeleteState = DaprClientHttp.STATE_PATH + "/" + deletedStateKey;
|
||||
String urlExistingState = DaprClientHttp.STATE_PATH + "/" + existingState;
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3500/" + urlDeleteState)
|
||||
.respond(200, ResponseBody.create(MediaType.parse("application/json"),
|
||||
|
@ -228,7 +227,7 @@ public class DaprHttpTest {
|
|||
.get("http://127.0.0.1:3500/" + urlExistingState)
|
||||
.respond(200, ResponseBody.create(MediaType.parse("application/json"),
|
||||
serializer.serialize(existingState)));
|
||||
DaprHttp daprHttp = new DaprHttp(3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> response = daprHttp.invokeApi("GET", urlExistingState, null, null, Context.current());
|
||||
assertEquals(existingState, serializer.deserialize(response.block().getBody(), String.class));
|
||||
Mono<DaprHttp.Response> responseDeleted = daprHttp.invokeApi("GET", urlDeleteState, null, null, Context.current());
|
||||
|
|
|
@ -8,13 +8,13 @@ package io.dapr.runtime;
|
|||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import io.dapr.client.DaprClient;
|
||||
import io.dapr.client.DaprClientHttp;
|
||||
import io.dapr.client.DaprClientTestBuilder;
|
||||
import io.dapr.client.DaprHttpStub;
|
||||
import io.dapr.client.domain.CloudEvent;
|
||||
import io.dapr.client.domain.HttpExtension;
|
||||
import io.dapr.serializer.DaprObjectSerializer;
|
||||
import io.dapr.serializer.DefaultObjectSerializer;
|
||||
import io.dapr.utils.Constants;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -121,7 +121,7 @@ public class DaprRuntimeTest {
|
|||
for (Message message : messages) {
|
||||
when(daprHttp.invokeApi(
|
||||
eq("POST"),
|
||||
eq(Constants.PUBLISH_PATH + "/" + PUBSUB_NAME + "/" + TOPIC_NAME),
|
||||
eq(DaprClientHttp.PUBLISH_PATH + "/" + PUBSUB_NAME + "/" + TOPIC_NAME),
|
||||
any(),
|
||||
eq(serializer.serialize(message.data)),
|
||||
eq(null),
|
||||
|
@ -209,7 +209,7 @@ public class DaprRuntimeTest {
|
|||
|
||||
when(daprHttp.invokeApi(
|
||||
eq("POST"),
|
||||
eq(Constants.INVOKE_PATH + "/" + APP_ID + "/method/" + METHOD_NAME),
|
||||
eq(DaprClientHttp.INVOKE_PATH + "/" + APP_ID + "/method/" + METHOD_NAME),
|
||||
any(),
|
||||
eq(serializer.serialize(message.data)),
|
||||
any(),
|
||||
|
|
Loading…
Reference in New Issue