Search in sources :

Example 11 with BatchingVisitable

use of com.palantir.common.base.BatchingVisitable in project atlasdb by palantir.

the class AbstractTransactionTest method testRangesTransactionColumnSelection.

@Test
public void testRangesTransactionColumnSelection() {
    Transaction t = startTransaction();
    put(t, "row1", "col1", "v1");
    t.commit();
    RangeRequest range1 = RangeRequest.builder().batchHint(3).build();
    RangeRequest range2 = range1.getBuilder().retainColumns(ColumnSelection.create(ImmutableSet.of(PtBytes.toBytes("col1")))).build();
    t = startTransaction();
    Iterable<BatchingVisitable<RowResult<byte[]>>> ranges = t.getRanges(TEST_TABLE, Iterables.limit(Iterables.cycle(range1, range2), 1000));
    for (BatchingVisitable<RowResult<byte[]>> batchingVisitable : ranges) {
        final List<RowResult<byte[]>> list = BatchingVisitables.copyToList(batchingVisitable);
        assertEquals(1, list.size());
        assertEquals(1, list.get(0).getColumns().size());
    }
    RangeRequest range3 = range1.getBuilder().retainColumns(ColumnSelection.create(ImmutableSet.of(PtBytes.toBytes("col2")))).build();
    verifyAllGetRangesImplsRangeSizes(t, range3, 0);
}
Also used : BatchingVisitable(com.palantir.common.base.BatchingVisitable) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) Transaction(com.palantir.atlasdb.transaction.api.Transaction) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Test(org.junit.Test)

Example 12 with BatchingVisitable

use of com.palantir.common.base.BatchingVisitable in project atlasdb by palantir.

the class AbstractTransactionTest method testReadMyDeletesColumnRangePagingTransaction.

@Test
public void testReadMyDeletesColumnRangePagingTransaction() {
    Transaction t = startTransaction();
    int totalPuts = 101;
    byte[] row = PtBytes.toBytes("row1");
    // Record expected results using byte ordering
    ImmutableSortedMap.Builder<Cell, byte[]> writes = ImmutableSortedMap.orderedBy(Ordering.from(UnsignedBytes.lexicographicalComparator()).onResultOf(key -> key.getColumnName()));
    for (int i = 0; i < totalPuts; i++) {
        put(t, "row1", "col" + i, "v" + i);
        if (i % 2 == 0) {
            writes.put(Cell.create(row, PtBytes.toBytes("col" + i)), PtBytes.toBytes("v" + i));
        }
    }
    t.commit();
    t = startTransaction();
    for (int i = 0; i < totalPuts; i++) {
        if (i % 2 == 1) {
            delete(t, "row1", "col" + i);
        }
    }
    Map<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> columnRange = t.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1));
    List<Map.Entry<Cell, byte[]>> expected = ImmutableList.copyOf(writes.build().entrySet());
    verifyMatchingResult(expected, row, columnRange);
}
Also used : RangeRequests(com.palantir.atlasdb.keyvalue.api.RangeRequests) Arrays(java.util.Arrays) AtlasDbDependencyException(com.palantir.common.exception.AtlasDbDependencyException) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) Throwables(com.palantir.common.base.Throwables) ClosableIterator(com.palantir.common.base.ClosableIterator) Random(java.util.Random) MapEntries(com.palantir.common.collect.MapEntries) BatchingVisitable(com.palantir.common.base.BatchingVisitable) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Assert.fail(org.junit.Assert.fail) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) 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) TransactionReadSentinelBehavior(com.palantir.atlasdb.transaction.api.TransactionReadSentinelBehavior) 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) ValueType(com.palantir.atlasdb.table.description.ValueType) Transaction(com.palantir.atlasdb.transaction.api.Transaction) Assert.assertFalse(org.junit.Assert.assertFalse) NoOpCleaner(com.palantir.atlasdb.cleaner.NoOpCleaner) Iterables(com.google.common.collect.Iterables) ConflictHandler(com.palantir.atlasdb.transaction.api.ConflictHandler) FutureTask(java.util.concurrent.FutureTask) Multimap(com.google.common.collect.Multimap) Iterators(com.google.common.collect.Iterators) PtBytes(com.palantir.atlasdb.encoding.PtBytes) Multimaps(com.google.common.collect.Multimaps) AtlasDbConstraintCheckingMode(com.palantir.atlasdb.transaction.api.AtlasDbConstraintCheckingMode) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) LegacyTimelockService(com.palantir.lock.impl.LegacyTimelockService) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) AbortingVisitors(com.palantir.common.base.AbortingVisitors) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) BatchingVisitables(com.palantir.common.base.BatchingVisitables) ExecutorService(java.util.concurrent.ExecutorService) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) TableMetadataPersistence(com.palantir.atlasdb.protos.generated.TableMetadataPersistence) UnsignedBytes(com.google.common.primitives.UnsignedBytes) Value(com.palantir.atlasdb.keyvalue.api.Value) BaseEncoding(com.google.common.io.BaseEncoding) Assert.assertTrue(org.junit.Assert.assertTrue) TimestampCache(com.palantir.atlasdb.cache.TimestampCache) Test(org.junit.Test) TokenBackedBasicResultsPage(com.palantir.util.paging.TokenBackedBasicResultsPage) Maps(com.google.common.collect.Maps) Pair(com.palantir.util.Pair) ExecutionException(java.util.concurrent.ExecutionException) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) Assert.assertNull(org.junit.Assert.assertNull) Ordering(com.google.common.collect.Ordering) TransactionTask(com.palantir.atlasdb.transaction.api.TransactionTask) MultiTableSweepQueueWriter(com.palantir.atlasdb.sweep.queue.MultiTableSweepQueueWriter) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) BatchingVisitable(com.palantir.common.base.BatchingVisitable) Transaction(com.palantir.atlasdb.transaction.api.Transaction) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Test(org.junit.Test)

