use of com.palantir.lock.impl.LegacyTimelockService in project atlasdb by palantir.
the class SnapshotTransactionTest method testLockAfterGet.
// If lock happens concurrent with get, we aren't sure that we can rollback the transaction
@Test
public void testLockAfterGet() throws Exception {
byte[] rowName = PtBytes.toBytes("1");
Mockery m = new Mockery();
final KeyValueService kvMock = m.mock(KeyValueService.class);
final LockService lockMock = m.mock(LockService.class);
LockService lock = MultiDelegateProxy.newProxyInstance(LockService.class, lockService, lockMock);
final Cell cell = Cell.create(rowName, rowName);
timestampService.getFreshTimestamp();
final long startTs = timestampService.getFreshTimestamp();
final long transactionTs = timestampService.getFreshTimestamp();
keyValueService.put(TABLE, ImmutableMap.of(cell, PtBytes.EMPTY_BYTE_ARRAY), startTs);
m.checking(new Expectations() {
{
oneOf(kvMock).get(TABLE, ImmutableMap.of(cell, transactionTs));
will(throwException(new RuntimeException()));
never(lockMock).lockWithFullLockResponse(with(LockClient.ANONYMOUS), with(any(LockRequest.class)));
}
});
SnapshotTransaction snapshot = new SnapshotTransaction(kvMock, new LegacyTimelockService(timestampService, lock, lockClient), transactionService, NoOpCleaner.INSTANCE, transactionTs, TestConflictDetectionManagers.createWithStaticConflictDetection(ImmutableMap.of(TABLE, ConflictHandler.RETRY_ON_WRITE_WRITE)), AtlasDbConstraintCheckingMode.NO_CONSTRAINT_CHECKING, TransactionReadSentinelBehavior.THROW_EXCEPTION, timestampCache, getRangesExecutor, defaultGetRangesConcurrency, sweepQueue);
try {
snapshot.get(TABLE, ImmutableSet.of(cell));
fail();
} catch (RuntimeException e) {
// expected
}
m.assertIsSatisfied();
}
use of com.palantir.lock.impl.LegacyTimelockService in project atlasdb by palantir.
the class LegacyTimeLockServicesCreator method createTimeLockServices.
@Override
public TimeLockServices createTimeLockServices(String client, Supplier<ManagedTimestampService> rawTimestampServiceSupplier, Supplier<LockService> rawLockServiceSupplier) {
log.info("Creating legacy timelock service for client {}", client);
ManagedTimestampService timestampService = instrumentInLeadershipProxy(ManagedTimestampService.class, rawTimestampServiceSupplier, client);
LockService lockService = instrumentInLeadershipProxy(LockService.class, rawLockServiceSupplier, client);
// The underlying primitives are already wrapped in a leadership proxy (and must be).
// Wrapping this means that we will make 2 paxos checks per request, which is silly.
TimelockService legacyTimelockService = instrument(TimelockService.class, createRawLegacyTimelockService(timestampService, lockService), client);
return TimeLockServices.create(timestampService, lockService, AsyncOrLegacyTimelockService.createFromLegacyTimelock(legacyTimelockService), timestampService);
}
Aggregations