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);
}
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);
}
Aggregations