Search in sources :

Example 21 with HeldLocksToken

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());
}
Also used : LockResponse(com.palantir.lock.LockResponse) HeldLocksToken(com.palantir.lock.HeldLocksToken) Builder(com.palantir.lock.LockRequest.Builder) Test(org.junit.Test)

Example 22 with HeldLocksToken

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();
}
Also used : HeldLocksToken(com.palantir.lock.HeldLocksToken) SimpleHeldLocksToken(com.palantir.lock.SimpleHeldLocksToken) LockRefreshToken(com.palantir.lock.LockRefreshToken) Test(org.junit.Test)

Example 23 with HeldLocksToken

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);
}
Also used : HeldLocksToken(com.palantir.lock.HeldLocksToken) SimpleHeldLocksToken(com.palantir.lock.SimpleHeldLocksToken) LockRefreshToken(com.palantir.lock.LockRefreshToken) Test(org.junit.Test)

Example 24 with HeldLocksToken

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);
}
Also used : Iterables(com.google.common.collect.Iterables) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HeldLocksToken(com.palantir.lock.HeldLocksToken) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) LockImmutableTimestampResponse(com.palantir.lock.v2.LockImmutableTimestampResponse) SimpleTimeDuration(com.palantir.lock.SimpleTimeDuration) SimpleHeldLocksToken(com.palantir.lock.SimpleHeldLocksToken) LockRefreshToken(com.palantir.lock.LockRefreshToken) LockServerOptions(com.palantir.lock.LockServerOptions) Future(java.util.concurrent.Future) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) After(org.junit.After) WaitForLocksResponse(com.palantir.lock.v2.WaitForLocksResponse) BadRequestException(javax.ws.rs.BadRequestException) HttpStatus(org.eclipse.jetty.http.HttpStatus) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) LockDescriptor(com.palantir.lock.LockDescriptor) ThrowableAssert(org.assertj.core.api.ThrowableAssert) LockResponse(com.palantir.lock.v2.LockResponse) ImmutableSet(com.google.common.collect.ImmutableSet) HeldLocksGrant(com.palantir.lock.HeldLocksGrant) AtlasDbRemoteException(com.palantir.atlasdb.http.errors.AtlasDbRemoteException) LockToken(com.palantir.lock.v2.LockToken) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) Test(org.junit.Test) LockMode(com.palantir.lock.LockMode) Collectors(java.util.stream.Collectors) LockImmutableTimestampRequest(com.palantir.lock.v2.LockImmutableTimestampRequest) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) LockRequest(com.palantir.lock.v2.LockRequest) LockClient(com.palantir.lock.LockClient) TimestampRange(com.palantir.timestamp.TimestampRange) StringLockDescriptor(com.palantir.lock.StringLockDescriptor) WaitForLocksRequest(com.palantir.lock.v2.WaitForLocksRequest) HeldLocksToken(com.palantir.lock.HeldLocksToken) SimpleHeldLocksToken(com.palantir.lock.SimpleHeldLocksToken) Test(org.junit.Test)

Example 25 with HeldLocksToken

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);
}
Also used : HeldLocksGrant(com.palantir.lock.HeldLocksGrant) HeldLocksToken(com.palantir.lock.HeldLocksToken) SimpleHeldLocksToken(com.palantir.lock.SimpleHeldLocksToken) Test(org.junit.Test)

Aggregations

HeldLocksToken (com.palantir.lock.HeldLocksToken)29 SimpleHeldLocksToken (com.palantir.lock.SimpleHeldLocksToken)19 Test (org.junit.Test)13 LockDescriptor (com.palantir.lock.LockDescriptor)8 Nullable (javax.annotation.Nullable)8 StringLockDescriptor (com.palantir.lock.StringLockDescriptor)7 HeldLocksGrant (com.palantir.lock.HeldLocksGrant)5 LockClient (com.palantir.lock.LockClient)5 LockRefreshToken (com.palantir.lock.LockRefreshToken)5 ImmutableSet (com.google.common.collect.ImmutableSet)4 LockResponse (com.palantir.lock.LockResponse)4 BigInteger (java.math.BigInteger)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 LockMode (com.palantir.lock.LockMode)3 SimpleTimeDuration (com.palantir.lock.SimpleTimeDuration)3 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)2 LockRequest (com.palantir.lock.LockRequest)2 TimeDuration (com.palantir.lock.TimeDuration)2 Set (java.util.Set)2 ImmutableList (com.google.common.collect.ImmutableList)1