From 073c0678cd9655ee48565e538e7a19728e7c64e0 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 29 May 2018 16:58:38 -0700 Subject: [PATCH] Adding queryWithMicrosecondPrecision test --- .../cloud/firestore/it/ITSystemTest.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java index 9ce4e602a892..2dad8bc58262 100644 --- a/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java +++ b/google-cloud-clients/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java @@ -201,7 +201,7 @@ public void serverTimestamp() throws Exception { } @Test - public void updateMicrosecondTimestamp() throws Exception { + public void timestamptDoesntGetTruncatedDuringUpdate() throws Exception { DocumentReference documentReference = addDocument("time", Timestamp.ofTimeSecondsAndNanos(0, 123000)); DocumentSnapshot documentSnapshot = documentReference.get().get(); @@ -265,6 +265,23 @@ public void noResults() throws Exception { assertNotNull(querySnapshot.getReadTime()); } + @Test + public void queryWithMicrosecondPrecision() throws Exception { + Timestamp microsecondTimestamp = Timestamp.ofTimeSecondsAndNanos(0, 123000); + + DocumentReference documentReference = addDocument("time", microsecondTimestamp); + DocumentSnapshot documentSnapshot = documentReference.get().get(); + + Query query = randomColl.whereEqualTo("time", microsecondTimestamp); + QuerySnapshot querySnapshot = query.get().get(); + assertEquals(1, querySnapshot.size()); + + // Using `.toDate()` truncates to millseconds, and hence the query doesn't match. + query = randomColl.whereEqualTo("time", microsecondTimestamp.toDate()); + querySnapshot = query.get().get(); + assertEquals(0, querySnapshot.size()); + } + @Test public void nestedQuery() throws Exception { randomColl = randomColl.document("foo").collection("bar");