Search in sources :

Example 1 with TimelockService

use of com.palantir.lock.v2.TimelockService in project atlasdb by palantir.

the class MultiNodePaxosTimeLockServerIntegrationTest method canCreateNewClientsDynamically.

@Test
public void canCreateNewClientsDynamically() {
    for (int i = 0; i < 5; i++) {
        String client = UUID.randomUUID().toString();
        TimelockService timelock = CLUSTER.timelockServiceForClient(client);
        timelock.getFreshTimestamp();
        LockToken token = timelock.lock(LockRequest.of(LOCKS, DEFAULT_LOCK_TIMEOUT_MS)).getToken();
        CLUSTER.unlock(token);
    }
}
Also used : TimelockService(com.palantir.lock.v2.TimelockService) LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 2 with TimelockService

use of com.palantir.lock.v2.TimelockService in project atlasdb by palantir.

the class PaxosTimeLockServerIntegrationTest method asyncLockServiceShouldNotAllowUsToRefreshLocksFromDifferentNamespaces.

@Test
public void asyncLockServiceShouldNotAllowUsToRefreshLocksFromDifferentNamespaces() throws InterruptedException {
    TimelockService lockService1 = getTimelockService(CLIENT_1);
    TimelockService lockService2 = getTimelockService(CLIENT_2);
    LockToken token = lockService1.lock(newLockV2Request(LOCK_1)).getToken();
    assertThat(lockService1.refreshLockLeases(ImmutableSet.of(token))).isNotEmpty();
    assertThat(lockService2.refreshLockLeases(ImmutableSet.of(token))).isEmpty();
    lockService1.unlock(ImmutableSet.of(token));
}
Also used : TimelockService(com.palantir.lock.v2.TimelockService) LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 3 with TimelockService

use of com.palantir.lock.v2.TimelockService in project atlasdb by palantir.

the class PaxosTimeLockServerIntegrationTest method asyncLockServiceShouldAllowUsToTakeOutSameLockInDifferentNamespaces.

@Test
public void asyncLockServiceShouldAllowUsToTakeOutSameLockInDifferentNamespaces() throws InterruptedException {
    TimelockService lockService1 = getTimelockService(CLIENT_1);
    TimelockService lockService2 = getTimelockService(CLIENT_2);
    LockToken token1 = lockService1.lock(newLockV2Request(LOCK_1)).getToken();
    LockToken token2 = lockService2.lock(newLockV2Request(LOCK_1)).getToken();
    lockService1.unlock(ImmutableSet.of(token1));
    lockService2.unlock(ImmutableSet.of(token2));
}
Also used : TimelockService(com.palantir.lock.v2.TimelockService) LockToken(com.palantir.lock.v2.LockToken) Test(org.junit.Test)

Example 4 with TimelockService

use of com.palantir.lock.v2.TimelockService 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);
}
Also used : LockService(com.palantir.lock.LockService) TimelockService(com.palantir.lock.v2.TimelockService) TransactionManager(com.palantir.atlasdb.transaction.api.TransactionManager) Test(org.junit.Test)

Example 5 with TimelockService

use of com.palantir.lock.v2.TimelockService 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);
}
Also used : LockService(com.palantir.lock.LockService) TimelockService(com.palantir.lock.v2.TimelockService) TransactionManager(com.palantir.atlasdb.transaction.api.TransactionManager) Test(org.junit.Test)

Aggregations

TimelockService (com.palantir.lock.v2.TimelockService)15 Test (org.junit.Test)11 InstrumentedTimelockService (com.palantir.atlasdb.transaction.impl.InstrumentedTimelockService)7 LockService (com.palantir.lock.LockService)5 LockToken (com.palantir.lock.v2.LockToken)4 TransactionManager (com.palantir.atlasdb.transaction.api.TransactionManager)3 LegacyTimelockService (com.palantir.lock.impl.LegacyTimelockService)3 TimelockTimestampServiceAdapter (com.palantir.atlasdb.transaction.impl.TimelockTimestampServiceAdapter)2 KvsBackedPersistentLockService (com.palantir.atlasdb.persistentlock.KvsBackedPersistentLockService)1 NoOpPersistentLockService (com.palantir.atlasdb.persistentlock.NoOpPersistentLockService)1 PersistentLockService (com.palantir.atlasdb.persistentlock.PersistentLockService)1 ManagedTimestampService (com.palantir.atlasdb.timelock.paxos.ManagedTimestampService)1 AsyncOrLegacyTimelockService (com.palantir.atlasdb.timelock.util.AsyncOrLegacyTimelockService)1 LockRefreshingLockService (com.palantir.lock.client.LockRefreshingLockService)1