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));
}
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));
}
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));
}
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);
}
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));
}
Aggregations