use of com.palantir.lock.LockService in project atlasdb by palantir.
the class PaxosTimeLockServerIntegrationTest method lockAndUnlockAndCountExceptions.
private int lockAndUnlockAndCountExceptions(List<LockService> lockServices, int numRequestsPerClient) throws Exception {
ExecutorService executorService = Executors.newFixedThreadPool(lockServices.size() * numRequestsPerClient);
Map<LockService, LockRefreshToken> tokenMap = new HashMap<>();
for (LockService service : lockServices) {
LockRefreshToken token = service.lock(CLIENT_1, REQUEST_LOCK_WITH_LONG_TIMEOUT);
assertNotNull(token);
tokenMap.put(service, token);
}
List<Future<LockRefreshToken>> futures = Lists.newArrayList();
for (LockService lockService : lockServices) {
for (int i = 0; i < numRequestsPerClient; i++) {
int currentTrial = i;
futures.add(executorService.submit(() -> lockService.lock(CLIENT_2 + String.valueOf(currentTrial), REQUEST_LOCK_WITH_LONG_TIMEOUT)));
}
}
executorService.shutdown();
executorService.awaitTermination(2, TimeUnit.SECONDS);
AtomicInteger exceptionCounter = new AtomicInteger(0);
futures.forEach(future -> {
try {
assertNull(future.get());
} catch (ExecutionException e) {
Throwable cause = e.getCause();
assertThat(cause.getClass().getName()).contains("RetryableException");
assertRemoteExceptionWithStatus(cause.getCause(), HttpStatus.TOO_MANY_REQUESTS_429);
exceptionCounter.getAndIncrement();
} catch (InterruptedException e) {
throw Throwables.propagate(e);
}
});
tokenMap.forEach((service, token) -> assertTrue(service.unlock(token)));
return exceptionCounter.get();
}
use of com.palantir.lock.LockService in project atlasdb by palantir.
the class PaxosTimeLockServerIntegrationTest method lockServiceShouldAllowUsToTakeOutLocks.
@Test
public void lockServiceShouldAllowUsToTakeOutLocks() throws InterruptedException {
LockService lockService = getLockService(CLIENT_1);
LockRefreshToken token = lockService.lock(LOCK_CLIENT_NAME, com.palantir.lock.LockRequest.builder(LOCK_MAP).doNotBlock().build());
assertThat(token).isNotNull();
lockService.unlock(token);
}
use of com.palantir.lock.LockService in project atlasdb by palantir.
the class TransactionManagerTest method shouldNotMakeRemoteCallsInAReadonlyTransactionIfNoWorkIsDone.
@Test
public void shouldNotMakeRemoteCallsInAReadonlyTransactionIfNoWorkIsDone() {
TimestampService mockTimestampService = mock(TimestampService.class);
LockService mockLockService = mock(LockService.class);
TransactionManager txnManagerWithMocks = SerializableTransactionManager.createForTest(getKeyValueService(), mockTimestampService, LockClient.of("foo"), mockLockService, transactionService, () -> AtlasDbConstraintCheckingMode.FULL_CONSTRAINT_CHECKING_THROWS_EXCEPTIONS, conflictDetectionManager, sweepStrategyManager, NoOpCleaner.INSTANCE, AbstractTransactionTest.GET_RANGES_THREAD_POOL_SIZE, AbstractTransactionTest.DEFAULT_GET_RANGES_CONCURRENCY, () -> AtlasDbConstants.DEFAULT_TIMESTAMP_CACHE_SIZE, MultiTableSweepQueueWriter.NO_OP);
// fetch an immutable timestamp once so it's cached
when(mockTimestampService.getFreshTimestamp()).thenReturn(1L);
when(mockLockService.getMinLockedInVersionId("foo")).thenReturn(1L);
txnManagerWithMocks.getImmutableTimestamp();
verify(mockTimestampService).getFreshTimestamp();
verify(mockLockService).getMinLockedInVersionId("foo");
// now execute a read transaction
txnManagerWithMocks.runTaskReadOnly(txn -> null);
verifyNoMoreInteractions(mockLockService);
verifyNoMoreInteractions(mockTimestampService);
}
use of com.palantir.lock.LockService in project atlasdb by palantir.
the class TransactionManagerTest method shouldNotConflictIfImmutableTimestampLockExpiresIfNoReadsOrWrites.
@Test
public void shouldNotConflictIfImmutableTimestampLockExpiresIfNoReadsOrWrites() {
TimelockService timelock = mock(TimelockService.class);
LockService mockLockService = mock(LockService.class);
TransactionManager txnManagerWithMocks = new SerializableTransactionManager(keyValueService, timelock, mockLockService, transactionService, () -> AtlasDbConstraintCheckingMode.FULL_CONSTRAINT_CHECKING_THROWS_EXCEPTIONS, conflictDetectionManager, sweepStrategyManager, NoOpCleaner.INSTANCE, TimestampTrackerImpl.createNoOpTracker(), () -> AtlasDbConstants.DEFAULT_TIMESTAMP_CACHE_SIZE, false, () -> AtlasDbConstants.DEFAULT_TRANSACTION_LOCK_ACQUIRE_TIMEOUT_MS, AbstractTransactionTest.GET_RANGES_THREAD_POOL_SIZE, AbstractTransactionTest.DEFAULT_GET_RANGES_CONCURRENCY, MultiTableSweepQueueWriter.NO_OP);
when(timelock.getFreshTimestamp()).thenReturn(1L);
when(timelock.lockImmutableTimestamp(any())).thenReturn(LockImmutableTimestampResponse.of(2L, LockToken.of(UUID.randomUUID())));
txnManagerWithMocks.runTaskThrowOnConflict(txn -> null);
}
use of com.palantir.lock.LockService in project atlasdb by palantir.
the class TransactionManagerTest method shouldConflictIfImmutableTimestampLockExpiresEvenIfNoWritesOnThoroughSweptTable.
@Test
public void shouldConflictIfImmutableTimestampLockExpiresEvenIfNoWritesOnThoroughSweptTable() {
TimelockService timelock = mock(TimelockService.class);
LockService mockLockService = mock(LockService.class);
TransactionManager txnManagerWithMocks = new SerializableTransactionManager(keyValueService, timelock, mockLockService, transactionService, () -> AtlasDbConstraintCheckingMode.FULL_CONSTRAINT_CHECKING_THROWS_EXCEPTIONS, conflictDetectionManager, sweepStrategyManager, NoOpCleaner.INSTANCE, TimestampTrackerImpl.createNoOpTracker(), () -> AtlasDbConstants.DEFAULT_TIMESTAMP_CACHE_SIZE, false, () -> AtlasDbConstants.DEFAULT_TRANSACTION_LOCK_ACQUIRE_TIMEOUT_MS, AbstractTransactionTest.GET_RANGES_THREAD_POOL_SIZE, AbstractTransactionTest.DEFAULT_GET_RANGES_CONCURRENCY, MultiTableSweepQueueWriter.NO_OP);
when(timelock.getFreshTimestamp()).thenReturn(1L);
when(timelock.lockImmutableTimestamp(any())).thenReturn(LockImmutableTimestampResponse.of(2L, LockToken.of(UUID.randomUUID())));
assertThatThrownBy(() -> txnManagerWithMocks.runTaskThrowOnConflict(txn -> {
get(txn, TEST_TABLE_THOROUGH, "row1", "col1");
return null;
})).isInstanceOf(TransactionFailedRetriableException.class);
}
Aggregations