Skip to content

Commit 1b297d6

Browse files
committed
Add kotlin
1 parent 3b2c14b commit 1b297d6

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

firebase-firestore/ktx/api.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ package com.google.firebase.firestore.ktx {
1212
method public static inline <reified T> T getField(@NonNull com.google.firebase.firestore.DocumentSnapshot, @NonNull com.google.firebase.firestore.FieldPath fieldPath, @NonNull com.google.firebase.firestore.DocumentSnapshot.ServerTimestampBehavior serverTimestampBehavior);
1313
method @NonNull public static com.google.firebase.firestore.FirebaseFirestore getFirestore(@NonNull com.google.firebase.ktx.Firebase);
1414
method @NonNull public static com.google.firebase.firestore.MemoryCacheSettings memoryCacheSettings(@NonNull kotlin.jvm.functions.Function1<? super com.google.firebase.firestore.MemoryCacheSettings.Builder,kotlin.Unit> init);
15+
method @NonNull public static com.google.firebase.firestore.MemoryEagerGcSettings memoryEagerGcSettings(@NonNull kotlin.jvm.functions.Function1<? super com.google.firebase.firestore.MemoryEagerGcSettings.Builder,kotlin.Unit> init);
16+
method @NonNull public static com.google.firebase.firestore.MemoryLruGcSettings memoryLruGcSettings(@NonNull kotlin.jvm.functions.Function1<? super com.google.firebase.firestore.MemoryLruGcSettings.Builder,kotlin.Unit> init);
1517
method @NonNull public static com.google.firebase.firestore.PersistentCacheSettings persistentCacheSettings(@NonNull kotlin.jvm.functions.Function1<? super com.google.firebase.firestore.PersistentCacheSettings.Builder,kotlin.Unit> init);
1618
method @NonNull public static kotlinx.coroutines.flow.Flow<com.google.firebase.firestore.DocumentSnapshot> snapshots(@NonNull com.google.firebase.firestore.DocumentReference, @NonNull com.google.firebase.firestore.MetadataChanges metadataChanges = com.google.firebase.firestore.MetadataChanges.EXCLUDE);
1719
method @NonNull public static kotlinx.coroutines.flow.Flow<com.google.firebase.firestore.QuerySnapshot> snapshots(@NonNull com.google.firebase.firestore.Query, @NonNull com.google.firebase.firestore.MetadataChanges metadataChanges = com.google.firebase.firestore.MetadataChanges.EXCLUDE);

firebase-firestore/ktx/src/main/kotlin/com/google/firebase/firestore/ktx/Firestore.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,22 @@ fun memoryCacheSettings(init: MemoryCacheSettings.Builder.() -> Unit): MemoryCac
182182
return builder.build()
183183
}
184184

185+
fun memoryEagerGcSettings(
186+
init: MemoryEagerGcSettings.Builder.() -> Unit
187+
): MemoryEagerGcSettings {
188+
val builder = MemoryEagerGcSettings.newBuilder()
189+
builder.init()
190+
return builder.build()
191+
}
192+
193+
fun memoryLruGcSettings(
194+
init: MemoryLruGcSettings.Builder.() -> Unit
195+
): MemoryLruGcSettings {
196+
val builder = MemoryLruGcSettings.newBuilder()
197+
builder.init()
198+
return builder.build()
199+
}
200+
185201
fun persistentCacheSettings(
186202
init: PersistentCacheSettings.Builder.() -> Unit
187203
): PersistentCacheSettings {

firebase-firestore/ktx/src/test/kotlin/com/google/firebase/firestore/ktx/FirestoreTests.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,31 @@ class FirestoreTests : BaseTestCase() {
124124
assertThat(otherSettings.isSslEnabled).isEqualTo(true)
125125
assertThat(otherSettings.isPersistenceEnabled).isFalse()
126126
}
127+
128+
@Test
129+
fun `MemoryCacheSettings Garbage Collector builder works`() {
130+
val host = "http://10.0.2.2:8080"
131+
val isSslEnabled = false
132+
133+
val settings = firestoreSettings {
134+
this.host = host
135+
this.isSslEnabled = isSslEnabled
136+
this.setLocalCacheSettings(memoryCacheSettings { })
137+
}
138+
139+
assertThat(host).isEqualTo(settings.host)
140+
assertThat(isSslEnabled).isEqualTo(settings.isSslEnabled)
141+
assertThat(settings.isPersistenceEnabled).isFalse()
142+
assertThat(settings.cacheSettings).isEqualTo(memoryCacheSettings { setGcSettings(
143+
memoryEagerGcSettings { }) })
144+
145+
val otherSettings = firestoreSettings { this.setLocalCacheSettings(memoryCacheSettings {setGcSettings(
146+
memoryLruGcSettings { setSizeBytes(1_000) })}) }
147+
148+
assertThat(otherSettings.host).isEqualTo(FirebaseFirestoreSettings.DEFAULT_HOST)
149+
assertThat(otherSettings.isPersistenceEnabled).isFalse()
150+
assertThat(otherSettings.cacheSizeBytes).isEqualTo(1_000)
151+
}
127152
}
128153

129154
@RunWith(RobolectricTestRunner::class)

0 commit comments

Comments
 (0)