use of com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse in project atlasdb by palantir.
the class TransactionStarterTest method shouldDeriveStartTransactionResponseFromBatchedResponse_singleTransaction.
@Test
public void shouldDeriveStartTransactionResponseFromBatchedResponse_singleTransaction() {
ConjureStartTransactionsResponse startTransactionResponse = StartTransactionsTestUtils.getStartTransactionResponse(12, 1);
when(lockLeaseService.startTransactionsWithWatches(version, 1)).thenReturn(startTransactionResponse);
StartIdentifiedAtlasDbTransactionResponse response = Iterables.getOnlyElement(transactionStarter.startIdentifiedAtlasDbTransactionBatch(1));
assertDerivableFromBatchedResponse(response, startTransactionResponse);
}
use of com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse in project atlasdb by palantir.
the class BatchingIdentifiedAtlasDbTransactionStarter method getStartTransactionResponses.
private static List<StartIdentifiedAtlasDbTransactionResponse> getStartTransactionResponses(LockLeaseService lockLeaseService, LockWatchCache cache, int numberOfTransactions) {
List<StartIdentifiedAtlasDbTransactionResponse> result = new ArrayList<>();
while (result.size() < numberOfTransactions) {
try {
Optional<LockWatchVersion> requestedVersion = cache.getEventCache().lastKnownVersion();
ConjureStartTransactionsResponse response = lockLeaseService.startTransactionsWithWatches(requestedVersion, numberOfTransactions - result.size());
TransactionStarterHelper.updateCacheWithStartTransactionResponse(cache, response);
result.addAll(TransactionStarterHelper.split(response));
} catch (Throwable t) {
TransactionStarterHelper.cleanUpCaches(cache, result);
TransactionStarterHelper.unlock(result.stream().map(response -> response.immutableTimestamp().getLock()).collect(Collectors.toSet()), lockLeaseService);
throw Throwables.throwUncheckedException(t);
}
}
return result;
}
use of com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse in project atlasdb by palantir.
the class TransactionStarterHelper method split.
static List<StartIdentifiedAtlasDbTransactionResponse> split(ConjureStartTransactionsResponse response) {
PartitionedTimestamps partitionedTimestamps = response.getTimestamps();
int partition = partitionedTimestamps.partition();
LockToken immutableTsLock = response.getImmutableTimestamp().getLock();
long immutableTs = response.getImmutableTimestamp().getImmutableTimestamp();
Stream<LockImmutableTimestampResponse> immutableTsAndLocks = LockTokenShare.share(immutableTsLock, partitionedTimestamps.count()).map(tokenShare -> LockImmutableTimestampResponse.of(immutableTs, tokenShare));
Stream<TimestampAndPartition> timestampAndPartitions = partitionedTimestamps.stream().mapToObj(timestamp -> TimestampAndPartition.of(timestamp, partition));
return Streams.zip(immutableTsAndLocks, timestampAndPartitions, StartIdentifiedAtlasDbTransactionResponse::of).collect(Collectors.toList());
}
use of com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse in project atlasdb by palantir.
the class AsyncTimelockServiceIntegrationTest method startIdentifiedAtlasDbTransactionGivesUsStartTimestampsInTheSamePartition.
@Test
public void startIdentifiedAtlasDbTransactionGivesUsStartTimestampsInTheSamePartition() {
StartIdentifiedAtlasDbTransactionResponse firstResponse = startSingleTransaction(namespace.timelockService());
StartIdentifiedAtlasDbTransactionResponse secondResponse = startSingleTransaction(namespace.timelockService());
assertThatStartIdentifiedTransactionResponseTimestampsInSamePartition(firstResponse, secondResponse);
}
use of com.palantir.lock.v2.StartIdentifiedAtlasDbTransactionResponse in project atlasdb by palantir.
the class AsyncTimelockServiceIntegrationTest method startIdentifiedAtlasDbTransactionGivesUsTimestampsInSequence.
@Test
public void startIdentifiedAtlasDbTransactionGivesUsTimestampsInSequence() {
StartIdentifiedAtlasDbTransactionResponse firstResponse = startSingleTransaction(namespace.timelockService());
StartIdentifiedAtlasDbTransactionResponse secondResponse = startSingleTransaction(namespace.timelockService());
assertThatStartIdentifiedTransactionResponseTimestampsInSequence(firstResponse, secondResponse);
}
Aggregations