Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions sdk/src/test/java/io/dapr/client/DaprClientGrpcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatcher;
import org.mockito.stubbing.Answer;
import reactor.core.publisher.Mono;
Expand All @@ -43,6 +44,7 @@
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -1548,6 +1550,29 @@ public void saveStatesIllegalArgumentExceptionTest() {
});
}

@Test
public void saveBulkStateTestNullEtag() {
List<State<?>> states = new ArrayList<State<?>>();
states.add(new State<String>("null_etag_value", "null_etag_key", null, (StateOptions)null));
states.add(new State<String>("empty_etag_value", "empty_etag_key", "", (StateOptions)null));

ArgumentCaptor<DaprProtos.SaveStateRequest> argument = ArgumentCaptor.forClass(DaprProtos.SaveStateRequest.class);
doAnswer((Answer<Void>) invocation -> {
StreamObserver<Empty> observer = (StreamObserver<Empty>) invocation.getArguments()[1];
observer.onNext(Empty.getDefaultInstance());
observer.onCompleted();
return null;
}).when(daprStub).saveState(argument.capture(), any());

StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE);
Mono<Void> result = client.saveBulkState(STATE_STORE_NAME, states);

result.block();
assertFalse(argument.getValue().getStates(0).hasEtag());
assertTrue(argument.getValue().getStates(1).hasEtag());
assertEquals("", argument.getValue().getStates(1).getEtag().getValue());
}

@Test
public void saveStateExceptionThrownTest() {
String key = "key1";
Expand Down Expand Up @@ -1621,6 +1646,26 @@ public void saveStateTest() {
result.block();
}

@Test
public void saveStateTestNullEtag() {
String key = "key1";
String etag = null;
String value = "State value";
ArgumentCaptor<DaprProtos.SaveStateRequest> argument = ArgumentCaptor.forClass(DaprProtos.SaveStateRequest.class);
doAnswer((Answer<Void>) invocation -> {
StreamObserver<Empty> observer = (StreamObserver<Empty>) invocation.getArguments()[1];
observer.onNext(Empty.getDefaultInstance());
observer.onCompleted();
return null;
}).when(daprStub).saveState(argument.capture(), any());

StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE);
Mono<Void> result = client.saveState(STATE_STORE_NAME, key, etag, value, options);

result.block();
assertFalse(argument.getValue().getStates(0).hasEtag());
}

@Test
public void saveStateTestNoHotMono() {
AtomicBoolean called = new AtomicBoolean(false);
Expand Down Expand Up @@ -1765,6 +1810,25 @@ public void getStateThenDelete() throws Exception {
resultDelete.block();
}

@Test
public void deleteStateNullEtag() {
String key = "key1";
String etag = null;
ArgumentCaptor<DaprProtos.DeleteStateRequest> argument = ArgumentCaptor.forClass(DaprProtos.DeleteStateRequest.class);
doAnswer((Answer<Void>) invocation -> {
StreamObserver<Empty> observer = (StreamObserver<Empty>) invocation.getArguments()[1];
observer.onNext(Empty.getDefaultInstance());
observer.onCompleted();
return null;
}).when(daprStub).deleteState(argument.capture(), any());

StateOptions options = buildStateOptions(StateOptions.Consistency.STRONG, StateOptions.Concurrency.FIRST_WRITE);
Mono<Void> result = client.deleteState(STATE_STORE_NAME, key, etag, options);

result.block();
assertFalse(argument.getValue().hasEtag());
}

@Test
public void getStateNullEtag() throws Exception {
String etag = null;
Expand Down