Example 13 with BatchingVisitable

use of com.palantir.common.base.BatchingVisitable in project atlasdb by palantir.

the class AbstractTransactionTest method testEmptyColumnRangePagingTransaction.

@Test
public void testEmptyColumnRangePagingTransaction() {
    byte[] row = PtBytes.toBytes("row1");
    Transaction t = startTransaction();
    Map<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> columnRange = t.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1));
    List<Map.Entry<Cell, byte[]>> expected = ImmutableList.of();
    verifyMatchingResult(expected, row, columnRange);
    put(t, "row1", "col1", "v1");
    t.commit();
    t = startTransaction();
    delete(t, "row1", "col1");
    columnRange = t.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1));
    verifyMatchingResult(expected, row, columnRange);
    t.commit();
    t = startTransaction();
    columnRange = t.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1));
    verifyMatchingResult(expected, row, columnRange);
}
Also used : BatchingVisitable(com.palantir.common.base.BatchingVisitable) Transaction(com.palantir.atlasdb.transaction.api.Transaction) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 14 with BatchingVisitable

use of com.palantir.common.base.BatchingVisitable in project atlasdb by palantir.

the class AbstractTransactionTest method testReadMyWritesColumnRangePagingTransaction.

@Test
public void testReadMyWritesColumnRangePagingTransaction() {
    Transaction t = startTransaction();
    int totalPuts = 101;
    byte[] row = PtBytes.toBytes("row1");
    // Record expected results using byte ordering
    ImmutableSortedMap.Builder<Cell, byte[]> writes = ImmutableSortedMap.orderedBy(Ordering.from(UnsignedBytes.lexicographicalComparator()).onResultOf(key -> key.getColumnName()));
    for (int i = 0; i < totalPuts; i++) {
        put(t, "row1", "col" + i, "v" + i);
        if (i % 2 == 0) {
            writes.put(Cell.create(row, PtBytes.toBytes("col" + i)), PtBytes.toBytes("v" + i));
        }
    }
    t.commit();
    t = startTransaction();
    for (int i = 0; i < totalPuts; i++) {
        if (i % 2 == 1) {
            put(t, "row1", "col" + i, "t_v" + i);
            writes.put(Cell.create(row, PtBytes.toBytes("col" + i)), PtBytes.toBytes("t_v" + i));
        }
    }
    Map<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> columnRange = t.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1));
    List<Map.Entry<Cell, byte[]>> expected = ImmutableList.copyOf(writes.build().entrySet());
    verifyMatchingResult(expected, row, columnRange);
}
Also used : RangeRequests(com.palantir.atlasdb.keyvalue.api.RangeRequests) Arrays(java.util.Arrays) AtlasDbDependencyException(com.palantir.common.exception.AtlasDbDependencyException) BatchColumnRangeSelection(com.palantir.atlasdb.keyvalue.api.BatchColumnRangeSelection) Throwables(com.palantir.common.base.Throwables) ClosableIterator(com.palantir.common.base.ClosableIterator) Random(java.util.Random) MapEntries(com.palantir.common.collect.MapEntries) BatchingVisitable(com.palantir.common.base.BatchingVisitable) Map(java.util.Map) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Assert.fail(org.junit.Assert.fail) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) 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) TransactionReadSentinelBehavior(com.palantir.atlasdb.transaction.api.TransactionReadSentinelBehavior) 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) ValueType(com.palantir.atlasdb.table.description.ValueType) Transaction(com.palantir.atlasdb.transaction.api.Transaction) Assert.assertFalse(org.junit.Assert.assertFalse) NoOpCleaner(com.palantir.atlasdb.cleaner.NoOpCleaner) Iterables(com.google.common.collect.Iterables) ConflictHandler(com.palantir.atlasdb.transaction.api.ConflictHandler) FutureTask(java.util.concurrent.FutureTask) Multimap(com.google.common.collect.Multimap) Iterators(com.google.common.collect.Iterators) PtBytes(com.palantir.atlasdb.encoding.PtBytes) Multimaps(com.google.common.collect.Multimaps) AtlasDbConstraintCheckingMode(com.palantir.atlasdb.transaction.api.AtlasDbConstraintCheckingMode) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ImmutableList(com.google.common.collect.ImmutableList) LegacyTimelockService(com.palantir.lock.impl.LegacyTimelockService) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) AbortingVisitors(com.palantir.common.base.AbortingVisitors) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) BatchingVisitables(com.palantir.common.base.BatchingVisitables) ExecutorService(java.util.concurrent.ExecutorService) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) TableMetadataPersistence(com.palantir.atlasdb.protos.generated.TableMetadataPersistence) UnsignedBytes(com.google.common.primitives.UnsignedBytes) Value(com.palantir.atlasdb.keyvalue.api.Value) BaseEncoding(com.google.common.io.BaseEncoding) Assert.assertTrue(org.junit.Assert.assertTrue) TimestampCache(com.palantir.atlasdb.cache.TimestampCache) Test(org.junit.Test) TokenBackedBasicResultsPage(com.palantir.util.paging.TokenBackedBasicResultsPage) Maps(com.google.common.collect.Maps) Pair(com.palantir.util.Pair) ExecutionException(java.util.concurrent.ExecutionException) RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) Assert.assertNull(org.junit.Assert.assertNull) Ordering(com.google.common.collect.Ordering) TransactionTask(com.palantir.atlasdb.transaction.api.TransactionTask) MultiTableSweepQueueWriter(com.palantir.atlasdb.sweep.queue.MultiTableSweepQueueWriter) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) BatchingVisitable(com.palantir.common.base.BatchingVisitable) Transaction(com.palantir.atlasdb.transaction.api.Transaction) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Test(org.junit.Test)

