Search in sources :

Example 16 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class AbstractKeyValueServiceTest method shouldAllowSameTablenameDifferentNamespace.

@Test
public void shouldAllowSameTablenameDifferentNamespace() {
    TableReference fooBar = TableReference.createUnsafe("foo.bar");
    TableReference bazBar = TableReference.createUnsafe("baz.bar");
    // try create table in same call
    keyValueService.createTables(ImmutableMap.of(fooBar, AtlasDbConstants.GENERIC_TABLE_METADATA, bazBar, AtlasDbConstants.GENERIC_TABLE_METADATA));
    // try create table spanned over different calls
    keyValueService.createTable(fooBar, AtlasDbConstants.GENERIC_TABLE_METADATA);
    keyValueService.createTable(bazBar, AtlasDbConstants.GENERIC_TABLE_METADATA);
    // test tables actually created
    assertThat(keyValueService.getAllTableNames(), hasItems(fooBar, bazBar));
    // clean up
    keyValueService.dropTables(ImmutableSet.of(fooBar, bazBar));
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Test(org.junit.Test)

Example 17 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class AbstractKeyValueServiceTest method doTestGetRangePagingLastRowEdgeCase.

private void doTestGetRangePagingLastRowEdgeCase(int numColumnsInMetadata, int batchSizeHint, boolean reverse) {
    TableReference tableRef = createTableWithNamedColumns(numColumnsInMetadata);
    byte[] last = reverse ? RangeRequests.getFirstRowName() : RangeRequests.getLastRowName();
    Map<Cell, byte[]> values = ImmutableMap.of(Cell.create(last, PtBytes.toBytes("c1")), PtBytes.toBytes("a"), Cell.create(last, last), PtBytes.toBytes("b"));
    keyValueService.put(tableRef, values, TEST_TIMESTAMP);
    RangeRequest request = RangeRequest.builder(reverse).batchHint(batchSizeHint).build();
    try (ClosableIterator<RowResult<Value>> iter = keyValueService.getRange(tableRef, request, Long.MAX_VALUE)) {
        List<RowResult<Value>> results = ImmutableList.copyOf(iter);
        List<RowResult<Value>> expected = ImmutableList.of(RowResult.create(last, ImmutableSortedMap.<byte[], Value>orderedBy(UnsignedBytes.lexicographicalComparator()).put(PtBytes.toBytes("c1"), Value.create(PtBytes.toBytes("a"), TEST_TIMESTAMP)).put(last, Value.create(PtBytes.toBytes("b"), TEST_TIMESTAMP)).build()));
        assertEquals(expected, results);
    }
}
Also used : RowResult(com.palantir.atlasdb.keyvalue.api.RowResult) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) RangeRequest(com.palantir.atlasdb.keyvalue.api.RangeRequest) Cell(com.palantir.atlasdb.keyvalue.api.Cell)

Example 18 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class AbstractKeyValueServiceTest method createTableWithNamedColumns.

private TableReference createTableWithNamedColumns(int numColumns) {
    TableReference tableRef = TableReference.createFromFullyQualifiedName("ns.pt_kvs_test_named_cols_" + numColumns);
    List<NamedColumnDescription> columns = new ArrayList<>();
    for (int i = 1; i <= numColumns; ++i) {
        columns.add(new NamedColumnDescription("c" + i, "column" + i, ColumnValueDescription.forType(ValueType.BLOB)));
    }
    keyValueService.createTable(tableRef, new TableMetadata(new NameMetadataDescription(), new ColumnMetadataDescription(columns), ConflictHandler.RETRY_ON_WRITE_WRITE, TableMetadataPersistence.LogSafety.SAFE).persistToBytes());
    keyValueService.truncateTable(tableRef);
    return tableRef;
}
Also used : TableMetadata(com.palantir.atlasdb.table.description.TableMetadata) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) ArrayList(java.util.ArrayList) NameMetadataDescription(com.palantir.atlasdb.table.description.NameMetadataDescription) ColumnMetadataDescription(com.palantir.atlasdb.table.description.ColumnMetadataDescription) NamedColumnDescription(com.palantir.atlasdb.table.description.NamedColumnDescription)

Example 19 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class AbstractTransactionTest method testKeyValueMultiput.

@Test
public void testKeyValueMultiput() {
    TableReference table = TableReference.createWithEmptyNamespace("table2");
    keyValueService.createTable(table, AtlasDbConstants.GENERIC_TABLE_METADATA);
    Cell k = Cell.create(PtBytes.toBytes("row"), PtBytes.toBytes("col"));
    String value = "whatever";
    byte[] v = PtBytes.toBytes(value);
    Map<Cell, byte[]> map = ImmutableMap.of(k, v);
    keyValueService.multiPut(ImmutableMap.of(TEST_TABLE, map, table, map), 0);
    assertEquals(value, getDirect("row", "col", 1).lhSide);
    assertEquals(value, getDirect(table, "row", "col", 1).lhSide);
    keyValueService.dropTable(table);
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Cell(com.palantir.atlasdb.keyvalue.api.Cell) Test(org.junit.Test)

Example 20 with TableReference

use of com.palantir.atlasdb.keyvalue.api.TableReference in project atlasdb by palantir.

the class TestKvsMigrationCommand method seedKvs.

private void seedKvs(AtlasDbServices services, int numTables, int numEntriesPerTable) {
    for (int i = 0; i < numTables; i++) {
        TableReference table = TableReference.create(Namespace.create("ns"), "table" + i);
        services.getKeyValueService().createTable(table, AtlasDbConstants.GENERIC_TABLE_METADATA);
        services.getTransactionManager().runTaskThrowOnConflict(t -> {
            ImmutableMap.Builder<Cell, byte[]> toWrite = ImmutableMap.builder();
            for (int j = 0; j < numEntriesPerTable; j++) {
                Cell cell = Cell.create(PtBytes.toBytes("row" + j), PtBytes.toBytes("col"));
                toWrite.put(cell, PtBytes.toBytes("val" + j));
            }
            t.put(table, toWrite.build());
            return null;
        });
    }
}
Also used : TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Cell(com.palantir.atlasdb.keyvalue.api.Cell) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)112 Cell (com.palantir.atlasdb.keyvalue.api.Cell)41 Test (org.junit.Test)41 Map (java.util.Map)17 ImmutableMap (com.google.common.collect.ImmutableMap)13 Multimap (com.google.common.collect.Multimap)13 Entry (java.util.Map.Entry)13 Set (java.util.Set)13 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)12 Value (com.palantir.atlasdb.keyvalue.api.Value)12 Collection (java.util.Collection)12 List (java.util.List)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 KeyValueService (com.palantir.atlasdb.keyvalue.api.KeyValueService)11 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)11 SortedMap (java.util.SortedMap)11 Lists (com.google.common.collect.Lists)10 AtlasDbConstants (com.palantir.atlasdb.AtlasDbConstants)10 Sets (com.google.common.collect.Sets)9 InsufficientConsistencyException (com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException)9