mirror of https://github.com/dapr/java-sdk.git
Merge pull request #454 from wcs1only/nullable-etag
Unit tests for nullable-etag (#442)
This commit is contained in:
commit
faf3bec6f7
|
@ -34,6 +34,7 @@ import io.grpc.stub.StreamObserver;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.ArgumentMatcher;
|
import org.mockito.ArgumentMatcher;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
@ -43,6 +44,7 @@ import java.io.IOException;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
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
|
@Test
|
||||||
public void saveStateExceptionThrownTest() {
|
public void saveStateExceptionThrownTest() {
|
||||||
String key = "key1";
|
String key = "key1";
|
||||||
|
@ -1621,6 +1646,26 @@ public class DaprClientGrpcTest {
|
||||||
result.block();
|
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
|
@Test
|
||||||
public void saveStateTestNoHotMono() {
|
public void saveStateTestNoHotMono() {
|
||||||
AtomicBoolean called = new AtomicBoolean(false);
|
AtomicBoolean called = new AtomicBoolean(false);
|
||||||
|
@ -1765,6 +1810,25 @@ public class DaprClientGrpcTest {
|
||||||
resultDelete.block();
|
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
|
@Test
|
||||||
public void getStateNullEtag() throws Exception {
|
public void getStateNullEtag() throws Exception {
|
||||||
String etag = null;
|
String etag = null;
|
||||||
|
|
Loading…
Reference in New Issue