@@ -1655,48 +1655,208 @@ public void sdkOrdersQueryByDocumentIdTheSameWayOnlineAndOffline() {
16551655 }
16561656
16571657 @ Test
1658- public void snapshotListenerSortsStringFieldsAsGetQuery () {
1658+ public void snapshotListenerSortsUnicodeStringsAsServer () {
16591659 Map <String , Map <String , Object >> testDocs =
1660- map (
1661- "a" , map ("value" , "Łukasiewicz" ),
1662- "b" , map ("value" , "Sierpiński" ),
1663- "c" , map ("value" , "岩澤" ),
1664- "d" , map ("value" , "🄟" ),
1665- "e" , map ("value" , "P" ),
1666- "f" , map ("value" , "︒" ),
1667- "g" , map ("value" , "🐵" )
1668- );
1660+ map (
1661+ "a" , map ("value" , "Łukasiewicz" ),
1662+ "b" , map ("value" , "Sierpiński" ),
1663+ "c" , map ("value" , "岩澤" ),
1664+ "d" , map ("value" , "🄟" ),
1665+ "e" , map ("value" , "P" ),
1666+ "f" , map ("value" , "︒" ),
1667+ "g" , map ("value" , "🐵" ));
16691668
16701669 CollectionReference colRef = testCollectionWithDocs (testDocs );
1671- // Test query
16721670 Query orderedQuery = colRef .orderBy ("value" );
1673- List <String > expectedDocIds =
1674- Arrays .asList (
1675- "b" , "a" , "c" , "f" , "e" , "d" , "g" );
1671+ List <String > expectedDocIds = Arrays .asList ("b" , "a" , "c" , "f" , "e" , "d" , "g" );
16761672
16771673 QuerySnapshot getSnapshot = waitFor (orderedQuery .get ());
16781674 List <String > getSnapshotDocIds =
1679- getSnapshot .getDocuments ().stream ().map (ds -> ds .getId ()).collect (Collectors .toList ());
1675+ getSnapshot .getDocuments ().stream ().map (ds -> ds .getId ()).collect (Collectors .toList ());
1676+
1677+ EventAccumulator <QuerySnapshot > eventAccumulator = new EventAccumulator <QuerySnapshot >();
1678+ ListenerRegistration registration =
1679+ orderedQuery .addSnapshotListener (eventAccumulator .listener ());
1680+
1681+ List <String > watchSnapshotDocIds = new ArrayList <>();
1682+ try {
1683+ QuerySnapshot watchSnapshot = eventAccumulator .await ();
1684+ watchSnapshotDocIds =
1685+ watchSnapshot .getDocuments ().stream ()
1686+ .map (documentSnapshot -> documentSnapshot .getId ())
1687+ .collect (Collectors .toList ());
1688+ } finally {
1689+ registration .remove ();
1690+ }
1691+
1692+ // Assert that get and snapshot listener requests sort docs in the same, expected order
1693+ assertTrue (getSnapshotDocIds .equals (expectedDocIds ));
1694+ assertTrue (watchSnapshotDocIds .equals (expectedDocIds ));
1695+
1696+ checkOnlineAndOfflineResultsMatch (orderedQuery , expectedDocIds .toArray (new String [0 ]));
1697+ }
1698+
1699+ public void snapshotListenerSortsUnicodeStringsInArrayFieldsAsServer () {
1700+ Map <String , Map <String , Object >> testDocs =
1701+ map (
1702+ "a" , map ("value" , Arrays .asList ("Łukasiewicz" )),
1703+ "b" , map ("value" , Arrays .asList ("Sierpiński" )),
1704+ "c" , map ("value" , Arrays .asList ("岩澤" )),
1705+ "d" , map ("value" , Arrays .asList ("🄟" )),
1706+ "e" , map ("value" , Arrays .asList ("P" )),
1707+ "f" , map ("value" , Arrays .asList ("︒" )),
1708+ "g" , map ("value" , Arrays .asList ("🐵" )));
1709+
1710+ CollectionReference colRef = testCollectionWithDocs (testDocs );
1711+ Query orderedQuery = colRef .orderBy ("value" );
1712+ List <String > expectedDocIds = Arrays .asList ("b" , "a" , "c" , "f" , "e" , "d" , "g" );
1713+
1714+ QuerySnapshot getSnapshot = waitFor (orderedQuery .get ());
1715+ List <String > getSnapshotDocIds =
1716+ getSnapshot .getDocuments ().stream ().map (ds -> ds .getId ()).collect (Collectors .toList ());
16801717
1681- // Run query with snapshot listener
16821718 EventAccumulator <QuerySnapshot > eventAccumulator = new EventAccumulator <QuerySnapshot >();
16831719 ListenerRegistration registration =
1684- orderedQuery .addSnapshotListener (eventAccumulator .listener ());
1720+ orderedQuery .addSnapshotListener (eventAccumulator .listener ());
16851721
16861722 List <String > watchSnapshotDocIds = new ArrayList <>();
16871723 try {
16881724 QuerySnapshot watchSnapshot = eventAccumulator .await ();
16891725 watchSnapshotDocIds =
1690- watchSnapshot .getDocuments ().stream ()
1691- .map (documentSnapshot -> documentSnapshot .getId ())
1692- .collect (Collectors .toList ());
1726+ watchSnapshot .getDocuments ().stream ()
1727+ .map (documentSnapshot -> documentSnapshot .getId ())
1728+ .collect (Collectors .toList ());
16931729 } finally {
16941730 registration .remove ();
16951731 }
16961732
16971733 // Assert that get and snapshot listener requests sort docs in the same, expected order
16981734 assertTrue (getSnapshotDocIds .equals (expectedDocIds ));
16991735 assertTrue (watchSnapshotDocIds .equals (expectedDocIds ));
1736+
1737+ checkOnlineAndOfflineResultsMatch (orderedQuery , expectedDocIds .toArray (new String [0 ]));
17001738 }
17011739
1740+ public void snapshotListenerSortsUnicodeStringsInMapAsServer () {
1741+ Map <String , Map <String , Object >> testDocs =
1742+ map (
1743+ "a" , map ("value" , map ("foo" , "Łukasiewicz" )),
1744+ "b" , map ("value" , map ("foo" , "Sierpiński" )),
1745+ "c" , map ("value" , map ("foo" , "岩澤" )),
1746+ "d" , map ("value" , map ("foo" , "🄟" )),
1747+ "e" , map ("value" , map ("foo" , "P" )),
1748+ "f" , map ("value" , map ("foo" , "︒" )),
1749+ "g" , map ("value" , map ("foo" , "🐵" )));
1750+
1751+ CollectionReference colRef = testCollectionWithDocs (testDocs );
1752+ Query orderedQuery = colRef .orderBy ("value" );
1753+ List <String > expectedDocIds = Arrays .asList ("b" , "a" , "c" , "f" , "e" , "d" , "g" );
1754+
1755+ QuerySnapshot getSnapshot = waitFor (orderedQuery .get ());
1756+ List <String > getSnapshotDocIds =
1757+ getSnapshot .getDocuments ().stream ().map (ds -> ds .getId ()).collect (Collectors .toList ());
1758+
1759+ EventAccumulator <QuerySnapshot > eventAccumulator = new EventAccumulator <QuerySnapshot >();
1760+ ListenerRegistration registration =
1761+ orderedQuery .addSnapshotListener (eventAccumulator .listener ());
1762+
1763+ List <String > watchSnapshotDocIds = new ArrayList <>();
1764+ try {
1765+ QuerySnapshot watchSnapshot = eventAccumulator .await ();
1766+ watchSnapshotDocIds =
1767+ watchSnapshot .getDocuments ().stream ()
1768+ .map (documentSnapshot -> documentSnapshot .getId ())
1769+ .collect (Collectors .toList ());
1770+ } finally {
1771+ registration .remove ();
1772+ }
1773+
1774+ // Assert that get and snapshot listener requests sort docs in the same, expected order
1775+ assertTrue (getSnapshotDocIds .equals (expectedDocIds ));
1776+ assertTrue (watchSnapshotDocIds .equals (expectedDocIds ));
1777+
1778+ checkOnlineAndOfflineResultsMatch (orderedQuery , expectedDocIds .toArray (new String [0 ]));
1779+ }
1780+
1781+ public void snapshotListenerSortsUnicodeStringsInMapKeyAsServer () {
1782+ Map <String , Map <String , Object >> testDocs =
1783+ map (
1784+ "a" , map ("value" , map ("Łukasiewicz" , "foo" )),
1785+ "b" , map ("value" , map ("Sierpiński" , "foo" )),
1786+ "c" , map ("value" , map ("岩澤" , "foo" )),
1787+ "d" , map ("value" , map ("🄟" , "foo" )),
1788+ "e" , map ("value" , map ("P" , "foo" )),
1789+ "f" , map ("value" , map ("︒" , "foo" )),
1790+ "g" , map ("value" , map ("🐵" , "foo" )));
1791+
1792+ CollectionReference colRef = testCollectionWithDocs (testDocs );
1793+ Query orderedQuery = colRef .orderBy ("value" );
1794+ List <String > expectedDocIds = Arrays .asList ("b" , "a" , "c" , "f" , "e" , "d" , "g" );
1795+
1796+ QuerySnapshot getSnapshot = waitFor (orderedQuery .get ());
1797+ List <String > getSnapshotDocIds =
1798+ getSnapshot .getDocuments ().stream ().map (ds -> ds .getId ()).collect (Collectors .toList ());
1799+
1800+ EventAccumulator <QuerySnapshot > eventAccumulator = new EventAccumulator <QuerySnapshot >();
1801+ ListenerRegistration registration =
1802+ orderedQuery .addSnapshotListener (eventAccumulator .listener ());
1803+
1804+ List <String > watchSnapshotDocIds = new ArrayList <>();
1805+ try {
1806+ QuerySnapshot watchSnapshot = eventAccumulator .await ();
1807+ watchSnapshotDocIds =
1808+ watchSnapshot .getDocuments ().stream ()
1809+ .map (documentSnapshot -> documentSnapshot .getId ())
1810+ .collect (Collectors .toList ());
1811+ } finally {
1812+ registration .remove ();
1813+ }
1814+
1815+ // Assert that get and snapshot listener requests sort docs in the same, expected order
1816+ assertTrue (getSnapshotDocIds .equals (expectedDocIds ));
1817+ assertTrue (watchSnapshotDocIds .equals (expectedDocIds ));
1818+
1819+ checkOnlineAndOfflineResultsMatch (orderedQuery , expectedDocIds .toArray (new String [0 ]));
1820+ }
1821+
1822+ public void snapshotListenerSortsUnicodeStringsInDocumentKeyAsServer () {
1823+ Map <String , Map <String , Object >> testDocs =
1824+ map (
1825+ "Łukasiewicz" , map ("value" , "foo" ),
1826+ "Sierpiński" , map ("value" , "foo" ),
1827+ "岩澤" , map ("value" , "foo" ),
1828+ "🄟" , map ("value" , "foo" ),
1829+ "P" , map ("value" , "foo" ),
1830+ "︒" , map ("value" , "foo" ),
1831+ "🐵" , map ("value" , "foo" ));
1832+
1833+ CollectionReference colRef = testCollectionWithDocs (testDocs );
1834+ Query orderedQuery = colRef .orderBy (FieldPath .documentId ());
1835+ List <String > expectedDocIds = Arrays .asList ("b" , "a" , "c" , "f" , "e" , "d" , "g" );
1836+
1837+ QuerySnapshot getSnapshot = waitFor (orderedQuery .get ());
1838+ List <String > getSnapshotDocIds =
1839+ getSnapshot .getDocuments ().stream ().map (ds -> ds .getId ()).collect (Collectors .toList ());
1840+
1841+ EventAccumulator <QuerySnapshot > eventAccumulator = new EventAccumulator <QuerySnapshot >();
1842+ ListenerRegistration registration =
1843+ orderedQuery .addSnapshotListener (eventAccumulator .listener ());
1844+
1845+ List <String > watchSnapshotDocIds = new ArrayList <>();
1846+ try {
1847+ QuerySnapshot watchSnapshot = eventAccumulator .await ();
1848+ watchSnapshotDocIds =
1849+ watchSnapshot .getDocuments ().stream ()
1850+ .map (documentSnapshot -> documentSnapshot .getId ())
1851+ .collect (Collectors .toList ());
1852+ } finally {
1853+ registration .remove ();
1854+ }
1855+
1856+ // Assert that get and snapshot listener requests sort docs in the same, expected order
1857+ assertTrue (getSnapshotDocIds .equals (expectedDocIds ));
1858+ assertTrue (watchSnapshotDocIds .equals (expectedDocIds ));
1859+
1860+ checkOnlineAndOfflineResultsMatch (orderedQuery , expectedDocIds .toArray (new String [0 ]));
1861+ }
17021862}
0 commit comments