mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2026-04-13 21:12:27 +00:00
Compare commits
3 Commits
04f82a03bf
...
0.25.3
| Author | SHA1 | Date | |
|---|---|---|---|
| d46cc3b09c | |||
| dfd23f8d60 | |||
| 28eb1a11e6 |
@@ -64,6 +64,56 @@ class SmartKeyRWLockerTests {
|
|||||||
assertFalse { locker.isWriteLocked(testKey) }
|
assertFalse { locker.isWriteLocked(testKey) }
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
|
fun readLockFailedOnWriteLockKeyTest() = runTest {
|
||||||
|
val locker = SmartKeyRWLocker<String>()
|
||||||
|
val testKey = "test"
|
||||||
|
locker.lockWrite(testKey)
|
||||||
|
|
||||||
|
assertTrue { locker.isWriteLocked(testKey) }
|
||||||
|
|
||||||
|
assertFails {
|
||||||
|
realWithTimeout(1.seconds) {
|
||||||
|
locker.acquireRead()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals(locker.readSemaphore().maxPermits - 1, locker.readSemaphore().freePermits)
|
||||||
|
|
||||||
|
locker.unlockWrite(testKey)
|
||||||
|
assertFalse { locker.isWriteLocked(testKey) }
|
||||||
|
|
||||||
|
realWithTimeout(1.seconds) {
|
||||||
|
locker.acquireRead()
|
||||||
|
}
|
||||||
|
assertEquals(locker.readSemaphore().maxPermits - 1, locker.readSemaphore().freePermits)
|
||||||
|
assertTrue { locker.releaseRead() }
|
||||||
|
assertEquals(locker.readSemaphore().maxPermits, locker.readSemaphore().freePermits)
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
fun writeLockFailedOnWriteLockKeyTest() = runTest {
|
||||||
|
val locker = SmartKeyRWLocker<String>()
|
||||||
|
val testKey = "test"
|
||||||
|
locker.lockWrite(testKey)
|
||||||
|
|
||||||
|
assertTrue { locker.isWriteLocked(testKey) }
|
||||||
|
|
||||||
|
assertFails {
|
||||||
|
realWithTimeout(1.seconds) {
|
||||||
|
locker.lockWrite()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertFalse(locker.isWriteLocked())
|
||||||
|
|
||||||
|
locker.unlockWrite(testKey)
|
||||||
|
assertFalse { locker.isWriteLocked(testKey) }
|
||||||
|
|
||||||
|
realWithTimeout(1.seconds) {
|
||||||
|
locker.lockWrite()
|
||||||
|
}
|
||||||
|
assertTrue(locker.isWriteLocked())
|
||||||
|
assertTrue { locker.unlockWrite() }
|
||||||
|
assertFalse(locker.isWriteLocked())
|
||||||
|
}
|
||||||
|
@Test
|
||||||
fun readsBlockingGlobalWrite() = runTest {
|
fun readsBlockingGlobalWrite() = runTest {
|
||||||
val locker = SmartKeyRWLocker<String>()
|
val locker = SmartKeyRWLocker<String>()
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[versions]
|
[versions]
|
||||||
|
|
||||||
kt = "2.1.10"
|
kt = "2.1.20"
|
||||||
kt-serialization = "1.8.0"
|
kt-serialization = "1.8.0"
|
||||||
kt-coroutines = "1.10.1"
|
kt-coroutines = "1.10.1"
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ koin = "4.0.2"
|
|||||||
|
|
||||||
okio = "3.10.2"
|
okio = "3.10.2"
|
||||||
|
|
||||||
ksp = "2.1.10-1.0.31"
|
ksp = "2.1.20-1.0.31"
|
||||||
kotlin-poet = "1.18.1"
|
kotlin-poet = "1.18.1"
|
||||||
|
|
||||||
versions = "0.51.0"
|
versions = "0.51.0"
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id "org.jetbrains.kotlin.multiplatform"
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
id "org.jetbrains.kotlin.plugin.serialization"
|
id "org.jetbrains.kotlin.plugin.serialization"
|
||||||
id "application"
|
|
||||||
id "com.google.devtools.ksp"
|
id "com.google.devtools.ksp"
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$mppJvmJsLinuxMingwProject"
|
apply from: "$mppJvmJsLinuxMingwProject"
|
||||||
|
|
||||||
kotlin {
|
kotlin {
|
||||||
|
jvm {
|
||||||
|
binaries {
|
||||||
|
executable {
|
||||||
|
mainClass.set("dev.inmo.micro_utils.startup.launcher.MainKt")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
sourceSets {
|
sourceSets {
|
||||||
commonMain {
|
commonMain {
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -23,10 +29,6 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
|
||||||
mainClassName = "dev.inmo.micro_utils.startup.launcher.MainKt"
|
|
||||||
}
|
|
||||||
|
|
||||||
java {
|
java {
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
|||||||
Reference in New Issue
Block a user