Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1653,4 +1653,56 @@ public void sdkOrdersQueryByDocumentIdTheSameWayOnlineAndOffline() {
// Run query with snapshot listener
checkOnlineAndOfflineResultsMatch(orderedQuery, expectedDocIds.toArray(new String[0]));
}

@Test
public void snapshotListenerSortsNumbersSameWayAsServer() {
Map<String, Map<String, Object>> testDocs =
map(
"intMin",
map("value", Long.MIN_VALUE),
"doubleMin",
map("value", ((double) Long.MIN_VALUE) - 100),
"intMax",
map("value", Long.MAX_VALUE),
"doubleMax",
map("value", ((double) Long.MAX_VALUE) + 100),
"NAN",
map("value", Double.NaN),
"integerMax",
map("value", (long) Integer.MAX_VALUE),
"integerMin",
map("value", (long) Integer.MIN_VALUE),
"negativeInfinity",
map("value", Double.NEGATIVE_INFINITY),
"positiveInfinity",
map("value", Double.POSITIVE_INFINITY));

CollectionReference colRef = testCollectionWithDocs(testDocs);

// Run get query
Query filteredQuery = colRef.orderBy("value");

QuerySnapshot getSnapshot = waitFor(filteredQuery.get());
List<String> getSnapshotDocIds =
getSnapshot.getDocuments().stream().map(ds -> ds.getId()).collect(Collectors.toList());

// Run query with snapshot listener
EventAccumulator<QuerySnapshot> eventAccumulator = new EventAccumulator<QuerySnapshot>();
ListenerRegistration registration =
filteredQuery.addSnapshotListener(eventAccumulator.listener());

List<String> watchSnapshotDocIds = new ArrayList<>();
try {
QuerySnapshot watchSnapshot = eventAccumulator.await();
watchSnapshotDocIds =
watchSnapshot.getDocuments().stream()
.map(documentSnapshot -> documentSnapshot.getId())
.collect(Collectors.toList());
} finally {
registration.remove();
}

// Assert that get and snapshot listener requests sort docs in the same, expected order
assertTrue(getSnapshotDocIds.equals(watchSnapshotDocIds));
}
}
Loading