mirror of https://github.com/dapr/java-sdk.git
chore: format some places to make the code more standardized (#578)
* chore: format some places to make the code more standardized * test: add unit test for {@code DaprClient#getState} to cover {@code StateOptions#getStateOptionsAsMap}
This commit is contained in:
parent
94448a9f09
commit
50f80d8af5
|
@ -33,7 +33,6 @@ import io.dapr.utils.TypeRef;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -91,6 +90,7 @@ abstract class AbstractDaprClient implements DaprClient {
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public <T> Mono<T> invokeMethod(
|
public <T> Mono<T> invokeMethod(
|
||||||
String appId,
|
String appId,
|
||||||
String methodName,
|
String methodName,
|
||||||
|
|
|
@ -16,9 +16,8 @@ import java.io.Closeable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A builder for the DaprClient,
|
* A builder for the DaprClient,
|
||||||
* Currently only and HTTP Client will be supported.
|
* Currently only gRPC and HTTP Client will be supported.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class DaprClientBuilder {
|
public class DaprClientBuilder {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -71,7 +71,6 @@ public class DaprClientGrpc extends AbstractDaprClient {
|
||||||
*/
|
*/
|
||||||
private DaprGrpc.DaprStub asyncStub;
|
private DaprGrpc.DaprStub asyncStub;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default access level constructor, in order to create an instance of this class use io.dapr.client.DaprClientBuilder
|
* Default access level constructor, in order to create an instance of this class use io.dapr.client.DaprClientBuilder
|
||||||
*
|
*
|
||||||
|
|
|
@ -161,6 +161,7 @@ public class DaprClientHttp extends AbstractDaprClient {
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public <T> Mono<T> invokeMethod(InvokeMethodRequest invokeMethodRequest, TypeRef<T> type) {
|
public <T> Mono<T> invokeMethod(InvokeMethodRequest invokeMethodRequest, TypeRef<T> type) {
|
||||||
try {
|
try {
|
||||||
final String appId = invokeMethodRequest.getAppId();
|
final String appId = invokeMethodRequest.getAppId();
|
||||||
|
|
|
@ -119,7 +119,6 @@ public final class CloudEvent {
|
||||||
this.binaryData = binaryData == null ? null : Arrays.copyOf(binaryData, binaryData.length);;
|
this.binaryData = binaryData == null ? null : Arrays.copyOf(binaryData, binaryData.length);;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deserialize a message topic from Dapr.
|
* Deserialize a message topic from Dapr.
|
||||||
*
|
*
|
||||||
|
|
|
@ -18,7 +18,6 @@ import java.util.Optional;
|
||||||
* This class is only needed if the app you are calling is listening on HTTP.
|
* This class is only needed if the app you are calling is listening on HTTP.
|
||||||
* It contains properties that represent data that may be populated for an HTTP receiver.
|
* It contains properties that represent data that may be populated for an HTTP receiver.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public final class HttpExtension {
|
public final class HttpExtension {
|
||||||
/**
|
/**
|
||||||
* Convenience HttpExtension object for {@link io.dapr.client.DaprHttp.HttpMethods#NONE} with empty queryString.
|
* Convenience HttpExtension object for {@link io.dapr.client.DaprHttp.HttpMethods#NONE} with empty queryString.
|
||||||
|
|
|
@ -52,16 +52,13 @@ public class StateOptions {
|
||||||
*/
|
*/
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public Map<String, String> getStateOptionsAsMap() {
|
public Map<String, String> getStateOptionsAsMap() {
|
||||||
Map<String, String> mapOptions = null;
|
Map<String, String> mapOptions = new HashMap<>();
|
||||||
if (this != null) {
|
|
||||||
mapOptions = new HashMap<>();
|
|
||||||
if (this.getConsistency() != null) {
|
if (this.getConsistency() != null) {
|
||||||
mapOptions.put("consistency", this.getConsistency().getValue());
|
mapOptions.put("consistency", this.getConsistency().getValue());
|
||||||
}
|
}
|
||||||
if (this.getConcurrency() != null) {
|
if (this.getConcurrency() != null) {
|
||||||
mapOptions.put("concurrency", this.getConcurrency().getValue());
|
mapOptions.put("concurrency", this.getConcurrency().getValue());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return Collections.unmodifiableMap(Optional.ofNullable(mapOptions).orElse(Collections.EMPTY_MAP));
|
return Collections.unmodifiableMap(Optional.ofNullable(mapOptions).orElse(Collections.EMPTY_MAP));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,6 +125,7 @@ public class StateOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class StateOptionDurationDeserializer extends StdDeserializer<Duration> {
|
public static class StateOptionDurationDeserializer extends StdDeserializer<Duration> {
|
||||||
|
|
||||||
public StateOptionDurationDeserializer(Class<?> vc) {
|
public StateOptionDurationDeserializer(Class<?> vc) {
|
||||||
super(vc);
|
super(vc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -742,6 +742,19 @@ public class DaprClientHttpTest {
|
||||||
assertEquals(monoMetadata.block().getKey(), "key");
|
assertEquals(monoMetadata.block().getKey(), "key");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
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")
|
||||||
|
.respond("\"" + EXPECTED_RESULT + "\"");
|
||||||
|
|
||||||
|
GetStateRequestBuilder builder = new GetStateRequestBuilder(STATE_STORE_NAME, "key");
|
||||||
|
builder.withStateOptions(stateOptions);
|
||||||
|
Mono<State<String>> monoOptions = daprClientHttp.getState(builder.build(), TypeRef.get(String.class));
|
||||||
|
assertEquals(monoOptions.block().getKey(), "key");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getStatesNullEtag() {
|
public void getStatesNullEtag() {
|
||||||
State<String> stateNullEtag = new State<>("key", "value", null, null);
|
State<String> stateNullEtag = new State<>("key", "value", null, null);
|
||||||
|
|
Loading…
Reference in New Issue