#2515 - Test case for expiration renewal not working after connection problem (refactor);
Signed-off-by: Emerson Dallagnol <edallagnol@live.com>pull/2518/head
parent
2464e06616
commit
7048a86059
@ -1,45 +0,0 @@
|
||||
package org.redisson;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.redisson.api.RLock;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
public class RedissonExpirationRenewalTest extends BaseTest {
|
||||
|
||||
private static final String LOCK_KEY = "LOCK_KEY";
|
||||
|
||||
@Test
|
||||
public void testExpirationRenewal() throws IOException, InterruptedException {
|
||||
redisson.getConfig().setLockWatchdogTimeout(3_000L);
|
||||
|
||||
{
|
||||
RLock lock = redisson.getLock(LOCK_KEY);
|
||||
lock.lock();
|
||||
try {
|
||||
Thread.sleep(5_000L);
|
||||
int port = RedisRunner.defaultRedisInstance.getRedisServerPort();
|
||||
// force expiration renewal error
|
||||
RedisRunner.shutDownDefaultRedisServerInstance();
|
||||
RedisRunner.defaultRedisInstance = new RedisRunner().nosave().randomDir().port(port).run();
|
||||
Thread.sleep(10_000L);
|
||||
} finally {
|
||||
assertThatThrownBy(lock::unlock).isInstanceOf(IllegalMonitorStateException.class);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
RLock lock = redisson.getLock(LOCK_KEY);
|
||||
lock.lock();
|
||||
try {
|
||||
// wait for timeout
|
||||
Thread.sleep(30_000L);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package org.redisson;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.redisson.config.Config;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
public class RedissonLockExpirationRenewalTest {
|
||||
|
||||
private static final String LOCK_KEY = "LOCK_KEY";
|
||||
public static final long LOCK_WATCHDOG_TIMEOUT = 1_000L;
|
||||
|
||||
private RedissonClient redisson;
|
||||
|
||||
@Before
|
||||
public void before() throws IOException, InterruptedException {
|
||||
RedisRunner.startDefaultRedisServerInstance();
|
||||
redisson = createInstance();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws InterruptedException {
|
||||
redisson.shutdown();
|
||||
RedisRunner.shutDownDefaultRedisServerInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExpirationRenewalIsWorkingAfterTimeout() throws IOException, InterruptedException {
|
||||
{
|
||||
RLock lock = redisson.getLock(LOCK_KEY);
|
||||
lock.lock();
|
||||
try {
|
||||
// force expiration renewal error
|
||||
restartRedisServer();
|
||||
// wait for timeout
|
||||
Thread.sleep(LOCK_WATCHDOG_TIMEOUT * 2);
|
||||
} finally {
|
||||
assertThatThrownBy(lock::unlock).isInstanceOf(IllegalMonitorStateException.class);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
RLock lock = redisson.getLock(LOCK_KEY);
|
||||
lock.lock();
|
||||
try {
|
||||
// wait for timeout
|
||||
Thread.sleep(LOCK_WATCHDOG_TIMEOUT * 2);
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void restartRedisServer() throws InterruptedException, IOException {
|
||||
int currentPort = RedisRunner.defaultRedisInstance.getRedisServerPort();
|
||||
RedisRunner.shutDownDefaultRedisServerInstance();
|
||||
RedisRunner.defaultRedisInstance = new RedisRunner().nosave().randomDir().port(currentPort).run();
|
||||
}
|
||||
|
||||
public static Config createConfig() {
|
||||
Config config = new Config();
|
||||
config.useSingleServer()
|
||||
.setAddress(RedisRunner.getDefaultRedisServerBindAddressAndPort());
|
||||
config.setLockWatchdogTimeout(LOCK_WATCHDOG_TIMEOUT);
|
||||
return config;
|
||||
}
|
||||
|
||||
public static RedissonClient createInstance() {
|
||||
Config config = createConfig();
|
||||
return Redisson.create(config);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue