use of com.google.cloud.firestore.BulkWriter in project java-firestore by googleapis.
the class ITSystemTest method testRecursiveDeleteWithCustomBulkWriterInstance.
@Test
public void testRecursiveDeleteWithCustomBulkWriterInstance() throws Exception {
setupRecursiveDeleteTest();
BulkWriter bulkWriter = firestore.bulkWriter();
final int[] callbackCount = { 0 };
bulkWriter.addWriteResultListener((documentReference, result) -> callbackCount[0]++);
firestore.recursiveDelete(randomColl, bulkWriter).get();
assertEquals(0, countCollectionChildren(randomColl));
assertEquals(6, callbackCount[0]);
}
use of com.google.cloud.firestore.BulkWriter in project java-firestore by googleapis.
the class ITBulkWriterTest method bulkWriterCreate.
@Test
public void bulkWriterCreate() throws Exception {
DocumentReference docRef = randomColl.document();
firestore.bulkWriter();
BulkWriter writer = firestore.bulkWriter();
ApiFuture<WriteResult> result = writer.create(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 ITBulkWriterTest method bulkWriterCreateAddsPrecondition.
@Test
public void bulkWriterCreateAddsPrecondition() throws Exception {
DocumentReference docRef = randomColl.document();
docRef.set(Collections.singletonMap("foo", "bar")).get();
BulkWriter writer = firestore.bulkWriter();
ApiFuture<WriteResult> result = writer.create(docRef, Collections.singletonMap("foo", "bar"));
writer.close();
try {
result.get();
fail("Create operation should have thrown exception");
} catch (Exception e) {
assertTrue(e.getMessage().contains("Document already exists"));
}
}
use of com.google.cloud.firestore.BulkWriter in project java-firestore by googleapis.
the class ITBulkWriterTest method bulkWriterDelete.
@Test
public void bulkWriterDelete() throws Exception {
DocumentReference docRef = randomColl.document();
docRef.set(Collections.singletonMap("foo", "oldValue")).get();
BulkWriter writer = firestore.bulkWriter();
ApiFuture<WriteResult> result = writer.delete(docRef);
writer.close();
assertNotNull(result.get().getUpdateTime());
// TODO(b/158502664): Remove this check once we can get write times.
assertEquals(Timestamp.ofTimeSecondsAndNanos(0, 0), result.get().getUpdateTime());
DocumentSnapshot snapshot = docRef.get().get();
assertNull(snapshot.get("foo"));
}
use of com.google.cloud.firestore.BulkWriter in project java-firestore by googleapis.
the class ITBulkWriterTest method bulkWriterOnError.
@Test
public void bulkWriterOnError() throws Exception {
class NamedThreadFactory implements ThreadFactory {
public Thread newThread(Runnable r) {
return new Thread(r, "bulkWriterException");
}
}
Executor executor = Executors.newSingleThreadExecutor(new NamedThreadFactory());
final List<String> operations = new ArrayList<>();
BulkWriter writer = firestore.bulkWriter();
writer.addWriteErrorListener(executor, error -> {
operations.add("operation-error");
assertTrue(Thread.currentThread().getName().contains("bulkWriterException"));
return false;
});
writer.addWriteResultListener(executor, (documentReference, result) -> fail("The success listener shouldn't be called"));
writer.update(randomDoc, "foo", "bar");
writer.flush().get();
assertEquals("operation-error", operations.get(0));
}
Aggregations