Search in sources :

Example 1 with ImmutableGetRangesQuery

use of com.palantir.atlasdb.transaction.api.ImmutableGetRangesQuery in project atlasdb by palantir.

the class AbstractTransactionTest method getRangesProcessesVisitableOnOriginalElements.

@Test
public void getRangesProcessesVisitableOnOriginalElements() {
    UnaryOperator<RangeRequest> fiveElementLimit = range -> range.withBatchHint(5);
    RangeRequest sevenElementRequest = RangeRequest.builder().startRowInclusive(PtBytes.toBytes("tom")).batchHint(7).build();
    RangeRequest nineElementRequest = RangeRequest.builder().startRowInclusive(PtBytes.toBytes("tom")).batchHint(9).build();
    BiFunction<RangeRequest, BatchingVisitable<RowResult<byte[]>>, RangeRequest> exposingProcessor = (rangeRequest, $) -> rangeRequest;
    Transaction transaction = startTransaction();
    List<RangeRequest> visited = transaction.getRanges(ImmutableGetRangesQuery.<RangeRequest>builder().tableRef(TEST_TABLE).rangeRequests(ImmutableList.of(sevenElementRequest, nineElementRequest)).rangeRequestOptimizer(fiveElementLimit).visitableProcessor(exposingProcessor).build()).collect(Collectors.toList());
    assertThat(visited).containsExactlyInAnyOrder(sevenElementRequest, nineElementRequest);
}
Also used : RangeRequests(com.palantir.atlasdb.keyvalue.api.RangeRequests) Arrays(java.util.Arrays) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) Throwables(com.palantir.common.base.Throwables) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ClosableIterator(com.palantir.common.base.ClosableIterator) BiFunction(java.util.function.BiFunction) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) MapEntries(com.palantir.common.collect.MapEntries) Random(java.util.Random) UnaryOperator(java.util.function.UnaryOperator) RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) BatchingVisitable(com.palantir.common.base.BatchingVisitable) ImmutableGetRangesQuery(com.palantir.atlasdb.transaction.api.ImmutableGetRangesQuery) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) KvsManager(com.palantir.atlasdb.keyvalue.impl.KvsManager) TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) KeyedStream(com.palantir.common.streams.KeyedStream) Set(java.util.Set) TableDefinition(com.palantir.atlasdb.table.description.TableDefinition) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) TransactionConflictException(com.palantir.atlasdb.transaction.api.TransactionConflictException) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IterableView(com.palantir.common.collect.IterableView) Stream(java.util.stream.Stream) ValueType(com.palantir.atlasdb.table.description.ValueType) Transaction(com.palantir.atlasdb.transaction.api.Transaction) KeyAlreadyExistsException(com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException) SortedMap(java.util.SortedMap) ColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.ColumnRangeSelection) IntStream(java.util.stream.IntStream) Iterables(com.google.common.collect.Iterables) ConflictHandler(com.palantir.atlasdb.transaction.api.ConflictHandler) FutureTask(java.util.concurrent.FutureTask) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) Iterators(com.google.common.collect.Iterators) PtBytes(com.palantir.atlasdb.encoding.PtBytes) TreeSet(java.util.TreeSet) Multimaps(com.google.common.collect.Multimaps) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) AbortingVisitors(com.palantir.common.base.AbortingVisitors) Assume(org.junit.Assume) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) BatchingVisitables(com.palantir.common.base.BatchingVisitables) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ExecutorService(java.util.concurrent.ExecutorService) TableMetadataPersistence(com.palantir.atlasdb.protos.generated.TableMetadataPersistence) UnsignedBytes(com.google.common.primitives.UnsignedBytes) Value(com.palantir.atlasdb.keyvalue.api.Value) Iterator(java.util.Iterator) BaseEncoding(com.google.common.io.BaseEncoding) Test(org.junit.Test) TransactionManagerManager(com.palantir.atlasdb.keyvalue.impl.TransactionManagerManager) TokenBackedBasicResultsPage(com.palantir.util.paging.TokenBackedBasicResultsPage) Pair(com.palantir.util.Pair) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) ExecutionException(java.util.concurrent.ExecutionException) Ordering(com.google.common.collect.Ordering) TransactionTask(com.palantir.atlasdb.transaction.api.TransactionTask) Collections(java.util.Collections) BatchingVisitable(com.palantir.common.base.BatchingVisitable) Transaction(com.palantir.atlasdb.transaction.api.Transaction) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Test(org.junit.Test)

Example 2 with ImmutableGetRangesQuery

use of com.palantir.atlasdb.transaction.api.ImmutableGetRangesQuery in project atlasdb by palantir.

the class AbstractTransactionTest method getRangesSendsQueriesThatHaveGoneThroughTheOptimizer.

