@Test public void lockImmutableTimestampLocksFreshTimestamp() throws InterruptedException { long immutableTs = 3L; LockRefreshToken expectedToken = mockImmutableTsLockResponse(); mockMinLockedInVersionIdResponse(immutableTs); LockImmutableTimestampResponse expectedResponse = LockImmutableTimestampResponse.of(immutableTs, toTokenV2(expectedToken)); assertThat(timelock.lockImmutableTimestamp()).isEqualTo(expectedResponse); }
@Override public LockImmutableTimestampResponse lockImmutableTimestamp() { long immutableLockTs = timestampService.getFreshTimestamp(); LockDescriptor lockDesc = AtlasTimestampLockDescriptor.of(immutableLockTs); com.palantir.lock.LockRequest lockRequest = com.palantir.lock.LockRequest.builder( ImmutableSortedMap.of(lockDesc, LockMode.READ)) .withLockedInVersionId(immutableLockTs).build(); LockRefreshToken lock; try { lock = lockService.lock(immutableTsLockClient.getClientId(), lockRequest); } catch (InterruptedException e) { throw Throwables.throwUncheckedException(e); } try { return LockImmutableTimestampResponse.of( getImmutableTimestampInternal(immutableLockTs), LockTokenConverter.toTokenV2(lock)); } catch (Throwable e) { if (lock != null) { try { lockService.unlock(lock); } catch (Throwable unlockThrowable) { e.addSuppressed(unlockThrowable); } } throw Throwables.rewrapAndThrowUncheckedException(e); } }
LegacyTimelockService implements TimelockService { @Override public LockImmutableTimestampResponse lockImmutableTimestamp() { long immutableLockTs = timestampService.getFreshTimestamp(); LockDescriptor lockDesc = AtlasTimestampLockDescriptor.of(immutableLockTs); com.palantir.lock.LockRequest lockRequest = com.palantir.lock.LockRequest.builder( ImmutableSortedMap.of(lockDesc, LockMode.READ)) .withLockedInVersionId(immutableLockTs).build(); LockRefreshToken lock; try { lock = lockService.lock(immutableTsLockClient.getClientId(), lockRequest); } catch (InterruptedException e) { throw Throwables.throwUncheckedException(e); } try { return LockImmutableTimestampResponse.of( getImmutableTimestampInternal(immutableLockTs), LockTokenConverter.toTokenV2(lock)); } catch (Throwable e) { if (lock != null) { try { lockService.unlock(lock); } catch (Throwable unlockThrowable) { e.addSuppressed(unlockThrowable); } } throw Throwables.rewrapAndThrowUncheckedException(e); } } }
LegacyTimelockService implements TimelockService { @Override public LockImmutableTimestampResponse lockImmutableTimestamp() { long immutableLockTs = timestampService.getFreshTimestamp(); LockDescriptor lockDesc = AtlasTimestampLockDescriptor.of(immutableLockTs); com.palantir.lock.LockRequest lockRequest = com.palantir.lock.LockRequest.builder( ImmutableSortedMap.of(lockDesc, LockMode.READ)) .withLockedInVersionId(immutableLockTs).build(); LockRefreshToken lock; try { lock = lockService.lock(immutableTsLockClient.getClientId(), lockRequest); } catch (InterruptedException e) { throw Throwables.throwUncheckedException(e); } try { return LockImmutableTimestampResponse.of( getImmutableTimestampInternal(immutableLockTs), LockTokenConverter.toTokenV2(lock)); } catch (Throwable e) { if (lock != null) { try { lockService.unlock(lock); } catch (Throwable unlockThrowable) { e.addSuppressed(unlockThrowable); } } throw Throwables.rewrapAndThrowUncheckedException(e); } } LegacyTimelockService(TimestampService timestampService, LockService lockService,
            LockClient immutableTsLockClient); }
