Skip to content

Commit e7e3ea1

Browse files
committed
addressing comments #1
1 parent 835ddc8 commit e7e3ea1

File tree

5 files changed

+40
-25
lines changed

5 files changed

+40
-25
lines changed

firebase-firestore/src/androidTest/java/com/google/firebase/firestore/FirestoreTest.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -1062,8 +1062,7 @@ public void testAppDeleteLeadsToFirestoreShutdown() {
10621062
@Test
10631063
public void testNewOperationThrowsAfterFirestoreShutdown() {
10641064
FirebaseFirestore instance = testFirestore();
1065-
final DocumentReference reference = instance.document("abc/123");
1066-
DocumentReference ref = reference;
1065+
DocumentReference reference = instance.document("abc/123");
10671066
waitFor(reference.set(Collections.singletonMap("Field", 100)));
10681067

10691068
instance.shutdown();
@@ -1080,4 +1079,21 @@ public void testNewOperationThrowsAfterFirestoreShutdown() {
10801079
() -> waitFor(instance.runTransaction(transaction -> transaction.get(reference))),
10811080
expectedMessage);
10821081
}
1082+
1083+
@Test
1084+
public void testShutdownCalledMultipleTimes() {
1085+
FirebaseFirestore instance = testFirestore();
1086+
DocumentReference reference = instance.document("abc/123");
1087+
waitFor(reference.set(Collections.singletonMap("Field", 100)));
1088+
1089+
instance.shutdown();
1090+
1091+
final String expectedMessage = "The client has already been shutdown";
1092+
expectError(() -> waitFor(reference.get()), expectedMessage);
1093+
1094+
// Calling a second time should go through and change nothing.
1095+
instance.shutdown();
1096+
1097+
expectError(() -> waitFor(reference.get()), expectedMessage);
1098+
}
10831099
}

firebase-firestore/src/main/java/com/google/firebase/firestore/FirebaseFirestore.java

+17-18
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ static FirebaseFirestore newInstance(
120120
FirebaseFirestore firestore =
121121
new FirebaseFirestore(context, databaseId, persistenceKey, provider, queue, app);
122122
app.addLifecycleEventListener(
123-
/* onDeleted */ (firebaseAppName, options) -> {
124-
firestore.shutdown(/* fromAppDeletion */ true);
123+
(firebaseAppName, options) -> {
124+
firestore.shutdown(/* fromAppDeletion= */ true);
125125
});
126126
return firestore;
127127
}
@@ -346,30 +346,29 @@ Task<Void> shutdown(boolean fromAppDeletion) {
346346
}
347347

348348
/**
349-
* Shuts down this Firestore SDK instance.
349+
* Shuts down this FirebaseFirestore instance.
350350
*
351-
* <p>IMPORTANT: If your application is designed to run with Firestore the entire life cycle, it
352-
* is not recommended to call `shutdown` explicitly, the shutting down happens naturally when the
353-
* application itself is shut down.
351+
* <p>After shutdown only the {@link #clearPersistence()} method may be used. Any other method
352+
* will throw an {@link IllegalStateException}.
354353
*
355-
* <p>For applications designed to run without Firestore from some point on (typically to save
356-
* resources as much as possible), you may call this method.
354+
* <p>To restart after shutdown, simply create a new instance of FirebaseFirestore with {@link
355+
* #getInstance()} or {@link #getInstance(FirebaseApp)}.
357356
*
358-
* <p>Once `shutdown` is called, trying to issue new reads/writes through this instance will
359-
* result in {@link IllegalStateException}. Already requested reads/writes might stop resolving.
360-
* Be sure to handle this well in your application if proceeding with Firestore shutting down is
361-
* desired in your case.
357+
* <p>Shutdown does not cancel any pending writes and any tasks that are awaiting a response from
358+
* the server will not be resolved. The next time you start this instance, it will resume
359+
* attempting to send these writes to the server.
362360
*
363-
* <p>Note that {@link #clearPersistence()} is an exception, it is designed to run when the
364-
* Firestore SDK instance is shutdown.
361+
* <p>Note: Under normal circumstances, calling <code>shutdown()</code> is not required. This
362+
* method is useful only when you want to force this instance to release all of its resources or
363+
* in combination with {@link #clearPersistence} to ensure that all local state is destroyed
364+
* between test runs.
365365
*
366-
* <p>To re-start a Firestore SDK instance, simply create a new instance via {@link
367-
* #getInstance()} or {@link #getInstance(FirebaseApp)}.
366+
* @return A <code>Task</code> that is resolved when the instance has been successfully shut down.
368367
*/
369368
@VisibleForTesting
370-
// TODO: Make this public and remove @VisibleForTesting
369+
// TODO(b/135755126): Make this public and remove @VisibleForTesting
371370
Task<Void> shutdown() {
372-
return shutdown(/* fromAppDeletion */ false);
371+
return shutdown(/* fromAppDeletion= */ false);
373372
}
374373

375374
@VisibleForTesting

firebase-firestore/src/main/java/com/google/firebase/firestore/FirestoreMultiDbComponent.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class FirestoreMultiDbComponent {
4343
this.authProvider = authProvider;
4444
}
4545

46-
/** Provides instances of Firestore for given database names. */
46+
/** Provides instances of Firestore for given database IDs. */
4747
@NonNull
4848
synchronized FirebaseFirestore get(@NonNull String databaseId) {
4949
FirebaseFirestore firestore = instances.get(databaseId);
@@ -55,7 +55,7 @@ synchronized FirebaseFirestore get(@NonNull String databaseId) {
5555
}
5656

5757
/**
58-
* Remove the instance of a given database name from this component, such that if {@link
58+
* Remove the instance of a given database ID from this component, such that if {@link
5959
* FirestoreMultiDbComponent#get(String)} is called again with the same name, a new instance of
6060
* {@link FirebaseFirestore} is created.
6161
*

firebase-firestore/src/main/java/com/google/firebase/firestore/core/FirestoreClient.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public Task<Void> shutdown() {
147147
});
148148
}
149149

150-
/** Has this client been shutdown. */
150+
/** Returns true if this client has been shutdown. */
151151
public boolean isShutdown() {
152152
// Technically, the asyncQueue is still running, but only accepting tasks related to shutdown
153153
// or supposed to be run after shutdown. It is effectively shut down to the eyes of users.

firebase-firestore/src/main/java/com/google/firebase/firestore/util/AsyncQueue.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,14 @@ public static <TResult> Task<TResult> callTask(Executor executor, Callable<Task<
178178
/**
179179
* A wrapper around a {@link ScheduledThreadPoolExecutor} class that provides:
180180
*
181-
* <ul>
181+
* <ol>
182182
* <li>1. Synchronized task scheduling. This is different from function 3, which is about task
183183
* execution in a single thread.
184184
* <li>2. Ability to do soft-shutdown: only critical tasks related to shutting Firestore SDK
185185
* down can be executed once the shutdown process initiated.
186186
* <li>3. Single threaded execution service, no concurrent execution among the `Runnable`s
187187
* scheduled in this Executor.
188-
* </ul>
188+
* </ol>
189189
*/
190190
private class SynchronizedShutdownAwareExecutor implements Executor {
191191
/**

0 commit comments

Comments
 (0)