Skip to content
Merged
Show file tree
Hide file tree
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 @@ -478,6 +478,18 @@ private List<Integer> parseIntList(@Nullable JSONArray arr) throws JSONException
return result;
}

/** Deeply parses a JSONArray into a List<String>. */
private List<String> parseStringList(@Nullable JSONArray arr) throws JSONException {
List<String> result = new ArrayList<>();
if (arr == null) {
return result;
}
for (int i = 0; i < arr.length(); ++i) {
result.add(arr.getString(i));
}
return result;
}

//
// Methods for doing the steps of the spec test.
//
Expand Down Expand Up @@ -665,15 +677,14 @@ private void doWatchEntity(JSONObject watchEntity) throws Exception {
}
}

private void doWatchFilter(JSONArray watchFilter) throws Exception {
List<Integer> targets = parseIntList(watchFilter.getJSONArray(0));
private void doWatchFilter(JSONObject watchFilter) throws Exception {
List<String> keys = parseStringList(watchFilter.getJSONArray("keys"));
List<Integer> targets = parseIntList(watchFilter.getJSONArray("targetIds"));
Assert.hardAssert(
targets.size() == 1, "ExistenceFilters currently support exactly one target only.");

int keyCount = watchFilter.length() == 0 ? 0 : watchFilter.length() - 1;

// TODO: extend this with different existence filters over time.
ExistenceFilter filter = new ExistenceFilter(keyCount);
ExistenceFilter filter = new ExistenceFilter(keys.size());
ExistenceFilterWatchChange change = new ExistenceFilterWatchChange(targets.get(0), filter);
writeWatchChange(change, SnapshotVersion.NONE);
}
Expand Down Expand Up @@ -850,7 +861,7 @@ private void doStep(JSONObject step) throws Exception {
} else if (step.has("watchEntity")) {
doWatchEntity(step.getJSONObject("watchEntity"));
} else if (step.has("watchFilter")) {
doWatchFilter(step.getJSONArray("watchFilter"));
doWatchFilter(step.getJSONObject("watchFilter"));
} else if (step.has("watchReset")) {
doWatchReset(step.getJSONArray("watchReset"));
} else if (step.has("watchSnapshot")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,14 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -366,13 +368,15 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1",
"collection/2"
],
"collection/1",
"collection/2"
]
"targetIds": [
2
]
}
},
{
"watchEntity": {
Expand Down Expand Up @@ -729,11 +733,13 @@
}
},
{
"watchFilter": [
[
"watchFilter": {
"keys": [
],
"targetIds": [
2
]
]
}
},
{
"watchRemove": {
Expand Down Expand Up @@ -910,12 +916,14 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -1203,12 +1211,14 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -1313,12 +1323,14 @@
}
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -1489,12 +1501,14 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -1846,12 +1860,14 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -2149,11 +2165,13 @@
]
},
{
"watchFilter": [
[
"watchFilter": {
"keys": [
],
"targetIds": [
2
]
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -2265,12 +2283,14 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down
25 changes: 14 additions & 11 deletions firebase-firestore/src/test/resources/json/limbo_spec_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -3445,11 +3445,13 @@
]
},
{
"watchFilter": [
[
"watchFilter": {
"keys": [
],
"targetIds": [
1
]
]
}
},
{
"watchCurrent": [
Expand Down Expand Up @@ -8201,15 +8203,16 @@
}
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/b1",
"collection/b2",
"collection/b3"
],
"collection/b1",
"collection/b2",
"collection/b3"
]

"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down
12 changes: 7 additions & 5 deletions firebase-firestore/src/test/resources/json/limit_spec_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -5611,12 +5611,14 @@
}
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/b"
],
"collection/b"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down