use of com.google.cloud.firestore.BulkWriter in project java-firestore by googleapis.
the class ITBulkWriterTest method bulkWriterOnResult.
@Test
public void bulkWriterOnResult() throws Exception {
class NamedThreadFactory implements ThreadFactory {
public Thread newThread(Runnable r) {
return new Thread(r, "bulkWriterSuccess");
}
}
Executor executor = Executors.newSingleThreadExecutor(new NamedThreadFactory());
final List<String> operations = new ArrayList<>();
BulkWriter writer = firestore.bulkWriter();
writer.addWriteResultListener(executor, (documentReference, result) -> {
operations.add("operation");
assertTrue(Thread.currentThread().getName().contains("bulkWriterSuccess"));
});
writer.set(randomDoc, Collections.singletonMap("foo", "bar"));
writer.flush().get();
assertEquals("operation", operations.get(0));
}
use of com.google.cloud.firestore.BulkWriter in project java-firestore by googleapis.
the class ITBulkWriterTest method bulkWriterUpdate.
@Test
public void bulkWriterUpdate() throws Exception {
DocumentReference docRef = randomColl.document();
docRef.set(Collections.singletonMap("foo", "oldValue")).get();
BulkWriter writer = firestore.bulkWriter();
ApiFuture<WriteResult> result = writer.update(docRef, "foo", "newValue");
writer.close();
assertNotNull(result.get().getUpdateTime());
DocumentSnapshot snapshot = docRef.get().get();
assertEquals("newValue", snapshot.get("foo"));
}
use of com.google.cloud.firestore.BulkWriter in project java-firestore by googleapis.
the class ITBulkWriterTest method bulkWriterUpdateAddsPrecondition.
@Test
public void bulkWriterUpdateAddsPrecondition() throws Exception {
DocumentReference docRef = randomColl.document();
BulkWriter writer = firestore.bulkWriter();
ApiFuture<WriteResult> result = writer.update(docRef, "foo", "newValue");
writer.close();
try {
result.get();
fail("Update operation should have thrown exception");
} catch (Exception e) {
assertTrue(e.getMessage().matches(".* No (document|entity) to update.*"));
}
}
use of com.google.cloud.firestore.BulkWriter in project java-firestore by googleapis.
the class ITBulkWriterTest method bulkWriterSet.
@Test
public void bulkWriterSet() throws Exception {
DocumentReference docRef = randomColl.document();
BulkWriter writer = firestore.bulkWriter();
ApiFuture<WriteResult> result = writer.set(docRef, Collections.singletonMap("foo", "bar"));
writer.close();
assertNotNull(result.get().getUpdateTime());
DocumentSnapshot snapshot = docRef.get().get();
assertEquals("bar", snapshot.get("foo"));
}
use of com.google.cloud.firestore.BulkWriter in project java-firestore by googleapis.
the class ITSystemTest method testEnforcesTimeouts.
@Test
public void testEnforcesTimeouts() {
FirestoreOptions firestoreOptions = FirestoreOptions.newBuilder().setRetrySettings(RetrySettings.newBuilder().setMaxRpcTimeout(Duration.ofMillis(1)).setTotalTimeout(Duration.ofMillis(1)).setInitialRpcTimeout(Duration.ofMillis(1)).build()).build();
firestore = firestoreOptions.getService();
CollectionReference collection = firestore.collection("timeout");
// RunQuery
assertThrows(ExecutionException.class, () -> collection.get().get());
// CommitRequest
assertThrows(ExecutionException.class, () -> collection.add(map()).get());
// BulkCommit
assertThrows(ExecutionException.class, () -> {
BulkWriter bulkWriter = firestore.bulkWriter();
ApiFuture<WriteResult> op = bulkWriter.set(collection.document(), map());
bulkWriter.close();
op.get();
});
// BatchGetDocuments
assertThrows(ExecutionException.class, () -> collection.document().get().get());
// ListDocuments
assertThrows(FirestoreException.class, () -> collection.listDocuments().iterator().hasNext());
// ListCollections
assertThrows(FirestoreException.class, () -> collection.document().listCollections().iterator().hasNext());
}
Aggregations