Merge pull request #454 from wcs1only/nullable-etag

Unit tests for nullable-etag (#442)
This commit is contained in:
Charlie Stanley 2021-01-25 14:09:57 -08:00 committed by GitHub
commit faf3bec6f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 64 additions and 0 deletions

View File

@ -34,6 +34,7 @@ import io.grpc.stub.StreamObserver;
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;
@ -43,6 +44,7 @@ import java.io.IOException;
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;
@ -1548,6 +1550,29 @@ public class DaprClientGrpcTest {
});
}
@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";
@ -1621,6 +1646,26 @@ public class DaprClientGrpcTest {
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);
@ -1765,6 +1810,25 @@ public class DaprClientGrpcTest {
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;