Example 15 with BatchingVisitable

use of com.palantir.common.base.BatchingVisitable in project atlasdb by palantir.

the class AbstractSerializableTransactionTest method testColumnRangeReadWriteNoConflict.

@Test
public void testColumnRangeReadWriteNoConflict() {
    byte[] row = PtBytes.toBytes("row1");
    writeColumns();
    Transaction t1 = startTransaction();
    Map<byte[], BatchingVisitable<Map.Entry<Cell, byte[]>>> columnRange = t1.getRowsColumnRange(TEST_TABLE, ImmutableList.of(row), BatchColumnRangeSelection.create(PtBytes.EMPTY_BYTE_ARRAY, PtBytes.EMPTY_BYTE_ARRAY, 1));
    // Serializable transaction records only the first column as read.
    Map.Entry<Cell, byte[]> read = BatchingVisitables.getFirst(Iterables.getOnlyElement(columnRange.values()));
    assertEquals(Cell.create(row, PtBytes.toBytes("col0")), read.getKey());
    // Write to avoid the read only path.
    put(t1, "row1_1", "col0", "v0");
    Transaction t2 = startTransaction();
    put(t2, "row1", "col1", "v0_0");
    t2.commit();
    t1.commit();
}
Also used : BatchingVisitable(com.palantir.common.base.BatchingVisitable) Transaction(com.palantir.atlasdb.transaction.api.Transaction) Map(java.util.Map) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) ImmutableMap(com.google.common.collect.ImmutableMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Aggregations

BatchingVisitable (com.palantir.common.base.BatchingVisitable)16 Cell (com.palantir.atlasdb.keyvalue.api.Cell)15 Map (java.util.Map)14 ImmutableMap (com.google.common.collect.ImmutableMap)13 Transaction (com.palantir.atlasdb.transaction.api.Transaction)13 Test (org.junit.Test)12 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)11 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)8 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)8 Iterables (com.google.common.collect.Iterables)7 PtBytes (com.palantir.atlasdb.encoding.PtBytes)7 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)7 ImmutableSet (com.google.common.collect.ImmutableSet)6 Multimap (com.google.common.collect.Multimap)6 Multimaps (com.google.common.collect.Multimaps)6 List (java.util.List)6 ExecutorService (java.util.concurrent.ExecutorService)6 Maps (com.google.common.collect.Maps)5 UnsignedBytes (com.google.common.primitives.UnsignedBytes)5 AtlasDbConstants (com.palantir.atlasdb.AtlasDbConstants)5