Skip to content

Commit ef85b50

Browse files
Update Spec tests with Bundle changes (#2348)
1 parent 843b963 commit ef85b50

16 files changed

+5308
-3448
lines changed

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public abstract class SpecTestCase implements RemoteStoreCallback {
190190
private Set<DocumentKey> expectedEnqueuedLimboDocs;
191191

192192
/** Set of expected active targets, keyed by target ID. */
193-
private Map<Integer, Pair<List<TargetData>, String>> expectedActiveTargets;
193+
private Map<Integer, List<TargetData>> expectedActiveTargets;
194194

195195
/**
196196
* The writes that have been sent to the SyncEngine via {@link SyncEngine#writeMutations} but not
@@ -466,9 +466,9 @@ private List<Integer> parseIntList(@Nullable JSONArray arr) throws JSONException
466466
// Methods for doing the steps of the spec test.
467467
//
468468

469-
private void doListen(JSONArray listenSpec) throws Exception {
470-
int expectedId = listenSpec.getInt(0);
471-
Query query = parseQuery(listenSpec.get(1));
469+
private void doListen(JSONObject listenSpec) throws Exception {
470+
int expectedId = listenSpec.getInt("targetId");
471+
Query query = parseQuery(listenSpec.getJSONObject("query"));
472472
// TODO: Allow customizing listen options in spec tests
473473
ListenOptions options = new ListenOptions();
474474
options.includeDocumentMetadataChanges = true;
@@ -784,7 +784,7 @@ private void doStep(JSONObject step) throws Exception {
784784
}
785785

786786
if (step.has("userListen")) {
787-
doListen(step.getJSONArray("userListen"));
787+
doListen(step.getJSONObject("userListen"));
788788
} else if (step.has("userUnlisten")) {
789789
doUnlisten(step.getJSONArray("userUnlisten"));
790790
} else if (step.has("userSet")) {
@@ -963,21 +963,29 @@ private void validateExpectedState(@Nullable JSONObject expectedState) throws JS
963963
int targetId = Integer.parseInt(targetIdString);
964964

965965
JSONObject queryDataJson = activeTargets.getJSONObject(targetIdString);
966-
String resumeToken = queryDataJson.getString("resumeToken");
967966
JSONArray queryArrayJson = queryDataJson.getJSONArray("queries");
968967

969-
expectedActiveTargets.put(targetId, new Pair<>(new ArrayList<>(), resumeToken));
968+
expectedActiveTargets.put(targetId, new ArrayList<>());
970969
for (int i = 0; i < queryArrayJson.length(); i++) {
971970
Query query = parseQuery(queryArrayJson.getJSONObject(i));
972971
// TODO: populate the purpose of the target once it's possible to encode that in the
973972
// spec tests. For now, hard-code that it's a listen despite the fact that it's not
974973
// always the right value.
975974
TargetData targetData =
976975
new TargetData(
977-
query.toTarget(), targetId, ARBITRARY_SEQUENCE_NUMBER, QueryPurpose.LISTEN)
978-
.withResumeToken(ByteString.copyFromUtf8(resumeToken), SnapshotVersion.NONE);
979-
980-
expectedActiveTargets.get(targetId).first.add(targetData);
976+
query.toTarget(), targetId, ARBITRARY_SEQUENCE_NUMBER, QueryPurpose.LISTEN);
977+
if (queryDataJson.has("resumeToken")) {
978+
targetData =
979+
targetData.withResumeToken(
980+
ByteString.copyFromUtf8(queryDataJson.getString("resumeToken")),
981+
SnapshotVersion.NONE);
982+
} else {
983+
targetData =
984+
targetData.withResumeToken(
985+
ByteString.EMPTY, version(queryDataJson.getInt("readTime")));
986+
}
987+
988+
expectedActiveTargets.get(targetId).add(targetData);
981989
}
982990
}
983991
}
@@ -1095,13 +1103,12 @@ private void validateActiveTargets() {
10951103
// Create a copy so we can modify it in tests
10961104
Map<Integer, TargetData> actualTargets = new HashMap<>(datastore.activeTargets());
10971105

1098-
for (Map.Entry<Integer, Pair<List<TargetData>, String>> expected :
1099-
expectedActiveTargets.entrySet()) {
1106+
for (Map.Entry<Integer, List<TargetData>> expected : expectedActiveTargets.entrySet()) {
11001107
assertTrue(
11011108
"Expected active target not found: " + expected.getValue(),
11021109
actualTargets.containsKey(expected.getKey()));
11031110

1104-
List<TargetData> expectedQueries = expected.getValue().first;
1111+
List<TargetData> expectedQueries = expected.getValue();
11051112
TargetData expectedTarget = expectedQueries.get(0);
11061113
TargetData actualTarget = actualTargets.get(expected.getKey());
11071114

0 commit comments

Comments
 (0)