diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Watch.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Watch.java index 9ca47be390de..cca1f379b646 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Watch.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/Watch.java @@ -196,8 +196,9 @@ public synchronized void onNext(ListenResponse listenResponse) { } break; case ADD: - Preconditions.checkState( - WATCH_TARGET_ID == change.getTargetIds(0), "Target ID must be 0xD0"); + if (WATCH_TARGET_ID != change.getTargetIds(0)) { + closeStream(FirestoreException.invalidState("Target ID must be 0x01")); + } break; case REMOVE: Status status = diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ConformanceTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ConformanceTest.java index 1a5a1be41942..71c37e69cd5e 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ConformanceTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/ConformanceTest.java @@ -439,7 +439,7 @@ private void runQueryTest(TestDefinition.QueryTest testCase) { } } - private void runWatchTest(TestDefinition.ListenTest testCase) + private void runWatchTest(final TestDefinition.ListenTest testCase) throws ExecutionException, InterruptedException { final SettableApiFuture testCaseStarted = SettableApiFuture.create(); final SettableApiFuture testCaseFinished = SettableApiFuture.create(); @@ -464,10 +464,20 @@ public ApiStreamObserver answer(InvocationOnMock invocationOnMock public void onEvent( @Nullable QuerySnapshot actualSnapshot, @Nullable FirestoreException error) { try { - Assert.assertFalse(expectedSnapshots.isEmpty()); - Snapshot expectedSnapshot = expectedSnapshots.remove(0); - Assert.assertEquals(convertQuerySnapshot(expectedSnapshot), actualSnapshot); - if (expectedSnapshots.isEmpty()) { + if (actualSnapshot != null) { + Assert.assertNull(error); + Assert.assertFalse(expectedSnapshots.isEmpty()); + Snapshot expectedSnapshot = expectedSnapshots.remove(0); + Assert.assertEquals(convertQuerySnapshot(expectedSnapshot), actualSnapshot); + if (expectedSnapshots.isEmpty()) { + if (!testCase.getIsError()) { + testCaseFinished.set(null); + } + } + } else { // Error case + Assert.assertNotNull(error); + Assert.assertTrue(expectedSnapshots.isEmpty()); + Assert.assertTrue(testCase.getIsError()); testCaseFinished.set(null); } } catch (AssertionError e) { diff --git a/google-cloud-firestore/src/test/resources/test-suite.binproto b/google-cloud-firestore/src/test/resources/test-suite.binproto index 917804995759..c3a4962d0cf4 100644 Binary files a/google-cloud-firestore/src/test/resources/test-suite.binproto and b/google-cloud-firestore/src/test/resources/test-suite.binproto differ