File tree Expand file tree Collapse file tree 5 files changed +25
-8
lines changed
androidTest/java/com/google/firebase/firestore
main/java/com/google/firebase/firestore Expand file tree Collapse file tree 5 files changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -1099,6 +1099,22 @@ public void testShutdownCalledMultipleTimes() {
1099
1099
expectError (() -> waitFor (reference .get ()), expectedMessage );
1100
1100
}
1101
1101
1102
+ @ Test
1103
+ public void testCanStopListeningAfterShutdown () {
1104
+ FirebaseFirestore instance = testFirestore ();
1105
+ DocumentReference reference = instance .document ("abc/123" );
1106
+ EventAccumulator <DocumentSnapshot > eventAccumulator = new EventAccumulator <>();
1107
+ ListenerRegistration registration = reference .addSnapshotListener (eventAccumulator .listener ());
1108
+ eventAccumulator .await ();
1109
+
1110
+ waitFor (instance .shutdown ());
1111
+
1112
+ // This should proceed without error.
1113
+ registration .remove ();
1114
+ // Multiple calls should proceed as an effectively no-op.
1115
+ registration .remove ();
1116
+ }
1117
+
1102
1118
@ Test
1103
1119
public void testWaitForPendingWritesResolves () {
1104
1120
DocumentReference documentReference = testCollection ("abc" ).document ("123" );
Original file line number Diff line number Diff line change 49
49
*/
50
50
public class FirebaseFirestore {
51
51
52
- /** Provides a registry management interface for {@code FirebaseFirestore} instances. */
52
+ /**
53
+ * Provides a registry management interface for {@code FirebaseFirestore} instances.
54
+ *
55
+ * @hide
56
+ */
53
57
public interface InstanceRegistry {
54
58
/** Removes the Cloud Firestore instance with given name from registry. */
55
59
void remove (@ NonNull String databaseId );
Original file line number Diff line number Diff line change @@ -93,23 +93,20 @@ public int addQueryListener(QueryListener queryListener) {
93
93
return queryInfo .targetId ;
94
94
}
95
95
96
- /** Removes a previously added listener and returns true if the listener was found. */
97
- public boolean removeQueryListener (QueryListener listener ) {
96
+ /** Removes a previously added listener. It's a no-op if the listener is not found. */
97
+ public void removeQueryListener (QueryListener listener ) {
98
98
Query query = listener .getQuery ();
99
99
QueryListenersInfo queryInfo = queries .get (query );
100
100
boolean lastListen = false ;
101
- boolean found = false ;
102
101
if (queryInfo != null ) {
103
- found = queryInfo .listeners .remove (listener );
102
+ queryInfo .listeners .remove (listener );
104
103
lastListen = queryInfo .listeners .isEmpty ();
105
104
}
106
105
107
106
if (lastListen ) {
108
107
queries .remove (query );
109
108
syncEngine .stopListening (query );
110
109
}
111
-
112
- return found ;
113
110
}
114
111
115
112
@ Override
Original file line number Diff line number Diff line change @@ -165,7 +165,6 @@ public QueryListener listen(
165
165
166
166
/** Stops listening to a query previously listened to. */
167
167
public void stopListening (QueryListener listener ) {
168
- this .verifyNotShutdown ();
169
168
asyncQueue .enqueueAndForget (() -> eventManager .removeQueryListener (listener ));
170
169
}
171
170
Original file line number Diff line number Diff line change @@ -336,6 +336,7 @@ public void handleRemoteEvent(RemoteEvent event) {
336
336
/** Applies an OnlineState change to the sync engine and notifies any views of the change. */
337
337
@ Override
338
338
public void handleOnlineStateChange (OnlineState onlineState ) {
339
+ assertCallback ("handleOnlineStateChange" );
339
340
ArrayList <ViewSnapshot > newViewSnapshots = new ArrayList <>();
340
341
for (Map .Entry <Query , QueryView > entry : queryViewsByQuery .entrySet ()) {
341
342
View view = entry .getValue ().getView ();
You can’t perform that action at this time.
0 commit comments