diff --git a/README.md b/README.md index 8eb262d..798ffb5 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,11 @@ It is minimalistic, lightweight, and easy to use library written in Kotlin and c ## Features -- **[RedLock](./redpulsar-core/src/main/kotlin/me/himadieiev/redpulsar/core/locks/RedLock.kt)**: Distributed lock mechanism on a resource, that uses consensus of the majority of data storage nodes to determine if check obtained successfully. -- **[Semaphore](./redpulsar-core/src/main/kotlin/me/himadieiev/redpulsar/core/locks/Semaphore.kt)**: Distributed semaphore implementation allowing multiple number of lock on a resource. It also uses consensus of the majority of data storage nodes to determine if check obtained successfully. -- **[SimpleLock](./redpulsar-core/src/main/kotlin/me/himadieiev/redpulsar/core/locks/SimpleLock.kt)**: Simplified distributed lock mechanism on a resource. Unlike [RedLock](./redpulsar-core/src/main/kotlin/me/himadieiev/redpulsar/core/locks/RedLock.kt) it uses single data storage node. -- **[ListeningCountDownLatch](./redpulsar-core/src/main/kotlin/me/himadieiev/redpulsar/core/locks/ListeningCountDownLatch.kt)**: Implementation of distributed Count Down Latch, it uses that uses consensus of the majority of data storage instances ensuring count down consistency. -[ListeningCountDownLatch](./redpulsar-core/src/main/kotlin/me/himadieiev/redpulsar/core/locks/ListeningCountDownLatch.kt) utilized [Redis Pub/Sub](https://redis.io/topics/pubsub) mechanism to notify waiting workloads about count reaching zero. +- **[Mutex](./redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/Mutex.kt)**: Distributed lock mechanism on a resource, that uses consensus of the majority of data storage nodes to determine if check obtained successfully. +- **[Semaphore](./redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/Semaphore.kt)**: Distributed semaphore implementation allowing multiple number of lock on a resource. It also uses consensus of the majority of data storage nodes to determine if check obtained successfully. +- **[SimplifiedMutex](./redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/SimplifiedMutex.kt)**: Simplified distributed lock mechanism on a resource. Unlike [Mutex](./redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/Mutex.kt) it uses single data storage node. +- **[ListeningCountDownLatch](./redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/ListeningCountDownLatch.kt)**: Implementation of distributed Count Down Latch, it uses that uses consensus of the majority of data storage instances ensuring count down consistency. +[ListeningCountDownLatch](./redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/ListeningCountDownLatch.kt) utilized [Redis Pub/Sub](https://redis.io/topics/pubsub) mechanism to notify waiting workloads about count reaching zero. ## Supporting data storages Currently, RedPulsar supports Redis as a data storage. It can be used with both Jedis or Lettuce clients. @@ -72,7 +72,7 @@ docker-compose up -d ### Extending RedPulsar to use other data stores Currently, all features are implemented with Redis. However, it is possible to extend RedPulsar to use other distributed data stores like AWS DynamoDB / Casandra / ScyllaDB etc. Even it could be implemented with RDBMS like MySQL or PostgreSQL. -RedPulsar project have an abstraction level for data storage called [Backend](./redpulsar-core/src/main/kotlin/me/himadieiev/redpulsar/core/locks/abstracts/Backend.kt). See package [com.himadieiev.redpulsar.core.locks.abstracts.backends](./redpulsar-core/src/main/kotlin/me/himadieiev/redpulsar/core/locks/abstracts/backends) for details what particular operation should be implemented. +RedPulsar project have an abstraction level for data storage called [Backend](./redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/abstracts/Backend.kt). See package [com.himadieiev.redpulsar.core.locks.abstracts.backends](./redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/abstracts/backends) for details what particular operation should be implemented. New data storage should use a new module and implement same abstractions as current Redis implementations. ### Contributing diff --git a/build.gradle.kts b/build.gradle.kts index 1c498a2..16ea9c5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,7 +18,7 @@ plugins { allprojects { group = "com.himadieiev" - version = "1.1.5" + version = "1.2.0" repositories { mavenCentral() diff --git a/redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/RedLock.kt b/redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/Mutex.kt similarity index 99% rename from redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/RedLock.kt rename to redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/Mutex.kt index 5c77b42..57de54f 100644 --- a/redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/RedLock.kt +++ b/redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/Mutex.kt @@ -16,7 +16,7 @@ import java.time.Duration * @param retryCount [Int] the number of retries to acquire lock. * @param retryDelay [Duration] the delay between retries. */ -class RedLock( +class Mutex( backends: List, retryCount: Int = 3, retryDelay: Duration = Duration.ofMillis(100), diff --git a/redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/SimpleLock.kt b/redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/SimplifiedMutex.kt similarity index 98% rename from redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/SimpleLock.kt rename to redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/SimplifiedMutex.kt index 09c2b52..0a5dbfb 100644 --- a/redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/SimpleLock.kt +++ b/redpulsar-core/src/main/kotlin/com/himadieiev/redpulsar/core/locks/SimplifiedMutex.kt @@ -13,7 +13,7 @@ import java.time.Duration * @param retryDelay [Duration] the delay between retries. * @param retryCount [Int] the number of retries to acquire lock. */ -class SimpleLock( +class SimplifiedMutex( private val backend: LocksBackend, private val retryDelay: Duration = Duration.ofMillis(100), private val retryCount: Int = 3, diff --git a/redpulsar-core/src/test/kotlin/com/himadieiev/redpulsar/core/locks/RedLockTest.kt b/redpulsar-core/src/test/kotlin/com/himadieiev/redpulsar/core/locks/MutexTest.kt similarity index 79% rename from redpulsar-core/src/test/kotlin/com/himadieiev/redpulsar/core/locks/RedLockTest.kt rename to redpulsar-core/src/test/kotlin/com/himadieiev/redpulsar/core/locks/MutexTest.kt index ff1acb8..0cf0521 100644 --- a/redpulsar-core/src/test/kotlin/com/himadieiev/redpulsar/core/locks/RedLockTest.kt +++ b/redpulsar-core/src/test/kotlin/com/himadieiev/redpulsar/core/locks/MutexTest.kt @@ -20,7 +20,7 @@ import org.junit.jupiter.params.provider.ValueSource import java.time.Duration @Tag(TestTags.UNIT) -class RedLockTest { +class MutexTest { @Nested inner class SingleRedisInstance { private lateinit var backend: LocksBackend @@ -35,8 +35,8 @@ class RedLockTest { fun `lock acquired`(ttl: Long) { every { backend.setLock(eq("test"), any(), eq(Duration.ofSeconds(ttl))) } returns "OK" - val redLock = RedLock(listOf(backend)) - val permit = redLock.lock("test", Duration.ofSeconds(ttl)) + val mutex = Mutex(listOf(backend)) + val permit = mutex.lock("test", Duration.ofSeconds(ttl)) assertTrue(permit) verify(exactly = 1) { backend.setLock(any(), any(), any()) } @@ -48,8 +48,8 @@ class RedLockTest { every { backend.setLock(eq("test"), any(), eq(Duration.ofSeconds(10))) } returns null every { backend.removeLock(eq("test"), any()) } returns "OK" - val redLock = RedLock(listOf(backend), retryCount = 3, retryDelay = Duration.ofMillis(20)) - val permit = redLock.lock("test") + val mutex = Mutex(listOf(backend), retryCount = 3, retryDelay = Duration.ofMillis(20)) + val permit = mutex.lock("test") assertFalse(permit) @@ -63,9 +63,9 @@ class RedLockTest { fun `unlock resource`() { every { backend.removeLock(eq("test"), any()) } returns "OK" - val redLock = RedLock(listOf(backend)) + val mutex = Mutex(listOf(backend)) // It cant be guarantied that the lock was actually acquired - redLock.unlock("test") + mutex.unlock("test") verify(exactly = 1) { backend.removeLock(eq("test"), any()) @@ -79,9 +79,9 @@ class RedLockTest { @ValueSource(ints = [-123, -1, 0, 1, 2, 5, 7, 10]) fun `validate retry count`(retryCount: Int) { if (retryCount > 0) { - Assertions.assertDoesNotThrow { RedLock(listOf(backend), retryCount = retryCount) } + Assertions.assertDoesNotThrow { Mutex(listOf(backend), retryCount = retryCount) } } else { - assertThrows { RedLock(listOf(backend), retryCount = retryCount) } + assertThrows { Mutex(listOf(backend), retryCount = retryCount) } } } @@ -89,18 +89,18 @@ class RedLockTest { @ValueSource(ints = [-123, -1, 0, 1, 2, 5, 7, 10]) fun `validate retry delay`(retryDelay: Long) { if (retryDelay > 0) { - Assertions.assertDoesNotThrow { RedLock(listOf(backend), retryDelay = Duration.ofMillis(retryDelay)) } + Assertions.assertDoesNotThrow { Mutex(listOf(backend), retryDelay = Duration.ofMillis(retryDelay)) } } else { assertThrows { - RedLock(listOf(backend), retryDelay = Duration.ofMillis(retryDelay)) + Mutex(listOf(backend), retryDelay = Duration.ofMillis(retryDelay)) } } } @Test fun `validate instance count`() { - Assertions.assertDoesNotThrow { RedLock(listOf(backend)) } - assertThrows { RedLock(listOf()) } + Assertions.assertDoesNotThrow { Mutex(listOf(backend)) } + assertThrows { Mutex(listOf()) } } @ParameterizedTest(name = "lock acquired with ttl - {0}") @@ -110,11 +110,11 @@ class RedLockTest { // validity can be rejected with tiny ttl every { backend.removeLock(eq("test"), any()) } returns "OK" - val redLock = RedLock(listOf(backend)) + val mutex = Mutex(listOf(backend)) if (ttl > 2) { - Assertions.assertDoesNotThrow { redLock.lock("test", Duration.ofMillis(ttl)) } + Assertions.assertDoesNotThrow { mutex.lock("test", Duration.ofMillis(ttl)) } } else { - assertThrows { redLock.lock("test", Duration.ofMillis(ttl)) } + assertThrows { mutex.lock("test", Duration.ofMillis(ttl)) } } } } @@ -142,8 +142,8 @@ class RedLockTest { } returns "OK" } - val redLock = RedLock(instances) - val permit = redLock.lock("test") + val mutex = Mutex(instances) + val permit = mutex.lock("test") assertTrue(permit) verify(exactly = 1) { @@ -160,8 +160,8 @@ class RedLockTest { every { backend2.setLock(eq("test"), any(), any()) } returns null every { backend3.setLock(eq("test"), any(), any()) } returns "OK" - val redLock = RedLock(instances) - val permit = redLock.lock("test") + val mutex = Mutex(instances) + val permit = mutex.lock("test") assertTrue(permit) verify(exactly = 1) { @@ -181,8 +181,8 @@ class RedLockTest { every { backend.removeLock(eq("test"), any()) } returns "OK" } - val redLock = RedLock(instances, retryCount = 3, retryDelay = Duration.ofMillis(20)) - val permit = redLock.lock("test") + val mutex = Mutex(instances, retryCount = 3, retryDelay = Duration.ofMillis(20)) + val permit = mutex.lock("test") assertFalse(permit) verify(exactly = 3) { @@ -205,8 +205,8 @@ class RedLockTest { every { backend.removeLock(eq("test"), any()) } returns "OK" } - val redLock = RedLock(instances, retryCount = 3, retryDelay = Duration.ofMillis(30)) - val permit = redLock.lock("test", Duration.ofMillis(30)) + val mutex = Mutex(instances, retryCount = 3, retryDelay = Duration.ofMillis(30)) + val permit = mutex.lock("test", Duration.ofMillis(30)) assertFalse(permit) verify(exactly = 3) { diff --git a/redpulsar-core/src/test/kotlin/com/himadieiev/redpulsar/core/locks/SimpleLockTest.kt b/redpulsar-core/src/test/kotlin/com/himadieiev/redpulsar/core/locks/SimplifiedMutexTest.kt similarity index 69% rename from redpulsar-core/src/test/kotlin/com/himadieiev/redpulsar/core/locks/SimpleLockTest.kt rename to redpulsar-core/src/test/kotlin/com/himadieiev/redpulsar/core/locks/SimplifiedMutexTest.kt index 18737d9..38530f5 100644 --- a/redpulsar-core/src/test/kotlin/com/himadieiev/redpulsar/core/locks/SimpleLockTest.kt +++ b/redpulsar-core/src/test/kotlin/com/himadieiev/redpulsar/core/locks/SimplifiedMutexTest.kt @@ -17,7 +17,7 @@ import org.junit.jupiter.params.provider.ValueSource import java.time.Duration @Tag(TestTags.UNIT) -class SimpleLockTest { +class SimplifiedMutexTest { private lateinit var backend: LocksBackend @BeforeEach @@ -30,8 +30,8 @@ class SimpleLockTest { fun `lock acquired`(ttl: Long) { every { backend.setLock(eq("test"), any(), eq(Duration.ofSeconds(ttl))) } returns "OK" - val simpleLock = SimpleLock(backend) - val permit = simpleLock.lock("test", Duration.ofSeconds(ttl)) + val simplifiedMutex = SimplifiedMutex(backend) + val permit = simplifiedMutex.lock("test", Duration.ofSeconds(ttl)) assertTrue(permit) verify(exactly = 1) { @@ -44,8 +44,8 @@ class SimpleLockTest { // every { redis.set(eq("test"), any(), any()) } returns null every { backend.setLock(eq("test"), any(), eq(Duration.ofSeconds(1))) } returns null - val simpleLock = SimpleLock(backend, retryDelay = Duration.ofMillis(20), retryCount = 3) - val permit = simpleLock.lock("test", Duration.ofSeconds(1)) + val simplifiedMutex = SimplifiedMutex(backend, retryDelay = Duration.ofMillis(20), retryCount = 3) + val permit = simplifiedMutex.lock("test", Duration.ofSeconds(1)) assertFalse(permit) @@ -56,8 +56,8 @@ class SimpleLockTest { fun `unlock resource`() { every { backend.removeLock(eq("test"), any()) } returns "OK" - val simpleLock = SimpleLock(backend) - simpleLock.unlock("test") + val simplifiedMutex = SimplifiedMutex(backend) + simplifiedMutex.unlock("test") verify(exactly = 1) { backend.removeLock(eq("test"), any()) @@ -71,9 +71,9 @@ class SimpleLockTest { @ValueSource(ints = [-123, -1, 0, 1, 2, 5, 7, 10]) fun `validate retry count`(retryCount: Int) { if (retryCount > 0) { - assertDoesNotThrow { SimpleLock(backend, retryCount = retryCount) } + assertDoesNotThrow { SimplifiedMutex(backend, retryCount = retryCount) } } else { - assertThrows { SimpleLock(backend, retryCount = retryCount) } + assertThrows { SimplifiedMutex(backend, retryCount = retryCount) } } } @@ -81,9 +81,9 @@ class SimpleLockTest { @ValueSource(ints = [-123, -1, 0, 1, 2, 5, 7, 10]) fun `validate retry delay`(retryDelay: Long) { if (retryDelay > 0) { - assertDoesNotThrow { SimpleLock(backend, retryDelay = Duration.ofMillis(retryDelay)) } + assertDoesNotThrow { SimplifiedMutex(backend, retryDelay = Duration.ofMillis(retryDelay)) } } else { - assertThrows { SimpleLock(backend, retryDelay = Duration.ofMillis(retryDelay)) } + assertThrows { SimplifiedMutex(backend, retryDelay = Duration.ofMillis(retryDelay)) } } } @@ -92,11 +92,11 @@ class SimpleLockTest { fun `validate ttl`(ttl: Long) { every { backend.setLock(eq("test"), any(), any()) } returns "OK" - val simpleLock = SimpleLock(backend) + val simplifiedMutex = SimplifiedMutex(backend) if (ttl > 2) { - assertDoesNotThrow { simpleLock.lock("test", Duration.ofMillis(ttl)) } + assertDoesNotThrow { simplifiedMutex.lock("test", Duration.ofMillis(ttl)) } } else { - assertThrows { simpleLock.lock("test", Duration.ofMillis(ttl)) } + assertThrows { simplifiedMutex.lock("test", Duration.ofMillis(ttl)) } } } } diff --git a/redpulsar-jedis/README.md b/redpulsar-jedis/README.md index 4981a92..d38174d 100644 --- a/redpulsar-jedis/README.md +++ b/redpulsar-jedis/README.md @@ -11,7 +11,7 @@ val client = JedisPooled(poolConfig, "localhost", 6379, 100) Creating lock: ```kotlin // Create lock -val lock = LockFactory.createSimpleLock(client) +val lock = LockFactory.createSimplifiedMutex(client) lock.lock("myResource", Duration.ofSeconds(1)) // do something lock.unlock("myResource") @@ -26,7 +26,7 @@ var client = new JedisPooled(poolConfig, "localhost", 6381, 100); Creating lock: ```java // Create lock -var lock = LockFactory.createSimpleLock(client, Duration.ofSeconds(1), 3); +var lock = LockFactory.createSimplifiedMutex(client, Duration.ofSeconds(1), 3); lock.lock("myResource", Duration.ofSeconds(1)); // do something lock.unlock("myResource"); diff --git a/redpulsar-jedis/src/main/kotlin/com/himadieiev/redpulsar/jedis/locks/LockFactory.kt b/redpulsar-jedis/src/main/kotlin/com/himadieiev/redpulsar/jedis/locks/LockFactory.kt index 3a22cd9..7f14804 100644 --- a/redpulsar-jedis/src/main/kotlin/com/himadieiev/redpulsar/jedis/locks/LockFactory.kt +++ b/redpulsar-jedis/src/main/kotlin/com/himadieiev/redpulsar/jedis/locks/LockFactory.kt @@ -1,9 +1,9 @@ package com.himadieiev.redpulsar.jedis.locks import com.himadieiev.redpulsar.core.locks.ListeningCountDownLatch -import com.himadieiev.redpulsar.core.locks.RedLock +import com.himadieiev.redpulsar.core.locks.Mutex import com.himadieiev.redpulsar.core.locks.Semaphore -import com.himadieiev.redpulsar.core.locks.SimpleLock +import com.himadieiev.redpulsar.core.locks.SimplifiedMutex import com.himadieiev.redpulsar.jedis.locks.backends.JedisCountDownLatchBackend import com.himadieiev.redpulsar.jedis.locks.backends.JedisLocksBackend import redis.clients.jedis.UnifiedJedis @@ -15,36 +15,36 @@ import java.time.Duration class LockFactory { companion object { /** - * Create a new [SimpleLock] instance. + * Create a new [SimplifiedMutex] instance. * @param client [UnifiedJedis] the Jedis client instance to use for lock. * @param retryDelay [Duration] the delay between retries. * @param retryCount [Int] the number of retries. - * @return [SimpleLock] the lock instance. + * @return [SimplifiedMutex] the lock instance. */ @JvmStatic - fun createSimpleLock( + fun createSimplifiedMutex( client: UnifiedJedis, retryDelay: Duration = Duration.ofMillis(100), retryCount: Int = 3, - ): SimpleLock { - return SimpleLock(JedisLocksBackend(client), retryDelay, retryCount) + ): SimplifiedMutex { + return SimplifiedMutex(JedisLocksBackend(client), retryDelay, retryCount) } /** - * Create a new [RedLock] instance. + * Create a new [Mutex] instance. * @param clients [List]<[UnifiedJedis]> the Jedis client instances to use for lock. * @param retryDelay [Duration] the delay between retries. * @param retryCount [Int] the number of retries. - * @return [RedLock] the lock instance. + * @return [Mutex] the lock instance. */ @JvmStatic - fun createRedLock( + fun createMutex( clients: List, retryDelay: Duration = Duration.ofMillis(100), retryCount: Int = 3, - ): RedLock { + ): Mutex { val backends = clients.map { JedisLocksBackend(it) } - return RedLock(backends, retryCount, retryDelay) + return Mutex(backends, retryCount, retryDelay) } /** diff --git a/redpulsar-jedis/src/test/kotlin/com/himadieiev/redpulsar/jedis/integrationtests/RedLockIntegrationTest.kt b/redpulsar-jedis/src/test/kotlin/com/himadieiev/redpulsar/jedis/integrationtests/MutexIntegrationTest.kt similarity index 55% rename from redpulsar-jedis/src/test/kotlin/com/himadieiev/redpulsar/jedis/integrationtests/RedLockIntegrationTest.kt rename to redpulsar-jedis/src/test/kotlin/com/himadieiev/redpulsar/jedis/integrationtests/MutexIntegrationTest.kt index 278d787..17bf7c8 100644 --- a/redpulsar-jedis/src/test/kotlin/com/himadieiev/redpulsar/jedis/integrationtests/RedLockIntegrationTest.kt +++ b/redpulsar-jedis/src/test/kotlin/com/himadieiev/redpulsar/jedis/integrationtests/MutexIntegrationTest.kt @@ -1,7 +1,7 @@ package com.himadieiev.redpulsar.jedis.integrationtests import TestTags -import com.himadieiev.redpulsar.core.locks.RedLock +import com.himadieiev.redpulsar.core.locks.Mutex import com.himadieiev.redpulsar.core.locks.abstracts.backends.LocksBackend import com.himadieiev.redpulsar.jedis.locks.backends.JedisLocksBackend import getInstances @@ -17,7 +17,7 @@ import redis.clients.jedis.UnifiedJedis import java.time.Duration @Tag(TestTags.INTEGRATIONS) -class RedLockIntegrationTest { +class MutexIntegrationTest { private lateinit var instances: List private lateinit var backends: List @@ -30,8 +30,8 @@ class RedLockIntegrationTest { @Test fun `obtain lock`() { - val redLock = RedLock(backends) - val permit = redLock.lock("test", Duration.ofSeconds(10)) + val mutex = Mutex(backends) + val permit = mutex.lock("test", Duration.ofSeconds(10)) assertTrue(permit) @@ -41,43 +41,43 @@ class RedLockIntegrationTest { @Test fun `release lock`() { - val redLock = RedLock(backends) - redLock.lock("test", Duration.ofSeconds(10)) - redLock.unlock("test") + val mutex = Mutex(backends) + mutex.lock("test", Duration.ofSeconds(10)) + mutex.unlock("test") instances.map { it.get("test") }.forEach { assertNull(it) } } @Test fun `another client can re-acquire lock`() { - val redLock = RedLock(backends) - val redLock2 = RedLock(backends = backends, retryCount = 2, retryDelay = Duration.ofMillis(50)) + val mutex = Mutex(backends) + val mutex2 = Mutex(backends = backends, retryCount = 2, retryDelay = Duration.ofMillis(50)) - assertTrue(redLock.lock("test", Duration.ofSeconds(10))) - assertFalse(redLock2.lock("test", Duration.ofMillis(100))) + assertTrue(mutex.lock("test", Duration.ofSeconds(10))) + assertFalse(mutex2.lock("test", Duration.ofMillis(100))) - redLock.unlock("test") - assertTrue(redLock2.lock("test", Duration.ofMillis(100))) + mutex.unlock("test") + assertTrue(mutex2.lock("test", Duration.ofMillis(100))) } @Test fun `another client can re-acquire lock due to expiration`() { - val redLock = RedLock(backends) - val redLock2 = RedLock(backends = backends, retryCount = 2, retryDelay = Duration.ofMillis(30)) + val mutex = Mutex(backends) + val mutex2 = Mutex(backends = backends, retryCount = 2, retryDelay = Duration.ofMillis(30)) - assertTrue(redLock.lock("test", Duration.ofMillis(200))) - assertFalse(redLock2.lock("test", Duration.ofMillis(100))) + assertTrue(mutex.lock("test", Duration.ofMillis(200))) + assertFalse(mutex2.lock("test", Duration.ofMillis(100))) runBlocking { delay(200) } - assertTrue(redLock2.lock("test", Duration.ofMillis(100))) + assertTrue(mutex2.lock("test", Duration.ofMillis(100))) } @Test fun `dont allow to lock again`() { - val redLock = RedLock(backends) - val redLock2 = RedLock(backends) + val mutex = Mutex(backends) + val mutex2 = Mutex(backends) - assertTrue(redLock.lock("test", Duration.ofSeconds(10))) - assertFalse(redLock2.lock("test", Duration.ofMillis(100))) + assertTrue(mutex.lock("test", Duration.ofSeconds(10))) + assertFalse(mutex2.lock("test", Duration.ofMillis(100))) } } diff --git a/redpulsar-jedis/src/test/kotlin/com/himadieiev/redpulsar/jedis/integrationtests/SimpleLockIntegrationTest.kt b/redpulsar-jedis/src/test/kotlin/com/himadieiev/redpulsar/jedis/integrationtests/SimpleLockIntegrationTest.kt deleted file mode 100644 index 1217360..0000000 --- a/redpulsar-jedis/src/test/kotlin/com/himadieiev/redpulsar/jedis/integrationtests/SimpleLockIntegrationTest.kt +++ /dev/null @@ -1,83 +0,0 @@ -package com.himadieiev.redpulsar.jedis.integrationtests - -import TestTags -import com.himadieiev.redpulsar.core.locks.SimpleLock -import com.himadieiev.redpulsar.core.locks.abstracts.backends.LocksBackend -import com.himadieiev.redpulsar.jedis.locks.backends.JedisLocksBackend -import getInstances -import kotlinx.coroutines.delay -import kotlinx.coroutines.runBlocking -import org.junit.jupiter.api.Assertions.assertFalse -import org.junit.jupiter.api.Assertions.assertNotNull -import org.junit.jupiter.api.Assertions.assertNull -import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.Tag -import org.junit.jupiter.api.Test -import redis.clients.jedis.UnifiedJedis -import java.time.Duration - -@Tag(TestTags.INTEGRATIONS) -class SimpleLockIntegrationTest { - private lateinit var redis: UnifiedJedis - private lateinit var backend: LocksBackend - - @BeforeEach - fun setUp() { - redis = getInstances()[0] - redis.flushAll() - backend = JedisLocksBackend(redis) - } - - @Test - fun `obtain lock`() { - val simpleLock = SimpleLock(backend) - val permit = simpleLock.lock("test", Duration.ofSeconds(10)) - - assertTrue(permit) - - assertNotNull(redis.get("test")) - } - - @Test - fun `release lock`() { - val simpleLock = SimpleLock(backend) - simpleLock.lock("test", Duration.ofSeconds(10)) - simpleLock.unlock("test") - - assertNull(redis.get("test")) - } - - @Test - fun `another client can re-acquire lock`() { - val simpleLock = SimpleLock(backend) - val simpleLock2 = SimpleLock(backend, retryDelay = Duration.ofMillis(50), retryCount = 2) - - assertTrue(simpleLock.lock("test", Duration.ofSeconds(10))) - assertFalse(simpleLock2.lock("test", Duration.ofMillis(10))) - - simpleLock.unlock("test") - assertTrue(simpleLock2.lock("test", Duration.ofMillis(10))) - } - - @Test - fun `another client can re-acquire lock due to expiration`() { - val simpleLock = SimpleLock(backend) - val simpleLock2 = SimpleLock(backend, retryDelay = Duration.ofMillis(30), retryCount = 2) - - assertTrue(simpleLock.lock("test", Duration.ofMillis(200))) - assertFalse(simpleLock2.lock("test", Duration.ofMillis(10))) - - runBlocking { delay(200) } - assertTrue(simpleLock2.lock("test", Duration.ofMillis(10))) - } - - @Test - fun `dont allow to lock again`() { - val simpleLock = SimpleLock(backend) - val simpleLock2 = SimpleLock(backend) - - assertTrue(simpleLock.lock("test", Duration.ofSeconds(10))) - assertFalse(simpleLock2.lock("test", Duration.ofMillis(10))) - } -} diff --git a/redpulsar-jedis/src/test/kotlin/com/himadieiev/redpulsar/jedis/integrationtests/SimplifiedMutexIntegrationTest.kt b/redpulsar-jedis/src/test/kotlin/com/himadieiev/redpulsar/jedis/integrationtests/SimplifiedMutexIntegrationTest.kt new file mode 100644 index 0000000..0ff22d2 --- /dev/null +++ b/redpulsar-jedis/src/test/kotlin/com/himadieiev/redpulsar/jedis/integrationtests/SimplifiedMutexIntegrationTest.kt @@ -0,0 +1,83 @@ +package com.himadieiev.redpulsar.jedis.integrationtests + +import TestTags +import com.himadieiev.redpulsar.core.locks.SimplifiedMutex +import com.himadieiev.redpulsar.core.locks.abstracts.backends.LocksBackend +import com.himadieiev.redpulsar.jedis.locks.backends.JedisLocksBackend +import getInstances +import kotlinx.coroutines.delay +import kotlinx.coroutines.runBlocking +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertNotNull +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Tag +import org.junit.jupiter.api.Test +import redis.clients.jedis.UnifiedJedis +import java.time.Duration + +@Tag(TestTags.INTEGRATIONS) +class SimplifiedMutexIntegrationTest { + private lateinit var redis: UnifiedJedis + private lateinit var backend: LocksBackend + + @BeforeEach + fun setUp() { + redis = getInstances()[0] + redis.flushAll() + backend = JedisLocksBackend(redis) + } + + @Test + fun `obtain lock`() { + val simplifiedMutex = SimplifiedMutex(backend) + val permit = simplifiedMutex.lock("test", Duration.ofSeconds(10)) + + assertTrue(permit) + + assertNotNull(redis.get("test")) + } + + @Test + fun `release lock`() { + val simplifiedMutex = SimplifiedMutex(backend) + simplifiedMutex.lock("test", Duration.ofSeconds(10)) + simplifiedMutex.unlock("test") + + assertNull(redis.get("test")) + } + + @Test + fun `another client can re-acquire lock`() { + val simplifiedMutex = SimplifiedMutex(backend) + val simplifiedMutex2 = SimplifiedMutex(backend, retryDelay = Duration.ofMillis(50), retryCount = 2) + + assertTrue(simplifiedMutex.lock("test", Duration.ofSeconds(10))) + assertFalse(simplifiedMutex2.lock("test", Duration.ofMillis(10))) + + simplifiedMutex.unlock("test") + assertTrue(simplifiedMutex2.lock("test", Duration.ofMillis(10))) + } + + @Test + fun `another client can re-acquire lock due to expiration`() { + val simplifiedMutex = SimplifiedMutex(backend) + val simplifiedMutex2 = SimplifiedMutex(backend, retryDelay = Duration.ofMillis(30), retryCount = 2) + + assertTrue(simplifiedMutex.lock("test", Duration.ofMillis(200))) + assertFalse(simplifiedMutex2.lock("test", Duration.ofMillis(10))) + + runBlocking { delay(200) } + assertTrue(simplifiedMutex2.lock("test", Duration.ofMillis(10))) + } + + @Test + fun `dont allow to lock again`() { + val simplifiedMutex = SimplifiedMutex(backend) + val simplifiedMutex2 = SimplifiedMutex(backend) + + assertTrue(simplifiedMutex.lock("test", Duration.ofSeconds(10))) + assertFalse(simplifiedMutex2.lock("test", Duration.ofMillis(10))) + } +} diff --git a/redpulsar-jedis/src/test/kotlin/com/himadieiev/redpulsar/jedis/locks/LockFactoryTest.kt b/redpulsar-jedis/src/test/kotlin/com/himadieiev/redpulsar/jedis/locks/LockFactoryTest.kt index ae0c648..4071703 100644 --- a/redpulsar-jedis/src/test/kotlin/com/himadieiev/redpulsar/jedis/locks/LockFactoryTest.kt +++ b/redpulsar-jedis/src/test/kotlin/com/himadieiev/redpulsar/jedis/locks/LockFactoryTest.kt @@ -7,25 +7,25 @@ import java.time.Duration class LockFactoryTest { @Test - fun createSimpleLock() { + fun createSimplifiedMutex() { assertThrows { - LockFactory.createSimpleLock(client = mockk(), retryDelay = Duration.ofSeconds(0)) + LockFactory.createSimplifiedMutex(client = mockk(), retryDelay = Duration.ofSeconds(0)) } assertThrows { - LockFactory.createSimpleLock(client = mockk(), retryCount = -1) + LockFactory.createSimplifiedMutex(client = mockk(), retryCount = -1) } } @Test - fun createRedLock() { + fun createMutex() { assertThrows { - LockFactory.createRedLock(clients = listOf()) + LockFactory.createMutex(clients = listOf()) } assertThrows { - LockFactory.createRedLock(clients = listOf(mockk()), retryDelay = Duration.ofSeconds(0)) + LockFactory.createMutex(clients = listOf(mockk()), retryDelay = Duration.ofSeconds(0)) } assertThrows { - LockFactory.createRedLock(clients = listOf(mockk()), retryCount = -1) + LockFactory.createMutex(clients = listOf(mockk()), retryCount = -1) } } diff --git a/redpulsar-lettuce/README.md b/redpulsar-lettuce/README.md index 83c58bc..57b1620 100644 --- a/redpulsar-lettuce/README.md +++ b/redpulsar-lettuce/README.md @@ -17,7 +17,7 @@ val pubSubClient = LettucePubSubPooled(poolConfig) { RedisClient.create("redis:/ Creating lock: ```kotlin // Create lock -val lock = LockFactory.createSimpleLock(client) +val lock = LockFactory.createSimplifiedMutex(client) lock.lock("myResource", Duration.ofSeconds(1)) // do something lock.unlock("myResource") @@ -40,7 +40,7 @@ var lettucePubSubPooled = new LettucePubSubPooled<>(poolConfig, client::connectP Creating lock: ```java // Create lock -var lock = LockFactory.createSimpleLock(lettucePooled, Duration.ofSeconds(1), 3); +var lock = LockFactory.createSimplifiedMutex(lettucePooled, Duration.ofSeconds(1), 3); lock.lock("myResource", Duration.ofSeconds(1)); // do something lock.unlock("myResource"); @@ -51,7 +51,7 @@ This module provides Lettuce pooled client that simplify connection management. Instead of creating new connection each time or manage connection pool manually you can use this module. Available options: -- **[LettucePooled](./src/main/kotlin/me/himadieiev/redpulsar/lettuce/LettucePooled.kt)** - Lettuce pooled client. -- **[LettucePubSubPooled](./src/main/kotlin/me/himadieiev/redpulsar/lettuce/LettucePubSubPooled.kt)** - Lettuce pooled client with Pub/Sub support. +- **[LettucePooled](./src/main/kotlin/com/himadieiev/redpulsar/lettuce/LettucePooled.kt)** - Lettuce pooled client. +- **[LettucePubSubPooled](./src/main/kotlin/com/himadieiev/redpulsar/lettuce/LettucePubSubPooled.kt)** - Lettuce pooled client with Pub/Sub support. Both clients support synchronous, asynchronous and reactive APIs. diff --git a/redpulsar-lettuce/src/main/kotlin/com/himadieiev/redpulsar/lettuce/locks/LockFactory.kt b/redpulsar-lettuce/src/main/kotlin/com/himadieiev/redpulsar/lettuce/locks/LockFactory.kt index 44a5798..17b8b67 100644 --- a/redpulsar-lettuce/src/main/kotlin/com/himadieiev/redpulsar/lettuce/locks/LockFactory.kt +++ b/redpulsar-lettuce/src/main/kotlin/com/himadieiev/redpulsar/lettuce/locks/LockFactory.kt @@ -1,9 +1,9 @@ package com.himadieiev.redpulsar.lettuce.locks import com.himadieiev.redpulsar.core.locks.ListeningCountDownLatch -import com.himadieiev.redpulsar.core.locks.RedLock +import com.himadieiev.redpulsar.core.locks.Mutex import com.himadieiev.redpulsar.core.locks.Semaphore -import com.himadieiev.redpulsar.core.locks.SimpleLock +import com.himadieiev.redpulsar.core.locks.SimplifiedMutex import com.himadieiev.redpulsar.lettuce.LettucePooled import com.himadieiev.redpulsar.lettuce.LettucePubSubPooled import com.himadieiev.redpulsar.lettuce.locks.backends.LettuceCountDownLatchBackend @@ -16,36 +16,36 @@ import java.time.Duration class LockFactory { companion object { /** - * Create a new [SimpleLock] instance. + * Create a new [SimplifiedMutex] instance. * @param client [LettucePooled] the Jedis client instance to use for lock. * @param retryDelay [Duration] the delay between retries. * @param retryCount [Int] the number of retries. - * @return [SimpleLock] the lock instance. + * @return [SimplifiedMutex] the lock instance. */ @JvmStatic - fun createSimpleLock( + fun createSimplifiedMutex( client: LettucePooled, retryDelay: Duration = Duration.ofMillis(100), retryCount: Int = 3, - ): SimpleLock { - return SimpleLock(LettuceLocksBackend(client), retryDelay, retryCount) + ): SimplifiedMutex { + return SimplifiedMutex(LettuceLocksBackend(client), retryDelay, retryCount) } /** - * Create a new [RedLock] instance. + * Create a new [Mutex] instance. * @param clients [List]<[LettucePooled]> the Jedis client instances to use for lock. * @param retryDelay [Duration] the delay between retries. * @param retryCount [Int] the number of retries. - * @return [RedLock] the lock instance. + * @return [Mutex] the lock instance. */ @JvmStatic - fun createRedLock( + fun createMutex( clients: List>, retryDelay: Duration = Duration.ofMillis(100), retryCount: Int = 3, - ): RedLock { + ): Mutex { val backends = clients.map { LettuceLocksBackend(it) } - return RedLock(backends, retryCount, retryDelay) + return Mutex(backends, retryCount, retryDelay) } /** diff --git a/redpulsar-lettuce/src/test/kotlin/com/himadieiev/redpulsar/lettuce/integrationtests/RedLockIntegrationTest.kt b/redpulsar-lettuce/src/test/kotlin/com/himadieiev/redpulsar/lettuce/integrationtests/MutexIntegrationTest.kt similarity index 57% rename from redpulsar-lettuce/src/test/kotlin/com/himadieiev/redpulsar/lettuce/integrationtests/RedLockIntegrationTest.kt rename to redpulsar-lettuce/src/test/kotlin/com/himadieiev/redpulsar/lettuce/integrationtests/MutexIntegrationTest.kt index 4c80c12..c9e74a1 100644 --- a/redpulsar-lettuce/src/test/kotlin/com/himadieiev/redpulsar/lettuce/integrationtests/RedLockIntegrationTest.kt +++ b/redpulsar-lettuce/src/test/kotlin/com/himadieiev/redpulsar/lettuce/integrationtests/MutexIntegrationTest.kt @@ -1,7 +1,7 @@ package com.himadieiev.redpulsar.lettuce.integrationtests import TestTags -import com.himadieiev.redpulsar.core.locks.RedLock +import com.himadieiev.redpulsar.core.locks.Mutex import com.himadieiev.redpulsar.core.locks.abstracts.backends.LocksBackend import com.himadieiev.redpulsar.lettuce.LettucePooled import com.himadieiev.redpulsar.lettuce.locks.backends.LettuceLocksBackend @@ -17,7 +17,7 @@ import org.junit.jupiter.api.Test import java.time.Duration @Tag(TestTags.INTEGRATIONS) -class RedLockIntegrationTest { +class MutexIntegrationTest { private lateinit var instances: List> private lateinit var backends: List @@ -30,8 +30,8 @@ class RedLockIntegrationTest { @Test fun `obtain lock`() { - val redLock = RedLock(backends) - val permit = redLock.lock("test", Duration.ofSeconds(10)) + val mutex = Mutex(backends) + val permit = mutex.lock("test", Duration.ofSeconds(10)) assertTrue(permit) @@ -41,43 +41,43 @@ class RedLockIntegrationTest { @Test fun `release lock`() { - val redLock = RedLock(backends) - redLock.lock("test", Duration.ofSeconds(10)) - redLock.unlock("test") + val mutex = Mutex(backends) + mutex.lock("test", Duration.ofSeconds(10)) + mutex.unlock("test") instances.map { it.sync { redis -> redis.get("test") } }.forEach { assertNull(it) } } @Test fun `another client can re-acquire lock`() { - val redLock = RedLock(backends) - val redLock2 = RedLock(backends = backends, retryCount = 2, retryDelay = Duration.ofMillis(50)) + val mutex = Mutex(backends) + val mutex2 = Mutex(backends = backends, retryCount = 2, retryDelay = Duration.ofMillis(50)) - assertTrue(redLock.lock("test", Duration.ofSeconds(10))) - assertFalse(redLock2.lock("test", Duration.ofMillis(100))) + assertTrue(mutex.lock("test", Duration.ofSeconds(10))) + assertFalse(mutex2.lock("test", Duration.ofMillis(100))) - redLock.unlock("test") - assertTrue(redLock2.lock("test", Duration.ofMillis(100))) + mutex.unlock("test") + assertTrue(mutex2.lock("test", Duration.ofMillis(100))) } @Test fun `another client can re-acquire lock due to expiration`() { - val redLock = RedLock(backends) - val redLock2 = RedLock(backends = backends, retryCount = 2, retryDelay = Duration.ofMillis(30)) + val mutex = Mutex(backends) + val mutex2 = Mutex(backends = backends, retryCount = 2, retryDelay = Duration.ofMillis(30)) - assertTrue(redLock.lock("test", Duration.ofMillis(200))) - assertFalse(redLock2.lock("test", Duration.ofMillis(100))) + assertTrue(mutex.lock("test", Duration.ofMillis(200))) + assertFalse(mutex2.lock("test", Duration.ofMillis(100))) runBlocking { delay(200) } - assertTrue(redLock2.lock("test", Duration.ofMillis(100))) + assertTrue(mutex2.lock("test", Duration.ofMillis(100))) } @Test fun `dont allow to lock again`() { - val redLock = RedLock(backends) - val redLock2 = RedLock(backends) + val mutex = Mutex(backends) + val mutex2 = Mutex(backends) - assertTrue(redLock.lock("test", Duration.ofSeconds(10))) - assertFalse(redLock2.lock("test", Duration.ofMillis(100))) + assertTrue(mutex.lock("test", Duration.ofSeconds(10))) + assertFalse(mutex2.lock("test", Duration.ofMillis(100))) } } diff --git a/redpulsar-lettuce/src/test/kotlin/com/himadieiev/redpulsar/lettuce/integrationtests/SimpleLockIntegrationTest.kt b/redpulsar-lettuce/src/test/kotlin/com/himadieiev/redpulsar/lettuce/integrationtests/SimplifiedMutexIntegrationTest.kt similarity index 51% rename from redpulsar-lettuce/src/test/kotlin/com/himadieiev/redpulsar/lettuce/integrationtests/SimpleLockIntegrationTest.kt rename to redpulsar-lettuce/src/test/kotlin/com/himadieiev/redpulsar/lettuce/integrationtests/SimplifiedMutexIntegrationTest.kt index e0f403f..e4364e0 100644 --- a/redpulsar-lettuce/src/test/kotlin/com/himadieiev/redpulsar/lettuce/integrationtests/SimpleLockIntegrationTest.kt +++ b/redpulsar-lettuce/src/test/kotlin/com/himadieiev/redpulsar/lettuce/integrationtests/SimplifiedMutexIntegrationTest.kt @@ -1,7 +1,7 @@ package com.himadieiev.redpulsar.lettuce.integrationtests import TestTags -import com.himadieiev.redpulsar.core.locks.SimpleLock +import com.himadieiev.redpulsar.core.locks.SimplifiedMutex import com.himadieiev.redpulsar.core.locks.abstracts.backends.LocksBackend import com.himadieiev.redpulsar.lettuce.LettucePooled import com.himadieiev.redpulsar.lettuce.locks.backends.LettuceLocksBackend @@ -18,7 +18,7 @@ import org.junit.jupiter.api.Test import java.time.Duration @Tag(TestTags.INTEGRATIONS) -class SimpleLockIntegrationTest { +class SimplifiedMutexIntegrationTest { private lateinit var redis: LettucePooled private lateinit var backend: LocksBackend @@ -31,8 +31,8 @@ class SimpleLockIntegrationTest { @Test fun `obtain lock`() { - val simpleLock = SimpleLock(backend) - val permit = simpleLock.lock("test", Duration.ofSeconds(10)) + val simplifiedMutex = SimplifiedMutex(backend) + val permit = simplifiedMutex.lock("test", Duration.ofSeconds(10)) assertTrue(permit) @@ -41,43 +41,43 @@ class SimpleLockIntegrationTest { @Test fun `release lock`() { - val simpleLock = SimpleLock(backend) - simpleLock.lock("test", Duration.ofSeconds(10)) - simpleLock.unlock("test") + val simplifiedMutex = SimplifiedMutex(backend) + simplifiedMutex.lock("test", Duration.ofSeconds(10)) + simplifiedMutex.unlock("test") assertNull(redis.sync { redis -> redis.get("test") }) } @Test fun `another client can re-acquire lock`() { - val simpleLock = SimpleLock(backend) - val simpleLock2 = SimpleLock(backend, retryDelay = Duration.ofMillis(50), retryCount = 2) + val simplifiedMutex = SimplifiedMutex(backend) + val simplifiedMutex2 = SimplifiedMutex(backend, retryDelay = Duration.ofMillis(50), retryCount = 2) - assertTrue(simpleLock.lock("test", Duration.ofSeconds(10))) - assertFalse(simpleLock2.lock("test", Duration.ofMillis(10))) + assertTrue(simplifiedMutex.lock("test", Duration.ofSeconds(10))) + assertFalse(simplifiedMutex2.lock("test", Duration.ofMillis(10))) - simpleLock.unlock("test") - assertTrue(simpleLock2.lock("test", Duration.ofMillis(10))) + simplifiedMutex.unlock("test") + assertTrue(simplifiedMutex2.lock("test", Duration.ofMillis(10))) } @Test fun `another client can re-acquire lock due to expiration`() { - val simpleLock = SimpleLock(backend) - val simpleLock2 = SimpleLock(backend, retryDelay = Duration.ofMillis(30), retryCount = 2) + val simplifiedMutex = SimplifiedMutex(backend) + val simplifiedMutex2 = SimplifiedMutex(backend, retryDelay = Duration.ofMillis(30), retryCount = 2) - assertTrue(simpleLock.lock("test", Duration.ofMillis(200))) - assertFalse(simpleLock2.lock("test", Duration.ofMillis(10))) + assertTrue(simplifiedMutex.lock("test", Duration.ofMillis(200))) + assertFalse(simplifiedMutex2.lock("test", Duration.ofMillis(10))) runBlocking { delay(200) } - assertTrue(simpleLock2.lock("test", Duration.ofMillis(10))) + assertTrue(simplifiedMutex2.lock("test", Duration.ofMillis(10))) } @Test fun `dont allow to lock again`() { - val simpleLock = SimpleLock(backend) - val simpleLock2 = SimpleLock(backend) + val simplifiedMutex = SimplifiedMutex(backend) + val simplifiedMutex2 = SimplifiedMutex(backend) - assertTrue(simpleLock.lock("test", Duration.ofSeconds(10))) - assertFalse(simpleLock2.lock("test", Duration.ofMillis(10))) + assertTrue(simplifiedMutex.lock("test", Duration.ofSeconds(10))) + assertFalse(simplifiedMutex2.lock("test", Duration.ofMillis(10))) } } diff --git a/redpulsar-lettuce/src/test/kotlin/com/himadieiev/redpulsar/lettuce/locks/LockFactoryTest.kt b/redpulsar-lettuce/src/test/kotlin/com/himadieiev/redpulsar/lettuce/locks/LockFactoryTest.kt index d1553c4..22c850f 100644 --- a/redpulsar-lettuce/src/test/kotlin/com/himadieiev/redpulsar/lettuce/locks/LockFactoryTest.kt +++ b/redpulsar-lettuce/src/test/kotlin/com/himadieiev/redpulsar/lettuce/locks/LockFactoryTest.kt @@ -7,25 +7,25 @@ import java.time.Duration class LockFactoryTest { @Test - fun createSimpleLock() { + fun createSimplifiedMutex() { assertThrows { - LockFactory.createSimpleLock(client = mockk(), retryDelay = Duration.ofSeconds(0)) + LockFactory.createSimplifiedMutex(client = mockk(), retryDelay = Duration.ofSeconds(0)) } assertThrows { - LockFactory.createSimpleLock(client = mockk(), retryCount = -1) + LockFactory.createSimplifiedMutex(client = mockk(), retryCount = -1) } } @Test - fun createRedLock() { + fun createMutex() { assertThrows { - LockFactory.createRedLock(clients = listOf()) + LockFactory.createMutex(clients = listOf()) } assertThrows { - LockFactory.createRedLock(clients = listOf(mockk()), retryDelay = Duration.ofSeconds(0)) + LockFactory.createMutex(clients = listOf(mockk()), retryDelay = Duration.ofSeconds(0)) } assertThrows { - LockFactory.createRedLock(clients = listOf(mockk()), retryCount = -1) + LockFactory.createMutex(clients = listOf(mockk()), retryCount = -1) } }