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 java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -91,6 +90,7 @@ abstract class AbstractDaprClient implements DaprClient {
|
|||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public <T> Mono<T> invokeMethod(
|
||||
String appId,
|
||||
String methodName,
|
||||
|
|
|
@ -16,9 +16,8 @@ import java.io.Closeable;
|
|||
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
/**
|
||||
|
|
|
@ -71,7 +71,6 @@ public class DaprClientGrpc extends AbstractDaprClient {
|
|||
*/
|
||||
private DaprGrpc.DaprStub asyncStub;
|
||||
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
@Override
|
||||
public <T> Mono<T> invokeMethod(InvokeMethodRequest invokeMethodRequest, TypeRef<T> type) {
|
||||
try {
|
||||
final String appId = invokeMethodRequest.getAppId();
|
||||
|
|
|
@ -118,7 +118,6 @@ public final class CloudEvent {
|
|||
this.datacontenttype = "application/octet-stream";
|
||||
this.binaryData = binaryData == null ? null : Arrays.copyOf(binaryData, binaryData.length);;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* It contains properties that represent data that may be populated for an HTTP receiver.
|
||||
*/
|
||||
|
||||
public final class HttpExtension {
|
||||
/**
|
||||
* Convenience HttpExtension object for {@link io.dapr.client.DaprHttp.HttpMethods#NONE} with empty queryString.
|
||||
|
|
|
@ -52,15 +52,12 @@ public class StateOptions {
|
|||
*/
|
||||
@JsonIgnore
|
||||
public Map<String, String> getStateOptionsAsMap() {
|
||||
Map<String, String> mapOptions = null;
|
||||
if (this != null) {
|
||||
mapOptions = new HashMap<>();
|
||||
if (this.getConsistency() != null) {
|
||||
mapOptions.put("consistency", this.getConsistency().getValue());
|
||||
}
|
||||
if (this.getConcurrency() != null) {
|
||||
mapOptions.put("concurrency", this.getConcurrency().getValue());
|
||||
}
|
||||
Map<String, String> mapOptions = new HashMap<>();
|
||||
if (this.getConsistency() != null) {
|
||||
mapOptions.put("consistency", this.getConsistency().getValue());
|
||||
}
|
||||
if (this.getConcurrency() != null) {
|
||||
mapOptions.put("concurrency", this.getConcurrency().getValue());
|
||||
}
|
||||
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 StateOptionDurationDeserializer(Class<?> vc) {
|
||||
super(vc);
|
||||
}
|
||||
|
|
|
@ -742,6 +742,19 @@ public class DaprClientHttpTest {
|
|||
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
|
||||
public void getStatesNullEtag() {
|
||||
State<String> stateNullEtag = new State<>("key", "value", null, null);
|
||||
|
|
Loading…
Reference in New Issue