use of com.google.firestore.v1.WriteResponse in project java-firestore by googleapis.
the class FirestoreClientTest method writeTest.
@Test
public void writeTest() throws Exception {
WriteResponse expectedResponse = WriteResponse.newBuilder().setStreamId("streamId1790933179").setStreamToken(ByteString.EMPTY).addAllWriteResults(new ArrayList<WriteResult>()).setCommitTime(Timestamp.newBuilder().build()).build();
mockFirestore.addResponse(expectedResponse);
WriteRequest request = WriteRequest.newBuilder().setDatabase("database1789464955").setStreamId("streamId1790933179").addAllWrites(new ArrayList<Write>()).setStreamToken(ByteString.EMPTY).putAllLabels(new HashMap<String, String>()).build();
MockStreamObserver<WriteResponse> responseObserver = new MockStreamObserver<>();
BidiStreamingCallable<WriteRequest, WriteResponse> callable = client.writeCallable();
ApiStreamObserver<WriteRequest> requestObserver = callable.bidiStreamingCall(responseObserver);
requestObserver.onNext(request);
requestObserver.onCompleted();
List<WriteResponse> actualResponses = responseObserver.future().get();
Assert.assertEquals(1, actualResponses.size());
Assert.assertEquals(expectedResponse, actualResponses.get(0));
}
use of com.google.firestore.v1.WriteResponse in project firebase-android-sdk by firebase.
the class RemoteSerializer method decodeMutationResult.
public MutationResult decodeMutationResult(com.google.firestore.v1.WriteResult proto, SnapshotVersion commitVersion) {
// NOTE: Deletes don't have an updateTime but the commit timestamp from the containing
// CommitResponse or WriteResponse indicates essentially that the delete happened no later than
// that. For our purposes we don't care exactly when the delete happened so long as we can tell
// when an update on the watch stream is at or later than that change.
SnapshotVersion version = decodeVersion(proto.getUpdateTime());
if (SnapshotVersion.NONE.equals(version)) {
version = commitVersion;
}
int transformResultsCount = proto.getTransformResultsCount();
List<Value> transformResults = new ArrayList<>(transformResultsCount);
for (int i = 0; i < transformResultsCount; i++) {
transformResults.add(proto.getTransformResults(i));
}
return new MutationResult(version, transformResults);
}
use of com.google.firestore.v1.WriteResponse in project java-firestore by googleapis.
the class FirestoreClientTest method writeExceptionTest.
@Test
public void writeExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockFirestore.addException(exception);
WriteRequest request = WriteRequest.newBuilder().setDatabase("database1789464955").setStreamId("streamId1790933179").addAllWrites(new ArrayList<Write>()).setStreamToken(ByteString.EMPTY).putAllLabels(new HashMap<String, String>()).build();
MockStreamObserver<WriteResponse> responseObserver = new MockStreamObserver<>();
BidiStreamingCallable<WriteRequest, WriteResponse> callable = client.writeCallable();
ApiStreamObserver<WriteRequest> requestObserver = callable.bidiStreamingCall(responseObserver);
requestObserver.onNext(request);
try {
List<WriteResponse> actualResponses = responseObserver.future().get();
Assert.fail("No exception thrown");
} catch (ExecutionException e) {
Assert.assertTrue(e.getCause() instanceof InvalidArgumentException);
InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
}
}
Aggregations