30
30
import androidx .test .ext .junit .runners .AndroidJUnit4 ;
31
31
import com .google .firebase .firestore .testutil .IntegrationTestUtil ;
32
32
import org .junit .After ;
33
- import org .junit .Before ;
34
33
import org .junit .Test ;
35
34
import org .junit .runner .RunWith ;
36
35
37
36
@ RunWith (AndroidJUnit4 .class )
38
37
public class CountTest {
39
38
40
- @ Before
41
- public void setUp () {
42
- // TODO(b/243368243): Remove this once backend is ready to support count.
43
- org .junit .Assume .assumeTrue (BuildConfig .USE_EMULATOR_FOR_TESTS );
44
- }
45
-
46
39
@ After
47
40
public void tearDown () {
48
41
IntegrationTestUtil .tearDown ();
@@ -88,8 +81,7 @@ public void testCanRunCount() {
88
81
"b" , map ("k" , "b" ),
89
82
"c" , map ("k" , "c" )));
90
83
91
- AggregateQuerySnapshot snapshot =
92
- waitFor (collection .count ().get (AggregateSource .SERVER_DIRECT ));
84
+ AggregateQuerySnapshot snapshot = waitFor (collection .count ().get (AggregateSource .SERVER ));
93
85
assertEquals (Long .valueOf (3 ), snapshot .getCount ());
94
86
}
95
87
@@ -103,7 +95,7 @@ public void testCanRunCountWithFilters() {
103
95
"c" , map ("k" , "c" )));
104
96
105
97
AggregateQuerySnapshot snapshot =
106
- waitFor (collection .whereEqualTo ("k" , "b" ).count ().get (AggregateSource .SERVER_DIRECT ));
98
+ waitFor (collection .whereEqualTo ("k" , "b" ).count ().get (AggregateSource .SERVER ));
107
99
assertEquals (Long .valueOf (1 ), snapshot .getCount ());
108
100
}
109
101
@@ -118,7 +110,7 @@ public void testCanRunCountWithOrderBy() {
118
110
"d" , map ("absent" , "d" )));
119
111
120
112
AggregateQuerySnapshot snapshot =
121
- waitFor (collection .orderBy ("k" ).count ().get (AggregateSource .SERVER_DIRECT ));
113
+ waitFor (collection .orderBy ("k" ).count ().get (AggregateSource .SERVER ));
122
114
// "d" is filtered out because it is ordered by "k".
123
115
assertEquals (Long .valueOf (3 ), snapshot .getCount ());
124
116
}
@@ -132,7 +124,7 @@ public void testTerminateDoesNotCrashWithFlyingCountQuery() {
132
124
"b" , map ("k" , "b" ),
133
125
"c" , map ("k" , "c" )));
134
126
135
- collection .orderBy ("k" ).count ().get (AggregateSource .SERVER_DIRECT );
127
+ collection .orderBy ("k" ).count ().get (AggregateSource .SERVER );
136
128
waitFor (collection .firestore .terminate ());
137
129
}
138
130
@@ -146,15 +138,15 @@ public void testSnapshotEquals() {
146
138
"c" , map ("k" , "c" )));
147
139
148
140
AggregateQuerySnapshot snapshot1 =
149
- waitFor (collection .whereEqualTo ("k" , "b" ).count ().get (AggregateSource .SERVER_DIRECT ));
141
+ waitFor (collection .whereEqualTo ("k" , "b" ).count ().get (AggregateSource .SERVER ));
150
142
AggregateQuerySnapshot snapshot1_same =
151
- waitFor (collection .whereEqualTo ("k" , "b" ).count ().get (AggregateSource .SERVER_DIRECT ));
143
+ waitFor (collection .whereEqualTo ("k" , "b" ).count ().get (AggregateSource .SERVER ));
152
144
153
145
AggregateQuerySnapshot snapshot2 =
154
- waitFor (collection .whereEqualTo ("k" , "a" ).count ().get (AggregateSource .SERVER_DIRECT ));
146
+ waitFor (collection .whereEqualTo ("k" , "a" ).count ().get (AggregateSource .SERVER ));
155
147
waitFor (collection .document ("d" ).set (map ("k" , "a" )));
156
148
AggregateQuerySnapshot snapshot2_different =
157
- waitFor (collection .whereEqualTo ("k" , "a" ).count ().get (AggregateSource .SERVER_DIRECT ));
149
+ waitFor (collection .whereEqualTo ("k" , "a" ).count ().get (AggregateSource .SERVER ));
158
150
159
151
assertTrue (snapshot1 .equals (snapshot1_same ));
160
152
assertEquals (snapshot1 .hashCode (), snapshot1_same .hashCode ());
@@ -196,7 +188,7 @@ public void testCanRunCollectionGroupQuery() {
196
188
waitFor (batch .commit ());
197
189
198
190
AggregateQuerySnapshot snapshot =
199
- waitFor (db .collectionGroup (collectionGroup ).count ().get (AggregateSource .SERVER_DIRECT ));
191
+ waitFor (db .collectionGroup (collectionGroup ).count ().get (AggregateSource .SERVER ));
200
192
assertEquals (
201
193
Long .valueOf (5 ), // "cg-doc1", "cg-doc2", "cg-doc3", "cg-doc4", "cg-doc5",
202
194
snapshot .getCount ());
@@ -213,17 +205,12 @@ public void testCanRunCountWithFiltersAndLimits() {
213
205
"d" , map ("k" , "d" )));
214
206
215
207
AggregateQuerySnapshot snapshot =
216
- waitFor (
217
- collection .whereEqualTo ("k" , "a" ).limit (2 ).count ().get (AggregateSource .SERVER_DIRECT ));
208
+ waitFor (collection .whereEqualTo ("k" , "a" ).limit (2 ).count ().get (AggregateSource .SERVER ));
218
209
assertEquals (Long .valueOf (2 ), snapshot .getCount ());
219
210
220
211
snapshot =
221
212
waitFor (
222
- collection
223
- .whereEqualTo ("k" , "a" )
224
- .limitToLast (2 )
225
- .count ()
226
- .get (AggregateSource .SERVER_DIRECT ));
213
+ collection .whereEqualTo ("k" , "a" ).limitToLast (2 ).count ().get (AggregateSource .SERVER ));
227
214
assertEquals (Long .valueOf (2 ), snapshot .getCount ());
228
215
229
216
snapshot =
@@ -232,20 +219,18 @@ public void testCanRunCountWithFiltersAndLimits() {
232
219
.whereEqualTo ("k" , "d" )
233
220
.limitToLast (1000 )
234
221
.count ()
235
- .get (AggregateSource .SERVER_DIRECT ));
222
+ .get (AggregateSource .SERVER ));
236
223
assertEquals (Long .valueOf (1 ), snapshot .getCount ());
237
224
}
238
225
239
226
@ Test
240
227
public void testCanRunCountOnNonExistentCollection () {
241
228
CollectionReference collection = testFirestore ().collection ("random-coll" );
242
229
243
- AggregateQuerySnapshot snapshot =
244
- waitFor (collection .count ().get (AggregateSource .SERVER_DIRECT ));
230
+ AggregateQuerySnapshot snapshot = waitFor (collection .count ().get (AggregateSource .SERVER ));
245
231
assertEquals (Long .valueOf (0 ), snapshot .getCount ());
246
232
247
- snapshot =
248
- waitFor (collection .whereEqualTo ("k" , 100 ).count ().get (AggregateSource .SERVER_DIRECT ));
233
+ snapshot = waitFor (collection .whereEqualTo ("k" , 100 ).count ().get (AggregateSource .SERVER ));
249
234
assertEquals (Long .valueOf (0 ), snapshot .getCount ());
250
235
}
251
236
@@ -259,14 +244,13 @@ public void testFailWithoutNetwork() {
259
244
"c" , map ("k" , "c" )));
260
245
waitFor (collection .getFirestore ().disableNetwork ());
261
246
262
- Exception e = waitForException (collection .count ().get (AggregateSource .SERVER_DIRECT ));
247
+ Exception e = waitForException (collection .count ().get (AggregateSource .SERVER ));
263
248
assertThat (e , instanceOf (FirebaseFirestoreException .class ));
264
249
assertEquals (
265
250
FirebaseFirestoreException .Code .UNAVAILABLE , ((FirebaseFirestoreException ) e ).getCode ());
266
251
267
252
waitFor (collection .getFirestore ().enableNetwork ());
268
- AggregateQuerySnapshot snapshot =
269
- waitFor (collection .count ().get (AggregateSource .SERVER_DIRECT ));
253
+ AggregateQuerySnapshot snapshot = waitFor (collection .count ().get (AggregateSource .SERVER ));
270
254
assertEquals (Long .valueOf (3 ), snapshot .getCount ());
271
255
}
272
256
}
0 commit comments