|
34 | 34 | import java.util.LinkedHashMap; |
35 | 35 | import java.util.List; |
36 | 36 | import java.util.Map; |
| 37 | +import java.util.concurrent.CountDownLatch; |
| 38 | +import java.util.ArrayList; |
37 | 39 | import java.util.concurrent.ExecutionException; |
38 | 40 | import java.util.concurrent.TimeUnit; |
39 | 41 | import java.util.concurrent.TimeoutException; |
@@ -1113,4 +1115,45 @@ public void testAggregateQueryProfile() throws Exception { |
1113 | 1115 | assertThat(stats.getResultsReturned()).isEqualTo(1); |
1114 | 1116 | assertThat(stats.getExecutionDuration()).isGreaterThan(Duration.ZERO); |
1115 | 1117 | } |
| 1118 | + |
| 1119 | + @Test |
| 1120 | + public void snapshotListenerSortsUnicodesSameWayAsServer() throws Exception { |
| 1121 | + CollectionReference col = createEmptyCollection(); |
| 1122 | + |
| 1123 | + firestore |
| 1124 | + .batch() |
| 1125 | + .set(col.document("a"), map("value", "Łukasiewicz")) |
| 1126 | + .set(col.document("b"), map("value", "Sierpiński")) |
| 1127 | + .set(col.document("c"), map("value", "岩澤")) |
| 1128 | + .set(col.document("d"), map("value", "🄟")) |
| 1129 | + .set(col.document("e"), map("value", "P")) |
| 1130 | + .set(col.document("f"), map("value", "︒")) |
| 1131 | + .set(col.document("g"), map("value", "🐵")) |
| 1132 | + |
| 1133 | + .commit() |
| 1134 | + .get(); |
| 1135 | + |
| 1136 | + Query query = col.orderBy("value", Direction.ASCENDING); |
| 1137 | + |
| 1138 | + QuerySnapshot snapshot = query.get().get(); |
| 1139 | + List<String> queryOrder = |
| 1140 | + snapshot.getDocuments().stream().map(doc -> doc.getId()).collect(Collectors.toList()); |
| 1141 | + |
| 1142 | + CountDownLatch latch = new CountDownLatch(1); |
| 1143 | + List<String> listenerOrder = new ArrayList<>(); |
| 1144 | + ListenerRegistration registration = |
| 1145 | + query.addSnapshotListener( |
| 1146 | + (value, error) -> { |
| 1147 | + listenerOrder.addAll( |
| 1148 | + value.getDocuments().stream() |
| 1149 | + .map(doc -> doc.getId()) |
| 1150 | + .collect(Collectors.toList())); |
| 1151 | + latch.countDown(); |
| 1152 | + }); |
| 1153 | + latch.await(); |
| 1154 | + registration.remove(); |
| 1155 | + |
| 1156 | + assertEquals(queryOrder, Arrays.asList("b", "a", "c", "f", "e", "d", "g")); |
| 1157 | + assertEquals(queryOrder, listenerOrder); // Assert order in the SDK |
| 1158 | + } |
1116 | 1159 | } |
0 commit comments