Skip to content

Commit

Permalink
Merge 7db4507 into 6c3fc22
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-hui committed Apr 3, 2024
2 parents 6c3fc22 + 7db4507 commit 55337e3
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class FirestoreTests : BaseTestCase() {
assertThat(isSslEnabled).isEqualTo(settings.isSslEnabled)
assertThat(settings.isPersistenceEnabled).isFalse()
assertThat(settings.cacheSettings)
.isEqualTo(memoryCacheSettings { setGcSettings(memoryEagerGcSettings {}) })
.isEqualTo(memoryCacheSettings { setGcSettings(memoryLruGcSettings {}) })

val otherSettings = firestoreSettings {
this.setLocalCacheSettings(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,14 @@ public void testLoadWithDocumentsThatAreAlreadyPulledFromBackend() throws Except

@Test
public void testLoadedDocumentsShouldNotBeGarbageCollectedRightAway() throws Exception {
// This test really only makes sense with memory persistence, as SQLite persistence only ever
// This test really only makes sense with memory eager GC, as LRU GCs
// lazily deletes data
db.setFirestoreSettings(
new FirebaseFirestoreSettings.Builder()
.setLocalCacheSettings(MemoryCacheSettings.newBuilder().build())
.setLocalCacheSettings(
MemoryCacheSettings.newBuilder()
.setGcSettings(MemoryLruGcSettings.newBuilder().build())
.build())
.build());

InputStream bundle = new ByteArrayInputStream(createBundle());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
Expand Down Expand Up @@ -1335,8 +1334,8 @@ public void testLegacyCacheConfigForMemoryCache() {

waitFor(instance.document("coll/doc").set(map("foo", "bar")));

assertThrows(
RuntimeException.class, () -> waitFor(instance.document("coll/doc").get(Source.CACHE)));
DocumentSnapshot snap = waitFor(instance.document("coll/doc").get(Source.CACHE));
assertEquals(map("foo", "bar"), snap.getData());
}

@Test
Expand All @@ -1363,8 +1362,8 @@ public void testNewCacheConfigForMemoryCache() {

waitFor(instance.document("coll/doc").set(map("foo", "bar")));

assertThrows(
RuntimeException.class, () -> waitFor(instance.document("coll/doc").get(Source.CACHE)));
DocumentSnapshot snap = waitFor(instance.document("coll/doc").get(Source.CACHE));
assertEquals(map("foo", "bar"), snap.getData());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public MemoryGarbageCollectorSettings getGarbageCollectorSettings() {

/** A Builder for creating {@code MemoryCacheSettings} instance. */
public static class Builder {
private MemoryGarbageCollectorSettings gcSettings = MemoryEagerGcSettings.newBuilder().build();
private MemoryGarbageCollectorSettings gcSettings = MemoryLruGcSettings.newBuilder().build();

private Builder() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ private boolean isMemoryLruGcEnabled(FirebaseFirestoreSettings settings) {
return memorySettings.getGarbageCollectorSettings() instanceof MemoryLruGcSettings;
}

return false;
// Enabled by default.
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void builderConstructorShouldCopyAllValuesFromTheGivenSettings() {
assertEquals(settings2.getHost(), "a.b.c");
assertEquals(settings2.isSslEnabled(), false);
assertEquals(settings2.isPersistenceEnabled(), false);
assertEquals(settings2.getCacheSizeBytes(), FirebaseFirestoreSettings.CACHE_SIZE_UNLIMITED);
assertEquals(settings2.getCacheSizeBytes(), FirebaseFirestoreSettings.DEFAULT_CACHE_SIZE_BYTES);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class FirestoreTests : BaseTestCase() {
assertThat(isSslEnabled).isEqualTo(settings.isSslEnabled)
assertThat(settings.isPersistenceEnabled).isFalse()
assertThat(settings.cacheSettings)
.isEqualTo(memoryCacheSettings { setGcSettings(memoryEagerGcSettings {}) })
.isEqualTo(memoryCacheSettings { setGcSettings(memoryLruGcSettings {}) })

val otherSettings = firestoreSettings {
this.setLocalCacheSettings(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class FirestoreTests : BaseTestCase() {
assertThat(isSslEnabled).isEqualTo(settings.isSslEnabled)
assertThat(settings.isPersistenceEnabled).isFalse()
assertThat(settings.cacheSettings)
.isEqualTo(memoryCacheSettings { setGcSettings(memoryEagerGcSettings {}) })
.isEqualTo(memoryCacheSettings { setGcSettings(memoryLruGcSettings {}) })

val otherSettings = firestoreSettings {
this.setLocalCacheSettings(
Expand Down

0 comments on commit 55337e3

Please sign in to comment.