Search in sources :

Example 6 with HeldLocksGrant

use of com.palantir.lock.HeldLocksGrant in project atlasdb by palantir.

the class LockServiceSerDeTest method testSerialisationAndDeserialisationOfHeldLocksGrant.

@Test
public void testSerialisationAndDeserialisationOfHeldLocksGrant() throws Exception {
    ImmutableSortedMap<LockDescriptor, LockMode> lockDescriptorLockMode = LockServiceTestUtils.getLockDescriptorLockMode(ImmutableList.of("lock1", "lock2"));
    HeldLocksGrant heldLocksGrant = new HeldLocksGrant(BigInteger.ONE, System.currentTimeMillis(), System.currentTimeMillis() + 10L, LockCollections.of(lockDescriptorLockMode), SimpleTimeDuration.of(100, TimeUnit.SECONDS), 10L);
    ObjectMapper mapper = new ObjectMapper();
    String serializedForm = mapper.writeValueAsString(heldLocksGrant);
    HeldLocksGrant deserialzedlockServerOptions = mapper.readValue(serializedForm, HeldLocksGrant.class);
    assertEquals(heldLocksGrant, deserialzedlockServerOptions);
}
Also used : StringLockDescriptor(com.palantir.lock.StringLockDescriptor) LockDescriptor(com.palantir.lock.LockDescriptor) HeldLocksGrant(com.palantir.lock.HeldLocksGrant) LockMode(com.palantir.lock.LockMode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 7 with HeldLocksGrant

use of com.palantir.lock.HeldLocksGrant 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

HeldLocksGrant (com.palantir.lock.HeldLocksGrant)7 HeldLocksToken (com.palantir.lock.HeldLocksToken)4 SimpleHeldLocksToken (com.palantir.lock.SimpleHeldLocksToken)4 Nullable (javax.annotation.Nullable)4 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 LockDescriptor (com.palantir.lock.LockDescriptor)1 LockMode (com.palantir.lock.LockMode)1 StringLockDescriptor (com.palantir.lock.StringLockDescriptor)1 BigInteger (java.math.BigInteger)1