GH-3672: Clean up Jdbc & ZK LockRegistry caches

Fixes https://github.com/spring-projects/spring-integration/issues/3672

* Clean up `JdbcLockRegistry`, `ZookeeperLockRegistry` cache automatically 
* setCapacity(int capacity) to cacheCapacity(int capacity)
* field rename `capacity`to `cacheCapacity`, add static
This commit is contained in:
Unseok Kim
2021-11-12 06:36:27 +09:00
committed by GitHub
parent 5452a6fbe6
commit db611028da
9 changed files with 447 additions and 42 deletions

View File

@@ -449,7 +449,7 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
final CountDownLatch countDownLatch = new CountDownLatch(THREAD_CNT);
final RedisConnectionFactory connectionFactory = getConnectionFactoryForTest();
final RedisLockRegistry registry = new RedisLockRegistry(connectionFactory, this.registryKey, 10000);
registry.setCapacity(CAPACITY_CNT);
registry.setCacheCapacity(CAPACITY_CNT);
final ExecutorService executorService = Executors.newFixedThreadPool(THREAD_CNT);
for (int i = 0; i < KEY_CNT; i++) {
@@ -490,7 +490,7 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
final CountDownLatch countDownLatch = new CountDownLatch(THREAD_CNT);
final RedisConnectionFactory connectionFactory = getConnectionFactoryForTest();
final RedisLockRegistry registry = new RedisLockRegistry(connectionFactory, this.registryKey, 10000);
registry.setCapacity(CAPACITY_CNT);
registry.setCacheCapacity(CAPACITY_CNT);
final ExecutorService executorService = Executors.newFixedThreadPool(THREAD_CNT);
final Queue<String> remainLockCheckQueue = new LinkedBlockingQueue<>();
@@ -538,7 +538,7 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
final CountDownLatch countDownLatch = new CountDownLatch(THREAD_CNT);
final RedisConnectionFactory connectionFactory = getConnectionFactoryForTest();
final RedisLockRegistry registry = new RedisLockRegistry(connectionFactory, this.registryKey, 10000);
registry.setCapacity(CAPACITY_CNT);
registry.setCacheCapacity(CAPACITY_CNT);
final ExecutorService executorService = Executors.newFixedThreadPool(THREAD_CNT);
final Queue<String> remainLockCheckQueue = new LinkedBlockingQueue<>();
@@ -585,14 +585,14 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
final int CAPACITY_CNT = 4;
final RedisConnectionFactory connectionFactory = getConnectionFactoryForTest();
final RedisLockRegistry registry = new RedisLockRegistry(connectionFactory, this.registryKey, 10000);
registry.setCapacity(CAPACITY_CNT);
registry.setCacheCapacity(CAPACITY_CNT);
registry.obtain("foo:1");
registry.obtain("foo:2");
registry.obtain("foo:3");
//capacity 4->3
registry.setCapacity(CAPACITY_CNT - 1);
registry.setCacheCapacity(CAPACITY_CNT - 1);
registry.obtain("foo:4");
@@ -600,7 +600,7 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
assertThat(getRedisLockRegistryLocks(registry)).containsKeys("foo:2", "foo:3", "foo:4");
//capacity 3->4
registry.setCapacity(CAPACITY_CNT);
registry.setCacheCapacity(CAPACITY_CNT);
registry.obtain("foo:5");
assertThat(TestUtils.getPropertyValue(registry, "locks", Map.class).size()).isEqualTo(4);
assertThat(getRedisLockRegistryLocks(registry)).containsKeys("foo:3", "foo:4", "foo:5");
@@ -636,8 +636,7 @@ public class RedisLockRegistryTests extends RedisAvailableTests {
}
@SuppressWarnings("unchecked")
private Map<String, Lock> getRedisLockRegistryLocks(RedisLockRegistry registry) {
private static Map<String, Lock> getRedisLockRegistryLocks(RedisLockRegistry registry) {
return TestUtils.getPropertyValue(registry, "locks", Map.class);
}
}