use of com.google.bigtable.repackaged.com.google.cloud.bigtable.data.v2.models.KeyOffset in project java-bigtable-hbase by googleapis.
the class TestSampledRowKeysAdapter method testEmptyRowList.
@Test
public void testEmptyRowList() {
List<KeyOffset> rowKeys = new ArrayList<>();
List<HRegionLocation> locations = adapter.adaptResponse(rowKeys);
Assert.assertEquals(1, locations.size());
HRegionLocation location = locations.get(0);
Assert.assertArrayEquals(HConstants.EMPTY_START_ROW, location.getRegionInfo().getStartKey());
Assert.assertArrayEquals(HConstants.EMPTY_END_ROW, location.getRegionInfo().getEndKey());
Assert.assertEquals("host", location.getHostname());
Assert.assertEquals(123, location.getPort());
}
use of com.google.bigtable.repackaged.com.google.cloud.bigtable.data.v2.models.KeyOffset in project java-bigtable-hbase by googleapis.
the class TestSampledRowKeysAdapter method testEmptyRow.
@Test
public void testEmptyRow() {
byte[] rowKey = new byte[0];
List<KeyOffset> responses = new ArrayList<>();
responses.add(KeyOffset.create(ByteString.copyFrom(rowKey), 0));
List<HRegionLocation> locations = adapter.adaptResponse(responses);
Assert.assertEquals(1, locations.size());
HRegionLocation location = locations.get(0);
Assert.assertArrayEquals(HConstants.EMPTY_START_ROW, location.getRegionInfo().getStartKey());
Assert.assertArrayEquals(HConstants.EMPTY_END_ROW, location.getRegionInfo().getEndKey());
}
use of com.google.bigtable.repackaged.com.google.cloud.bigtable.data.v2.models.KeyOffset in project java-bigtable-hbase by googleapis.
the class TestSampledRowKeysAdapter method testOneRow.
@Test
public void testOneRow() {
byte[] rowKey = Bytes.toBytes("row");
List<KeyOffset> responses = new ArrayList<>();
responses.add(KeyOffset.create(ByteString.copyFrom(rowKey), 0));
List<HRegionLocation> locations = adapter.adaptResponse(responses);
Assert.assertEquals(2, locations.size());
HRegionLocation location = locations.get(0);
Assert.assertArrayEquals(HConstants.EMPTY_START_ROW, location.getRegionInfo().getStartKey());
Assert.assertArrayEquals(rowKey, location.getRegionInfo().getEndKey());
location = locations.get(1);
Assert.assertArrayEquals(rowKey, location.getRegionInfo().getStartKey());
Assert.assertArrayEquals(HConstants.EMPTY_END_ROW, location.getRegionInfo().getEndKey());
}
use of com.google.bigtable.repackaged.com.google.cloud.bigtable.data.v2.models.KeyOffset in project java-bigtable-hbase by googleapis.
the class CloudBigtableIOIntegrationTest method testEstimatedAndSplitForSmallTable.
@Test
@Ignore
public void testEstimatedAndSplitForSmallTable() throws Exception {
try (Admin admin = connection.getAdmin()) {
LOG.info("Creating table in testEstimatedAndSplitForSmallTable()");
TableName tableName = createNewTable(admin);
try (Table table = connection.getTable(tableName)) {
table.put(Arrays.asList(new Put(Bytes.toBytes("row1")).addColumn(COLUMN_FAMILY, QUALIFIER1, Bytes.toBytes("1")), new Put(Bytes.toBytes("row2")).addColumn(COLUMN_FAMILY, QUALIFIER1, Bytes.toBytes("2"))));
}
LOG.info("getSampleKeys() in testEstimatedAndSplitForSmallTable()");
try {
CloudBigtableIO.Source source = (CloudBigtableIO.Source) CloudBigtableIO.read(createScanConfig(tableName));
List<KeyOffset> sampleRowKeys = source.getSampleRowKeys();
LOG.info("Creating BoundedSource in testEstimatedAndSplitForSmallTable()");
long estimatedSizeBytes = source.getEstimatedSizeBytes(null);
KeyOffset lastSample = sampleRowKeys.get(sampleRowKeys.size() - 1);
Assert.assertEquals(lastSample.getOffsetBytes(), estimatedSizeBytes);
LOG.info("Creating Bundles in testEstimatedAndSplitForSmallTable()");
List<? extends BoundedSource<Result>> bundles = source.split(estimatedSizeBytes / 2 + 1, null);
// This will be a small table with no splits, so we return HConstants.EMPTY_START_ROW
// which can't be split.
LOG.info("Created Bundles in testEstimatedAndSplitForSmallTable()");
Assert.assertEquals(sampleRowKeys.size() * 2 - 1, bundles.size());
Assert.assertSame(sampleRowKeys, source.getSampleRowKeys());
} finally {
LOG.info("Deleting table in testEstimatedAndSplitForSmallTable()");
admin.deleteTable(tableName);
LOG.info("Deleted table in testEstimatedAndSplitForSmallTable()");
}
}
}
use of com.google.bigtable.repackaged.com.google.cloud.bigtable.data.v2.models.KeyOffset in project java-bigtable-hbase by googleapis.
the class CloudBigtableIOTest method testSampleRowKeys.
@Test
public void testSampleRowKeys() throws Exception {
List<KeyOffset> sampleRowKeys = new ArrayList<>();
int count = (int) (AbstractSource.COUNT_MAX_SPLIT_COUNT * 3 - 5);
byte[][] keys = Bytes.split("A".getBytes(), "Z".getBytes(), count - 2);
long tabletSize = 2L * 1024L * 1024L * 1024L;
long boundary = 0;
for (byte[] currentKey : keys) {
boundary += tabletSize;
try {
sampleRowKeys.add(KeyOffset.create(ByteString.copyFrom(currentKey), boundary));
} catch (NoClassDefFoundError e) {
// This could cause some problems for javadoc or cobertura because of the shading magic we
// do.
e.printStackTrace();
return;
}
}
Source source = (Source) CloudBigtableIO.read(scanConfig);
source.setSampleRowKeys(sampleRowKeys);
List<SourceWithKeys> splits = source.getSplits(20000);
Collections.sort(splits, new Comparator<SourceWithKeys>() {
@Override
public int compare(SourceWithKeys o1, SourceWithKeys o2) {
return ByteStringComparator.INSTANCE.compare(o1.getConfiguration().getStartRowByteString(), o2.getConfiguration().getStartRowByteString());
}
});
Assert.assertTrue(splits.size() <= AbstractSource.COUNT_MAX_SPLIT_COUNT);
Iterator<SourceWithKeys> iter = splits.iterator();
SourceWithKeys last = iter.next();
while (iter.hasNext()) {
SourceWithKeys current = iter.next();
Assert.assertTrue(Bytes.equals(current.getConfiguration().getZeroCopyStartRow(), last.getConfiguration().getZeroCopyStopRow()));
// The last source will have a stop key of empty.
if (iter.hasNext()) {
Assert.assertTrue(Bytes.compareTo(current.getConfiguration().getZeroCopyStartRow(), current.getConfiguration().getZeroCopyStopRow()) < 0);
}
Assert.assertTrue(current.getEstimatedSize() >= tabletSize);
last = current;
}
// check first and last
}
Aggregations