Search in sources :

Example 6 with AbstractTransaction

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

the class AbstractSchemaApiTest method testRowRangeSecondColumnFirstTwoResults.

@Test
public void testRowRangeSecondColumnFirstTwoResults() {
    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);
    Cell cellToBeDroppedFromResults = getCell(TEST_ROW_KEY3, SECOND_COL_SHORT_NAME);
    RangeRequest expectedRange = RangeRequest.builder().startRowInclusive(TEST_ROW_KEY.getBytes()).endRowExclusive(RANGE_END_ROW_KEY.getBytes()).retainColumns(SECOND_COLUMN_SELECTION).batchHint(2).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)), RowResult.of(cellToBeDroppedFromResults, STRING_VALUE_PERSISTER.persistToBytes(TEST_VALUE_STRING3)))));
    Map<String, StringValue> result = getRangeSecondColumnOnlyFirstTwoResults(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 7 with AbstractTransaction

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

the class AbstractSchemaApiTest method testDeleteFirstColumn.

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

Example 8 with AbstractTransaction

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

the class SchemaApiTestV2Impl method testUpdateEntryIfEntryExists.

@Test
public void testUpdateEntryIfEntryExists() {
    AbstractTransaction transaction = mock(AbstractTransaction.class);
    SchemaApiTestV2Table table = spy(tableFactory.getSchemaApiTestV2Table(transaction));
    doReturn(Optional.of(TEST_VALUE_LONG)).when(table).getColumn1(TEST_ROW_KEY);
    table.updateColumn1(TEST_ROW_KEY, entry -> entry + 1);
    verify(table, times(1)).putColumn1(TEST_ROW_KEY, TEST_VALUE_LONG + 1);
}
Also used : SchemaApiTestV2Table(com.palantir.atlasdb.table.description.generated.SchemaApiTestV2Table) AbstractTransaction(com.palantir.atlasdb.transaction.impl.AbstractTransaction) Test(org.junit.Test)

Example 9 with AbstractTransaction

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

the class SchemaApiTestV2Impl method testUpdateEntryIfEntryDoesNotExist.

@Test
public void testUpdateEntryIfEntryDoesNotExist() {
    AbstractTransaction transaction = mock(AbstractTransaction.class);
    SchemaApiTestV2Table table = spy(tableFactory.getSchemaApiTestV2Table(transaction));
    doReturn(Optional.empty()).when(table).getColumn1(TEST_ROW_KEY);
    table.updateColumn1(TEST_ROW_KEY, entry -> entry + 1);
    verify(table, never()).putColumn1(any(), anyLong());
}
Also used : SchemaApiTestV2Table(com.palantir.atlasdb.table.description.generated.SchemaApiTestV2Table) AbstractTransaction(com.palantir.atlasdb.transaction.impl.AbstractTransaction) 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