Search in sources :

Example 1 with AbstractTransaction

use of com.palantir.atlasdb.transaction.impl.AbstractTransaction in project atlasdb by palantir.

the class AbstractSchemaApiTest method testGetMultipleRowsFirstColumn.

@Test
public void testGetMultipleRowsFirstColumn() {
    AbstractTransaction transaction = mock(AbstractTransaction.class);
    SortedMap<byte[], RowResult<byte[]>> resultsMap = new TreeMap<>(UnsignedBytes.lexicographicalComparator());
    addToResultsMap(resultsMap, TEST_ROW_KEY, FIRST_COL_SHORT_NAME, encodeLong(TEST_VALUE_LONG));
    addToResultsMap(resultsMap, TEST_ROW_KEY2, FIRST_COL_SHORT_NAME, encodeLong(TEST_VALUE_LONG2));
    when(transaction.getRows(eq(tableRef), any(), eq(FIRST_COLUMN_SELECTION))).thenReturn(resultsMap);
    Map<String, Long> result = getMultipleRowsFirstColumn(transaction, Arrays.asList(TEST_ROW_KEY, TEST_ROW_KEY2));
    assertThat(result).isEqualTo(ImmutableMap.of(TEST_ROW_KEY, TEST_VALUE_LONG, TEST_ROW_KEY2, TEST_VALUE_LONG2));
    ArgumentCaptor<Iterable> argument = ArgumentCaptor.forClass(Iterable.class);
    verify(transaction, times(1)).getRows(eq(tableRef), argument.capture(), eq(FIRST_COLUMN_SELECTION));
    List<byte[]> argumentRows = Lists.newArrayList(argument.getValue());
    assertThat(argumentRows.size()).isEqualTo(2);
    assertThat(argumentRows.get(0)).usingComparator(UnsignedBytes.lexicographicalComparator()).isEqualTo(PtBytes.toBytes(TEST_ROW_KEY));
    assertThat(argumentRows.get(1)).usingComparator(UnsignedBytes.lexicographicalComparator()).isEqualTo(PtBytes.toBytes(TEST_ROW_KEY2));
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) BatchingVisitableFromIterable(com.palantir.common.base.BatchingVisitableFromIterable) AbstractTransaction(com.palantir.atlasdb.transaction.impl.AbstractTransaction) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 2 with AbstractTransaction

use of com.palantir.atlasdb.transaction.impl.AbstractTransaction in project atlasdb by palantir.

the class AbstractSchemaApiTest method testGetSingleRowFirstColumn.

@Test
public void testGetSingleRowFirstColumn() {
    AbstractTransaction transaction = mock(AbstractTransaction.class);
    SortedMap<byte[], RowResult<byte[]>> resultsMap = new TreeMap<>(UnsignedBytes.lexicographicalComparator());
    addToResultsMap(resultsMap, TEST_ROW_KEY, FIRST_COL_SHORT_NAME, encodeLong(TEST_VALUE_LONG));
    when(transaction.getRows(eq(tableRef), any(), eq(FIRST_COLUMN_SELECTION))).thenReturn(resultsMap);
    long value = getSingleRowFirstColumn(transaction, TEST_ROW_KEY);
    assertThat(value).isEqualTo(TEST_VALUE_LONG);
    ArgumentCaptor<Iterable> argument = ArgumentCaptor.forClass(Iterable.class);
    verify(transaction, times(1)).getRows(eq(tableRef), argument.capture(), eq(FIRST_COLUMN_SELECTION));
    Iterable<byte[]> argumentRows = argument.getValue();
    assertThat(Iterables.getOnlyElement(argumentRows)).usingComparator(UnsignedBytes.lexicographicalComparator()).isEqualTo(PtBytes.toBytes(TEST_ROW_KEY));
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) BatchingVisitableFromIterable(com.palantir.common.base.BatchingVisitableFromIterable) AbstractTransaction(com.palantir.atlasdb.transaction.impl.AbstractTransaction) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 3 with AbstractTransaction

use of com.palantir.atlasdb.transaction.impl.AbstractTransaction in project atlasdb by palantir.

the class AbstractSchemaApiTest method testDeleteWholeRow.

