Skip to content

Commit 8542008

Browse files
Merge branch 'mrschmidt/indexfree-1' into mrschmidt/indexfree-3
2 parents 650764c + 1353528 commit 8542008

File tree

38 files changed

+2401
-393
lines changed

38 files changed

+2401
-393
lines changed

.idea/runConfigurations/Firestore_Integration_Tests__Firestore_Emulator_.xml

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

firebase-config/src/main/java/com/google/firebase/remoteconfig/internal/ConfigStorageClient.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ private ConfigStorageClient(Context context, String fileName) {
7676
*/
7777
public synchronized Void write(ConfigContainer container) throws IOException {
7878
// TODO(issues/262): Consider using the AtomicFile class instead.
79-
try (FileOutputStream outputStream = context.openFileOutput(fileName, Context.MODE_PRIVATE)) {
79+
FileOutputStream outputStream = context.openFileOutput(fileName, Context.MODE_PRIVATE);
80+
try {
8081
outputStream.write(container.toString().getBytes(JSON_STRING_ENCODING));
82+
} finally {
83+
outputStream.close();
8184
}
8285
return null;
8386
}
@@ -90,7 +93,10 @@ public synchronized Void write(ConfigContainer container) throws IOException {
9093
*/
9194
@Nullable
9295
public synchronized ConfigContainer read() throws IOException {
93-
try (FileInputStream fileInputStream = context.openFileInput(fileName)) {
96+
97+
FileInputStream fileInputStream = null;
98+
try {
99+
fileInputStream = context.openFileInput(fileName);
94100
byte[] bytes = new byte[fileInputStream.available()];
95101
fileInputStream.read(bytes, 0, bytes.length);
96102
String containerJsonString = new String(bytes, JSON_STRING_ENCODING);
@@ -100,6 +106,8 @@ public synchronized ConfigContainer read() throws IOException {
100106
} catch (JSONException | FileNotFoundException e) {
101107
// File might not have been written to yet, so this not an irrecoverable error.
102108
return null;
109+
} finally {
110+
if (fileInputStream != null) fileInputStream.close();
103111
}
104112
}
105113

firebase-firestore/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# Unreleased
2+
- [changed] Transactions are now more flexible. Some sequences of operations
3+
that were previously incorrectly disallowed are now allowed. For example,
4+
after reading a document that doesn't exist, you can now set it multiple
5+
times successfully in a transaction.
6+
- [fixed] Fixed an issue where query results were temporarily missing documents
7+
that previously had not matched but had been updated to now match the
8+
query (#155).
29

310
# 20.2.0
411
- [feature] Added a `@DocumentId` annotation which can be used on a

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,16 @@ public static FirebaseFirestore newFirebaseFirestore(
3131
String persistenceKey,
3232
CredentialsProvider credentialsProvider,
3333
AsyncQueue asyncQueue,
34-
FirebaseApp firebaseApp) {
34+
FirebaseApp firebaseApp,
35+
FirebaseFirestore.InstanceRegistry instanceRegistry) {
3536
return new FirebaseFirestore(
36-
context, databaseId, persistenceKey, credentialsProvider, asyncQueue, firebaseApp);
37+
context,
38+
databaseId,
39+
persistenceKey,
40+
credentialsProvider,
41+
asyncQueue,
42+
firebaseApp,
43+
instanceRegistry);
3744
}
3845

3946
/** Makes the shutdown method accessible. */

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testCollection;
2121
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testCollectionWithDocs;
2222
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testDocument;
23+
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testFirebaseApp;
2324
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.testFirestore;
2425
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.waitFor;
2526
import static com.google.firebase.firestore.testutil.IntegrationTestUtil.waitForException;
@@ -30,6 +31,7 @@
3031
import static org.junit.Assert.assertFalse;
3132
import static org.junit.Assert.assertNotEquals;
3233
import static org.junit.Assert.assertNotNull;
34+
import static org.junit.Assert.assertNotSame;
3335
import static org.junit.Assert.assertNull;
3436
import static org.junit.Assert.assertSame;
3537
import static org.junit.Assert.assertTrue;
@@ -38,6 +40,7 @@
3840
import androidx.test.ext.junit.runners.AndroidJUnit4;
3941
import com.google.android.gms.tasks.Task;
4042
import com.google.android.gms.tasks.TaskCompletionSource;
43+
import com.google.firebase.FirebaseApp;
4144
import com.google.firebase.Timestamp;
4245
import com.google.firebase.firestore.FirebaseFirestoreException.Code;
4346
import com.google.firebase.firestore.Query.Direction;
@@ -1023,4 +1026,74 @@ public void testClearPersistenceWhileRunningFails() {
10231026
FirebaseFirestoreException firestoreException = (FirebaseFirestoreException) e;
10241027
assertEquals(Code.FAILED_PRECONDITION, firestoreException.getCode());
10251028
}
1029+
1030+
@Test
1031+
public void testRestartFirestoreLeadsToNewInstance() {
1032+
FirebaseApp app = testFirebaseApp();
1033+
FirebaseFirestore instance = FirebaseFirestore.getInstance(app);
1034+
FirebaseFirestore sameInstance = FirebaseFirestore.getInstance(app);
1035+
1036+
assertSame(instance, sameInstance);
1037+
waitFor(instance.document("abc/123").set(Collections.singletonMap("field", 100L)));
1038+
1039+
instance.shutdown();
1040+
FirebaseFirestore newInstance = FirebaseFirestore.getInstance(app);
1041+
1042+
// Verify new instance works.
1043+
DocumentSnapshot doc = waitFor(newInstance.document("abc/123").get());
1044+
assertEquals(doc.get("field"), 100L);
1045+
waitFor(newInstance.document("abc/123").delete());
1046+
1047+
// Verify it is different instance.
1048+
assertNotSame(instance, newInstance);
1049+
}
1050+
1051+
@Test
1052+
public void testAppDeleteLeadsToFirestoreShutdown() {
1053+
FirebaseApp app = testFirebaseApp();
1054+
FirebaseFirestore instance = FirebaseFirestore.getInstance(app);
1055+
waitFor(instance.document("abc/123").set(Collections.singletonMap("Field", 100)));
1056+
1057+
app.delete();
1058+
1059+
assertTrue(instance.getClient().isShutdown());
1060+
}
1061+
1062+
@Test
1063+
public void testNewOperationThrowsAfterFirestoreShutdown() {
1064+
FirebaseFirestore instance = testFirestore();
1065+
DocumentReference reference = instance.document("abc/123");
1066+
waitFor(reference.set(Collections.singletonMap("Field", 100)));
1067+
1068+
instance.shutdown();
1069+
1070+
final String expectedMessage = "The client has already been shutdown";
1071+
expectError(() -> waitFor(reference.get()), expectedMessage);
1072+
expectError(() -> waitFor(reference.update("Field", 1)), expectedMessage);
1073+
expectError(
1074+
() -> waitFor(reference.set(Collections.singletonMap("Field", 1))), expectedMessage);
1075+
expectError(
1076+
() -> waitFor(instance.runBatch((batch) -> batch.update(reference, "Field", 1))),
1077+
expectedMessage);
1078+
expectError(
1079+
() -> waitFor(instance.runTransaction(transaction -> transaction.get(reference))),
1080+
expectedMessage);
1081+
}
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+
}
10261099
}

0 commit comments

Comments
 (0)