Skip to content

Commit

Permalink
fix unit-test for redis
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang181230 committed Dec 1, 2023
1 parent 9a1ae70 commit 810fe98
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class RedisDistributedLockerTest {

private String retryRollbacking = "RetryRollbacking";
private String retryCommiting = "RetryCommiting";
private String retryRollbacking2 = "RetryRollbacking2";
private String lockValue = "127.1.1.1:9081";
private static DistributedLocker distributedLocker;
private static Jedis jedis;
Expand All @@ -69,25 +70,29 @@ public static void after() throws IOException {

@Test
public void test_acquireScheduledLock_success() {
boolean acquire = distributedLocker.acquireLock(new DistributedLockDO(retryRollbacking, lockValue, 60000L));
String lockKey = retryRollbacking;

boolean acquire = distributedLocker.acquireLock(new DistributedLockDO(lockKey, lockValue, 60000L));
Assertions.assertTrue(acquire);
String lockValueExisted = jedis.get(retryRollbacking);
String lockValueExisted = jedis.get(lockKey);
Assertions.assertEquals(lockValue, lockValueExisted);
boolean release = distributedLocker.releaseLock(new DistributedLockDO(retryRollbacking, lockValue, null));
boolean release = distributedLocker.releaseLock(new DistributedLockDO(lockKey, lockValue, null));
Assertions.assertTrue(release);
Assertions.assertNull(jedis.get(retryRollbacking));
Assertions.assertNull(jedis.get(lockKey));
}

@Test
public void test_acquireScheduledLock_success_() throws UnknownHostException {
String lockKey = retryRollbacking2;

SessionHolder.init(SessionMode.REDIS);
boolean accquire = SessionHolder.acquireDistributedLock(retryRollbacking);
boolean accquire = SessionHolder.acquireDistributedLock(lockKey);
Assertions.assertTrue(accquire);
String lockValueExisted = jedis.get(retryRollbacking);
String lockValueExisted = jedis.get(lockKey);
Assertions.assertEquals(XID.getIpAddressAndPort(), lockValueExisted);
boolean release = SessionHolder.releaseDistributedLock(retryRollbacking);
boolean release = SessionHolder.releaseDistributedLock(lockKey);
Assertions.assertTrue(release);
Assertions.assertNull(jedis.get(retryRollbacking));
Assertions.assertNull(jedis.get(lockKey));
}

@Test
Expand Down

0 comments on commit 810fe98

Please sign in to comment.