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