use of com.palantir.lock.HeldLocksToken in project atlasdb by palantir.
the class LockRefreshingLockServiceTest method testSimpleRefresh.
@Test
public void testSimpleRefresh() throws InterruptedException {
Builder builder = LockRequest.builder(ImmutableSortedMap.of(lock1, LockMode.WRITE));
builder.timeoutAfter(SimpleTimeDuration.of(5, TimeUnit.SECONDS));
LockResponse lock = server.lockWithFullLockResponse(LockClient.ANONYMOUS, builder.build());
Thread.sleep(10000);
Set<HeldLocksToken> refreshTokens = server.refreshTokens(ImmutableList.of(lock.getToken()));
Assert.assertEquals(1, refreshTokens.size());
}
use of com.palantir.lock.HeldLocksToken in project atlasdb by palantir.
the class AsyncTimelockServiceIntegrationTest method unlockAndFreezeDoesNotAllowRefreshes.
@Test
public void unlockAndFreezeDoesNotAllowRefreshes() throws InterruptedException {
HeldLocksToken token = lockWithFullResponse(requestForWriteLock(LOCK_A), TEST_CLIENT);
cluster.lockService().unlockAndFreeze(token);
Set<LockRefreshToken> lockRefreshTokens = cluster.lockService().refreshLockRefreshTokens(ImmutableList.of(token.getLockRefreshToken()));
assertThat(lockRefreshTokens).isEmpty();
}
use of com.palantir.lock.HeldLocksToken in project atlasdb by palantir.
the class AsyncTimelockServiceIntegrationTest method canPerformLockAndRefreshLock.
@Test
public void canPerformLockAndRefreshLock() throws InterruptedException {
HeldLocksToken token1 = lockWithFullResponse(requestForWriteLock(LOCK_A), TEST_CLIENT);
LockRefreshToken token = token1.getLockRefreshToken();
Set<LockRefreshToken> lockRefreshTokens = cluster.lockService().refreshLockRefreshTokens(ImmutableList.of(token));
assertThat(lockRefreshTokens).contains(token);
unlock(token1);
}
use of com.palantir.lock.HeldLocksToken in project atlasdb by palantir.
the class AsyncTimelockServiceIntegrationTest method testGetAndRefreshTokens.
@Test
public void testGetAndRefreshTokens() throws InterruptedException {
HeldLocksToken token1 = lockWithFullResponse(requestForWriteLock(LOCK_A), TEST_CLIENT);
HeldLocksToken token2 = lockWithFullResponse(requestForWriteLock(LOCK_B), TEST_CLIENT);
Set<HeldLocksToken> tokens = cluster.lockService().getTokens(TEST_CLIENT);
assertThat(tokens.stream().map(token -> Iterables.getOnlyElement(token.getLocks()).getLockDescriptor()).collect(Collectors.toList())).containsExactlyInAnyOrder(LOCK_A, LOCK_B);
Set<HeldLocksToken> heldLocksTokens = cluster.lockService().refreshTokens(tokens);
assertThat(heldLocksTokens.stream().map(token -> Iterables.getOnlyElement(token.getLocks()).getLockDescriptor()).collect(Collectors.toList())).containsExactlyInAnyOrder(LOCK_A, LOCK_B);
unlock(token1, token2);
}
use of com.palantir.lock.HeldLocksToken in project atlasdb by palantir.
the class AsyncTimelockServiceIntegrationTest method lockGrantsCanBeServedAndRefreshed.
@Test
public void lockGrantsCanBeServedAndRefreshed() throws InterruptedException {
HeldLocksToken heldLocksToken = lockWithFullResponse(requestForReadLock(LOCK_A), TEST_CLIENT);
HeldLocksGrant heldLocksGrant = cluster.lockService().convertToGrant(heldLocksToken);
assertThat(cluster.lockService().getTokens(TEST_CLIENT)).isEmpty();
HeldLocksGrant refreshedLockGrant = cluster.lockService().refreshGrant(heldLocksGrant);
assertThat(refreshedLockGrant).isEqualTo(heldLocksGrant);
HeldLocksGrant refreshedLockGrant2 = cluster.lockService().refreshGrant(heldLocksGrant.getGrantId());
assertThat(refreshedLockGrant2).isEqualTo(heldLocksGrant);
cluster.lockService().useGrant(TEST_CLIENT_2, heldLocksGrant);
assertThat(Iterables.getOnlyElement(cluster.lockService().getTokens(TEST_CLIENT_2)).getLockDescriptors()).contains(LOCK_A);
assertThatThrownBy(() -> cluster.lockService().useGrant(TEST_CLIENT_3, heldLocksGrant.getGrantId())).isInstanceOf(AtlasDbRemoteException.class);
}
Aggregations