- no caching on stored delegates, fix problens with memory storage connections

+ optStored now properly load/store only non-null values
* possible concurrent modification in KVStorage.clear fixed
This commit is contained in:
sergeych committed 2024-11-30 13:37:20 +07:00
1 parent 2eb38e27ed
commit d29bf960aa
4 files changed
+86 -42

No files matched your search

@@ -0,0 +1,44 @@
package bipack
import net.sergeych.bintools.*
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
class StorageTest {
@Test
fun storageTest3() {
val s1 = MemoryKVStorage()
val s2 = defaultNamedStorage("test_mp_bintools2")
s2.clear()
s1.write("foo", "bar")
s1.write("foo2", "bar2")
s2.write("foo", "foobar")
s2.write("bar", "buzz")
s2.write("reason", 42)
assertEquals("bar", s1.read("foo"))
assertEquals("bar2", s1.read("foo2"))
assertNull(s1.get("bar"))
val reason: Int? by s1.optStored()
assertNull(s1.get("reason"))
assertNull(reason)
s1.connectToStorage(s2)
// s1 overwrites s2!
assertEquals("bar", s1.read("foo"))
// don't change
assertEquals("bar2", s1.read("foo2"))
// pull from s1
assertEquals("buzz", s1.read("bar"))
assertEquals(42, s1.read("reason"))
assertEquals(42, reason)
}
}