mirror of https://github.com/dapr/java-sdk.git
Change "127.0.0.1" to SIDECAR_IP to dynamically account for IPv4 vs. IPv6 environments (#649)
* Generate updated javadocs for 1.3.1 (#643) Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * Migrated out of JCenter as a Maven repository manager (#648) * Upgrade okhttp-mock dependency Version 1.3.2 was never deployed to Maven Central * No longer refer to JCenter, as it has been shut down Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * initial commit: modified ./dapr/client/DaprClientHttpTest.java unit test Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * refactored hardcoded 127.0.0.1 localhost IP to use Dapr sidecar IP Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * refactored hardcoded 127.0.0.1 localhost IP to use Dapr sidecar IP Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * cleaned up unused imports Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * fixed tabbing and imports Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * added utils for getting local host and test utils for ipv6 addresses Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * Add auto-assign dapr_bot workflow (#654) Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * Bump actions/setup-java from 2.3.1 to 2.4.0 (#663) Bumps [actions/setup-java](https://github.com/actions/setup-java) from 2.3.1 to 2.4.0. - [Release notes](https://github.com/actions/setup-java/releases) - [Commits](https://github.com/actions/setup-java/compare/v2.3.1...v2.4.0) --- updated-dependencies: - dependency-name: actions/setup-java dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * added HTTP client tests for IPv6 addresses Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * fixed tests by returning SIDECAR_IP to IPv4 address Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * changes to address PMD code validation violations Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * changing back to loopback address for DEFAULT_SIDECAR_IP fallback Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * Fix vault example + Upgrade Dapr CLI and runtime. (#666) * Upgrade Dapr CLI and runtime. Signed-off-by: Artur Souza <artursouza.ms@outlook.com> * Fix expected vault output. Signed-off-by: Artur Souza <artursouza.ms@outlook.com> Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * Update LICENSE to Apache 2.0 (#657) * Update LICENSE to Apache 2.0 Signed-off-by: Artur Souza <artursouza.ms@outlook.com> * Update headers to Apache 2. Signed-off-by: Artur Souza <artursouza.ms@outlook.com> Co-authored-by: Artur Souza <artursouza.ms@outlook.com> Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * Bump actions/github-script from 1 to 5 (#655) Bumps [actions/github-script](https://github.com/actions/github-script) from 1 to 5. - [Release notes](https://github.com/actions/github-script/releases) - [Commits](https://github.com/actions/github-script/compare/v1...v5) --- updated-dependencies: - dependency-name: actions/github-script dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * Add DCO requirements and updated code of conduct (#669) Issue reference: dapr/docs#2039 Signed-off-by: Will <william.wl.tsai@gmail.com> Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * Bump actions/setup-java from 2.4.0 to 2.5.0 (#668) Bumps [actions/setup-java](https://github.com/actions/setup-java) from 2.4.0 to 2.5.0. - [Release notes](https://github.com/actions/setup-java/releases) - [Commits](https://github.com/actions/setup-java/compare/v2.4.0...v2.5.0) --- updated-dependencies: - dependency-name: actions/setup-java dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Artur Souza <artursouza.ms@outlook.com> Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * Config api support (#670) * inital draft for config api Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com> * Introducing new client for preview apis and code refactoring Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com> * Unit tests and code refactoring Signed-off-by: Pravin Pushkar <ppushkar@microsoft.com> * Adding integration test Signed-off-by: pravinpushkar <ppushkar@microsoft.com> * Copyright changes Signed-off-by: pravinpushkar <ppushkar@microsoft.com> * Review comments fixes Signed-off-by: pravinpushkar <ppushkar@microsoft.com> * Removed DaprPreviewClientProxy and updated example README Signed-off-by: pravinpushkar <ppushkar@microsoft.com> * Adding validate workflow for cofiguration api example Signed-off-by: pravinpushkar <ppushkar@microsoft.com> * fixing example autovalidation and code coverage Signed-off-by: pravinpushkar <ppushkar@microsoft.com> * Fixing autovalidation and removing getAllConfiguration Signed-off-by: pravinpushkar <ppushkar@microsoft.com> * Fixing review comments Signed-off-by: pravinpushkar <ppushkar@microsoft.com> * Add regex header checkstyle. Signed-off-by: Artur Souza <artursouza.ms@outlook.com> * Fix headers and add javadocs to some. Signed-off-by: Artur Souza <artursouza.ms@outlook.com> Co-authored-by: Artur Souza <artursouza.ms@outlook.com> Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * Update for next release: 1.5.0 snapshot (#672) * Update CLI and runtime to 1.6.0-rc.x Signed-off-by: Artur Souza <artursouza.ms@outlook.com> * Upgrade the version to 1.5.0-SNAPSHOT Signed-off-by: Artur Souza <artursouza.ms@outlook.com> Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * Update proto RC. (#674) Signed-off-by: Artur Souza <artursouza.ms@outlook.com> Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * Java SDK - Documentation for configuration API methods (#676) * Java SDK - Documentation for configuration API methods Signed-off-by: pravinpushkar <ppushkar@microsoft.com> * review comment fixes Signed-off-by: pravinpushkar <ppushkar@microsoft.com> Co-authored-by: Artur Souza <artursouza.ms@outlook.com> Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * Generate updated javadocs for 1.4.0 (#677) Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * address package dependency issue on integration test Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * added comment to include spec for ipv6 represention in url Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * corrected comment in NetworkUtils.getHostLoopbackAddress() Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * added comment to include spec for ipv6 represention in url Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * updated dependency scope to test Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> * fix NetworkUtils.java Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com> * checkstyle fix in NetworkUtils.java Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com> * fix imports Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com> * fix ipv6 formatting issues Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com> * fix ipv6 formatting issues Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com> * fix code style nits Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com> * refactor formatIpAddress method in actors utls Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com> --------- Signed-off-by: Will Tsai <william.wl.tsai@gmail.com> Signed-off-by: Artur Souza <artursouza.ms@outlook.com> Signed-off-by: Will <william.wl.tsai@gmail.com> Signed-off-by: Will <28876888+willtsai@users.noreply.github.com> Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com> Co-authored-by: Artur Souza <artursouza.ms@outlook.com> Co-authored-by: Maarten Mulders <mthmulders@users.noreply.github.com> Co-authored-by: Mukundan Sundararajan <musundar@microsoft.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: greenie-msft <56556602+greenie-msft@users.noreply.github.com> Co-authored-by: Pravin Pushkar <ppushkar@microsoft.com> Co-authored-by: Cassie Coyle <cassie@diagrid.io>
This commit is contained in:
parent
92ccca5185
commit
57b86c5d2e
|
@ -4,6 +4,7 @@
|
|||
.run/
|
||||
.vs/
|
||||
.vscode/
|
||||
.devcontainer/
|
||||
|
||||
# Output folders
|
||||
**/target/
|
||||
|
|
|
@ -61,6 +61,12 @@
|
|||
<version>${grpc.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-validator</groupId>
|
||||
<artifactId>commons-validator</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -16,6 +16,7 @@ package io.dapr.actors;
|
|||
import io.dapr.exceptions.DaprException;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
import org.apache.commons.validator.routines.InetAddressValidator;
|
||||
|
||||
public final class TestUtils {
|
||||
|
||||
|
@ -54,4 +55,12 @@ public final class TestUtils {
|
|||
Assertions.assertEquals(expectedErrorCode, daprException.getErrorCode());
|
||||
Assertions.assertEquals(expectedErrorMessage, daprException.getMessage());
|
||||
}
|
||||
|
||||
public static String formatIpAddress(final String ipAddress) {
|
||||
String formattedIpAddress = ipAddress;
|
||||
if(InetAddressValidator.getInstance().isValidInet6Address(ipAddress)) {
|
||||
formattedIpAddress = "[" + ipAddress + "]"; // per URL spec https://url.spec.whatwg.org/#host-writing
|
||||
}
|
||||
return formattedIpAddress;
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@ import org.junit.jupiter.api.BeforeEach;
|
|||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import static io.dapr.actors.TestUtils.formatIpAddress;
|
||||
import static io.dapr.actors.TestUtils.assertThrowsDaprException;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
@ -36,10 +37,13 @@ public class DaprHttpClientTest {
|
|||
|
||||
private MockInterceptor mockInterceptor;
|
||||
|
||||
private String sidecarIp;
|
||||
|
||||
private final String EXPECTED_RESULT = "{\"data\":\"ewoJCSJwcm9wZXJ0eUEiOiAidmFsdWVBIiwKCQkicHJvcGVydHlCIjogInZhbHVlQiIKCX0=\"}";
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
sidecarIp = formatIpAddress(Properties.SIDECAR_IP.get());
|
||||
mockInterceptor = new MockInterceptor(Behavior.UNORDERED);
|
||||
okHttpClient = new OkHttpClient.Builder().addInterceptor(mockInterceptor).build();
|
||||
}
|
||||
|
@ -47,24 +51,40 @@ public class DaprHttpClientTest {
|
|||
@Test
|
||||
public void invokeActorMethod() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/actors/DemoActor/1/method/Payment")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/actors/DemoActor/1/method/Payment")
|
||||
.respond(EXPECTED_RESULT);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(sidecarIp, 3000, okHttpClient);
|
||||
DaprHttpClient = new DaprHttpClient(daprHttp);
|
||||
Mono<byte[]> mono =
|
||||
DaprHttpClient.invoke("DemoActor", "1", "Payment", "".getBytes());
|
||||
assertEquals(new String(mono.block()), EXPECTED_RESULT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeActorMethodIPv6() {
|
||||
String prevSidecarIp = sidecarIp;
|
||||
System.setProperty(Properties.SIDECAR_IP.getName(), "2001:db8:3333:4444:5555:6666:7777:8888");
|
||||
sidecarIp = formatIpAddress(Properties.SIDECAR_IP.get());
|
||||
mockInterceptor.addRule()
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/actors/DemoActor/1/method/Payment")
|
||||
.respond(EXPECTED_RESULT);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(sidecarIp, 3000, okHttpClient);
|
||||
DaprHttpClient = new DaprHttpClient(daprHttp);
|
||||
System.setProperty(Properties.SIDECAR_IP.getName(), prevSidecarIp);
|
||||
Mono<byte[]> mono =
|
||||
DaprHttpClient.invoke("DemoActor", "1", "Payment", "".getBytes());
|
||||
assertEquals(new String(mono.block()), EXPECTED_RESULT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeActorMethodError() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/actors/DemoActor/1/method/Payment")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/actors/DemoActor/1/method/Payment")
|
||||
.respond(404,
|
||||
ResponseBody.create("" +
|
||||
"{\"errorCode\":\"ERR_SOMETHING\"," +
|
||||
"\"message\":\"error message\"}", MediaTypes.MEDIATYPE_JSON));
|
||||
DaprHttp daprHttp = new DaprHttpProxy(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(sidecarIp, 3000, okHttpClient);
|
||||
DaprHttpClient = new DaprHttpClient(daprHttp);
|
||||
Mono<byte[]> mono =
|
||||
DaprHttpClient.invoke("DemoActor", "1", "Payment", "".getBytes());
|
||||
|
|
|
@ -38,6 +38,7 @@ import java.util.List;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static io.dapr.actors.TestUtils.formatIpAddress;
|
||||
|
||||
public class DaprHttpClientTest {
|
||||
|
||||
|
@ -47,10 +48,13 @@ public class DaprHttpClientTest {
|
|||
|
||||
private MockInterceptor mockInterceptor;
|
||||
|
||||
private String sidecarIp;
|
||||
|
||||
private final String EXPECTED_RESULT = "{\"data\":\"ewoJCSJwcm9wZXJ0eUEiOiAidmFsdWVBIiwKCQkicHJvcGVydHlCIjogInZhbHVlQiIKCX0=\"}";
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
sidecarIp = formatIpAddress(Properties.SIDECAR_IP.get());
|
||||
mockInterceptor = new MockInterceptor(Behavior.UNORDERED);
|
||||
okHttpClient = new OkHttpClient.Builder().addInterceptor(mockInterceptor).build();
|
||||
}
|
||||
|
@ -58,21 +62,35 @@ public class DaprHttpClientTest {
|
|||
@Test
|
||||
public void getActorState() {
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/actors/DemoActor/1/state/order")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/actors/DemoActor/1/state/order")
|
||||
.respond(EXPECTED_RESULT);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(sidecarIp, 3000, okHttpClient);
|
||||
DaprHttpClient = new DaprHttpClient(daprHttp);
|
||||
Mono<byte[]> mono = DaprHttpClient.getState("DemoActor", "1", "order");
|
||||
assertEquals(new String(mono.block()), EXPECTED_RESULT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getActorStateIPv6() {
|
||||
String prevSidecarIp = sidecarIp;
|
||||
System.setProperty(Properties.SIDECAR_IP.getName(), "2001:db8:3333:4444:5555:6666:7777:8888");
|
||||
sidecarIp = formatIpAddress(Properties.SIDECAR_IP.get());
|
||||
mockInterceptor.addRule()
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/actors/DemoActor/1/state/order")
|
||||
.respond(EXPECTED_RESULT);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(sidecarIp, 3000, okHttpClient);
|
||||
DaprHttpClient = new DaprHttpClient(daprHttp);
|
||||
System.setProperty(Properties.SIDECAR_IP.getName(), prevSidecarIp);
|
||||
Mono<byte[]> mono = DaprHttpClient.getState("DemoActor", "1", "order");
|
||||
assertEquals(new String(mono.block()), EXPECTED_RESULT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveActorStateTransactionally() {
|
||||
mockInterceptor.addRule()
|
||||
.put("http://127.0.0.1:3000/v1.0/actors/DemoActor/1/state")
|
||||
.put("http://" + sidecarIp + ":3000/v1.0/actors/DemoActor/1/state")
|
||||
.respond(EXPECTED_RESULT);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(sidecarIp, 3000, okHttpClient);
|
||||
DaprHttpClient = new DaprHttpClient(daprHttp);
|
||||
List<ActorStateOperation> ops = Collections.singletonList(new ActorStateOperation("UPSERT", "key", "value"));
|
||||
Mono<Void> mono = DaprHttpClient.saveStateTransactionally("DemoActor", "1", ops);
|
||||
|
@ -82,9 +100,9 @@ public class DaprHttpClientTest {
|
|||
@Test
|
||||
public void registerActorReminder() {
|
||||
mockInterceptor.addRule()
|
||||
.put("http://127.0.0.1:3000/v1.0/actors/DemoActor/1/reminders/reminder")
|
||||
.put("http://" + sidecarIp + ":3000/v1.0/actors/DemoActor/1/reminders/reminder")
|
||||
.respond(EXPECTED_RESULT);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(sidecarIp, 3000, okHttpClient);
|
||||
DaprHttpClient = new DaprHttpClient(daprHttp);
|
||||
Mono<Void> mono =
|
||||
DaprHttpClient.registerReminder(
|
||||
|
@ -98,9 +116,9 @@ public class DaprHttpClientTest {
|
|||
@Test
|
||||
public void unregisterActorReminder() {
|
||||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/actors/DemoActor/1/reminders/reminder")
|
||||
.delete("http://" + sidecarIp + ":3000/v1.0/actors/DemoActor/1/reminders/reminder")
|
||||
.respond(EXPECTED_RESULT);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(sidecarIp, 3000, okHttpClient);
|
||||
DaprHttpClient = new DaprHttpClient(daprHttp);
|
||||
Mono<Void> mono = DaprHttpClient.unregisterReminder("DemoActor", "1", "reminder");
|
||||
assertNull(mono.block());
|
||||
|
@ -110,7 +128,7 @@ public class DaprHttpClientTest {
|
|||
public void registerActorTimer() {
|
||||
String data = "hello world";
|
||||
mockInterceptor.addRule()
|
||||
.put("http://127.0.0.1:3000/v1.0/actors/DemoActor/1/timers/timer")
|
||||
.put("http://" + sidecarIp + ":3000/v1.0/actors/DemoActor/1/timers/timer")
|
||||
.answer(new RuleAnswer() {
|
||||
@Override
|
||||
public Response.Builder respond(Request request) {
|
||||
|
@ -132,7 +150,7 @@ public class DaprHttpClientTest {
|
|||
.body(ResponseBody.create("{}", MediaType.get("application/json")));
|
||||
}
|
||||
});
|
||||
DaprHttp daprHttp = new DaprHttpProxy(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(sidecarIp, 3000, okHttpClient);
|
||||
DaprHttpClient = new DaprHttpClient(daprHttp);
|
||||
Mono<Void> mono =
|
||||
DaprHttpClient.registerTimer(
|
||||
|
@ -150,9 +168,9 @@ public class DaprHttpClientTest {
|
|||
@Test
|
||||
public void unregisterActorTimer() {
|
||||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/actors/DemoActor/1/timers/timer")
|
||||
.delete("http://" + sidecarIp + ":3000/v1.0/actors/DemoActor/1/timers/timer")
|
||||
.respond(EXPECTED_RESULT);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttpProxy(sidecarIp, 3000, okHttpClient);
|
||||
DaprHttpClient = new DaprHttpClient(daprHttp);
|
||||
Mono<Void> mono = DaprHttpClient.unregisterTimer("DemoActor", "1", "timer");
|
||||
assertNull(mono.block());
|
||||
|
|
|
@ -15,6 +15,7 @@ package io.dapr.it.state;
|
|||
|
||||
import io.dapr.it.BaseIT;
|
||||
import io.dapr.it.DaprRun;
|
||||
import io.dapr.config.Properties;
|
||||
import io.dapr.v1.DaprGrpc;
|
||||
import io.dapr.v1.DaprProtos;
|
||||
import io.grpc.ManagedChannel;
|
||||
|
@ -34,7 +35,7 @@ public class HelloWorldClientIT extends BaseIT {
|
|||
2000
|
||||
);
|
||||
ManagedChannel channel =
|
||||
ManagedChannelBuilder.forAddress("127.0.0.1", daprRun.getGrpcPort()).usePlaintext().build();
|
||||
ManagedChannelBuilder.forAddress(Properties.SIDECAR_IP.get(), daprRun.getGrpcPort()).usePlaintext().build();
|
||||
DaprGrpc.DaprBlockingStub client = DaprGrpc.newBlockingStub(channel);
|
||||
|
||||
String key = "mykey";
|
||||
|
|
|
@ -14,6 +14,7 @@ limitations under the License.
|
|||
package io.dapr.it.state;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import io.dapr.config.Properties;
|
||||
import io.dapr.v1.CommonProtos.StateItem;
|
||||
import io.dapr.v1.DaprGrpc;
|
||||
import io.dapr.v1.DaprGrpc.DaprBlockingStub;
|
||||
|
@ -37,7 +38,7 @@ public class HelloWorldGrpcStateService {
|
|||
|
||||
// If port string is not valid, it will throw an exception.
|
||||
int grpcPortInt = Integer.parseInt(grpcPort);
|
||||
ManagedChannel channel = ManagedChannelBuilder.forAddress("127.0.0.1", grpcPortInt).usePlaintext().build();
|
||||
ManagedChannel channel = ManagedChannelBuilder.forAddress(Properties.SIDECAR_IP.get(), grpcPortInt).usePlaintext().build();
|
||||
DaprBlockingStub client = DaprGrpc.newBlockingStub(channel);
|
||||
|
||||
String key = "mykey";
|
||||
|
|
|
@ -128,6 +128,12 @@
|
|||
<artifactId>junit-jupiter-migrationsupport</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-validator</groupId>
|
||||
<artifactId>commons-validator</artifactId>
|
||||
<version>1.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-test</artifactId>
|
||||
|
|
|
@ -14,6 +14,7 @@ limitations under the License.
|
|||
package io.dapr.config;
|
||||
|
||||
import io.dapr.client.DaprApiProtocol;
|
||||
import io.dapr.utils.NetworkUtils;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
@ -27,7 +28,7 @@ public class Properties {
|
|||
/**
|
||||
* Dapr's default IP for HTTP and gRPC communication.
|
||||
*/
|
||||
private static final String DEFAULT_SIDECAR_IP = "127.0.0.1";
|
||||
private static final String DEFAULT_SIDECAR_IP = NetworkUtils.getHostLoopbackAddress();
|
||||
|
||||
/**
|
||||
* Dapr's default HTTP port.
|
||||
|
|
|
@ -19,9 +19,11 @@ import io.grpc.ManagedChannel;
|
|||
import io.grpc.ManagedChannelBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
/**
|
||||
* Utility methods for network, internal to Dapr SDK.
|
||||
|
@ -112,4 +114,12 @@ public final class NetworkUtils {
|
|||
Thread.sleep(Math.min(remaining, RETRY_WAIT_MILLISECONDS));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve loopback address for the host.
|
||||
* @return The loopback address String
|
||||
*/
|
||||
public static String getHostLoopbackAddress() {
|
||||
return InetAddress.getLoopbackAddress().getHostAddress();
|
||||
}
|
||||
}
|
|
@ -72,6 +72,8 @@ import uk.org.webcompere.systemstubs.stream.SystemOut;
|
|||
|
||||
import static io.dapr.utils.TestUtils.assertThrowsDaprException;
|
||||
import static io.dapr.utils.TestUtils.findFreePort;
|
||||
import static io.dapr.utils.TestUtils.formatIpAddress;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
|
@ -86,6 +88,8 @@ public class DaprClientHttpTest {
|
|||
private final String EXPECTED_RESULT =
|
||||
"{\"data\":\"ewoJCSJwcm9wZXJ0eUEiOiAidmFsdWVBIiwKCQkicHJvcGVydHlCIjogInZhbHVlQiIKCX0=\"}";
|
||||
|
||||
private String sidecarIp;
|
||||
|
||||
private DaprClient daprClientHttp;
|
||||
|
||||
private DaprClient daprClientHttpXML;
|
||||
|
@ -98,9 +102,10 @@ public class DaprClientHttpTest {
|
|||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
sidecarIp = formatIpAddress(Properties.SIDECAR_IP.get());
|
||||
mockInterceptor = new MockInterceptor(Behavior.UNORDERED);
|
||||
okHttpClient = new OkHttpClient.Builder().addInterceptor(mockInterceptor).build();
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(sidecarIp, 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientProxy(new DaprClientHttp(daprHttp));
|
||||
daprClientHttpXML = new DaprClientProxy(new DaprClientHttp(daprHttp, new XmlSerializer(), new XmlSerializer()));
|
||||
}
|
||||
|
@ -186,7 +191,7 @@ public class DaprClientHttpTest {
|
|||
public void waitForSidecarOK() throws Exception {
|
||||
int port = findFreePort();
|
||||
System.setProperty(Properties.HTTP_PORT.getName(), Integer.toString(port));
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), port, okHttpClient);
|
||||
daprHttp = new DaprHttp(sidecarIp, port, okHttpClient);
|
||||
DaprClientHttp daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
|
||||
mockInterceptor.addRule()
|
||||
|
@ -217,7 +222,7 @@ public class DaprClientHttpTest {
|
|||
}
|
||||
});
|
||||
t.start();
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), port, okHttpClient);
|
||||
daprHttp = new DaprHttp(sidecarIp, port, okHttpClient);
|
||||
DaprClientHttp daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
daprClientHttp.waitForSidecar(10000).block();
|
||||
}
|
||||
|
@ -226,19 +231,35 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void publishEventInvocation() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/publish/mypubsubname/A")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/publish/mypubsubname/A")
|
||||
.respond(EXPECTED_RESULT);
|
||||
String event = "{ \"message\": \"This is a test\" }";
|
||||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprHttp = new DaprHttp(sidecarIp, 3000, okHttpClient);
|
||||
DaprClientHttp daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
Mono<Void> mono = daprClientHttp.publishEvent("mypubsubname", "A", event, null);
|
||||
assertNull(mono.block());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void publishEventInvocationIPv6() {
|
||||
String prevSidecarIp = sidecarIp;
|
||||
System.setProperty(Properties.SIDECAR_IP.getName(), "2001:db8:3333:4444:5555:6666:7777:8888");
|
||||
sidecarIp = formatIpAddress(Properties.SIDECAR_IP.get());
|
||||
mockInterceptor.addRule()
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/publish/mypubsubname/A")
|
||||
.respond(EXPECTED_RESULT);
|
||||
String event = "{ \"message\": \"This is a test\" }";
|
||||
daprHttp = new DaprHttp(sidecarIp, 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
System.setProperty(Properties.SIDECAR_IP.getName(), prevSidecarIp);
|
||||
Mono<Void> mono = daprClientHttp.publishEvent("mypubsubname", "A", event, null);
|
||||
assertNull(mono.block());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void publishEvent() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/publish/mypubsubname/A")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/publish/mypubsubname/A")
|
||||
.header("content-type", "application/json")
|
||||
.respond(EXPECTED_RESULT);
|
||||
String event = "{ \"message\": \"This is a test\" }";
|
||||
|
@ -250,7 +271,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void publishEventContentTypeOverride() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/publish/mypubsubname/A")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/publish/mypubsubname/A")
|
||||
.header("content-type", "text/plain")
|
||||
.respond(EXPECTED_RESULT);
|
||||
String event = "{ \"message\": \"This is a test\" }";
|
||||
|
@ -284,7 +305,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void publishEventNoHotMono() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/publish/mypubsubname/A")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/publish/mypubsubname/A")
|
||||
.respond(EXPECTED_RESULT);
|
||||
String event = "{ \"message\": \"This is a test\" }";
|
||||
|
||||
|
@ -295,7 +316,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void invokeServiceVerbNull() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/publish/A")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/publish/A")
|
||||
.respond(EXPECTED_RESULT);
|
||||
String event = "{ \"message\": \"This is a test\" }";
|
||||
|
||||
|
@ -306,7 +327,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void invokeServiceIllegalArgumentException() {
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/invoke/41/method/badorder")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/invoke/41/method/badorder")
|
||||
.respond("INVALID JSON");
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
|
@ -342,7 +363,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void invokeServiceDaprError() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/invoke/myapp/method/mymethod")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/invoke/myapp/method/mymethod")
|
||||
.respond(500,
|
||||
ResponseBody.create(
|
||||
"{ \"errorCode\": \"MYCODE\", \"message\": \"My Message\"}",
|
||||
|
@ -359,7 +380,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void invokeServiceDaprErrorFromGRPC() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/invoke/myapp/method/mymethod")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/invoke/myapp/method/mymethod")
|
||||
.respond(500,
|
||||
ResponseBody.create(
|
||||
"{ \"code\": 7 }",
|
||||
|
@ -376,7 +397,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void invokeServiceDaprErrorUnknownJSON() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/invoke/myapp/method/mymethod")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/invoke/myapp/method/mymethod")
|
||||
.respond(500,
|
||||
ResponseBody.create(
|
||||
"{ \"anything\": 7 }",
|
||||
|
@ -394,7 +415,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void invokeServiceDaprErrorEmptyString() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/invoke/myapp/method/mymethod")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/invoke/myapp/method/mymethod")
|
||||
.respond(500,
|
||||
ResponseBody.create(
|
||||
"",
|
||||
|
@ -412,7 +433,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void invokeServiceMethodNull() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/publish/A")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/publish/A")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
|
@ -422,7 +443,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void invokeService() {
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/invoke/41/method/neworder")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/invoke/41/method/neworder")
|
||||
.respond("\"hello world\"");
|
||||
|
||||
Mono<String> mono = daprClientHttp.invokeMethod("41", "neworder", null, HttpExtension.GET, null, String.class);
|
||||
|
@ -432,7 +453,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void invokeServiceNullResponse() {
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/invoke/41/method/neworder")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/invoke/41/method/neworder")
|
||||
.respond(new byte[0]);
|
||||
|
||||
Mono<String> mono = daprClientHttp.invokeMethod("41", "neworder", null, HttpExtension.GET, null, String.class);
|
||||
|
@ -442,7 +463,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void simpleInvokeService() {
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/invoke/41/method/neworder")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/invoke/41/method/neworder")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
Mono<byte[]> mono = daprClientHttp.invokeMethod("41", "neworder", null, HttpExtension.GET, byte[].class);
|
||||
|
@ -453,7 +474,7 @@ public class DaprClientHttpTest {
|
|||
public void invokeServiceWithMetadataMap() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/invoke/41/method/neworder")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/invoke/41/method/neworder")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
Mono<byte[]> mono = daprClientHttp.invokeMethod("41", "neworder", (byte[]) null, HttpExtension.GET, map);
|
||||
|
@ -465,7 +486,7 @@ public class DaprClientHttpTest {
|
|||
public void invokeServiceWithOutRequest() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/invoke/41/method/neworder")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/invoke/41/method/neworder")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
Mono<Void> mono = daprClientHttp.invokeMethod("41", "neworder", HttpExtension.GET, map);
|
||||
|
@ -476,7 +497,7 @@ public class DaprClientHttpTest {
|
|||
public void invokeServiceWithRequest() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/invoke/41/method/neworder")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/invoke/41/method/neworder")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
Mono<Void> mono = daprClientHttp.invokeMethod("41", "neworder", "", HttpExtension.GET, map);
|
||||
|
@ -487,7 +508,7 @@ public class DaprClientHttpTest {
|
|||
public void invokeServiceWithRequestAndQueryString() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/invoke/41/method/neworder?param1=1¶m2=a¶m2=b%2Fc")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/invoke/41/method/neworder?param1=1¶m2=a¶m2=b%2Fc")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
Map<String, List<String>> queryString = new HashMap<>();
|
||||
|
@ -502,7 +523,7 @@ public class DaprClientHttpTest {
|
|||
public void invokeServiceNoHotMono() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/invoke/41/method/neworder")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/invoke/41/method/neworder")
|
||||
.respond(500);
|
||||
|
||||
daprClientHttp.invokeMethod("41", "neworder", "", HttpExtension.GET, map);
|
||||
|
@ -518,7 +539,7 @@ public class DaprClientHttpTest {
|
|||
.put("tracestate", tracestate)
|
||||
.put("not_added", "xyz");
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/invoke/41/method/neworder")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/invoke/41/method/neworder")
|
||||
.header("traceparent", traceparent)
|
||||
.header("tracestate", tracestate)
|
||||
.respond(new byte[0]);
|
||||
|
@ -535,7 +556,7 @@ public class DaprClientHttpTest {
|
|||
public void invokeBinding() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/bindings/sample-topic")
|
||||
.respond("");
|
||||
|
||||
Mono<Void> mono = daprClientHttp.invokeBinding("sample-topic", "myoperation", "");
|
||||
|
@ -546,7 +567,7 @@ public class DaprClientHttpTest {
|
|||
public void invokeBindingNullData() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/bindings/sample-topic")
|
||||
.respond("");
|
||||
|
||||
Mono<Void> mono = daprClientHttp.invokeBinding("sample-topic", "myoperation", null);
|
||||
|
@ -556,7 +577,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void invokeBindingErrors() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/bindings/sample-topic")
|
||||
.respond("NOT VALID JSON");
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
|
@ -579,7 +600,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void invokeBindingResponseNull() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/bindings/sample-topic")
|
||||
.respond(new byte[0]);
|
||||
|
||||
Mono<String> mono = daprClientHttp.invokeBinding("sample-topic", "myoperation", "", null, String.class);
|
||||
|
@ -589,7 +610,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void invokeBindingResponseObject() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/bindings/sample-topic")
|
||||
.respond("\"OK\"");
|
||||
|
||||
Mono<String> mono = daprClientHttp.invokeBinding("sample-topic", "myoperation", "", null, String.class);
|
||||
|
@ -600,7 +621,7 @@ public class DaprClientHttpTest {
|
|||
public void invokeBindingResponseDouble() {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/bindings/sample-topic")
|
||||
.respond("1.5");
|
||||
|
||||
Mono<Double> mono = daprClientHttp.invokeBinding("sample-topic", "myoperation", "", map, double.class);
|
||||
|
@ -610,7 +631,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void invokeBindingResponseFloat() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/bindings/sample-topic")
|
||||
.respond("1.5");
|
||||
|
||||
Mono<Float> mono = daprClientHttp.invokeBinding("sample-topic", "myoperation", "", null, float.class);
|
||||
|
@ -620,7 +641,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void invokeBindingResponseChar() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/bindings/sample-topic")
|
||||
.respond("\"a\"");
|
||||
|
||||
Mono<Character> mono = daprClientHttp.invokeBinding("sample-topic", "myoperation", "", null, char.class);
|
||||
|
@ -630,7 +651,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void invokeBindingResponseByte() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/bindings/sample-topic")
|
||||
.respond("\"2\"");
|
||||
|
||||
Mono<Byte> mono = daprClientHttp.invokeBinding("sample-topic", "myoperation", "", null, byte.class);
|
||||
|
@ -640,7 +661,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void invokeBindingResponseLong() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/bindings/sample-topic")
|
||||
.respond("1");
|
||||
|
||||
Mono<Long> mono = daprClientHttp.invokeBinding("sample-topic", "myoperation", "", null, long.class);
|
||||
|
@ -650,7 +671,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void invokeBindingResponseInt() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/bindings/sample-topic")
|
||||
.respond("1");
|
||||
|
||||
Mono<Integer> mono = daprClientHttp.invokeBinding("sample-topic", "myoperation", "", null, int.class);
|
||||
|
@ -660,7 +681,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void invokeBindingNullName() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/bindings/sample-topic")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
|
@ -670,7 +691,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void invokeBindingNullOpName() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/bindings/sample-topic")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
|
@ -680,7 +701,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void bindingNoHotMono() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/bindings/sample-topic")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/bindings/sample-topic")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
daprClientHttp.invokeBinding(null, "", "");
|
||||
|
@ -690,7 +711,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void getStatesErrors() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore/bulk")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/bulk")
|
||||
.respond("NOT VALID JSON");
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
|
@ -720,7 +741,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void getStatesString() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore/bulk")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/bulk")
|
||||
.respond("[{\"key\": \"100\", \"data\": \"hello world\", \"etag\": \"1\"}," +
|
||||
"{\"key\": \"200\", \"error\": \"not found\"}]");
|
||||
|
||||
|
@ -740,7 +761,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void getStatesInteger() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore/bulk")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/bulk")
|
||||
.respond("[{\"key\": \"100\", \"data\": 1234, \"etag\": \"1\"}," +
|
||||
"{\"key\": \"200\", \"error\": \"not found\"}]");
|
||||
|
||||
|
@ -761,7 +782,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void getStatesBoolean() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore/bulk")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/bulk")
|
||||
.respond("[{\"key\": \"100\", \"data\": true, \"etag\": \"1\"}," +
|
||||
"{\"key\": \"200\", \"error\": \"not found\"}]");
|
||||
|
||||
|
@ -784,7 +805,7 @@ public class DaprClientHttpTest {
|
|||
byte[] value = new byte[]{1, 2, 3};
|
||||
String base64Value = Base64.getEncoder().encodeToString(value);
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore/bulk")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/bulk")
|
||||
.respond("[{\"key\": \"100\", \"data\": \"" + base64Value + "\", \"etag\": \"1\"}," +
|
||||
"{\"key\": \"200\", \"error\": \"not found\"}]");
|
||||
|
||||
|
@ -807,7 +828,7 @@ public class DaprClientHttpTest {
|
|||
public void getStatesObject() {
|
||||
MyObject object = new MyObject(1, "Event");
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore/bulk")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/bulk")
|
||||
.respond("[{\"key\": \"100\", \"data\": " +
|
||||
"{ \"id\": \"" + object.id + "\", \"value\": \"" + object.value + "\"}, \"etag\": \"1\"}," +
|
||||
"{\"key\": \"200\", \"error\": \"not found\"}]");
|
||||
|
@ -835,10 +856,10 @@ public class DaprClientHttpTest {
|
|||
State<String> stateKeyEmpty = new State<>("", "value", "etag", stateOptions);
|
||||
State<String> stateKeyBadPayload = new State<>("keyBadPayload", "value", "etag", stateOptions);
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/key")
|
||||
.respond("\"" + EXPECTED_RESULT + "\"");
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/state/MyStateStore/keyBadPayload")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/keyBadPayload")
|
||||
.respond("NOT VALID");
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
|
@ -866,7 +887,7 @@ public class DaprClientHttpTest {
|
|||
public void getStatesEmptyEtag() {
|
||||
State<String> stateEmptyEtag = new State<>("key", "value", "", null);
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/key")
|
||||
.respond("\"" + EXPECTED_RESULT + "\"");
|
||||
|
||||
State<String> monoEmptyEtag = daprClientHttp.getState(STATE_STORE_NAME, stateEmptyEtag, String.class).block();
|
||||
|
@ -879,7 +900,7 @@ public class DaprClientHttpTest {
|
|||
Map<String, String> metadata = new HashMap<>();
|
||||
metadata.put("key_1", "val_1");
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/state/MyStateStore/key?metadata.key_1=val_1")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/key?metadata.key_1=val_1")
|
||||
.respond("\"" + EXPECTED_RESULT + "\"");
|
||||
|
||||
GetStateRequest request = new GetStateRequest(STATE_STORE_NAME, "key");
|
||||
|
@ -892,7 +913,7 @@ public class DaprClientHttpTest {
|
|||
public void getStateWithStateOptions() {
|
||||
StateOptions stateOptions = new StateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE);
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/state/MyStateStore/key?consistency=strong&concurrency=first-write")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/key?consistency=strong&concurrency=first-write")
|
||||
.respond("\"" + EXPECTED_RESULT + "\"");
|
||||
|
||||
GetStateRequest request = new GetStateRequest(STATE_STORE_NAME, "key");
|
||||
|
@ -905,7 +926,7 @@ public class DaprClientHttpTest {
|
|||
public void getStatesNullEtag() {
|
||||
State<String> stateNullEtag = new State<>("key", "value", null, null);
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/key")
|
||||
.respond("\"" + EXPECTED_RESULT + "\"");
|
||||
|
||||
State<String> monoNullEtag = daprClientHttp.getState(STATE_STORE_NAME, stateNullEtag, String.class).block();
|
||||
|
@ -917,7 +938,7 @@ public class DaprClientHttpTest {
|
|||
public void getStatesNoHotMono() {
|
||||
State<String> stateNullEtag = new State<>("key", "value", null, null);
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/key")
|
||||
.respond(500);
|
||||
|
||||
daprClientHttp.getState(STATE_STORE_NAME, stateNullEtag, String.class);
|
||||
|
@ -929,7 +950,7 @@ public class DaprClientHttpTest {
|
|||
State<String> stateKeyValue = new State<>("key", "value", "etag", null);
|
||||
List<State<?>> stateKeyValueList = Collections.singletonList(stateKeyValue);
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
Mono<Void> mono = daprClientHttp.saveBulkState(STATE_STORE_NAME, stateKeyValueList);
|
||||
|
@ -960,7 +981,7 @@ public class DaprClientHttpTest {
|
|||
List<State<?>> stateKeyValueList = new ArrayList<>();
|
||||
stateKeyValueList.add(null);
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
Mono<Void> mono1 = daprClientHttp.saveBulkState(STATE_STORE_NAME, stateKeyValueList);
|
||||
|
@ -972,7 +993,7 @@ public class DaprClientHttpTest {
|
|||
State<String> stateKeyValue = new State<>("key", "value", null, null);
|
||||
List<State<?>> stateKeyValueList = Collections.singletonList(stateKeyValue);
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
Mono<Void> mono = daprClientHttp.saveBulkState(STATE_STORE_NAME, stateKeyValueList);
|
||||
|
@ -984,7 +1005,7 @@ public class DaprClientHttpTest {
|
|||
State<String> stateKeyValue = new State<>("key", "value", "", null);
|
||||
List<State<?>> stateKeyValueList = Collections.singletonList(stateKeyValue);
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
Mono<Void> mono = daprClientHttp.saveBulkState(STATE_STORE_NAME, stateKeyValueList);
|
||||
|
@ -994,7 +1015,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void simpleSaveStates() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore")
|
||||
.respond(EXPECTED_RESULT);
|
||||
StateOptions stateOptions = mock(StateOptions.class);
|
||||
|
||||
|
@ -1005,7 +1026,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void saveStatesNoHotMono() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore")
|
||||
.respond(500);
|
||||
StateOptions stateOptions = mock(StateOptions.class);
|
||||
|
||||
|
@ -1016,7 +1037,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void simpleExecuteTransaction() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore/transaction")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/transaction")
|
||||
.matches(new BodyMatcher(
|
||||
"{\"operations\":[{\"operation\":\"upsert\",\"request\":{\"value\":\"my data\",\"key\":\"key1\"," +
|
||||
"\"etag\":\"ETag1\",\"options\":{}}},{\"operation\":\"delete\",\"request\":{\"key\":\"deleteKey\"}}]}"
|
||||
|
@ -1043,7 +1064,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void simpleExecuteTransactionXMLData() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore/transaction")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/transaction")
|
||||
.matches(new BodyMatcher("{\"operations\":[{\"operation\":\"upsert\"," +
|
||||
"\"request\":{\"value\":\"PFN0cmluZz5teSBkYXRhPC9TdHJpbmc+\",\"key\":\"key1\",\"etag\":\"ETag1\"," +
|
||||
"\"options\":{}}},{\"operation\":\"delete\",\"request\":{\"value\":\"PG51bGwvPg==\"," +
|
||||
|
@ -1070,7 +1091,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void simpleExecuteTransactionNullEtag() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore/transaction")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/transaction")
|
||||
.respond(EXPECTED_RESULT);
|
||||
String etag = null;
|
||||
String key = "key1";
|
||||
|
@ -1093,7 +1114,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void simpleExecuteTransactionEmptyEtag() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore/transaction")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/transaction")
|
||||
.respond(EXPECTED_RESULT);
|
||||
String etag = "empty";
|
||||
String key = "key1";
|
||||
|
@ -1116,7 +1137,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void simpleExecuteTransactionNullOperationAndNullState() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore/transaction")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/transaction")
|
||||
.respond(EXPECTED_RESULT);
|
||||
String etag = null;
|
||||
String key = "key1";
|
||||
|
@ -1154,7 +1175,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void simpleExecuteTransactionNull() {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore/transaction")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/transaction")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
Mono<Void> mono = daprClientHttp.executeStateTransaction(STATE_STORE_NAME, null);
|
||||
|
@ -1168,7 +1189,7 @@ public class DaprClientHttpTest {
|
|||
StateOptions stateOptions = mock(StateOptions.class);
|
||||
State<String> stateKeyValue = new State<>("key", "value", "etag", stateOptions);
|
||||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.delete("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/key")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
Mono<Void> mono = daprClientHttp.deleteState(STATE_STORE_NAME, stateKeyValue.getKey(), stateKeyValue.getEtag(), stateOptions);
|
||||
|
@ -1182,7 +1203,7 @@ public class DaprClientHttpTest {
|
|||
StateOptions stateOptions = mock(StateOptions.class);
|
||||
State<String> stateKeyValue = new State<>("key", "value", "etag", stateOptions);
|
||||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/state/MyStateStore/key?metadata.key_1=val_1")
|
||||
.delete("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/key?metadata.key_1=val_1")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
DeleteStateRequest request = new DeleteStateRequest(STATE_STORE_NAME, stateKeyValue.getKey());
|
||||
|
@ -1198,7 +1219,7 @@ public class DaprClientHttpTest {
|
|||
StateOptions stateOptions = mock(StateOptions.class);
|
||||
State<String> stateKeyValue = new State<>("key", "value", "etag", stateOptions);
|
||||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.delete("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/key")
|
||||
.respond(500);
|
||||
|
||||
daprClientHttp.deleteState(STATE_STORE_NAME, stateKeyValue.getKey(), stateKeyValue.getEtag(), stateOptions);
|
||||
|
@ -1209,7 +1230,7 @@ public class DaprClientHttpTest {
|
|||
public void deleteStateNullEtag() {
|
||||
State<String> stateKeyValue = new State<>("key", "value", null, null);
|
||||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.delete("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/key")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
Mono<Void> mono = daprClientHttp.deleteState(STATE_STORE_NAME, stateKeyValue.getKey(), stateKeyValue.getEtag(), null);
|
||||
|
@ -1220,7 +1241,7 @@ public class DaprClientHttpTest {
|
|||
public void deleteStateEmptyEtag() {
|
||||
State<String> stateKeyValue = new State<>("key", "value", "", null);
|
||||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.delete("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/key")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
Mono<Void> mono = daprClientHttp.deleteState(STATE_STORE_NAME, stateKeyValue.getKey(), stateKeyValue.getEtag(), null);
|
||||
|
@ -1232,7 +1253,7 @@ public class DaprClientHttpTest {
|
|||
State<String> stateKeyValueNull = new State<>(null, "value", "etag", null);
|
||||
State<String> stateKeyValueEmpty = new State<>("", "value", "etag", null);
|
||||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.delete("http://" + sidecarIp + ":3000/v1.0/state/MyStateStore/key")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
|
@ -1258,7 +1279,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void getSecrets() {
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/secrets/MySecretStore/key")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/secrets/MySecretStore/key")
|
||||
.respond("{ \"mysecretkey\": \"mysecretvalue\"}");
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
|
@ -1273,7 +1294,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void getSecretsSpecialCharsInKey() {
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/secrets/MySecretStore/key%2Fone")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/secrets/MySecretStore/key%2Fone")
|
||||
.respond("{ \"mysecretkey\": \"mysecretvalue\"}");
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
|
@ -1288,7 +1309,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void getSecretsEmpty() {
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/secrets/MySecretStore/key")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/secrets/MySecretStore/key")
|
||||
.respond("");
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
|
@ -1302,7 +1323,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void getSecrets404() {
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/secrets/MySecretStore/key")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/secrets/MySecretStore/key")
|
||||
.respond(404);
|
||||
|
||||
assertThrowsDaprException("UNKNOWN", () ->
|
||||
|
@ -1313,7 +1334,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void getSecrets404WithErrorCode() {
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/secrets/MySecretStore/key")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/secrets/MySecretStore/key")
|
||||
.respond(404,
|
||||
ResponseBody.create("" +
|
||||
"{\"errorCode\":\"ERR_SECRET_STORE_NOT_FOUND\"," +
|
||||
|
@ -1327,7 +1348,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void getSecretsErrors() {
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/secrets/MySecretStore/key")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/secrets/MySecretStore/key")
|
||||
.respond("INVALID JSON");
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
|
@ -1348,10 +1369,10 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void getSecretsWithMetadata() {
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/secrets/MySecretStore/key")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/secrets/MySecretStore/key")
|
||||
.respond("{ \"mysecretkey\": \"mysecretvalue\"}");
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/secrets/MySecretStore/key?metadata.metakey=metavalue")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/secrets/MySecretStore/key?metadata.metakey=metavalue")
|
||||
.respond("{ \"mysecretkey2\": \"mysecretvalue2\"}");
|
||||
|
||||
{
|
||||
|
@ -1378,7 +1399,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void getBulkSecrets() {
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/secrets/MySecretStore/bulk")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/secrets/MySecretStore/bulk")
|
||||
.respond("{ \"one\": { \"mysecretkey\": \"mysecretvalue\"}, \"two\": { \"a\": \"1\", \"b\": \"2\"}}");
|
||||
|
||||
Map<String, Map<String, String>> secrets = daprClientHttp.getBulkSecret(SECRET_STORE_NAME).block();
|
||||
|
@ -1394,7 +1415,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void getBulkSecretsWithMetadata() {
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/secrets/MySecretStore/bulk?metadata.metakey=metavalue")
|
||||
.get("http://" + sidecarIp + ":3000/v1.0/secrets/MySecretStore/bulk?metadata.metakey=metavalue")
|
||||
.respond("{ \"one\": { \"mysecretkey\": \"mysecretvalue\"}, \"two\": { \"a\": \"1\", \"b\": \"2\"}}");
|
||||
|
||||
Map<String, Map<String, String>> secrets =
|
||||
|
@ -1545,7 +1566,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void shutdown() throws Exception {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/shutdown")
|
||||
.post("http://" + sidecarIp + ":3000/v1.0/shutdown")
|
||||
.respond(204);
|
||||
|
||||
final Mono<Void> mono = daprClientHttp.shutdown();
|
||||
|
|
|
@ -38,6 +38,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.dapr.utils.TestUtils.formatIpAddress;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
@ -53,6 +54,8 @@ public class DaprHttpTest {
|
|||
private static final String EXPECTED_RESULT =
|
||||
"{\"data\":\"ewoJCSJwcm9wZXJ0eUEiOiAidmFsdWVBIiwKCQkicHJvcGVydHlCIjogInZhbHVlQiIKCX0=\"}";
|
||||
|
||||
private String sidecarIp;
|
||||
|
||||
private OkHttpClient okHttpClient;
|
||||
|
||||
private MockInterceptor mockInterceptor;
|
||||
|
@ -61,6 +64,7 @@ public class DaprHttpTest {
|
|||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
sidecarIp = formatIpAddress(Properties.SIDECAR_IP.get());
|
||||
mockInterceptor = new MockInterceptor(Behavior.UNORDERED);
|
||||
okHttpClient = new OkHttpClient.Builder().addInterceptor(mockInterceptor).build();
|
||||
}
|
||||
|
@ -68,12 +72,12 @@ public class DaprHttpTest {
|
|||
@Test
|
||||
public void invokeApi_daprApiToken_present() throws IOException {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3500/v1.0/state")
|
||||
.post("http://" + sidecarIp + ":3500/v1.0/state")
|
||||
.hasHeader(Headers.DAPR_API_TOKEN)
|
||||
.respond(serializer.serialize(EXPECTED_RESULT));
|
||||
environmentVariables.set(Properties.API_TOKEN.getEnvName(), "xyz");
|
||||
assertEquals("xyz", Properties.API_TOKEN.get());
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(sidecarIp, 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono =
|
||||
daprHttp.invokeApi("POST", "v1.0/state".split("/"), null, (byte[]) null, null, Context.empty());
|
||||
DaprHttp.Response response = mono.block();
|
||||
|
@ -84,12 +88,12 @@ public class DaprHttpTest {
|
|||
@Test
|
||||
public void invokeApi_daprApiToken_absent() throws IOException {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3500/v1.0/state")
|
||||
.post("http://" + sidecarIp + ":3500/v1.0/state")
|
||||
.not()
|
||||
.hasHeader(Headers.DAPR_API_TOKEN)
|
||||
.respond(serializer.serialize(EXPECTED_RESULT));
|
||||
assertNull(Properties.API_TOKEN.get());
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(sidecarIp, 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono =
|
||||
daprHttp.invokeApi("POST", "v1.0/state".split("/"), null, (byte[]) null, null, Context.empty());
|
||||
DaprHttp.Response response = mono.block();
|
||||
|
@ -103,9 +107,29 @@ public class DaprHttpTest {
|
|||
headers.put("content-type", "text/html");
|
||||
headers.put("header1", "value1");
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3500/v1.0/state")
|
||||
.post("http://" + sidecarIp + ":3500/v1.0/state")
|
||||
.respond(serializer.serialize(EXPECTED_RESULT));
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(sidecarIp, 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono =
|
||||
daprHttp.invokeApi("POST", "v1.0/state".split("/"), null, (byte[]) null, headers, Context.empty());
|
||||
DaprHttp.Response response = mono.block();
|
||||
String body = serializer.deserialize(response.getBody(), String.class);
|
||||
assertEquals(EXPECTED_RESULT, body);
|
||||
}
|
||||
|
||||
@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());
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("content-type", "text/html");
|
||||
headers.put("header1", "value1");
|
||||
mockInterceptor.addRule()
|
||||
.post("http://" + sidecarIp + ":3500/v1.0/state")
|
||||
.respond(serializer.serialize(EXPECTED_RESULT));
|
||||
DaprHttp daprHttp = new DaprHttp(sidecarIp, 3500, okHttpClient);
|
||||
System.setProperty(Properties.SIDECAR_IP.getName(), prevSidecarIp);
|
||||
Mono<DaprHttp.Response> mono =
|
||||
daprHttp.invokeApi("POST", "v1.0/state".split("/"), null, (byte[]) null, headers, Context.empty());
|
||||
DaprHttp.Response response = mono.block();
|
||||
|
@ -116,10 +140,10 @@ public class DaprHttpTest {
|
|||
@Test
|
||||
public void invokePostMethod() throws IOException {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3500/v1.0/state")
|
||||
.post("http://" + sidecarIp + ":3500/v1.0/state")
|
||||
.respond(serializer.serialize(EXPECTED_RESULT))
|
||||
.addHeader("Header", "Value");
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(sidecarIp, 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono =
|
||||
daprHttp.invokeApi("POST", "v1.0/state".split("/"), null, "", null, Context.empty());
|
||||
DaprHttp.Response response = mono.block();
|
||||
|
@ -130,9 +154,9 @@ public class DaprHttpTest {
|
|||
@Test
|
||||
public void invokeDeleteMethod() throws IOException {
|
||||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3500/v1.0/state")
|
||||
.delete("http://" + sidecarIp + ":3500/v1.0/state")
|
||||
.respond(serializer.serialize(EXPECTED_RESULT));
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(sidecarIp, 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono =
|
||||
daprHttp.invokeApi("DELETE", "v1.0/state".split("/"), null, (String) null, null, Context.empty());
|
||||
DaprHttp.Response response = mono.block();
|
||||
|
@ -153,9 +177,9 @@ public class DaprHttpTest {
|
|||
@Test
|
||||
public void invokeGetMethod() throws IOException {
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3500/v1.0/get")
|
||||
.get("http://" + sidecarIp + ":3500/v1.0/get")
|
||||
.respond(serializer.serialize(EXPECTED_RESULT));
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(sidecarIp, 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono = daprHttp.invokeApi("GET", "v1.0/get".split("/"), null, null, Context.empty());
|
||||
DaprHttp.Response response = mono.block();
|
||||
String body = serializer.deserialize(response.getBody(), String.class);
|
||||
|
@ -170,9 +194,9 @@ public class DaprHttpTest {
|
|||
Map<String, List<String>> urlParameters = new HashMap<>();
|
||||
urlParameters.put("orderId", Collections.singletonList("41"));
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3500/v1.0/state/order?orderId=41")
|
||||
.get("http://" + sidecarIp + ":3500/v1.0/state/order?orderId=41")
|
||||
.respond(serializer.serialize(EXPECTED_RESULT));
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(sidecarIp, 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono =
|
||||
daprHttp.invokeApi("GET", "v1.0/state/order".split("/"), urlParameters, headers, Context.empty());
|
||||
DaprHttp.Response response = mono.block();
|
||||
|
@ -183,9 +207,9 @@ public class DaprHttpTest {
|
|||
@Test
|
||||
public void invokePostMethodRuntime() throws IOException {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3500/v1.0/state")
|
||||
.post("http://" + sidecarIp + ":3500/v1.0/state")
|
||||
.respond(500);
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(sidecarIp, 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono =
|
||||
daprHttp.invokeApi("POST", "v1.0/state".split("/"), null, null, Context.empty());
|
||||
StepVerifier.create(mono).expectError(RuntimeException.class).verify();
|
||||
|
@ -194,10 +218,10 @@ public class DaprHttpTest {
|
|||
@Test
|
||||
public void invokePostDaprError() throws IOException {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3500/v1.0/state")
|
||||
.post("http://" + sidecarIp + ":3500/v1.0/state")
|
||||
.respond(500, ResponseBody.create(MediaType.parse("text"),
|
||||
"{\"errorCode\":null,\"message\":null}"));
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(sidecarIp, 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono = daprHttp.invokeApi("POST", "v1.0/state".split("/"), null, null, Context.empty());
|
||||
StepVerifier.create(mono).expectError(RuntimeException.class).verify();
|
||||
}
|
||||
|
@ -205,10 +229,10 @@ public class DaprHttpTest {
|
|||
@Test
|
||||
public void invokePostMethodUnknownError() throws IOException {
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3500/v1.0/state")
|
||||
.post("http://" + sidecarIp + ":3500/v1.0/state")
|
||||
.respond(500, ResponseBody.create(MediaType.parse("application/json"),
|
||||
"{\"errorCode\":\"null\",\"message\":\"null\"}"));
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(sidecarIp, 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> mono = daprHttp.invokeApi("POST", "v1.0/state".split("/"), null, null, Context.empty());
|
||||
StepVerifier.create(mono).expectError(RuntimeException.class).verify();
|
||||
}
|
||||
|
@ -268,17 +292,17 @@ public class DaprHttpTest {
|
|||
String urlDeleteState = STATE_PATH + "/" + deletedStateKey;
|
||||
String urlExistingState = STATE_PATH + "/" + existingState;
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3500/" + urlDeleteState)
|
||||
.get("http://" + sidecarIp + ":3500/" + urlDeleteState)
|
||||
.respond(200, ResponseBody.create(MediaType.parse("application/json"),
|
||||
deletedStateKey));
|
||||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3500/" + urlDeleteState)
|
||||
.delete("http://" + sidecarIp + ":3500/" + urlDeleteState)
|
||||
.respond(204);
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3500/" + urlExistingState)
|
||||
.get("http://" + sidecarIp + ":3500/" + urlExistingState)
|
||||
.respond(200, ResponseBody.create(MediaType.parse("application/json"),
|
||||
serializer.serialize(existingState)));
|
||||
DaprHttp daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3500, okHttpClient);
|
||||
DaprHttp daprHttp = new DaprHttp(sidecarIp, 3500, okHttpClient);
|
||||
Mono<DaprHttp.Response> response = daprHttp.invokeApi("GET", urlExistingState.split("/"), null, null, Context.empty());
|
||||
assertEquals(existingState, serializer.deserialize(response.block().getBody(), String.class));
|
||||
Mono<DaprHttp.Response> responseDeleted = daprHttp.invokeApi("GET", urlDeleteState.split("/"), null, null, Context.empty());
|
||||
|
@ -287,7 +311,7 @@ public class DaprHttpTest {
|
|||
assertNull(serializer.deserialize(responseDeleteKey.block().getBody(), String.class));
|
||||
mockInterceptor.reset();
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3500/" + urlDeleteState)
|
||||
.get("http://" + sidecarIp + ":3500/" + urlDeleteState)
|
||||
.respond(404, ResponseBody.create(MediaType.parse("application/json"),
|
||||
"{\"errorCode\":\"404\",\"message\":\"State Not Found\"}"));
|
||||
try {
|
||||
|
|
|
@ -17,6 +17,7 @@ import io.dapr.exceptions.DaprErrorDetails;
|
|||
import io.dapr.exceptions.DaprException;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.function.Executable;
|
||||
import org.apache.commons.validator.routines.InetAddressValidator;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.ServerSocket;
|
||||
|
@ -79,4 +80,12 @@ public final class TestUtils {
|
|||
return socket.getLocalPort();
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatIpAddress(final String ipAddress) {
|
||||
String formattedIpAddress = ipAddress;
|
||||
if(InetAddressValidator.getInstance().isValidInet6Address(ipAddress)) {
|
||||
formattedIpAddress = "[" + ipAddress + "]"; // per URL spec https://url.spec.whatwg.org/#host-writing
|
||||
}
|
||||
return formattedIpAddress;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue