Skip to content

Commit c76b67c

Browse files
committed
Port spec test changes from firebase/firebase-js-sdk#7021 (Bundle the readTime and resumeToken into a data structure)
1 parent 7509feb commit c76b67c

File tree

4 files changed

+105
-69
lines changed

4 files changed

+105
-69
lines changed

firebase-firestore/src/test/java/com/google/firebase/firestore/spec/SpecTestCase.java

+17-6
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,18 @@ private List<Integer> parseIntList(@Nullable JSONArray arr) throws JSONException
478478
return result;
479479
}
480480

481+
/** Deeply parses a JSONArray into a List<String>. */
482+
private List<String> parseStringList(@Nullable JSONArray arr) throws JSONException {
483+
List<String> result = new ArrayList<>();
484+
if (arr == null) {
485+
return result;
486+
}
487+
for (int i = 0; i < arr.length(); ++i) {
488+
result.add(arr.getString(i));
489+
}
490+
return result;
491+
}
492+
481493
//
482494
// Methods for doing the steps of the spec test.
483495
//
@@ -665,15 +677,14 @@ private void doWatchEntity(JSONObject watchEntity) throws Exception {
665677
}
666678
}
667679

668-
private void doWatchFilter(JSONArray watchFilter) throws Exception {
669-
List<Integer> targets = parseIntList(watchFilter.getJSONArray(0));
680+
private void doWatchFilter(JSONObject watchFilter) throws Exception {
681+
List<String> keys = parseStringList(watchFilter.getJSONArray("keys"));
682+
List<Integer> targets = parseIntList(watchFilter.getJSONArray("targetIds"));
670683
Assert.hardAssert(
671684
targets.size() == 1, "ExistenceFilters currently support exactly one target only.");
672685

673-
int keyCount = watchFilter.length() == 0 ? 0 : watchFilter.length() - 1;
674-
675686
// TODO: extend this with different existence filters over time.
676-
ExistenceFilter filter = new ExistenceFilter(keyCount);
687+
ExistenceFilter filter = new ExistenceFilter(keys.size());
677688
ExistenceFilterWatchChange change = new ExistenceFilterWatchChange(targets.get(0), filter);
678689
writeWatchChange(change, SnapshotVersion.NONE);
679690
}
@@ -850,7 +861,7 @@ private void doStep(JSONObject step) throws Exception {
850861
} else if (step.has("watchEntity")) {
851862
doWatchEntity(step.getJSONObject("watchEntity"));
852863
} else if (step.has("watchFilter")) {
853-
doWatchFilter(step.getJSONArray("watchFilter"));
864+
doWatchFilter(step.getJSONObject("watchFilter"));
854865
} else if (step.has("watchReset")) {
855866
doWatchReset(step.getJSONArray("watchReset"));
856867
} else if (step.has("watchSnapshot")) {

firebase-firestore/src/test/resources/json/existence_filter_spec_test.json

+67-47
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,14 @@
132132
]
133133
},
134134
{
135-
"watchFilter": [
136-
[
137-
2
135+
"watchFilter": {
136+
"keys": [
137+
"collection/1"
138138
],
139-
"collection/1"
140-
]
139+
"targetIds": [
140+
2
141+
]
142+
}
141143
},
142144
{
143145
"watchSnapshot": {
@@ -366,13 +368,15 @@
366368
]
367369
},
368370
{
369-
"watchFilter": [
370-
[
371-
2
371+
"watchFilter": {
372+
"keys": [
373+
"collection/1",
374+
"collection/2"
372375
],
373-
"collection/1",
374-
"collection/2"
375-
]
376+
"targetIds": [
377+
2
378+
]
379+
}
376380
},
377381
{
378382
"watchEntity": {
@@ -729,11 +733,13 @@
729733
}
730734
},
731735
{
732-
"watchFilter": [
733-
[
736+
"watchFilter": {
737+
"keys": [
738+
],
739+
"targetIds": [
734740
2
735741
]
736-
]
742+
}
737743
},
738744
{
739745
"watchRemove": {
@@ -910,12 +916,14 @@
910916
]
911917
},
912918
{
913-
"watchFilter": [
914-
[
915-
2
919+
"watchFilter": {
920+
"keys": [
921+
"collection/1"
916922
],
917-
"collection/1"
918-
]
923+
"targetIds": [
924+
2
925+
]
926+
}
919927
},
920928
{
921929
"watchSnapshot": {
@@ -1203,12 +1211,14 @@
12031211
]
12041212
},
12051213
{
1206-
"watchFilter": [
1207-
[
1208-
2
1214+
"watchFilter": {
1215+
"keys": [
1216+
"collection/1"
12091217
],
1210-
"collection/1"
1211-
]
1218+
"targetIds": [
1219+
2
1220+
]
1221+
}
12121222
},
12131223
{
12141224
"watchSnapshot": {
@@ -1313,12 +1323,14 @@
13131323
}
13141324
},
13151325
{
1316-
"watchFilter": [
1317-
[
1318-
2
1326+
"watchFilter": {
1327+
"keys": [
1328+
"collection/1"
13191329
],
1320-
"collection/1"
1321-
]
1330+
"targetIds": [
1331+
2
1332+
]
1333+
}
13221334
},
13231335
{
13241336
"watchSnapshot": {
@@ -1489,12 +1501,14 @@
14891501
]
14901502
},
14911503
{
1492-
"watchFilter": [
1493-
[
1494-
2
1504+
"watchFilter": {
1505+
"keys": [
1506+
"collection/1"
14951507
],
1496-
"collection/1"
1497-
]
1508+
"targetIds": [
1509+
2
1510+
]
1511+
}
14981512
},
14991513
{
15001514
"watchSnapshot": {
@@ -1846,12 +1860,14 @@
18461860
]
18471861
},
18481862
{
1849-
"watchFilter": [
1850-
[
1851-
2
1863+
"watchFilter": {
1864+
"keys": [
1865+
"collection/1"
18521866
],
1853-
"collection/1"
1854-
]
1867+
"targetIds": [
1868+
2
1869+
]
1870+
}
18551871
},
18561872
{
18571873
"watchSnapshot": {
@@ -2149,11 +2165,13 @@
21492165
]
21502166
},
21512167
{
2152-
"watchFilter": [
2153-
[
2168+
"watchFilter": {
2169+
"keys": [
2170+
],
2171+
"targetIds": [
21542172
2
21552173
]
2156-
]
2174+
}
21572175
},
21582176
{
21592177
"watchSnapshot": {
@@ -2265,12 +2283,14 @@
22652283
]
22662284
},
22672285
{
2268-
"watchFilter": [
2269-
[
2270-
2
2286+
"watchFilter": {
2287+
"keys": [
2288+
"collection/1"
22712289
],
2272-
"collection/1"
2273-
]
2290+
"targetIds": [
2291+
2
2292+
]
2293+
}
22742294
},
22752295
{
22762296
"watchSnapshot": {

firebase-firestore/src/test/resources/json/limbo_spec_test.json

+14-11
Original file line numberDiff line numberDiff line change
@@ -3445,11 +3445,13 @@
34453445
]
34463446
},
34473447
{
3448-
"watchFilter": [
3449-
[
3448+
"watchFilter": {
3449+
"keys": [
3450+
],
3451+
"targetIds": [
34503452
1
34513453
]
3452-
]
3454+
}
34533455
},
34543456
{
34553457
"watchCurrent": [
@@ -8201,15 +8203,16 @@
82018203
}
82028204
},
82038205
{
8204-
"watchFilter": [
8205-
[
8206-
2
8206+
"watchFilter": {
8207+
"keys": [
8208+
"collection/b1",
8209+
"collection/b2",
8210+
"collection/b3"
82078211
],
8208-
"collection/b1",
8209-
"collection/b2",
8210-
"collection/b3"
8211-
]
8212-
8212+
"targetIds": [
8213+
2
8214+
]
8215+
}
82138216
},
82148217
{
82158218
"watchSnapshot": {

firebase-firestore/src/test/resources/json/limit_spec_test.json

+7-5
Original file line numberDiff line numberDiff line change
@@ -5611,12 +5611,14 @@
56115611
}
56125612
},
56135613
{
5614-
"watchFilter": [
5615-
[
5616-
2
5614+
"watchFilter": {
5615+
"keys": [
5616+
"collection/b"
56175617
],
5618-
"collection/b"
5619-
]
5618+
"targetIds": [
5619+
2
5620+
]
5621+
}
56205622
},
56215623
{
56225624
"watchSnapshot": {

0 commit comments

Comments
 (0)