@Test
public void testDeleteWholeRow() {
    AbstractTransaction transaction = mock(AbstractTransaction.class);
    deleteWholeRow(transaction, TEST_ROW_KEY);
    Cell expectedDeletedFirstCell = getCell(TEST_ROW_KEY, FIRST_COL_SHORT_NAME);
    Cell expectedDeletedSecondCell = getCell(TEST_ROW_KEY, SECOND_COL_SHORT_NAME);
    verify(transaction, times(1)).delete(tableRef, ImmutableSet.of(expectedDeletedFirstCell, expectedDeletedSecondCell));
}
Also used : AbstractTransaction(com.palantir.atlasdb.transaction.impl.AbstractTransaction) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 4 with AbstractTransaction

use of com.palantir.atlasdb.transaction.impl.AbstractTransaction in project atlasdb by palantir.

the class AbstractSchemaApiTest method testRowRangeSecondColumn.

@Test
public void testRowRangeSecondColumn() {
    AbstractTransaction transaction = mock(AbstractTransaction.class);
    Cell expectedCell = getCell(TEST_ROW_KEY, SECOND_COL_SHORT_NAME);
    Cell anotherExpectedCell = getCell(TEST_ROW_KEY2, SECOND_COL_SHORT_NAME);
    RangeRequest expectedRange = RangeRequest.builder().startRowInclusive(TEST_ROW_KEY.getBytes()).endRowExclusive(RANGE_END_ROW_KEY.getBytes()).retainColumns(SECOND_COLUMN_SELECTION).build();
    when(transaction.getRange(tableRef, expectedRange)).thenReturn(BatchingVisitableFromIterable.create(Arrays.asList(RowResult.of(expectedCell, STRING_VALUE_PERSISTER.persistToBytes(TEST_VALUE_STRING)), RowResult.of(anotherExpectedCell, STRING_VALUE_PERSISTER.persistToBytes(TEST_VALUE_STRING2)))));
    Map<String, StringValue> result = getRangeSecondColumn(transaction, TEST_ROW_KEY, RANGE_END_ROW_KEY);
    assertThat(result).isEqualTo(ImmutableMap.of(TEST_ROW_KEY, TEST_VALUE_STRING, TEST_ROW_KEY2, TEST_VALUE_STRING2));
    verify(transaction, times(1)).getRange(tableRef, expectedRange);
}
Also used : RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) AbstractTransaction(com.palantir.atlasdb.transaction.impl.AbstractTransaction) StringValue(com.palantir.atlasdb.table.description.test.StringValue) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 5 with AbstractTransaction

use of com.palantir.atlasdb.transaction.impl.AbstractTransaction in project atlasdb by palantir.

the class AbstractSchemaApiTest method testPutSingleRowFirstColumn.

@Test
public void testPutSingleRowFirstColumn() {
    AbstractTransaction transaction = mock(AbstractTransaction.class);
    putSingleRowFirstColumn(transaction, TEST_ROW_KEY, TEST_VALUE_LONG);
    ArgumentCaptor<Map> argument = ArgumentCaptor.forClass(Map.class);
    verify(transaction, times(1)).put(eq(tableRef), argument.capture());
    Map<Cell, byte[]> foundMap = argument.getValue();
    Cell expectedCell = getCell(TEST_ROW_KEY, FIRST_COL_SHORT_NAME);
    assertThat(Iterables.getOnlyElement(foundMap.keySet())).isEqualTo(expectedCell);
    assertThat(Iterables.getOnlyElement(foundMap.values())).usingComparator(UnsignedBytes.lexicographicalComparator()).isEqualTo(encodeLong(TEST_VALUE_LONG));
}
Also used : AbstractTransaction(com.palantir.atlasdb.transaction.impl.AbstractTransaction) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Aggregations

AbstractTransaction (com.palantir.atlasdb.transaction.impl.AbstractTransaction)9 Test (org.junit.Test)9 Cell (com.palantir.atlasdb.keyvalue.api.Cell)5 TreeMap (java.util.TreeMap)3 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)2 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)2 SchemaApiTestV2Table (com.palantir.atlasdb.table.description.generated.SchemaApiTestV2Table)2 StringValue (com.palantir.atlasdb.table.description.test.StringValue)2 BatchingVisitableFromIterable (com.palantir.common.base.BatchingVisitableFromIterable)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1