-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: BoD <[email protected]>
- Loading branch information
Showing
20 changed files
with
235 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="org.mobilenativefoundation.store.cache5" /> | ||
<manifest /> |
106 changes: 106 additions & 0 deletions
106
cache/src/commonTest/kotlin/org/mobilenativefoundation/store/cache5/CacheTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package org.mobilenativefoundation.store.cache5 | ||
|
||
import kotlinx.coroutines.test.runTest | ||
import kotlin.test.Ignore | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.time.Duration.Companion.milliseconds | ||
|
||
class CacheTests { | ||
private val cache: Cache<String, String> = CacheBuilder<String, String>().build() | ||
|
||
@Test | ||
fun getIfPresent() { | ||
cache.put("key", "value") | ||
assertEquals("value", cache.getIfPresent("key")) | ||
} | ||
|
||
@Test | ||
fun getOrPut() { | ||
assertEquals("value", cache.getOrPut("key") { "value" }) | ||
} | ||
|
||
@Ignore // Not implemented yet | ||
@Test | ||
fun getAllPresent() { | ||
cache.put("key1", "value1") | ||
cache.put("key2", "value2") | ||
assertEquals(mapOf("key1" to "value1", "key2" to "value2"), cache.getAllPresent(listOf("key1", "key2"))) | ||
} | ||
|
||
@Ignore // Not implemented yet | ||
@Test | ||
fun putAll() { | ||
cache.putAll(mapOf("key1" to "value1", "key2" to "value2")) | ||
assertEquals(mapOf("key1" to "value1", "key2" to "value2"), cache.getAllPresent(listOf("key1", "key2"))) | ||
} | ||
|
||
@Test | ||
fun invalidate() { | ||
cache.put("key", "value") | ||
cache.invalidate("key") | ||
assertEquals(null, cache.getIfPresent("key")) | ||
} | ||
|
||
@Ignore // Not implemented yet | ||
@Test | ||
fun invalidateAll() { | ||
cache.put("key1", "value1") | ||
cache.put("key2", "value2") | ||
cache.invalidateAll(listOf("key1", "key2")) | ||
assertEquals(null, cache.getIfPresent("key1")) | ||
assertEquals(null, cache.getIfPresent("key2")) | ||
} | ||
|
||
@Ignore // Not implemented yet | ||
@Test | ||
fun size() { | ||
cache.put("key1", "value1") | ||
cache.put("key2", "value2") | ||
assertEquals(2, cache.size()) | ||
} | ||
|
||
@Test | ||
fun maximumSize() { | ||
val cache = CacheBuilder<String, String>().maximumSize(1).build() | ||
cache.put("key1", "value1") | ||
cache.put("key2", "value2") | ||
assertEquals(null, cache.getIfPresent("key1")) | ||
assertEquals("value2", cache.getIfPresent("key2")) | ||
} | ||
|
||
@Test | ||
fun maximumWeight() { | ||
val cache = CacheBuilder<String, String>().weigher(399) { _, _ -> 100 }.build() | ||
cache.put("key1", "value1") | ||
cache.put("key2", "value2") | ||
assertEquals(null, cache.getIfPresent("key1")) | ||
assertEquals("value2", cache.getIfPresent("key2")) | ||
} | ||
|
||
@Test | ||
fun expireAfterAccess() = runTest { | ||
var timeNs = 0L | ||
val cache = CacheBuilder<String, String>().expireAfterAccess(100.milliseconds).ticker { timeNs }.build() | ||
cache.put("key", "value") | ||
|
||
timeNs += 50.milliseconds.inWholeNanoseconds | ||
assertEquals("value", cache.getIfPresent("key")) | ||
|
||
timeNs += 100.milliseconds.inWholeNanoseconds | ||
assertEquals(null, cache.getIfPresent("key")) | ||
} | ||
|
||
@Test | ||
fun expireAfterWrite() = runTest { | ||
var timeNs = 0L | ||
val cache = CacheBuilder<String, String>().expireAfterWrite(100.milliseconds).ticker { timeNs }.build() | ||
cache.put("key", "value") | ||
|
||
timeNs += 50.milliseconds.inWholeNanoseconds | ||
assertEquals("value", cache.getIfPresent("key")) | ||
|
||
timeNs += 50.milliseconds.inWholeNanoseconds | ||
assertEquals(null, cache.getIfPresent("key")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="org.mobilenativefoundation.store.core5"/> | ||
<manifest /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#Sat Jun 17 09:25:41 EDT 2023 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.