LockClient client = heldLocks.realToken.getClient(); if (client.isAnonymous()) { heldLocksTokenMap.put(token, heldLocks);
public static SimpleTokenInfo of(HeldLocksToken token, LockMode lockMode) { return ImmutableSimpleTokenInfo.builder() .lockMode(lockMode) .expiresIn(token.getExpirationDateMs() - System.currentTimeMillis()) .createdAtTs(token.getCreationDateMs()) .tokenId(token.getTokenId().toString()) .clientId(Preconditions.checkNotNull(token.getClient()).getClientId()) .requestThread(token.getRequestingThread()) .createAt(new Date(token.getCreationDateMs()).toString()) .versionId(token.getVersionId()) .build(); }
changeOwner(heldLocks.locks, heldLocks.realToken.getClient(), INTERNAL_LOCK_GRANT_CLIENT); } catch (IllegalMonitorStateException e) { throw e; lockClientMultimap.remove(heldLocks.realToken.getClient(), token); HeldLocksGrant grant = createHeldLocksGrant(heldLocks.realToken.getLockDescriptors(), heldLocks.locks, heldLocks.realToken.getLockTimeout(),
/** Convert a write lock to a read lock */ @Test public void testConvertWriteToRead() throws Exception { final LockRequest request1 = LockRequest.builder(ImmutableSortedMap.of(lock1, LockMode.WRITE)) .build(); final LockRequest request2 = LockRequest.builder(ImmutableSortedMap.of(lock1, LockMode.READ)) .build(); HeldLocksToken token1 = server.lockWithFullLockResponse(client, request1).getToken(); Assert.assertNotNull(token1); Assert.assertEquals(client, token1.getClient()); Assert.assertEquals(request1.getLockDescriptors(), token1.getLockDescriptors()); Future<?> future = executor.submit((Callable<Void>) () -> { barrier.await(); HeldLocksToken validToken = server.lockWithFullLockResponse(LockClient.ANONYMOUS, request2).getToken(); Assert.assertNotNull(validToken); Assert.assertEquals(LockClient.ANONYMOUS, validToken.getClient()); Assert.assertEquals(request2.getLockDescriptors(), validToken.getLockDescriptors()); Assert.assertTrue(server.unlock(validToken)); return null; }); barrier.await(); Thread.sleep(50); HeldLocksToken token2 = server.lockWithFullLockResponse(client, request2).getToken(); Assert.assertNotNull(token2); Assert.assertEquals(client, token2.getClient()); Assert.assertEquals(request2.getLockDescriptors(), token2.getLockDescriptors()); Assert.assertTrue(server.unlock(token1)); future.get(); Assert.assertTrue(server.unlock(token2)); Assert.assertTrue(server.getTokens(client).isEmpty()); }
HeldLocksToken token = server.lockWithFullLockResponse(LockClient.ANONYMOUS, request).getToken(); Assert.assertNotNull(token); Assert.assertEquals(LockClient.ANONYMOUS, token.getClient()); Assert.assertEquals(request.getLockDescriptors(), token.getLockDescriptors()); server.unlock(token);
HeldLocksToken token1 = response1.getToken(); Assert.assertNotNull(token1); Assert.assertEquals(LockClient.ANONYMOUS, token1.getClient()); Assert.assertEquals(request1.getLockDescriptors(), token1.getLockDescriptors()); Assert.assertTrue(currentTimeMs + lockTimeoutMs <= token1.getExpirationDateMs());
HeldLocksToken token = server.lockWithFullLockResponse(client, request).getToken(); Assert.assertNotNull(token); Assert.assertEquals(client, token.getClient()); Assert.assertEquals(request.getLockDescriptors(), token.getLockDescriptors()); Thread.sleep(51); Assert.assertEquals(LockClient.ANONYMOUS, token.getClient()); Assert.assertEquals(request.getLockDescriptors(), token.getLockDescriptors()); Assert.assertEquals(client, token.getClient()); Assert.assertEquals(request.getLockDescriptors(), token.getLockDescriptors()); server.unlock(token);
HeldLocksToken readWriteToken = server.lockWithFullLockResponse(client, requestAllLocks).getToken(); Assert.assertNotNull(readWriteToken); Assert.assertEquals(client, readWriteToken.getClient()); Assert.assertEquals(LockCollections.of(ImmutableSortedMap.copyOf(lockMap)), readWriteToken.getLockDescriptors()); HeldLocksToken token = server.lockWithFullLockResponse(client, requestAllLocks).getToken(); Assert.assertNotNull(token); Assert.assertEquals(client, token.getClient()); Assert.assertEquals(LockCollections.of(ImmutableSortedMap.copyOf(lockMap)), token.getLockDescriptors()); token = server.lockWithFullLockResponse(client2, requestAllLocks).getToken(); Assert.assertNotNull(token); Assert.assertEquals(client2, token.getClient()); lockMap = Maps.newTreeMap(); for (int i = 0; i < numLocks; ++i) { token = server.lockWithFullLockResponse(client2, requestAllLocks).getToken(); Assert.assertNotNull(token); Assert.assertEquals(client2, token.getClient()); lockMap = Maps.newTreeMap(); for (int i = 0; i < numLocks; ++i) {
HeldLocksToken token1 = response.getToken(); Assert.assertNotNull(token1); Assert.assertEquals(client, token1.getClient()); Assert.assertEquals(request1.getLockDescriptors(), token1.getLockDescriptors()); System.out.println(response.getLockHolders()); Assert.assertNotNull(token2); Assert.assertEquals(LockClient.ANONYMOUS, token2.getClient()); Assert.assertEquals(request2.getLockDescriptors(), token2.getLockDescriptors()); HeldLocksToken token3 = response.getToken(); Assert.assertNotNull(token3); Assert.assertEquals(client, token3.getClient()); Assert.assertEquals(LockCollections.of(ImmutableSortedMap.of(lock1, LockMode.READ)), token3.getLockDescriptors());
Assert.assertEquals(client2, validToken.getClient()); server.unlock(validToken); token1 = server.lockWithFullLockResponse(client, requestWrite).getToken(); Assert.assertNotNull(token1); Assert.assertEquals(client, token1.getClient()); Future<?> future = executor.submit((Callable<Void>) () -> { HeldLocksToken validToken1 = server.lockWithFullLockResponse(LockClient.ANONYMOUS, LockRequest.builder( ImmutableSortedMap.of(lock1, LockMode.WRITE)).build()).getToken(); Assert.assertNotNull(validToken1); Assert.assertEquals(LockClient.ANONYMOUS, validToken1.getClient()); server.unlock(validToken1); Assert.assertEquals(client2, validToken.getClient());
HeldLocksToken token1 = response.getToken(); Assert.assertNotNull(token1); Assert.assertEquals(client, token1.getClient()); Assert.assertEquals(request.getLockDescriptors(), token1.getLockDescriptors()); Assert.assertTrue(currentTimeMs + lockTimeoutMs <= token1.getExpirationDateMs());
} else { numSuccess.set(numSuccess.get() + 1); Assert.assertEquals(Integer.toString(clientID), token.getClient().getClientId()); Assert.assertEquals(request.getLockDescriptors(), token.getLockDescriptors()); try {
HeldLocksToken token = server.lockWithFullLockResponse(LockClient.ANONYMOUS, request).getToken(); Assert.assertNotNull(token); Assert.assertEquals(LockClient.ANONYMOUS, token.getClient()); Assert.assertEquals(LockCollections.of(ImmutableSortedMap.of(lock1, LockMode.WRITE)), token.getLockDescriptors()); try { HeldLocksToken token2 = server.lockWithFullLockResponse(client, request).getToken(); Assert.assertNotNull(token2); Assert.assertEquals(client, token2.getClient()); Assert.assertEquals(LockCollections.of(ImmutableSortedMap.of(lock1, LockMode.WRITE)), token2.getLockDescriptors()); server.unlockAndFreeze(token2);
HeldLocksToken token1 = response.getToken(); Assert.assertNotNull(token1); Assert.assertEquals(client, token1.getClient()); Assert.assertEquals(10, (long) token1.getVersionId()); Assert.assertEquals(request.getLockDescriptors(), token1.getLockDescriptors());
HeldLocksToken token1 = response.getToken(); Assert.assertNotNull(token1); Assert.assertEquals(client, token1.getClient()); Assert.assertEquals(request.getLockDescriptors(), token1.getLockDescriptors()); Assert.assertTrue(currentTimeMs + lockTimeoutMs <= token1.getExpirationDateMs());
Assert.assertEquals(ImmutableMap.of(lock3, client), response.getLockHolders()); HeldLocksToken token = response.getToken(); Assert.assertEquals(LockClient.ANONYMOUS, token.getClient()); Assert.assertEquals(LockCollections.of(ImmutableSortedMap.of(lock1, LockMode.READ)), token.getLockDescriptors()); Assert.assertEquals(ImmutableMap.of(lock4, client), response.getLockHolders()); token = response.getToken(); Assert.assertEquals(LockClient.ANONYMOUS, token.getClient()); Assert.assertEquals(LockCollections.of(ImmutableSortedMap.of(lock2, LockMode.READ)), token.getLockDescriptors()); Assert.assertTrue(response.getLockHolders().isEmpty()); token = response.getToken(); Assert.assertEquals(LockClient.ANONYMOUS, token.getClient()); Assert.assertEquals(LockCollections.of(ImmutableSortedMap.of(lock1, LockMode.READ, lock2, LockMode.READ)), token.getLockDescriptors());
Assert.assertEquals(client, token.getClient()); Assert.assertEquals(LockCollections.of(ImmutableSortedMap.of(lock, LockMode.READ)), token.getLockDescriptors());