Skip to content

Commit 64f3b2b

Browse files
gremi64sduskis
authored andcommitted
Fixes #4423 - Getter on mutations size (#4424)
* 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
1 parent bb2bb7c commit 64f3b2b

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UpdateBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,4 +664,9 @@ public List<WriteResult> apply(CommitResponse commitResponse) {
664664
boolean isEmpty() {
665665
return mutations.isEmpty();
666666
}
667+
668+
/** Get the number of mutations. */
669+
public int getMutationsSize() {
670+
return mutations.size();
671+
}
667672
}

google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/WriteBatchTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public void updateDocument() throws Exception {
9191
batch.update(documentReference, updateTime, "foo", "bar");
9292
batch.update(documentReference, LocalFirestoreHelper.SINGLE_FIELD_MAP, updateTime);
9393

94+
assertEquals(4, batch.getMutationsSize());
95+
9496
List<WriteResult> writeResults = batch.commit().get();
9597
List<Write> writes = new ArrayList<>();
9698

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

131+
assertEquals(4, batch.getMutationsSize());
132+
129133
List<WriteResult> writeResults = batch.commit().get();
130134
for (int i = 0; i < writeResults.size(); ++i) {
131135
assertEquals(Timestamp.ofTimeSecondsAndNanos(i, i), writeResults.get(i).getUpdateTime());
@@ -144,6 +148,8 @@ public void omitWriteResultForDocumentTransforms() throws Exception {
144148

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

151+
assertEquals(1, batch.getMutationsSize());
152+
147153
List<WriteResult> writeResults = batch.commit().get();
148154
assertEquals(1, writeResults.size());
149155
}
@@ -159,6 +165,8 @@ public void createDocument() throws Exception {
159165
.create(documentReference, LocalFirestoreHelper.SINGLE_FIELD_MAP)
160166
.create(documentReference, LocalFirestoreHelper.SINGLE_FIELD_OBJECT);
161167

168+
assertEquals(2, batch.getMutationsSize());
169+
162170
List<WriteResult> writeResults = batch.commit().get();
163171
List<Write> writes = new ArrayList<>();
164172

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

199+
assertEquals(2, batch.getMutationsSize());
200+
191201
List<WriteResult> writeResults = batch.commit().get();
192202

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

0 commit comments

Comments
 (0)