@@ -190,7 +190,7 @@ public abstract class SpecTestCase implements RemoteStoreCallback {
190
190
private Set <DocumentKey > expectedEnqueuedLimboDocs ;
191
191
192
192
/** 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 ;
194
194
195
195
/**
196
196
* 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
466
466
// Methods for doing the steps of the spec test.
467
467
//
468
468
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" ));
472
472
// TODO: Allow customizing listen options in spec tests
473
473
ListenOptions options = new ListenOptions ();
474
474
options .includeDocumentMetadataChanges = true ;
@@ -784,7 +784,7 @@ private void doStep(JSONObject step) throws Exception {
784
784
}
785
785
786
786
if (step .has ("userListen" )) {
787
- doListen (step .getJSONArray ("userListen" ));
787
+ doListen (step .getJSONObject ("userListen" ));
788
788
} else if (step .has ("userUnlisten" )) {
789
789
doUnlisten (step .getJSONArray ("userUnlisten" ));
790
790
} else if (step .has ("userSet" )) {
@@ -963,21 +963,29 @@ private void validateExpectedState(@Nullable JSONObject expectedState) throws JS
963
963
int targetId = Integer .parseInt (targetIdString );
964
964
965
965
JSONObject queryDataJson = activeTargets .getJSONObject (targetIdString );
966
- String resumeToken = queryDataJson .getString ("resumeToken" );
967
966
JSONArray queryArrayJson = queryDataJson .getJSONArray ("queries" );
968
967
969
- expectedActiveTargets .put (targetId , new Pair <>( new ArrayList <>(), resumeToken ));
968
+ expectedActiveTargets .put (targetId , new ArrayList <>());
970
969
for (int i = 0 ; i < queryArrayJson .length (); i ++) {
971
970
Query query = parseQuery (queryArrayJson .getJSONObject (i ));
972
971
// TODO: populate the purpose of the target once it's possible to encode that in the
973
972
// spec tests. For now, hard-code that it's a listen despite the fact that it's not
974
973
// always the right value.
975
974
TargetData targetData =
976
975
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 );
981
989
}
982
990
}
983
991
}
@@ -1095,13 +1103,12 @@ private void validateActiveTargets() {
1095
1103
// Create a copy so we can modify it in tests
1096
1104
Map <Integer , TargetData > actualTargets = new HashMap <>(datastore .activeTargets ());
1097
1105
1098
- for (Map .Entry <Integer , Pair <List <TargetData >, String >> expected :
1099
- expectedActiveTargets .entrySet ()) {
1106
+ for (Map .Entry <Integer , List <TargetData >> expected : expectedActiveTargets .entrySet ()) {
1100
1107
assertTrue (
1101
1108
"Expected active target not found: " + expected .getValue (),
1102
1109
actualTargets .containsKey (expected .getKey ()));
1103
1110
1104
- List <TargetData > expectedQueries = expected .getValue (). first ;
1111
+ List <TargetData > expectedQueries = expected .getValue ();
1105
1112
TargetData expectedTarget = expectedQueries .get (0 );
1106
1113
TargetData actualTarget = actualTargets .get (expected .getKey ());
1107
1114
0 commit comments