mirror of https://github.com/dapr/java-sdk.git
Increase test coverage. Fix some code inspection issues. (#372)
This commit is contained in:
parent
eb7763f126
commit
44732875cb
|
|
@ -5,8 +5,6 @@
|
|||
|
||||
package io.dapr.client;
|
||||
|
||||
import com.google.protobuf.Any;
|
||||
import com.google.protobuf.ByteString;
|
||||
import io.dapr.client.domain.DeleteStateRequest;
|
||||
import io.dapr.client.domain.DeleteStateRequestBuilder;
|
||||
import io.dapr.client.domain.ExecuteStateTransactionRequest;
|
||||
|
|
@ -30,16 +28,12 @@ import io.dapr.client.domain.StateOptions;
|
|||
import io.dapr.client.domain.TransactionalStateOperation;
|
||||
import io.dapr.serializer.DaprObjectSerializer;
|
||||
import io.dapr.utils.TypeRef;
|
||||
import io.dapr.v1.CommonProtos;
|
||||
import io.dapr.v1.DaprProtos;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Abstract class with convenient methods common between client implementations.
|
||||
|
|
@ -360,7 +354,7 @@ abstract class AbstractDaprClient implements DaprClient {
|
|||
@Override
|
||||
public Mono<Void> saveState(String stateStoreName, String key, String etag, Object value, StateOptions options) {
|
||||
State<?> state = new State<>(value, key, etag, options);
|
||||
return this.saveStates(stateStoreName, Arrays.asList(state));
|
||||
return this.saveStates(stateStoreName, Collections.singletonList(state));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -383,44 +377,6 @@ abstract class AbstractDaprClient implements DaprClient {
|
|||
return deleteState(request).then();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the object io.dapr.{@link io.dapr.v1.DaprProtos.InvokeServiceRequest} to be send based on the parameters.
|
||||
*
|
||||
* @param httpExtension Object for HttpExtension
|
||||
* @param appId The application id to be invoked
|
||||
* @param method The application method to be invoked
|
||||
* @param request The body of the request to be send as part of the invocation
|
||||
* @param <K> The Type of the Body
|
||||
* @return The object to be sent as part of the invocation.
|
||||
* @throws java.io.IOException If there's an issue serializing the request.
|
||||
*/
|
||||
private <K> DaprProtos.InvokeServiceRequest buildInvokeServiceRequest(
|
||||
HttpExtension httpExtension, String appId, String method, K request) throws IOException {
|
||||
if (httpExtension == null) {
|
||||
throw new IllegalArgumentException("HttpExtension cannot be null. Use HttpExtension.NONE instead.");
|
||||
}
|
||||
CommonProtos.InvokeRequest.Builder requestBuilder = CommonProtos.InvokeRequest.newBuilder();
|
||||
requestBuilder.setMethod(method);
|
||||
if (request != null) {
|
||||
byte[] byteRequest = objectSerializer.serialize(request);
|
||||
Any data = Any.newBuilder().setValue(ByteString.copyFrom(byteRequest)).build();
|
||||
requestBuilder.setData(data);
|
||||
} else {
|
||||
requestBuilder.setData(Any.newBuilder().build());
|
||||
}
|
||||
CommonProtos.HTTPExtension.Builder httpExtensionBuilder = CommonProtos.HTTPExtension.newBuilder();
|
||||
httpExtensionBuilder.setVerb(CommonProtos.HTTPExtension.Verb.valueOf(httpExtension.getMethod().toString()))
|
||||
.putAllQuerystring(httpExtension.getQueryString());
|
||||
requestBuilder.setHttpExtension(httpExtensionBuilder.build());
|
||||
|
||||
requestBuilder.setContentType(objectSerializer.getContentType());
|
||||
|
||||
DaprProtos.InvokeServiceRequest.Builder envelopeBuilder = DaprProtos.InvokeServiceRequest.newBuilder()
|
||||
.setId(appId)
|
||||
.setMessage(requestBuilder.build());
|
||||
return envelopeBuilder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ public class DaprClientGrpc extends AbstractDaprClient {
|
|||
return null;
|
||||
}
|
||||
return buildStateKeyValue(response, key, options, type);
|
||||
})).map(s -> new Response(context, s));
|
||||
})).map(s -> new Response<>(context, s));
|
||||
} catch (Exception ex) {
|
||||
return Mono.error(ex);
|
||||
}
|
||||
|
|
@ -304,7 +304,7 @@ public class DaprClientGrpc extends AbstractDaprClient {
|
|||
}
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
})).map(s -> new Response(context, s));
|
||||
})).map(s -> new Response<>(context, s));
|
||||
} catch (Exception ex) {
|
||||
return Mono.error(ex);
|
||||
}
|
||||
|
|
@ -335,8 +335,7 @@ public class DaprClientGrpc extends AbstractDaprClient {
|
|||
byte[] data = payload == null ? null : payload.toByteArray();
|
||||
T value = stateSerializer.deserialize(data, type);
|
||||
String etag = response.getEtag();
|
||||
String key = requestedKey;
|
||||
return new State<>(value, key, etag, stateOptions);
|
||||
return new State<>(value, requestedKey, etag, stateOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -358,7 +357,7 @@ public class DaprClientGrpc extends AbstractDaprClient {
|
|||
if (metadata != null) {
|
||||
builder.putAllMetadata(metadata);
|
||||
}
|
||||
for (TransactionalStateOperation operation: operations) {
|
||||
for (TransactionalStateOperation<?> operation: operations) {
|
||||
DaprProtos.TransactionalStateOperation.Builder operationBuilder = DaprProtos.TransactionalStateOperation
|
||||
.newBuilder();
|
||||
operationBuilder.setOperationType(operation.getOperation().toString().toLowerCase());
|
||||
|
|
@ -374,7 +373,7 @@ public class DaprClientGrpc extends AbstractDaprClient {
|
|||
return Mono.error(e);
|
||||
}
|
||||
return Mono.empty();
|
||||
}).thenReturn(new Response<Void>(context, null));
|
||||
}).thenReturn(new Response<>(context, null));
|
||||
} catch (IOException e) {
|
||||
return Mono.error(e);
|
||||
}
|
||||
|
|
@ -394,7 +393,7 @@ public class DaprClientGrpc extends AbstractDaprClient {
|
|||
}
|
||||
DaprProtos.SaveStateRequest.Builder builder = DaprProtos.SaveStateRequest.newBuilder();
|
||||
builder.setStoreName(stateStoreName);
|
||||
for (State state : states) {
|
||||
for (State<?> state : states) {
|
||||
builder.addStates(buildStateRequest(state).build());
|
||||
}
|
||||
DaprProtos.SaveStateRequest req = builder.build();
|
||||
|
|
@ -406,7 +405,7 @@ public class DaprClientGrpc extends AbstractDaprClient {
|
|||
return Mono.error(ex);
|
||||
}
|
||||
return Mono.empty();
|
||||
}).thenReturn(new Response<Void>(context, null));
|
||||
}).thenReturn(new Response<>(context, null));
|
||||
} catch (Exception ex) {
|
||||
return Mono.error(ex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ public class DaprClientHttp extends AbstractDaprClient {
|
|||
} catch (Exception ex) {
|
||||
return Mono.error(ex);
|
||||
}
|
||||
}).map(r -> new Response(context, r));
|
||||
}).map(r -> new Response<>(context, r));
|
||||
} catch (Exception ex) {
|
||||
return Mono.error(ex);
|
||||
}
|
||||
|
|
@ -268,7 +268,7 @@ public class DaprClientHttp extends AbstractDaprClient {
|
|||
} catch (Exception ex) {
|
||||
return Mono.error(ex);
|
||||
}
|
||||
}).map(r -> new Response<T>(context, r));
|
||||
}).map(r -> new Response<>(context, r));
|
||||
} catch (Exception ex) {
|
||||
return Mono.error(ex);
|
||||
}
|
||||
|
|
@ -523,12 +523,11 @@ public class DaprClientHttp extends AbstractDaprClient {
|
|||
DaprHttp.Response response, String requestedKey, StateOptions stateOptions, TypeRef<T> type) throws IOException {
|
||||
// The state is in the body directly, so we use the state serializer here.
|
||||
T value = stateSerializer.deserialize(response.getBody(), type);
|
||||
String key = requestedKey;
|
||||
String etag = null;
|
||||
if (response.getHeaders() != null && response.getHeaders().containsKey("Etag")) {
|
||||
etag = response.getHeaders().get("Etag");
|
||||
}
|
||||
return new State<>(value, key, etag, stateOptions);
|
||||
return new State<>(value, requestedKey, etag, stateOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ public class ObjectSerializer {
|
|||
* @param javaType Type of the expected result type.
|
||||
* @param <T> Result type.
|
||||
* @return Result as corresponding type.
|
||||
* @throws Exception if cannot deserialize primitive time.
|
||||
* @throws IOException if cannot deserialize primitive time.
|
||||
*/
|
||||
private static <T> T deserializePrimitives(byte[] content, JavaType javaType) throws IOException {
|
||||
if ((content == null) || (content.length == 0)) {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ package io.dapr.client.domain;
|
|||
|
||||
import io.grpc.Context;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
|
|||
|
|
@ -65,8 +65,8 @@ public class TransactionalStateOperation<T> {
|
|||
+ '}';
|
||||
}
|
||||
|
||||
public static enum OperationType {
|
||||
public enum OperationType {
|
||||
@JsonProperty("upsert") UPSERT,
|
||||
@JsonProperty("delete") DELETE;
|
||||
@JsonProperty("delete") DELETE
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@
|
|||
|
||||
package io.dapr.config;
|
||||
|
||||
import io.opentelemetry.trace.propagation.HttpTraceContext;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -18,21 +18,21 @@ public abstract class TypeRef<T> {
|
|||
|
||||
public static final TypeRef<String> STRING = new TypeRef<String>() {};
|
||||
|
||||
public static final TypeRef<Boolean> BOOLEAN = new TypeRef(boolean.class) {};
|
||||
public static final TypeRef<Boolean> BOOLEAN = new TypeRef<Boolean>(boolean.class) {};
|
||||
|
||||
public static final TypeRef<Integer> INT = new TypeRef(int.class) {};
|
||||
public static final TypeRef<Integer> INT = new TypeRef<Integer>(int.class) {};
|
||||
|
||||
public static final TypeRef<Long> LONG = new TypeRef(long.class) {};
|
||||
public static final TypeRef<Long> LONG = new TypeRef<Long>(long.class) {};
|
||||
|
||||
public static final TypeRef<Character> CHAR = new TypeRef(char.class) {};
|
||||
public static final TypeRef<Character> CHAR = new TypeRef<Character>(char.class) {};
|
||||
|
||||
public static final TypeRef<Byte> BYTE = new TypeRef(byte.class) {};
|
||||
public static final TypeRef<Byte> BYTE = new TypeRef<Byte>(byte.class) {};
|
||||
|
||||
public static final TypeRef<Void> VOID = new TypeRef(void.class) {};
|
||||
public static final TypeRef<Void> VOID = new TypeRef<Void>(void.class) {};
|
||||
|
||||
public static final TypeRef<Float> FLOAT = new TypeRef(float.class) {};
|
||||
public static final TypeRef<Float> FLOAT = new TypeRef<Float>(float.class) {};
|
||||
|
||||
public static final TypeRef<Double> DOUBLE = new TypeRef(double.class) {};
|
||||
public static final TypeRef<Double> DOUBLE = new TypeRef<Double>(double.class) {};
|
||||
|
||||
public static final TypeRef<byte[]> BYTE_ARRAY = new TypeRef<byte[]>() {};
|
||||
|
||||
|
|
|
|||
|
|
@ -12,13 +12,18 @@ import com.google.protobuf.ByteString;
|
|||
import com.google.protobuf.Empty;
|
||||
import io.dapr.client.domain.DeleteStateRequest;
|
||||
import io.dapr.client.domain.DeleteStateRequestBuilder;
|
||||
import io.dapr.client.domain.ExecuteStateTransactionRequest;
|
||||
import io.dapr.client.domain.ExecuteStateTransactionRequestBuilder;
|
||||
import io.dapr.client.domain.GetStateRequest;
|
||||
import io.dapr.client.domain.GetStateRequestBuilder;
|
||||
import io.dapr.client.domain.GetStatesRequest;
|
||||
import io.dapr.client.domain.GetStatesRequestBuilder;
|
||||
import io.dapr.client.domain.HttpExtension;
|
||||
import io.dapr.client.domain.Response;
|
||||
import io.dapr.client.domain.State;
|
||||
import io.dapr.client.domain.StateOptions;
|
||||
import io.dapr.client.domain.TransactionalStateOperation;
|
||||
import io.dapr.serializer.DaprObjectSerializer;
|
||||
import io.dapr.serializer.DefaultObjectSerializer;
|
||||
import io.dapr.utils.TypeRef;
|
||||
import io.dapr.v1.CommonProtos;
|
||||
|
|
@ -98,7 +103,7 @@ public class DaprClientGrpcTest {
|
|||
public void publishEventCallbackExceptionThrownTest() {
|
||||
SettableFuture<Empty> settableFuture = SettableFuture.create();
|
||||
RuntimeException ex = new RuntimeException("An Exception");
|
||||
MockCallback<Empty> callback = new MockCallback<Empty>(ex);
|
||||
MockCallback<Empty> callback = new MockCallback<>(ex);
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
when(client.publishEvent(any(DaprProtos.PublishEventRequest.class)))
|
||||
.thenReturn(settableFuture);
|
||||
|
|
@ -107,10 +112,22 @@ public class DaprClientGrpcTest {
|
|||
result.block();
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void publishEventSerializeException() throws IOException {
|
||||
DaprObjectSerializer mockSerializer = mock(DaprObjectSerializer.class);
|
||||
adapter = new DaprClientGrpc(closeable, client, mockSerializer, new DefaultObjectSerializer());
|
||||
SettableFuture<Empty> settableFuture = SettableFuture.create();
|
||||
when(client.publishEvent(any(DaprProtos.PublishEventRequest.class)))
|
||||
.thenReturn(settableFuture);
|
||||
when(mockSerializer.serialize(any())).thenThrow(IOException.class);
|
||||
Mono<Void> result = adapter.publishEvent("pubsubname","topic", "{invalid-json");
|
||||
result.block();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void publishEventTest() {
|
||||
SettableFuture<Empty> settableFuture = SettableFuture.create();
|
||||
MockCallback<Empty> callback = new MockCallback<Empty>(Empty.newBuilder().build());
|
||||
MockCallback<Empty> callback = new MockCallback<>(Empty.newBuilder().build());
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
when(client.publishEvent(any(DaprProtos.PublishEventRequest.class)))
|
||||
.thenReturn(settableFuture);
|
||||
|
|
@ -123,7 +140,7 @@ public class DaprClientGrpcTest {
|
|||
@Test
|
||||
public void publishEventNoHotMono() {
|
||||
SettableFuture<Empty> settableFuture = SettableFuture.create();
|
||||
MockCallback<Empty> callback = new MockCallback<Empty>(Empty.newBuilder().build());
|
||||
MockCallback<Empty> callback = new MockCallback<>(Empty.newBuilder().build());
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
when(client.publishEvent(any(DaprProtos.PublishEventRequest.class)))
|
||||
.thenAnswer(c -> {
|
||||
|
|
@ -138,7 +155,7 @@ public class DaprClientGrpcTest {
|
|||
@Test
|
||||
public void publishEventObjectTest() {
|
||||
SettableFuture<Empty> settableFuture = SettableFuture.create();
|
||||
MockCallback<Empty> callback = new MockCallback<Empty>(Empty.newBuilder().build());
|
||||
MockCallback<Empty> callback = new MockCallback<>(Empty.newBuilder().build());
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
when(client.publishEvent(any(DaprProtos.PublishEventRequest.class)))
|
||||
.thenReturn(settableFuture);
|
||||
|
|
@ -149,6 +166,38 @@ public class DaprClientGrpcTest {
|
|||
assertTrue(callback.wasCalled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invokeBindingIllegalArgumentExceptionTest() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// empty binding name
|
||||
adapter.invokeBinding("", "MyOperation", "request".getBytes(), Collections.EMPTY_MAP).block();
|
||||
});
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// null binding name
|
||||
adapter.invokeBinding(null, "MyOperation", "request".getBytes(), Collections.EMPTY_MAP).block();
|
||||
});
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// null binding operation
|
||||
adapter.invokeBinding("BindingName", null, "request".getBytes(), Collections.EMPTY_MAP).block();
|
||||
});
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// empty binding operation
|
||||
adapter.invokeBinding("BindingName", "", "request".getBytes(), Collections.EMPTY_MAP).block();
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void invokeBindingSerializeException() throws IOException {
|
||||
DaprObjectSerializer mockSerializer = mock(DaprObjectSerializer.class);
|
||||
adapter = new DaprClientGrpc(closeable, client, mockSerializer, new DefaultObjectSerializer());
|
||||
SettableFuture<DaprProtos.InvokeBindingResponse> settableFuture = SettableFuture.create();
|
||||
when(client.invokeBinding(any(DaprProtos.InvokeBindingRequest.class)))
|
||||
.thenReturn(settableFuture);
|
||||
when(mockSerializer.serialize(any())).thenThrow(IOException.class);
|
||||
Mono<Void> result = adapter.invokeBinding("BindingName", "MyOperation", "request".getBytes(), Collections.EMPTY_MAP);
|
||||
result.block();
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void invokeBindingExceptionThrownTest() {
|
||||
when(client.invokeService(any(DaprProtos.InvokeServiceRequest.class)))
|
||||
|
|
@ -252,7 +301,7 @@ public class DaprClientGrpcTest {
|
|||
@Test
|
||||
public void invokeBindingObjectNoHotMono() {
|
||||
SettableFuture<Empty> settableFuture = SettableFuture.create();
|
||||
MockCallback<Empty> callback = new MockCallback<Empty>(Empty.newBuilder().build());
|
||||
MockCallback<Empty> callback = new MockCallback<>(Empty.newBuilder().build());
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
when(client.invokeBinding(any(DaprProtos.InvokeBindingRequest.class)))
|
||||
.thenAnswer(c -> {
|
||||
|
|
@ -273,6 +322,16 @@ public class DaprClientGrpcTest {
|
|||
result.block();
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void invokeServiceIllegalArgumentExceptionThrownTest() {
|
||||
SettableFuture<CommonProtos.InvokeResponse> settableFuture = SettableFuture.create();
|
||||
when(client.invokeService(any(DaprProtos.InvokeServiceRequest.class)))
|
||||
.thenReturn(settableFuture);
|
||||
// HttpExtension cannot be null
|
||||
Mono<Void> result = adapter.invokeService("appId", "method", "request", null);
|
||||
result.block();
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void invokeServiceEmptyRequestVoidExceptionThrownTest() {
|
||||
when(client.invokeService(any(DaprProtos.InvokeServiceRequest.class)))
|
||||
|
|
@ -285,8 +344,7 @@ public class DaprClientGrpcTest {
|
|||
public void invokeServiceVoidCallbackExceptionThrownTest() {
|
||||
SettableFuture<CommonProtos.InvokeResponse> settableFuture = SettableFuture.create();
|
||||
RuntimeException ex = new RuntimeException("An Exception");
|
||||
MockCallback<CommonProtos.InvokeResponse> callback =
|
||||
new MockCallback<CommonProtos.InvokeResponse>(ex);
|
||||
MockCallback<CommonProtos.InvokeResponse> callback = new MockCallback<>(ex);
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
settableFuture.setException(ex);
|
||||
when(client.invokeService(any(DaprProtos.InvokeServiceRequest.class)))
|
||||
|
|
@ -299,8 +357,7 @@ public class DaprClientGrpcTest {
|
|||
public void invokeServiceVoidTest() throws Exception {
|
||||
SettableFuture<CommonProtos.InvokeResponse> settableFuture = SettableFuture.create();
|
||||
|
||||
MockCallback<CommonProtos.InvokeResponse> callback =
|
||||
new MockCallback<CommonProtos.InvokeResponse>(CommonProtos.InvokeResponse.newBuilder()
|
||||
MockCallback<CommonProtos.InvokeResponse> callback = new MockCallback<>(CommonProtos.InvokeResponse.newBuilder()
|
||||
.setData(getAny("Value")).build());
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
when(client.invokeService(any(DaprProtos.InvokeServiceRequest.class)))
|
||||
|
|
@ -315,8 +372,7 @@ public class DaprClientGrpcTest {
|
|||
public void invokeServiceVoidObjectTest() throws Exception {
|
||||
SettableFuture<CommonProtos.InvokeResponse> settableFuture = SettableFuture.create();
|
||||
|
||||
MockCallback<CommonProtos.InvokeResponse> callback =
|
||||
new MockCallback<CommonProtos.InvokeResponse>(CommonProtos.InvokeResponse.newBuilder()
|
||||
MockCallback<CommonProtos.InvokeResponse> callback = new MockCallback<>(CommonProtos.InvokeResponse.newBuilder()
|
||||
.setData(getAny("Value")).build());
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
when(client.invokeService(any(DaprProtos.InvokeServiceRequest.class)))
|
||||
|
|
@ -356,8 +412,7 @@ public class DaprClientGrpcTest {
|
|||
public void invokeServiceCallbackExceptionThrownTest() {
|
||||
SettableFuture<CommonProtos.InvokeResponse> settableFuture = SettableFuture.create();
|
||||
RuntimeException ex = new RuntimeException("An Exception");
|
||||
MockCallback<CommonProtos.InvokeResponse> callback =
|
||||
new MockCallback<CommonProtos.InvokeResponse>(ex);
|
||||
MockCallback<CommonProtos.InvokeResponse> callback = new MockCallback<>(ex);
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
when(client.invokeService(any(DaprProtos.InvokeServiceRequest.class)))
|
||||
.thenReturn(settableFuture);
|
||||
|
|
@ -385,8 +440,7 @@ public class DaprClientGrpcTest {
|
|||
.build();
|
||||
String expected = "Value";
|
||||
SettableFuture<CommonProtos.InvokeResponse> settableFuture = SettableFuture.create();
|
||||
MockCallback<CommonProtos.InvokeResponse> callback =
|
||||
new MockCallback<CommonProtos.InvokeResponse>(CommonProtos.InvokeResponse.newBuilder()
|
||||
MockCallback<CommonProtos.InvokeResponse> callback = new MockCallback<>(CommonProtos.InvokeResponse.newBuilder()
|
||||
.setData(getAny(expected)).build());
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
settableFuture.set(CommonProtos.InvokeResponse.newBuilder().setData(getAny(expected)).build());
|
||||
|
|
@ -401,8 +455,7 @@ public class DaprClientGrpcTest {
|
|||
public void invokeServiceTest() throws Exception {
|
||||
String expected = "Value";
|
||||
SettableFuture<CommonProtos.InvokeResponse> settableFuture = SettableFuture.create();
|
||||
MockCallback<CommonProtos.InvokeResponse> callback =
|
||||
new MockCallback<CommonProtos.InvokeResponse>(CommonProtos.InvokeResponse.newBuilder()
|
||||
MockCallback<CommonProtos.InvokeResponse> callback = new MockCallback<>(CommonProtos.InvokeResponse.newBuilder()
|
||||
.setData(getAny(expected)).build());
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
settableFuture.set(CommonProtos.InvokeResponse.newBuilder().setData(getAny(expected)).build());
|
||||
|
|
@ -417,8 +470,7 @@ public class DaprClientGrpcTest {
|
|||
public void invokeServiceObjectTest() throws Exception {
|
||||
MyObject object = new MyObject(1, "Value");
|
||||
SettableFuture<CommonProtos.InvokeResponse> settableFuture = SettableFuture.create();
|
||||
MockCallback<CommonProtos.InvokeResponse> callback =
|
||||
new MockCallback<CommonProtos.InvokeResponse>(CommonProtos.InvokeResponse.newBuilder()
|
||||
MockCallback<CommonProtos.InvokeResponse> callback = new MockCallback<>(CommonProtos.InvokeResponse.newBuilder()
|
||||
.setData(getAny(object)).build());
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
settableFuture.set(CommonProtos.InvokeResponse.newBuilder().setData(getAny(object)).build());
|
||||
|
|
@ -434,7 +486,7 @@ public class DaprClientGrpcTest {
|
|||
public void invokeServiceNoRequestBodyExceptionThrownTest() {
|
||||
when(client.invokeService(any(DaprProtos.InvokeServiceRequest.class)))
|
||||
.thenThrow(RuntimeException.class);
|
||||
Mono<String> result = adapter.invokeService("appId", "method", (Object)null, HttpExtension.NONE, (Class)String.class);
|
||||
Mono<String> result = adapter.invokeService("appId", "method", (Object)null, HttpExtension.NONE, String.class);
|
||||
result.block();
|
||||
}
|
||||
|
||||
|
|
@ -442,8 +494,7 @@ public class DaprClientGrpcTest {
|
|||
public void invokeServiceNoRequestCallbackExceptionThrownTest() {
|
||||
SettableFuture<CommonProtos.InvokeResponse> settableFuture = SettableFuture.create();
|
||||
RuntimeException ex = new RuntimeException("An Exception");
|
||||
MockCallback<CommonProtos.InvokeResponse> callback =
|
||||
new MockCallback<CommonProtos.InvokeResponse>(ex);
|
||||
MockCallback<CommonProtos.InvokeResponse> callback = new MockCallback<>(ex);
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
when(client.invokeService(any(DaprProtos.InvokeServiceRequest.class)))
|
||||
.thenReturn(settableFuture);
|
||||
|
|
@ -457,8 +508,7 @@ public class DaprClientGrpcTest {
|
|||
String expected = "Value";
|
||||
SettableFuture<CommonProtos.InvokeResponse> settableFuture = SettableFuture.create();
|
||||
|
||||
MockCallback<CommonProtos.InvokeResponse> callback =
|
||||
new MockCallback<CommonProtos.InvokeResponse>(CommonProtos.InvokeResponse.newBuilder()
|
||||
MockCallback<CommonProtos.InvokeResponse> callback = new MockCallback<>(CommonProtos.InvokeResponse.newBuilder()
|
||||
.setData(getAny(expected)).build());
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
settableFuture.set(CommonProtos.InvokeResponse.newBuilder().setData(getAny(expected)).build());
|
||||
|
|
@ -474,8 +524,7 @@ public class DaprClientGrpcTest {
|
|||
MyObject object = new MyObject(1, "Value");
|
||||
SettableFuture<CommonProtos.InvokeResponse> settableFuture = SettableFuture.create();
|
||||
|
||||
MockCallback<CommonProtos.InvokeResponse> callback =
|
||||
new MockCallback<CommonProtos.InvokeResponse>(CommonProtos.InvokeResponse.newBuilder()
|
||||
MockCallback<CommonProtos.InvokeResponse> callback = new MockCallback<>(CommonProtos.InvokeResponse.newBuilder()
|
||||
.setData(getAny(object)).build());
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
settableFuture.set(CommonProtos.InvokeResponse.newBuilder().setData(getAny(object)).build());
|
||||
|
|
@ -501,8 +550,7 @@ public class DaprClientGrpcTest {
|
|||
public void invokeServiceByteRequestCallbackExceptionThrownTest() throws IOException {
|
||||
SettableFuture<CommonProtos.InvokeResponse> settableFuture = SettableFuture.create();
|
||||
RuntimeException ex = new RuntimeException("An Exception");
|
||||
MockCallback<CommonProtos.InvokeResponse> callback =
|
||||
new MockCallback<CommonProtos.InvokeResponse>(ex);
|
||||
MockCallback<CommonProtos.InvokeResponse> callback = new MockCallback<>(ex);
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
when(client.invokeService(any(DaprProtos.InvokeServiceRequest.class)))
|
||||
.thenReturn(settableFuture);
|
||||
|
|
@ -518,8 +566,7 @@ public class DaprClientGrpcTest {
|
|||
public void invokeByteRequestServiceTest() throws Exception {
|
||||
String expected = "Value";
|
||||
SettableFuture<CommonProtos.InvokeResponse> settableFuture = SettableFuture.create();
|
||||
MockCallback<CommonProtos.InvokeResponse> callback =
|
||||
new MockCallback<CommonProtos.InvokeResponse>(CommonProtos.InvokeResponse.newBuilder()
|
||||
MockCallback<CommonProtos.InvokeResponse> callback = new MockCallback<>(CommonProtos.InvokeResponse.newBuilder()
|
||||
.setData(getAny(expected)).build());
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
settableFuture.set(CommonProtos.InvokeResponse.newBuilder().setData(getAny(expected)).build());
|
||||
|
|
@ -538,8 +585,7 @@ public class DaprClientGrpcTest {
|
|||
public void invokeServiceByteRequestObjectTest() throws Exception {
|
||||
MyObject resultObj = new MyObject(1, "Value");
|
||||
SettableFuture<CommonProtos.InvokeResponse> settableFuture = SettableFuture.create();
|
||||
MockCallback<CommonProtos.InvokeResponse> callback =
|
||||
new MockCallback<CommonProtos.InvokeResponse>(CommonProtos.InvokeResponse.newBuilder()
|
||||
MockCallback<CommonProtos.InvokeResponse> callback = new MockCallback<>(CommonProtos.InvokeResponse.newBuilder()
|
||||
.setData(getAny(resultObj)).build());
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
settableFuture.set(CommonProtos.InvokeResponse.newBuilder().setData(getAny(resultObj)).build());
|
||||
|
|
@ -564,8 +610,7 @@ public class DaprClientGrpcTest {
|
|||
public void invokeServiceNoRequestNoClassCallbackExceptionThrownTest() {
|
||||
SettableFuture<CommonProtos.InvokeResponse> settableFuture = SettableFuture.create();
|
||||
RuntimeException ex = new RuntimeException("An Exception");
|
||||
MockCallback<CommonProtos.InvokeResponse> callback =
|
||||
new MockCallback<CommonProtos.InvokeResponse>(ex);
|
||||
MockCallback<CommonProtos.InvokeResponse> callback = new MockCallback<>(ex);
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
when(client.invokeService(any(DaprProtos.InvokeServiceRequest.class)))
|
||||
.thenReturn(settableFuture);
|
||||
|
|
@ -578,8 +623,7 @@ public class DaprClientGrpcTest {
|
|||
public void invokeServiceNoRequestNoClassBodyTest() throws Exception {
|
||||
String expected = "Value";
|
||||
SettableFuture<CommonProtos.InvokeResponse> settableFuture = SettableFuture.create();
|
||||
MockCallback<CommonProtos.InvokeResponse> callback =
|
||||
new MockCallback<CommonProtos.InvokeResponse>(CommonProtos.InvokeResponse.newBuilder()
|
||||
MockCallback<CommonProtos.InvokeResponse> callback = new MockCallback<>(CommonProtos.InvokeResponse.newBuilder()
|
||||
.setData(getAny(expected)).build());
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
when(client.invokeService(any(DaprProtos.InvokeServiceRequest.class)))
|
||||
|
|
@ -594,8 +638,7 @@ public class DaprClientGrpcTest {
|
|||
public void invokeServiceNoRequestNoHotMono() throws Exception {
|
||||
String expected = "Value";
|
||||
SettableFuture<CommonProtos.InvokeResponse> settableFuture = SettableFuture.create();
|
||||
MockCallback<CommonProtos.InvokeResponse> callback =
|
||||
new MockCallback<CommonProtos.InvokeResponse>(CommonProtos.InvokeResponse.newBuilder()
|
||||
MockCallback<CommonProtos.InvokeResponse> callback = new MockCallback<>(CommonProtos.InvokeResponse.newBuilder()
|
||||
.setData(getAny(expected)).build());
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
when(client.invokeService(any(DaprProtos.InvokeServiceRequest.class)))
|
||||
|
|
@ -613,8 +656,7 @@ public class DaprClientGrpcTest {
|
|||
MyObject resultObj = new MyObject(1, "Value");
|
||||
SettableFuture<CommonProtos.InvokeResponse> settableFuture = SettableFuture.create();
|
||||
|
||||
MockCallback<CommonProtos.InvokeResponse> callback =
|
||||
new MockCallback<CommonProtos.InvokeResponse>(CommonProtos.InvokeResponse.newBuilder()
|
||||
MockCallback<CommonProtos.InvokeResponse> callback = new MockCallback<>(CommonProtos.InvokeResponse.newBuilder()
|
||||
.setData(getAny(resultObj)).build());
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
settableFuture.set(CommonProtos.InvokeResponse.newBuilder().setData(getAny(resultObj)).build());
|
||||
|
|
@ -625,6 +667,27 @@ public class DaprClientGrpcTest {
|
|||
assertTrue(callback.wasCalled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStateIllegalArgumentExceptionTest() {
|
||||
State<String> key = buildStateKey(null, "Key1", "ETag1", null);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// empty state store name
|
||||
adapter.getState("", key, String.class).block();
|
||||
});
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// null state store name
|
||||
adapter.getState(null, key, String.class).block();
|
||||
});
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// null key
|
||||
adapter.getState(STATE_STORE_NAME, (String)null, String.class).block();
|
||||
});
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// empty key
|
||||
adapter.getState(STATE_STORE_NAME, "", String.class).block();
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void getStateExceptionThrownTest() {
|
||||
when(client.getState(any(io.dapr.v1.DaprProtos.GetStateRequest.class))).thenThrow(RuntimeException.class);
|
||||
|
|
@ -719,7 +782,7 @@ public class DaprClientGrpcTest {
|
|||
String key = "key1";
|
||||
MyObject expectedValue = new MyObject(1, "The Value");
|
||||
StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE);
|
||||
Map<String, String> metadata = new HashMap<String, String>();
|
||||
Map<String, String> metadata = new HashMap<>();
|
||||
metadata.put("key_1", "val_1");
|
||||
State<MyObject> expectedState = buildStateKey(expectedValue, key, etag, options);
|
||||
DaprProtos.GetStateResponse responseEnvelope = DaprProtos.GetStateResponse.newBuilder()
|
||||
|
|
@ -763,6 +826,32 @@ public class DaprClientGrpcTest {
|
|||
assertEquals(expectedState, result.block());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStatesIllegalArgumentExceptionTest() {
|
||||
State<String> key = buildStateKey(null, "Key1", "ETag1", null);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// empty state store name
|
||||
adapter.getStates("", Collections.singletonList("100"), String.class).block();
|
||||
});
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// null state store name
|
||||
adapter.getStates(null, Collections.singletonList("100"), String.class).block();
|
||||
});
|
||||
assertThrows(NullPointerException.class, () -> {
|
||||
// null key
|
||||
// null pointer exception due to keys being converted to an unmodifiable list
|
||||
adapter.getStates(STATE_STORE_NAME, null, String.class).block();
|
||||
});
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// empty key list
|
||||
adapter.getStates(STATE_STORE_NAME, Collections.emptyList(), String.class).block();
|
||||
});
|
||||
// negative parallelism
|
||||
GetStatesRequest req = new GetStatesRequestBuilder(STATE_STORE_NAME, Collections.singletonList("100"))
|
||||
.withParallelism(-1)
|
||||
.build();
|
||||
assertThrows(IllegalArgumentException.class, () -> adapter.getStates(req, TypeRef.BOOLEAN).block());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStatesString() throws IOException {
|
||||
|
|
@ -948,12 +1037,32 @@ public class DaprClientGrpcTest {
|
|||
result.block();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteStateIllegalArgumentExceptionTest() {
|
||||
State<String> key = buildStateKey(null, "Key1", "ETag1", null);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// empty state store name
|
||||
adapter.deleteState("", key.getKey(), "etag", null).block();
|
||||
});
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// null state store name
|
||||
adapter.deleteState(null, key.getKey(), "etag", null).block();
|
||||
});
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// null state store name
|
||||
adapter.deleteState(STATE_STORE_NAME, null, "etag", null).block();
|
||||
});
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// null state store name
|
||||
adapter.deleteState(STATE_STORE_NAME, "", "etag", null).block();
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void deleteStateCallbackExcpetionThrownTest() {
|
||||
SettableFuture<Empty> settableFuture = SettableFuture.create();
|
||||
RuntimeException ex = new RuntimeException("An Exception");
|
||||
MockCallback<Empty> callback =
|
||||
new MockCallback<Empty>(ex);
|
||||
MockCallback<Empty> callback = new MockCallback<>(ex);
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
when(client.deleteState(any(io.dapr.v1.DaprProtos.DeleteStateRequest.class)))
|
||||
.thenReturn(settableFuture);
|
||||
|
|
@ -1003,7 +1112,7 @@ public class DaprClientGrpcTest {
|
|||
String etag = "ETag1";
|
||||
String key = "key1";
|
||||
StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE);
|
||||
Map<String, String> metadata = new HashMap<String, String>();
|
||||
Map<String, String> metadata = new HashMap<>();
|
||||
metadata.put("key_1", "val_1");
|
||||
SettableFuture<Empty> settableFuture = SettableFuture.create();
|
||||
MockCallback<Empty> callback = new MockCallback<>(Empty.newBuilder().build());
|
||||
|
|
@ -1075,6 +1184,75 @@ public class DaprClientGrpcTest {
|
|||
assertTrue(callback.wasCalled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void executeTransactionIllegalArgumentExceptionTest() {
|
||||
State<String> key = buildStateKey(null, "Key1", "ETag1", null);
|
||||
TransactionalStateOperation<String> upsertOperation = new TransactionalStateOperation<>(
|
||||
TransactionalStateOperation.OperationType.UPSERT,
|
||||
key);
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// empty state store name
|
||||
adapter.executeTransaction("", Collections.singletonList(upsertOperation)).block();
|
||||
});
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// null state store name
|
||||
adapter.executeTransaction(null, Collections.singletonList(upsertOperation)).block();
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void executeTransactionSerializerExceptionTest() throws IOException {
|
||||
DaprObjectSerializer mockSerializer = mock(DaprObjectSerializer.class);
|
||||
adapter = new DaprClientGrpc(closeable, client, mockSerializer, mockSerializer);
|
||||
String etag = "ETag1";
|
||||
String key = "key1";
|
||||
String data = "my data";
|
||||
StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, null);
|
||||
SettableFuture<Empty> settableFuture = SettableFuture.create();
|
||||
when(client.executeStateTransaction(any(DaprProtos.ExecuteStateTransactionRequest.class)))
|
||||
.thenReturn(settableFuture);
|
||||
when(mockSerializer.serialize(any())).thenThrow(IOException.class);
|
||||
State<String> stateKey = buildStateKey(data, key, etag, options);
|
||||
TransactionalStateOperation<String> upsertOperation = new TransactionalStateOperation<>(
|
||||
TransactionalStateOperation.OperationType.UPSERT,
|
||||
stateKey);
|
||||
ExecuteStateTransactionRequest request = new ExecuteStateTransactionRequestBuilder(STATE_STORE_NAME)
|
||||
.withTransactionalStates(upsertOperation)
|
||||
.build();
|
||||
Mono<Response<Void>> result = adapter.executeTransaction(request);
|
||||
result.block();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void executeTransactionWithMetadataTest() {
|
||||
String etag = "ETag1";
|
||||
String key = "key1";
|
||||
String data = "my data";
|
||||
StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, null);
|
||||
SettableFuture<Empty> settableFuture = SettableFuture.create();
|
||||
MockCallback<Empty> callback = new MockCallback<>(Empty.newBuilder().build());
|
||||
addCallback(settableFuture, callback, directExecutor());
|
||||
when(client.executeStateTransaction(any(DaprProtos.ExecuteStateTransactionRequest.class)))
|
||||
.thenReturn(settableFuture);
|
||||
State<String> stateKey = buildStateKey(data, key, etag, options);
|
||||
TransactionalStateOperation<String> upsertOperation = new TransactionalStateOperation<>(
|
||||
TransactionalStateOperation.OperationType.UPSERT,
|
||||
stateKey);
|
||||
TransactionalStateOperation<String> deleteOperation = new TransactionalStateOperation<>(
|
||||
TransactionalStateOperation.OperationType.DELETE,
|
||||
new State<>("testKey"));
|
||||
Map<String, String> metadata = new HashMap<>();
|
||||
metadata.put("testKey", "testValue");
|
||||
ExecuteStateTransactionRequest request = new ExecuteStateTransactionRequestBuilder(STATE_STORE_NAME)
|
||||
.withTransactionalStates(upsertOperation, deleteOperation)
|
||||
.withMetadata(metadata)
|
||||
.build();
|
||||
Mono<Response<Void>> result = adapter.executeTransaction(request);
|
||||
settableFuture.set(Empty.newBuilder().build());
|
||||
result.block();
|
||||
assertTrue(callback.wasCalled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void executeTransactionTest() {
|
||||
String etag = "ETag1";
|
||||
|
|
@ -1137,6 +1315,18 @@ public class DaprClientGrpcTest {
|
|||
result.block();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void saveStatesIllegalArgumentExceptionTest() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// empty state store name
|
||||
adapter.saveStates("", Collections.emptyList()).block();
|
||||
});
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// empty state store name
|
||||
adapter.saveStates(null, Collections.emptyList()).block();
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void saveStateExceptionThrownTest() {
|
||||
String key = "key1";
|
||||
|
|
@ -1260,7 +1450,7 @@ public class DaprClientGrpcTest {
|
|||
}
|
||||
|
||||
private <T> State<T> buildStateKey(T value, String key, String etag, StateOptions options) {
|
||||
return new State(value, key, etag, options);
|
||||
return new State<>(value, key, etag, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1381,8 +1571,26 @@ public class DaprClientGrpcTest {
|
|||
return settableFuture;
|
||||
});
|
||||
|
||||
assertThrows(RuntimeException.class, () -> {
|
||||
Map<String, String> result = adapter.getSecret(SECRET_STORE_NAME, "key").block();
|
||||
assertThrows(RuntimeException.class, () -> adapter.getSecret(SECRET_STORE_NAME, "key").block());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSecretsIllegalArgumentException() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// empty secret store name
|
||||
adapter.getSecret("", "key").block();
|
||||
});
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// null secret store name
|
||||
adapter.getSecret(null, "key").block();
|
||||
});
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// empty key
|
||||
adapter.getSecret(SECRET_STORE_NAME, "").block();
|
||||
});
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
// null key
|
||||
adapter.getSecret(SECRET_STORE_NAME, null).block();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -1502,7 +1710,7 @@ public class DaprClientGrpcTest {
|
|||
return ByteString.copyFrom(byteValue);
|
||||
}
|
||||
|
||||
private final class MockCallback<T> implements FutureCallback<T> {
|
||||
private static final class MockCallback<T> implements FutureCallback<T> {
|
||||
private T value = null;
|
||||
private Throwable failure = null;
|
||||
private boolean wasCalled = false;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
|
@ -425,6 +426,7 @@ public class DaprClientHttpTest {
|
|||
assertEquals("not found", result.stream().skip(1).findFirst().get().getError());
|
||||
}
|
||||
|
||||
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||
@Test
|
||||
public void getStatesBoolean() {
|
||||
mockInterceptor.addRule()
|
||||
|
|
@ -435,9 +437,10 @@ public class DaprClientHttpTest {
|
|||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
List<State<Boolean>> result =
|
||||
daprClientHttp.getStates(STATE_STORE_NAME, Arrays.asList("100", "200"), boolean.class).block();
|
||||
assertNotNull(result);
|
||||
assertEquals(2, result.size());
|
||||
assertEquals("100", result.stream().findFirst().get().getKey());
|
||||
assertEquals(true, (boolean)result.stream().findFirst().get().getValue());
|
||||
assertTrue((boolean) result.stream().findFirst().get().getValue());
|
||||
assertEquals("1", result.stream().findFirst().get().getEtag());
|
||||
assertNull(result.stream().findFirst().get().getError());
|
||||
assertEquals("200", result.stream().skip(1).findFirst().get().getKey());
|
||||
|
|
@ -499,8 +502,8 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void getState() {
|
||||
StateOptions stateOptions = mock(StateOptions.class);
|
||||
State<String> stateKeyValue = new State("value", "key", "etag", stateOptions);
|
||||
State<String> stateKeyNull = new State("value", null, "etag", stateOptions);
|
||||
State<String> stateKeyValue = new State<>("value", "key", "etag", stateOptions);
|
||||
State<String> stateKeyNull = new State<>("value", null, "etag", stateOptions);
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.respond("\"" + EXPECTED_RESULT + "\"");
|
||||
|
|
@ -510,12 +513,14 @@ public class DaprClientHttpTest {
|
|||
daprClientHttp.getState(STATE_STORE_NAME, stateKeyNull, String.class).block();
|
||||
});
|
||||
Mono<State<String>> mono = daprClientHttp.getState(STATE_STORE_NAME, stateKeyValue, String.class);
|
||||
assertEquals(mono.block().getKey(), "key");
|
||||
State<String> result = mono.block();
|
||||
assertNotNull(result);
|
||||
assertEquals(result.getKey(), "key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStatesEmptyEtag() {
|
||||
State<String> stateEmptyEtag = new State("value", "key", "", null);
|
||||
State<String> stateEmptyEtag = new State<>("value", "key", "", null);
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.respond("\"" + EXPECTED_RESULT + "\"");
|
||||
|
|
@ -527,7 +532,7 @@ public class DaprClientHttpTest {
|
|||
|
||||
@Test
|
||||
public void getStateWithMetadata() {
|
||||
Map<String, String> metadata = new HashMap<String, String>();
|
||||
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?key_1=val_1")
|
||||
|
|
@ -542,7 +547,7 @@ public class DaprClientHttpTest {
|
|||
|
||||
@Test
|
||||
public void getStatesNullEtag() {
|
||||
State<String> stateNullEtag = new State("value", "key", null, null);
|
||||
State<String> stateNullEtag = new State<>("value", "key", null, null);
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.respond("\"" + EXPECTED_RESULT + "\"");
|
||||
|
|
@ -554,7 +559,7 @@ public class DaprClientHttpTest {
|
|||
|
||||
@Test
|
||||
public void getStatesNoHotMono() {
|
||||
State<String> stateNullEtag = new State("value", "key", null, null);
|
||||
State<String> stateNullEtag = new State<>("value", "key", null, null);
|
||||
mockInterceptor.addRule()
|
||||
.get("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.respond(500);
|
||||
|
|
@ -566,8 +571,8 @@ public class DaprClientHttpTest {
|
|||
|
||||
@Test
|
||||
public void saveStates() {
|
||||
State<String> stateKeyValue = new State("value", "key", "etag", null);
|
||||
List<State<?>> stateKeyValueList = Arrays.asList(stateKeyValue);
|
||||
State<String> stateKeyValue = new State<>("value", "key", "etag", null);
|
||||
List<State<?>> stateKeyValueList = Collections.singletonList(stateKeyValue);
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
|
@ -587,7 +592,7 @@ public class DaprClientHttpTest {
|
|||
|
||||
@Test
|
||||
public void saveStatesNull() {
|
||||
List<State<?>> stateKeyValueList = new ArrayList();
|
||||
List<State<?>> stateKeyValueList = new ArrayList<>();
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
|
@ -601,8 +606,8 @@ public class DaprClientHttpTest {
|
|||
|
||||
@Test
|
||||
public void saveStatesEtagNull() {
|
||||
State<String> stateKeyValue = new State("value", "key", null, null);
|
||||
List<State<?>> stateKeyValueList = Arrays.asList(stateKeyValue);
|
||||
State<String> stateKeyValue = new State<>("value", "key", null, null);
|
||||
List<State<?>> stateKeyValueList = Collections.singletonList(stateKeyValue);
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
|
@ -614,8 +619,8 @@ public class DaprClientHttpTest {
|
|||
|
||||
@Test
|
||||
public void saveStatesEtagEmpty() {
|
||||
State<String> stateKeyValue = new State("value", "key", "", null);
|
||||
List<State<?>> stateKeyValueList = Arrays.asList(stateKeyValue);
|
||||
State<String> stateKeyValue = new State<>("value", "key", "", null);
|
||||
List<State<?>> stateKeyValueList = Collections.singletonList(stateKeyValue);
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3000/v1.0/state/MyStateStore")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
|
@ -661,7 +666,7 @@ public class DaprClientHttpTest {
|
|||
daprHttp = new DaprHttp(Properties.SIDECAR_IP.get(), 3000, okHttpClient);
|
||||
daprClientHttp = new DaprClientHttp(daprHttp);
|
||||
|
||||
State<String> stateKey = new State(data, key, etag, stateOptions);
|
||||
State<String> stateKey = new State<>(data, key, etag, stateOptions);
|
||||
TransactionalStateOperation<String> upsertOperation = new TransactionalStateOperation<>(
|
||||
TransactionalStateOperation.OperationType.UPSERT,
|
||||
stateKey);
|
||||
|
|
@ -701,7 +706,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void deleteState() {
|
||||
StateOptions stateOptions = mock(StateOptions.class);
|
||||
State<String> stateKeyValue = new State("value", "key", "etag", stateOptions);
|
||||
State<String> stateKeyValue = new State<>("value", "key", "etag", stateOptions);
|
||||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
|
@ -713,10 +718,10 @@ public class DaprClientHttpTest {
|
|||
|
||||
@Test
|
||||
public void deleteStateWithMetadata() {
|
||||
Map<String, String> metadata = new HashMap<String, String>();
|
||||
Map<String, String> metadata = new HashMap<>();
|
||||
metadata.put("key_1", "val_1");
|
||||
StateOptions stateOptions = mock(StateOptions.class);
|
||||
State<String> stateKeyValue = new State("value", "key", "etag", stateOptions);
|
||||
State<String> stateKeyValue = new State<>("value", "key", "etag", stateOptions);
|
||||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/state/MyStateStore/key?key_1=val_1")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
|
@ -731,7 +736,7 @@ public class DaprClientHttpTest {
|
|||
@Test
|
||||
public void deleteStateNoHotMono() {
|
||||
StateOptions stateOptions = mock(StateOptions.class);
|
||||
State<String> stateKeyValue = new State("value", "key", "etag", stateOptions);
|
||||
State<String> stateKeyValue = new State<>("value", "key", "etag", stateOptions);
|
||||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.respond(500);
|
||||
|
|
@ -743,7 +748,7 @@ public class DaprClientHttpTest {
|
|||
|
||||
@Test
|
||||
public void deleteStateNullEtag() {
|
||||
State<String> stateKeyValue = new State("value", "key", null, null);
|
||||
State<String> stateKeyValue = new State<>("value", "key", null, null);
|
||||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
|
@ -755,7 +760,7 @@ public class DaprClientHttpTest {
|
|||
|
||||
@Test
|
||||
public void deleteStateEmptyEtag() {
|
||||
State<String> stateKeyValue = new State("value", "key", "", null);
|
||||
State<String> stateKeyValue = new State<>("value", "key", "", null);
|
||||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
|
@ -767,8 +772,8 @@ public class DaprClientHttpTest {
|
|||
|
||||
@Test
|
||||
public void deleteStateIllegalArgumentException() {
|
||||
State<String> stateKeyValueNull = new State("value", null, "etag", null);
|
||||
State<String> stateKeyValueEmpty = new State("value", "", "etag", null);
|
||||
State<String> stateKeyValueNull = new State<>("value", null, "etag", null);
|
||||
State<String> stateKeyValueEmpty = new State<>("value", "", "etag", null);
|
||||
mockInterceptor.addRule()
|
||||
.delete("http://127.0.0.1:3000/v1.0/state/MyStateStore/key")
|
||||
.respond(EXPECTED_RESULT);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ public class DaprHttpBuilderTest {
|
|||
assertSame(getOkHttpClient(daprHttp), getOkHttpClient(anotherDaprHttp));
|
||||
}
|
||||
|
||||
|
||||
private static OkHttpClient getOkHttpClient(DaprHttp daprHttp) throws Exception {
|
||||
Field httpClientField = DaprHttp.class.getDeclaredField("httpClient");
|
||||
httpClientField.setAccessible(true);
|
||||
|
|
|
|||
|
|
@ -58,6 +58,5 @@ public class DaprHttpStub extends DaprHttp {
|
|||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -167,6 +167,7 @@ public class DaprHttpTest {
|
|||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void invokePostDaprError() throws IOException {
|
||||
|
||||
mockInterceptor.addRule()
|
||||
.post("http://127.0.0.1:3500/v1.0/state")
|
||||
.respond(500, ResponseBody.create(MediaType.parse("text"),
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public class StateTest {
|
|||
+ ", etag='" + ETAG + "'"
|
||||
+ ", error='null'"
|
||||
+ ", options={'null'}"
|
||||
+ "}";;
|
||||
+ "}";
|
||||
assertEquals(expected, state.toString());
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ public class StateTest {
|
|||
+ ", etag='" + ETAG + "'"
|
||||
+ ", error='null'"
|
||||
+ ", options={'" + OPTIONS.toString() + "'}"
|
||||
+ "}";;
|
||||
+ "}";
|
||||
assertEquals(expected, state.toString());
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ public class StateTest {
|
|||
+ ", etag='" + ETAG + "'"
|
||||
+ ", error='null'"
|
||||
+ ", options={'" + OPTIONS.toString() + "'}"
|
||||
+ "}";;
|
||||
+ "}";
|
||||
assertEquals(expected, state.toString());
|
||||
assertEquals("value", state.getValue());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,8 +123,7 @@ public final class Dapr implements DaprRuntime {
|
|||
|
||||
try {
|
||||
HandleRequest request = new HandleRequest(name, payload, metadata);
|
||||
Mono<byte[]> response = handler.apply(request);
|
||||
return response;
|
||||
return handler.apply(request);
|
||||
} catch (Exception e) {
|
||||
// Handling exception in user code by propagating up via Mono.
|
||||
return Mono.error(e);
|
||||
|
|
|
|||
|
|
@ -286,15 +286,15 @@ public class DaprRuntimeTest {
|
|||
result.block();
|
||||
}
|
||||
|
||||
private static final String generateMessageId() {
|
||||
private static String generateMessageId() {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
private static final String generatePayload() {
|
||||
private static String generatePayload() {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
private static final Map<String, String> generateSingleMetadata() {
|
||||
private static Map<String, String> generateSingleMetadata() {
|
||||
return Collections.singletonMap(UUID.randomUUID().toString(), UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import java.util.List;
|
|||
import java.util.function.Function;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
|
@ -444,8 +445,8 @@ public class DefaultObjectSerializerTest {
|
|||
MyObjectTestToSerialize objResult = SERIALIZER.deserialize(null, MyObjectTestToSerialize.class);
|
||||
assertNull(objResult);
|
||||
boolean boolResult = SERIALIZER.deserialize(null, boolean.class);
|
||||
assertEquals(false, boolResult);
|
||||
byte expectedByteResult = Byte.valueOf((byte) 0);
|
||||
assertFalse(boolResult);
|
||||
byte expectedByteResult = (byte) 0;
|
||||
byte byteResult = SERIALIZER.deserialize(null, byte.class);
|
||||
assertEquals(expectedByteResult, byteResult);
|
||||
short expectedShortResult = (short) 0;
|
||||
|
|
@ -460,7 +461,7 @@ public class DefaultObjectSerializerTest {
|
|||
float expectedFloatResult = 0f;
|
||||
float floatResult = SERIALIZER.deserialize(null, float.class);
|
||||
assertEquals(expectedFloatResult, floatResult, 0.0f);
|
||||
double expectedDoubleResult = (double) 0;
|
||||
double expectedDoubleResult = 0;
|
||||
double doubleResult = SERIALIZER.deserialize(null, double.class);
|
||||
assertEquals(expectedDoubleResult, doubleResult, 0.0);
|
||||
} catch (IOException exception) {
|
||||
|
|
@ -812,7 +813,7 @@ public class DefaultObjectSerializerTest {
|
|||
|
||||
@Test
|
||||
public void deserializeListOfString() throws IOException {
|
||||
List<String> r = SERIALIZER.deserialize("[\"1\", \"2\", \"3\"]".getBytes(), new ArrayList<String>().getClass());
|
||||
List<String> r = SERIALIZER.deserialize("[\"1\", \"2\", \"3\"]".getBytes(), ArrayList.class);
|
||||
|
||||
assertNotNull(r);
|
||||
assertEquals(3, r.size());
|
||||
|
|
|
|||
Loading…
Reference in New Issue