Skip to content

Commit

Permalink
Fixes #4423 - Getter on mutations size (#4424)
Browse files Browse the repository at this point in the history
* Fixes #4423

Getter over mutations size
Allow knowing the size of the list. For exemple, the batch size is limited to 500 mutations

* Fixes #4423 - Getter on mutations size

Allow knowing the size of the list. For exemple, the batch size is limited to 500 mutations

Fixes #4423

* Correction format code
  • Loading branch information
gremi64 authored and sduskis committed Feb 8, 2019
1 parent bb2bb7c commit 64f3b2b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -664,4 +664,9 @@ public List<WriteResult> apply(CommitResponse commitResponse) {
boolean isEmpty() {
return mutations.isEmpty();
}

/** Get the number of mutations. */
public int getMutationsSize() {
return mutations.size();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public void updateDocument() throws Exception {
batch.update(documentReference, updateTime, "foo", "bar");
batch.update(documentReference, LocalFirestoreHelper.SINGLE_FIELD_MAP, updateTime);

assertEquals(4, batch.getMutationsSize());

List<WriteResult> writeResults = batch.commit().get();
List<Write> writes = new ArrayList<>();

Expand Down Expand Up @@ -126,6 +128,8 @@ public void setDocument() throws Exception {
writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO, Arrays.asList("foo")));
writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO, Arrays.asList("foo")));

assertEquals(4, batch.getMutationsSize());

List<WriteResult> writeResults = batch.commit().get();
for (int i = 0; i < writeResults.size(); ++i) {
assertEquals(Timestamp.ofTimeSecondsAndNanos(i, i), writeResults.get(i).getUpdateTime());
Expand All @@ -144,6 +148,8 @@ public void omitWriteResultForDocumentTransforms() throws Exception {

batch.set(documentReference, map("time", FieldValue.serverTimestamp()));

assertEquals(1, batch.getMutationsSize());

List<WriteResult> writeResults = batch.commit().get();
assertEquals(1, writeResults.size());
}
Expand All @@ -159,6 +165,8 @@ public void createDocument() throws Exception {
.create(documentReference, LocalFirestoreHelper.SINGLE_FIELD_MAP)
.create(documentReference, LocalFirestoreHelper.SINGLE_FIELD_OBJECT);

assertEquals(2, batch.getMutationsSize());

List<WriteResult> writeResults = batch.commit().get();
List<Write> writes = new ArrayList<>();

Expand Down Expand Up @@ -188,6 +196,8 @@ public void deleteDocument() throws Exception {
precondition.getUpdateTimeBuilder().setSeconds(1).setNanos(2);
writes.add(delete(precondition.build()));

assertEquals(2, batch.getMutationsSize());

List<WriteResult> writeResults = batch.commit().get();

for (int i = 0; i < writeResults.size(); ++i) {
Expand Down

0 comments on commit 64f3b2b

Please sign in to comment.