Skip to content

Commit 4b9fe80

Browse files
Praful Makanisduskis
authored andcommitted
---
yaml --- r: 22375 b: refs/heads/autosynth-asset c: 554c109 h: refs/heads/master i: 22373: a5f3bbd 22371: a0f4ff8 22367: f4ee76d
1 parent 767a6dc commit 4b9fe80

5 files changed

Lines changed: 77 additions & 2 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ refs/heads/autosynth-vision: 3866c747a5e87b5dfd530d7134907a7ed1fb16de
120120
refs/heads/spanner: b01127f885b4611bf1852abb0ce481eeb7fcc131
121121
refs/tags/v0.68.0: 9cc799fcf68c82ab431d425fefa58ef615ce8e5b
122122
refs/tags/v0.69.0: 78f67a29e8b9c46ba01de566a2eae0fd1c03edea
123-
refs/heads/autosynth-asset: 95a9cdf4f95ddfb2e157135e14b0c5dc406a02b2
123+
refs/heads/autosynth-asset: 554c109518b4d70e6264a1cd2b1a13be65e230f9
124124
refs/heads/autosynth-automl: 2a8b018cf05811fd472e5d1053e67a12ceec0b64
125125
refs/heads/autosynth-bigquerydatatransfer: 564833a85642d4194adc025f021e10e723154246
126126
refs/heads/autosynth-bigquerystorage: a75c34ed7a11741669121be69a7021a00f1133ce

branches/autosynth-asset/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/CustomClassMapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.google.cloud.firestore.annotation.PropertyName;
2323
import com.google.cloud.firestore.annotation.ServerTimestamp;
2424
import com.google.cloud.firestore.annotation.ThrowOnExtraProperties;
25+
import com.google.firestore.v1.Value;
2526
import java.lang.reflect.AccessibleObject;
2627
import java.lang.reflect.Constructor;
2728
import java.lang.reflect.Field;
@@ -166,7 +167,8 @@ private static <T> Object serialize(T o, ErrorPath path) {
166167
|| o instanceof GeoPoint
167168
|| o instanceof Blob
168169
|| o instanceof DocumentReference
169-
|| o instanceof FieldValue) {
170+
|| o instanceof FieldValue
171+
|| o instanceof Value) {
170172
return o;
171173
} else {
172174
Class<T> clazz = (Class<T>) o.getClass();

branches/autosynth-asset/google-cloud-clients/google-cloud-firestore/src/main/java/com/google/cloud/firestore/UserDataConverter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ static Value encodeValue(
148148
} else if (sanitizedObject instanceof Blob) {
149149
Blob blob = (Blob) sanitizedObject;
150150
return Value.newBuilder().setBytesValue(blob.toByteString()).build();
151+
} else if (sanitizedObject instanceof Value) {
152+
return (Value) sanitizedObject;
151153
} else if (sanitizedObject instanceof DocumentReference) {
152154
DocumentReference docRef = (DocumentReference) sanitizedObject;
153155
return Value.newBuilder().setReferenceValue(docRef.getName()).build();

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,36 @@ public void setDocument() throws Exception {
139139
assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
140140
}
141141

142+
@Test
143+
public void setDocumentWithValue() throws Exception {
144+
doReturn(commitResponse(4, 0))
145+
.when(firestoreMock)
146+
.sendRequest(
147+
commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
148+
149+
batch
150+
.set(documentReference, LocalFirestoreHelper.SINGLE_FIELD_PROTO)
151+
.set(documentReference, LocalFirestoreHelper.SINGLE_FIELD_OBJECT)
152+
.set(documentReference, LocalFirestoreHelper.SINGLE_FIELD_PROTO, SetOptions.merge())
153+
.set(documentReference, LocalFirestoreHelper.SINGLE_FIELD_OBJECT, SetOptions.merge());
154+
155+
List<Write> writes = new ArrayList<>();
156+
writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO));
157+
writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO));
158+
writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO, Arrays.asList("foo")));
159+
writes.add(set(LocalFirestoreHelper.SINGLE_FIELD_PROTO, Arrays.asList("foo")));
160+
161+
assertEquals(4, batch.getMutationsSize());
162+
163+
List<WriteResult> writeResults = batch.commit().get();
164+
for (int i = 0; i < writeResults.size(); ++i) {
165+
assertEquals(Timestamp.ofTimeSecondsAndNanos(i, i), writeResults.get(i).getUpdateTime());
166+
}
167+
168+
CommitRequest commitRequest = commitCapture.getValue();
169+
assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
170+
}
171+
142172
@Test
143173
public void omitWriteResultForDocumentTransforms() throws Exception {
144174
doReturn(commitResponse(2, 0))
@@ -179,6 +209,31 @@ public void createDocument() throws Exception {
179209
assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
180210
}
181211

212+
@Test
213+
public void createDocumentWithValue() throws Exception {
214+
doReturn(commitResponse(2, 0))
215+
.when(firestoreMock)
216+
.sendRequest(
217+
commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
218+
219+
batch
220+
.create(documentReference, LocalFirestoreHelper.SINGLE_FIELD_PROTO)
221+
.create(documentReference, LocalFirestoreHelper.SINGLE_FIELD_OBJECT);
222+
223+
assertEquals(2, batch.getMutationsSize());
224+
225+
List<WriteResult> writeResults = batch.commit().get();
226+
List<Write> writes = new ArrayList<>();
227+
228+
for (int i = 0; i < writeResults.size(); ++i) {
229+
assertEquals(Timestamp.ofTimeSecondsAndNanos(i, i), writeResults.get(i).getUpdateTime());
230+
writes.add(create(LocalFirestoreHelper.SINGLE_FIELD_PROTO));
231+
}
232+
233+
CommitRequest commitRequest = commitCapture.getValue();
234+
assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
235+
}
236+
182237
@Test
183238
public void deleteDocument() throws Exception {
184239
doReturn(commitResponse(2, 0))

branches/autosynth-asset/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ public void createDocument() throws Exception {
149149
assertEquals(SINGLE_FIELD_OBJECT, documentSnapshot.toObject(SingleField.class));
150150
}
151151

152+
@Test
153+
public void createDocumentWithValue() throws Exception {
154+
assertEquals(20, randomDoc.getId().length());
155+
randomDoc.create(LocalFirestoreHelper.SINGLE_FIELD_PROTO).get();
156+
DocumentSnapshot documentSnapshot = randomDoc.get().get();
157+
assertEquals(SINGLE_FIELD_OBJECT, documentSnapshot.toObject(SingleField.class));
158+
}
159+
152160
@Test
153161
public void setDocument() throws Exception {
154162
Map<String, Object> nanNullMap = new HashMap<>();
@@ -160,6 +168,14 @@ public void setDocument() throws Exception {
160168
assertEquals(null, documentSnapshot.get("null"));
161169
}
162170

171+
@Test
172+
public void setDocumentWithValue() throws Exception {
173+
assertEquals(20, randomDoc.getId().length());
174+
randomDoc.set(LocalFirestoreHelper.SINGLE_FIELD_PROTO).get();
175+
DocumentSnapshot documentSnapshot = randomDoc.get().get();
176+
assertEquals(SINGLE_FIELD_OBJECT, documentSnapshot.toObject(SingleField.class));
177+
}
178+
163179
@Test
164180
public void setDocumentWithMerge() throws Exception {
165181
Map<String, Object> originalMap =

0 commit comments

Comments
 (0)