diff --git a/redpulsar-core/src/test/kotlin/io/redpulsar/core/locks/RedLockTest.kt b/redpulsar-core/src/test/kotlin/io/redpulsar/core/locks/RedLockTest.kt index bd639ee..5369ffd 100644 --- a/redpulsar-core/src/test/kotlin/io/redpulsar/core/locks/RedLockTest.kt +++ b/redpulsar-core/src/test/kotlin/io/redpulsar/core/locks/RedLockTest.kt @@ -63,7 +63,7 @@ class RedLockTest { @Test fun `lock throws exception`() { - every { backend.setLock(eq("test"), any(), any()) } throws RuntimeException() + every { backend.setLock(eq("test"), any(), any()) } throws RuntimeException("test exception") val redLock = RedLock(listOf(backend)) val permit = redLock.lock("test") @@ -76,7 +76,7 @@ class RedLockTest { @Test fun `lock throws cancellation exception`() { - every { backend.setLock(eq("test"), any(), any()) } throws CancellationException() + every { backend.setLock(eq("test"), any(), any()) } throws CancellationException("test exception") every { backend.removeLock(eq("test"), any()) } returns "OK" val redLock = RedLock(listOf(backend)) @@ -90,7 +90,7 @@ class RedLockTest { @Test fun `unlock throws exception`() { - every { backend.removeLock(eq("test"), any()) } throws RuntimeException() + every { backend.removeLock(eq("test"), any()) } throws RuntimeException("test exception") val redLock = RedLock(listOf(backend)) redLock.unlock("test") @@ -101,7 +101,7 @@ class RedLockTest { @Test fun `unlock throws cancellation exception`() { - every { backend.removeLock(eq("test"), any()) } throws CancellationException() + every { backend.removeLock(eq("test"), any()) } throws CancellationException("test exception") val redLock = RedLock(listOf(backend)) redLock.unlock("test") diff --git a/redpulsar-core/src/test/kotlin/io/redpulsar/core/locks/SemaphoreTest.kt b/redpulsar-core/src/test/kotlin/io/redpulsar/core/locks/SemaphoreTest.kt index af6b5e9..7fed070 100644 --- a/redpulsar-core/src/test/kotlin/io/redpulsar/core/locks/SemaphoreTest.kt +++ b/redpulsar-core/src/test/kotlin/io/redpulsar/core/locks/SemaphoreTest.kt @@ -286,7 +286,6 @@ class SemaphoreTest { @ParameterizedTest(name = "lock acquired with ttl - {0}") @ValueSource(ints = [-123, -1, 0, 1, 2, 5, 7, 10]) fun `validate ttl`(ttl: Int) { - // every { redis.eval(any(), any>(), any>()) } returns "OK" every { backend.setSemaphoreLock( eq("semaphore:leasers:test"), diff --git a/redpulsar-jedis/src/test/kotlin/io/redpulsar/jedis/locks/JedisLocksBackendTest.kt b/redpulsar-jedis/src/test/kotlin/io/redpulsar/jedis/locks/JedisLocksBackendTest.kt index 6d92d9f..182a96b 100644 --- a/redpulsar-jedis/src/test/kotlin/io/redpulsar/jedis/locks/JedisLocksBackendTest.kt +++ b/redpulsar-jedis/src/test/kotlin/io/redpulsar/jedis/locks/JedisLocksBackendTest.kt @@ -85,7 +85,7 @@ class JedisLocksBackendTest { it.equalsTo(SetParams().nx().px(200.milliseconds.inWholeMilliseconds)) }, ) - } throws IOException() + } throws IOException("test exception") val permit = lock.setLock("test", clientId, 200.milliseconds) assertNull(permit) @@ -121,7 +121,7 @@ class JedisLocksBackendTest { @Test fun `remove lock throws exception`() { val clientId = "uuid" - every { redis.eval(any(), eq(listOf("test")), eq(listOf(clientId))) } throws IOException() + every { redis.eval(any(), eq(listOf("test")), eq(listOf(clientId))) } throws IOException("test exception") val permit = lock.removeLock("test", clientId) assertNull(permit) @@ -163,7 +163,7 @@ class JedisLocksBackendTest { val clientId = "uuid" every { redis.eval(any(), eq(listOf("test-key1", "test-key2")), eq(listOf(clientId, "10", "100"))) - } throws IOException() + } throws IOException("test exception") val permit = lock.setSemaphoreLock("test-key1", "test-key2", clientId, 10, 100.milliseconds) assertNull(permit) @@ -202,7 +202,8 @@ class JedisLocksBackendTest { every { redis.pipelined() } returns pipelined every { pipelined.srem(any(), any()) } returns mockk() every { pipelined.del(any()) } returns mockk() - every { pipelined.sync() } throws IOException() + every { pipelined.sync() } throws IOException("test exception") + every { pipelined.close() } returns Unit val permit = lock.removeSemaphoreLock("test-key1", "test-key2", clientId) assertNull(permit) @@ -241,7 +242,13 @@ class JedisLocksBackendTest { @Test fun `clean up semaphore locks throws exception`() { - every { redis.eval(any(), eq(listOf("test-key")), eq(listOf("test-key-prefix"))) } throws IOException() + every { + redis.eval( + any(), + eq(listOf("test-key")), + eq(listOf("test-key-prefix")), + ) + } throws IOException("test exception") val permit = lock.cleanUpExpiredSemaphoreLocks("test-key", "test-key-prefix") assertNull(permit) diff --git a/redpulsar-lettuce/src/main/kotlin/io/redpulsar/lettuce/locks/LettuceLocksBackend.kt b/redpulsar-lettuce/src/main/kotlin/io/redpulsar/lettuce/locks/LettuceLocksBackend.kt index aafd80c..d161b16 100644 --- a/redpulsar-lettuce/src/main/kotlin/io/redpulsar/lettuce/locks/LettuceLocksBackend.kt +++ b/redpulsar-lettuce/src/main/kotlin/io/redpulsar/lettuce/locks/LettuceLocksBackend.kt @@ -28,11 +28,11 @@ internal class LettuceLocksBackend(private val redis: LettucePooled sync.eval(luaScript, ScriptOutputType.VALUE, arrayOf(resourceName), clientId) }, + redis.sync { sync -> sync.eval(luaScript, ScriptOutputType.INTEGER, arrayOf(resourceName), clientId) }, ) } } @@ -99,13 +99,14 @@ internal class LettuceLocksBackend(private val redis: LettucePooled sync.eval( luaScript, - ScriptOutputType.VALUE, + ScriptOutputType.STATUS, arrayOf(leasersKey), leaserValidityKeyPrefix, ) diff --git a/redpulsar-lettuce/src/test/kotlin/io/redpulsar/lettuce/locks/LettuceLocksBackendTest.kt b/redpulsar-lettuce/src/test/kotlin/io/redpulsar/lettuce/locks/LettuceLocksBackendTest.kt index ae85bf4..7fd59d1 100644 --- a/redpulsar-lettuce/src/test/kotlin/io/redpulsar/lettuce/locks/LettuceLocksBackendTest.kt +++ b/redpulsar-lettuce/src/test/kotlin/io/redpulsar/lettuce/locks/LettuceLocksBackendTest.kt @@ -67,7 +67,11 @@ class LettuceLocksBackendTest { fun `set lock failed`() { val clientId = "uuid" every { - sync.set(eq("test"), eq(clientId), eq(SetArgs().nx().px(10.seconds.inWholeMilliseconds))) + sync.set( + eq("test"), + eq(clientId), + match { it.equalsTo(SetArgs().nx().px(10.seconds.inWholeMilliseconds)) }, + ) } returns null val permit = backend.setLock("test", clientId, 10.seconds) @@ -78,8 +82,12 @@ class LettuceLocksBackendTest { fun `set lock throws exception`() { val clientId = "uuid" every { - sync.set(eq("test"), eq(clientId), eq(SetArgs().nx().px(200.milliseconds.inWholeMilliseconds))) - } throws IOException() + sync.set( + eq("test"), + eq(clientId), + match { it.equalsTo(SetArgs().nx().px(200.milliseconds.inWholeMilliseconds)) }, + ) + } throws IOException("test exception") val permit = backend.setLock("test", clientId, 200.milliseconds) assertNull(permit) @@ -92,13 +100,13 @@ class LettuceLocksBackendTest { fun `remove lock successful`() { val clientId = "uuid" every { - sync.eval(any(), eq(ScriptOutputType.VALUE), eq(arrayOf("test")), eq(clientId)) + sync.eval(any(), eq(ScriptOutputType.INTEGER), eq(arrayOf("test")), eq(clientId)) } returns "OK" val permit = backend.removeLock("test", clientId) assertEquals("OK", permit) verify(exactly = 1) { - sync.eval(any(), eq(ScriptOutputType.VALUE), eq(arrayOf("test")), eq(clientId)) + sync.eval(any(), eq(ScriptOutputType.INTEGER), eq(arrayOf("test")), eq(clientId)) } verify(exactly = 0) { sync.set(any(), any(), any()) @@ -109,7 +117,7 @@ class LettuceLocksBackendTest { fun `remove lock failed`() { val clientId = "uuid" every { - sync.eval(any(), eq(ScriptOutputType.VALUE), eq(arrayOf("test")), eq(clientId)) + sync.eval(any(), eq(ScriptOutputType.INTEGER), eq(arrayOf("test")), eq(clientId)) } returns null val permit = backend.removeLock("test", clientId) @@ -120,8 +128,8 @@ class LettuceLocksBackendTest { fun `remove lock throws exception`() { val clientId = "uuid" every { - sync.eval(any(), eq(ScriptOutputType.VALUE), eq(arrayOf("test")), eq(clientId)) - } throws IOException() + sync.eval(any(), eq(ScriptOutputType.INTEGER), eq(arrayOf("test")), eq(clientId)) + } throws IOException("test exception") val permit = backend.removeLock("test", clientId) assertNull(permit) @@ -198,7 +206,7 @@ class LettuceLocksBackendTest { eq("10"), eq("100"), ) - } throws IOException() + } throws IOException("test exception") val permit = backend.setSemaphoreLock("test-key1", "test-key2", clientId, 10, 100.milliseconds) assertNull(permit) @@ -235,7 +243,7 @@ class LettuceLocksBackendTest { fun `remove semaphore lock failed`() { val clientId = "uuid" every { sync.srem(eq("test-key1"), eq(clientId)) } returns 1 - every { sync.del(eq("test-key2")) } throws IOException() + every { sync.del(eq("test-key2")) } throws IOException("test exception") val permit = backend.removeSemaphoreLock("test-key1", "test-key2", clientId) assertNull(permit) @@ -253,7 +261,7 @@ class LettuceLocksBackendTest { every { sync.eval( any(), - eq(ScriptOutputType.VALUE), + eq(ScriptOutputType.STATUS), eq(arrayOf("test-key")), eq("test-key-prefix"), ) @@ -264,7 +272,7 @@ class LettuceLocksBackendTest { verify(exactly = 1) { sync.eval( any(), - eq(ScriptOutputType.VALUE), + eq(ScriptOutputType.STATUS), eq(arrayOf("test-key")), eq("test-key-prefix"), ) @@ -276,7 +284,7 @@ class LettuceLocksBackendTest { every { sync.eval( any(), - eq(ScriptOutputType.VALUE), + eq(ScriptOutputType.STATUS), eq(arrayOf("test-key")), eq("test-key-prefix"), ) @@ -287,7 +295,7 @@ class LettuceLocksBackendTest { verify(exactly = 1) { sync.eval( any(), - eq(ScriptOutputType.VALUE), + eq(ScriptOutputType.STATUS), eq(arrayOf("test-key")), eq("test-key-prefix"), ) @@ -299,18 +307,18 @@ class LettuceLocksBackendTest { every { sync.eval( any(), - eq(ScriptOutputType.VALUE), + eq(ScriptOutputType.STATUS), eq(arrayOf("test-key")), eq("test-key-prefix"), ) - } throws IOException() + } throws IOException("test exception") val permit = backend.cleanUpExpiredSemaphoreLocks("test-key", "test-key-prefix") assertNull(permit) verify(exactly = 1) { sync.eval( any(), - eq(ScriptOutputType.VALUE), + eq(ScriptOutputType.STATUS), eq(arrayOf("test-key")), eq("test-key-prefix"), )