use of com.google.firestore.v1.WriteRequest 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.WriteRequest in project firebase-android-sdk by firebase.
the class WatchStream method unwatchTarget.
/**
* Unregisters interest in the results of the query associated with the given target ID.
*/
public void unwatchTarget(int targetId) {
hardAssert(isOpen(), "Unwatching targets requires an open stream");
ListenRequest request = ListenRequest.newBuilder().setDatabase(serializer.databaseName()).setRemoveTarget(targetId).build();
writeRequest(request);
}
use of com.google.firestore.v1.WriteRequest in project firebase-android-sdk by firebase.
the class WriteStream method writeMutations.
/**
* Sends a list of mutations to the Firestore backend to apply
*
* @param mutations The mutations
*/
void writeMutations(List<Mutation> mutations) {
hardAssert(isOpen(), "Writing mutations requires an opened stream");
hardAssert(handshakeComplete, "Handshake must be complete before writing mutations");
WriteRequest.Builder request = WriteRequest.newBuilder();
for (Mutation mutation : mutations) {
request.addWrites(serializer.encodeMutation(mutation));
}
request.setStreamToken(lastStreamToken);
writeRequest(request.build());
}
use of com.google.firestore.v1.WriteRequest 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