Skip to content

Commit 044ae65

Browse files
Praful Makanisduskis
authored andcommitted
---
yaml --- r: 26071 b: refs/heads/pubsub-ordering-keys c: 554c109 h: refs/heads/master i: 26069: b57cff7 26067: 1d09b1e 26063: 506c608
1 parent d35afe3 commit 044ae65

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
@@ -155,7 +155,7 @@ refs/tags/v0.72.0: a7703f2593ba312c0b2dde6fdfd4f5c764bb55ac
155155
refs/tags/v0.73.0: 21241ea8be9439cc5764c4944cdce21d34ce4f9e
156156
refs/tags/v0.74.0: 9d1f733dbbf790de7b494418523b69c4a9a57638
157157
refs/heads/ignoretest: 23c412ae07af3d0ab1caa2d44d5bc5c0ccb8b31d
158-
refs/heads/pubsub-ordering-keys: 95a9cdf4f95ddfb2e157135e14b0c5dc406a02b2
158+
refs/heads/pubsub-ordering-keys: 554c109518b4d70e6264a1cd2b1a13be65e230f9
159159
"refs/heads/update_mvn_badge": ae2d773814db0f71197ccf5a8612ee1d8056f8de
160160
refs/tags/v0.75.0: c3673089ae09a897c1b4cf7dfe167fe4f8ab32fb
161161
refs/tags/v0.76.0: 395b016826d3ddf9cb8b34919636df15a4dbd032

branches/pubsub-ordering-keys/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/pubsub-ordering-keys/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/pubsub-ordering-keys/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/pubsub-ordering-keys/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)