LegacyTimelockService implements TimelockService { @Override public LockImmutableTimestampResponse lockImmutableTimestamp() { long immutableLockTs = timestampService.getFreshTimestamp(); LockDescriptor lockDesc = AtlasTimestampLockDescriptor.of(immutableLockTs); com.palantir.lock.LockRequest lockRequest = com.palantir.lock.LockRequest.builder( ImmutableSortedMap.of(lockDesc, LockMode.READ)) .withLockedInVersionId(immutableLockTs).build(); LockRefreshToken lock; try { lock = lockService.lock(immutableTsLockClient.getClientId(), lockRequest); } catch (InterruptedException e) { throw Throwables.throwUncheckedException(e); } try { return LockImmutableTimestampResponse.of( getImmutableTimestampInternal(immutableLockTs), LockTokenConverter.toTokenV2(lock)); } catch (Throwable e) { if (lock != null) { try { lockService.unlock(lock); } catch (Throwable unlockThrowable) { e.addSuppressed(unlockThrowable); } } throw Throwables.rewrapAndThrowUncheckedException(e); } } LegacyTimelockService(TimestampService timestampService, LockService lockService,
            LockClient immutableTsLockClient); @Override boolean isInitialized(); @Override long getFreshTimestamp(); @Override long getCommitTimestamp(long startTs, LockToken commitLocksToken); @Override TimestampRange getFreshTimestamps(int numTimestampsRequested); @Override LockImmutableTimestampResponse lockImmutableTimestamp(); @Override List<StartIdentifiedAtlasDbTransactionResponse> startIdentifiedAtlasDbTransactionBatch(int count); @Override long getImmutableTimestamp(); @Override LockResponse lock(LockRequest request); @Override WaitForLocksResponse waitForLocks(WaitForLocksRequest request); @Override Set<LockToken> refreshLockLeases(Set<LockToken> tokens); @Override Set<LockToken> unlock(Set<LockToken> tokens); @Override void tryUnlock(Set<LockToken> tokens); @Override long currentTimeMillis(); }
LegacyTimelockService implements TimelockService { @Override public LockImmutableTimestampResponse lockImmutableTimestamp() { long immutableLockTs = timestampService.getFreshTimestamp(); LockDescriptor lockDesc = AtlasTimestampLockDescriptor.of(immutableLockTs); com.palantir.lock.LockRequest lockRequest = com.palantir.lock.LockRequest.builder( ImmutableSortedMap.of(lockDesc, LockMode.READ)) .withLockedInVersionId(immutableLockTs).build(); LockRefreshToken lock; try { lock = lockService.lock(immutableTsLockClient.getClientId(), lockRequest); } catch (InterruptedException e) { throw Throwables.throwUncheckedException(e); } try { return LockImmutableTimestampResponse.of( getImmutableTimestampInternal(immutableLockTs), LockTokenConverter.toTokenV2(lock)); } catch (Throwable e) { if (lock != null) { try { lockService.unlock(lock); } catch (Throwable unlockThrowable) { e.addSuppressed(unlockThrowable); } } throw Throwables.rewrapAndThrowUncheckedException(e); } } LegacyTimelockService(TimestampService timestampService, LockService lockService,
            LockClient immutableTsLockClient); @Override boolean isInitialized(); @Override long getFreshTimestamp(); @Override long getCommitTimestamp(long startTs, LockToken commitLocksToken); @Override TimestampRange getFreshTimestamps(int numTimestampsRequested); @Override LockImmutableTimestampResponse lockImmutableTimestamp(); @Override List<StartIdentifiedAtlasDbTransactionResponse> startIdentifiedAtlasDbTransactionBatch(int count); @Override long getImmutableTimestamp(); @Override LockResponse lock(LockRequest request); @Override WaitForLocksResponse waitForLocks(WaitForLocksRequest request); @Override Set<LockToken> refreshLockLeases(Set<LockToken> tokens); @Override Set<LockToken> unlock(Set<LockToken> tokens); @Override void tryUnlock(Set<LockToken> tokens); @Override long currentTimeMillis();  }