@Test
public void getRangesSendsQueriesThatHaveGoneThroughTheOptimizer() {
    RangeRequest goldenRequest = RangeRequest.builder().startRowInclusive(PtBytes.toBytes("tom")).build();
    RangeRequest otherRequest = RangeRequest.builder().startRowInclusive(PtBytes.toBytes("zzzz")).build();
    // Contract is not entirely valid, but we don't have a good way of mocking out the KVS.
    UnaryOperator<RangeRequest> goldenForcingOperator = $ -> goldenRequest;
    putDirect("tom", "col", "value", 0);
    BiFunction<RangeRequest, BatchingVisitable<RowResult<byte[]>>, byte[]> singleValueExtractor = ($, visitable) -> Iterables.getOnlyElement(BatchingVisitables.copyToList(visitable)).getOnlyColumnValue();
    Transaction transaction = startTransaction();
    List<byte[]> extractedValue = transaction.getRanges(ImmutableGetRangesQuery.<byte[]>builder().tableRef(TEST_TABLE).rangeRequests(ImmutableList.of(otherRequest)).rangeRequestOptimizer(goldenForcingOperator).visitableProcessor(singleValueExtractor).build()).collect(Collectors.toList());
    assertThat(extractedValue).containsExactly(PtBytes.toBytes("value"));
}
Also used : RangeRequests(com.palantir.atlasdb.keyvalue.api.RangeRequests) Arrays(java.util.Arrays) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) Throwables(com.palantir.common.base.Throwables) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ClosableIterator(com.palantir.common.base.ClosableIterator) BiFunction(java.util.function.BiFunction) SafeIllegalStateException(com.palantir.logsafe.exceptions.SafeIllegalStateException) MapEntries(com.palantir.common.collect.MapEntries) Random(java.util.Random) UnaryOperator(java.util.function.UnaryOperator) RowColumnRangeIterator(com.palantir.atlasdb.keyvalue.api.RowColumnRangeIterator) BatchingVisitable(com.palantir.common.base.BatchingVisitable) ImmutableGetRangesQuery(com.palantir.atlasdb.transaction.api.ImmutableGetRangesQuery) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) KvsManager(com.palantir.atlasdb.keyvalue.impl.KvsManager) TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) KeyedStream(com.palantir.common.streams.KeyedStream) Set(java.util.Set) TableDefinition(com.palantir.atlasdb.table.description.TableDefinition) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) ColumnSelection(com.palantir.atlasdb.keyvalue.api.ColumnSelection) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) TransactionConflictException(com.palantir.atlasdb.transaction.api.TransactionConflictException) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IterableView(com.palantir.common.collect.IterableView) Stream(java.util.stream.Stream) ValueType(com.palantir.atlasdb.table.description.ValueType) Transaction(com.palantir.atlasdb.transaction.api.Transaction) KeyAlreadyExistsException(com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException) SortedMap(java.util.SortedMap) ColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.ColumnRangeSelection) IntStream(java.util.stream.IntStream) Iterables(com.google.common.collect.Iterables) ConflictHandler(com.palantir.atlasdb.transaction.api.ConflictHandler) FutureTask(java.util.concurrent.FutureTask) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) Iterators(com.google.common.collect.Iterators) PtBytes(com.palantir.atlasdb.encoding.PtBytes) TreeSet(java.util.TreeSet) Multimaps(com.google.common.collect.Multimaps) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) AbortingVisitors(com.palantir.common.base.AbortingVisitors) Assume(org.junit.Assume) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) BatchingVisitables(com.palantir.common.base.BatchingVisitables) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ExecutorService(java.util.concurrent.ExecutorService) TableMetadataPersistence(com.palantir.atlasdb.protos.generated.TableMetadataPersistence) UnsignedBytes(com.google.common.primitives.UnsignedBytes) Value(com.palantir.atlasdb.keyvalue.api.Value) Iterator(java.util.Iterator) BaseEncoding(com.google.common.io.BaseEncoding) Test(org.junit.Test) TransactionManagerManager(com.palantir.atlasdb.keyvalue.impl.TransactionManagerManager) TokenBackedBasicResultsPage(com.palantir.util.paging.TokenBackedBasicResultsPage) Pair(com.palantir.util.Pair) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) ExecutionException(java.util.concurrent.ExecutionException) Ordering(com.google.common.collect.Ordering) TransactionTask(com.palantir.atlasdb.transaction.api.TransactionTask) Collections(java.util.Collections) BatchingVisitable(com.palantir.common.base.BatchingVisitable) Transaction(com.palantir.atlasdb.transaction.api.Transaction) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Test(org.junit.Test)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)2 Iterables (com.google.common.collect.Iterables)2 Iterators (com.google.common.collect.Iterators)2 Lists (com.google.common.collect.Lists)2 Multimap (com.google.common.collect.Multimap)2 Multimaps (com.google.common.collect.Multimaps)2 Ordering (com.google.common.collect.Ordering)2 BaseEncoding (com.google.common.io.BaseEncoding)2 UnsignedBytes (com.google.common.primitives.UnsignedBytes)2 AtlasDbConstants (com.palantir.atlasdb.AtlasDbConstants)2 PtBytes (com.palantir.atlasdb.encoding.PtBytes)2 BatchColumnRangeSelection (com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection)2 Cell (com.palantir.atlasdb.keyvalue.api.Cell)2 ColumnRangeSelection (com.palantir.atlasdb.keyvalue.api.ColumnRangeSelection)2 ColumnSelection (com.palantir.atlasdb.keyvalue.api.ColumnSelection)2 KeyAlreadyExistsException (com.palantir.atlasdb.keyvalue.api.KeyAlreadyExistsException)2