@Test public void validateLockIdWithNoRecord() throws Exception { long badLockId = 1; mThrown.expect(BlockDoesNotExistException.class); mThrown.expectMessage(ExceptionMessage.LOCK_RECORD_NOT_FOUND_FOR_LOCK_ID.getMessage(badLockId)); mLockManager.validateLock(TEST_SESSION_ID, TEST_BLOCK_ID, badLockId); }
public void validateLock(long sessionId, long blockId, long lockId) throws BlockDoesNotExistException, InvalidWorkerStateException { try (LockResource r = new LockResource(mSharedMapsLock.readLock())) { LockRecord record = mLockIdToRecordMap.get(lockId); if (record == null) { throw new BlockDoesNotExistException(ExceptionMessage.LOCK_RECORD_NOT_FOUND_FOR_LOCK_ID, lockId); } if (sessionId != record.getSessionId()) { throw new InvalidWorkerStateException(ExceptionMessage.LOCK_ID_FOR_DIFFERENT_SESSION, lockId, record.getSessionId(), sessionId); } if (blockId != record.getBlockId()) { throw new InvalidWorkerStateException(ExceptionMessage.LOCK_ID_FOR_DIFFERENT_BLOCK, lockId, record.getBlockId(), blockId); } } }
BlockLockManager { public void validateLock(long sessionId, long blockId, long lockId) throws BlockDoesNotExistException, InvalidWorkerStateException { try (LockResource r = new LockResource(mSharedMapsLock.readLock())) { LockRecord record = mLockIdToRecordMap.get(lockId); if (record == null) { throw new BlockDoesNotExistException(ExceptionMessage.LOCK_RECORD_NOT_FOUND_FOR_LOCK_ID, lockId); } if (sessionId != record.getSessionId()) { throw new InvalidWorkerStateException(ExceptionMessage.LOCK_ID_FOR_DIFFERENT_SESSION, lockId, record.getSessionId(), sessionId); } if (blockId != record.getBlockId()) { throw new InvalidWorkerStateException(ExceptionMessage.LOCK_ID_FOR_DIFFERENT_BLOCK, lockId, record.getBlockId(), blockId); } } } }
BlockLockManager { public void validateLock(long sessionId, long blockId, long lockId) throws BlockDoesNotExistException, InvalidWorkerStateException { try (LockResource r = new LockResource(mSharedMapsLock.readLock())) { LockRecord record = mLockIdToRecordMap.get(lockId); if (record == null) { throw new BlockDoesNotExistException(ExceptionMessage.LOCK_RECORD_NOT_FOUND_FOR_LOCK_ID, lockId); } if (sessionId != record.getSessionId()) { throw new InvalidWorkerStateException(ExceptionMessage.LOCK_ID_FOR_DIFFERENT_SESSION, lockId, record.getSessionId(), sessionId); } if (blockId != record.getBlockId()) { throw new InvalidWorkerStateException(ExceptionMessage.LOCK_ID_FOR_DIFFERENT_BLOCK, lockId, record.getBlockId(), blockId); } } } BlockLockManager(); }
BlockLockManager { public void validateLock(long sessionId, long blockId, long lockId) throws BlockDoesNotExistException, InvalidWorkerStateException { try (LockResource r = new LockResource(mSharedMapsLock.readLock())) { LockRecord record = mLockIdToRecordMap.get(lockId); if (record == null) { throw new BlockDoesNotExistException(ExceptionMessage.LOCK_RECORD_NOT_FOUND_FOR_LOCK_ID, lockId); } if (sessionId != record.getSessionId()) { throw new InvalidWorkerStateException(ExceptionMessage.LOCK_ID_FOR_DIFFERENT_SESSION, lockId, record.getSessionId(), sessionId); } if (blockId != record.getBlockId()) { throw new InvalidWorkerStateException(ExceptionMessage.LOCK_ID_FOR_DIFFERENT_BLOCK, lockId, record.getBlockId(), blockId); } } } BlockLockManager(); long lockBlock(long sessionId, long blockId, BlockLockType blockLockType); boolean unlockBlockNoException(long lockId); void unlockBlock(long lockId); boolean unlockBlock(long sessionId, long blockId); void validateLock(long sessionId, long blockId, long lockId); void cleanupSession(long sessionId); Set<Long> getLockedBlocks(); void validate(); }
BlockLockManager { public void validateLock(long sessionId, long blockId, long lockId) throws BlockDoesNotExistException, InvalidWorkerStateException { try (LockResource r = new LockResource(mSharedMapsLock.readLock())) { LockRecord record = mLockIdToRecordMap.get(lockId); if (record == null) { throw new BlockDoesNotExistException(ExceptionMessage.LOCK_RECORD_NOT_FOUND_FOR_LOCK_ID, lockId); } if (sessionId != record.getSessionId()) { throw new InvalidWorkerStateException(ExceptionMessage.LOCK_ID_FOR_DIFFERENT_SESSION, lockId, record.getSessionId(), sessionId); } if (blockId != record.getBlockId()) { throw new InvalidWorkerStateException(ExceptionMessage.LOCK_ID_FOR_DIFFERENT_BLOCK, lockId, record.getBlockId(), blockId); } } } BlockLockManager(); long lockBlock(long sessionId, long blockId, BlockLockType blockLockType); boolean unlockBlockNoException(long lockId); void unlockBlock(long lockId); boolean unlockBlock(long sessionId, long blockId); void validateLock(long sessionId, long blockId, long lockId); void cleanupSession(long sessionId); Set<Long> getLockedBlocks(); void validate(); static final long INVALID_LOCK_ID; }