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..7e77aba60e95 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 timestampDoesntGetTruncatedDuringUpdate() 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");