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 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 by googleapis.
the class SampleRowsIT method test.
@Test
public void test() throws InterruptedException, ExecutionException, TimeoutException {
BigtableDataClient client = testEnvRule.env().getDataClient();
String rowPrefix = UUID.randomUUID().toString();
// Create some data so that sample row keys has something to show
List<ApiFuture<?>> futures = Lists.newArrayList();
for (int i = 0; i < 10; i++) {
ApiFuture<Void> future = client.mutateRowAsync(RowMutation.create(testEnvRule.env().getTableId(), rowPrefix + "-" + i).setCell(testEnvRule.env().getFamilyId(), "", "value"));
futures.add(future);
}
ApiFutures.allAsList(futures).get(1, TimeUnit.MINUTES);
ApiFuture<List<KeyOffset>> future = client.sampleRowKeysAsync(testEnvRule.env().getTableId());
List<KeyOffset> results = future.get(1, TimeUnit.MINUTES);
assertThat(results).isNotEmpty();
assertThat(results.get(results.size() - 1).getOffsetBytes()).isGreaterThan(0L);
}
use of com.google.bigtable.repackaged.com.google.cloud.bigtable.data.v2.models.KeyOffset in project java-bigtable-hbase by googleapis.
the class TestAbstractBigtableConnection method testRegionLocator.
@Test
public void testRegionLocator() throws IOException {
assertEquals(1, connection.getAllRegionInfos(TABLE_NAME).size());
assertEquals(regionInfo, connection.getAllRegionInfos(TABLE_NAME).get(0));
List<HRegionLocation> expectedRegionLocations = ImmutableList.of(new HRegionLocation(regionInfo, ServerName.valueOf(HOST_NAME, server.getPort(), 0)));
when(mockSampledAdapter.adaptResponse(Mockito.<List<KeyOffset>>any())).thenReturn(expectedRegionLocations);
RegionLocator regionLocator = connection.getRegionLocator(TABLE_NAME);
assertEquals(expectedRegionLocations, regionLocator.getAllRegionLocations());
}
use of com.google.bigtable.repackaged.com.google.cloud.bigtable.data.v2.models.KeyOffset in project java-bigtable-hbase by googleapis.
the class SampledRowKeysAdapter method adaptResponse.
/**
* adaptResponse.
*
* @param responses a {@link java.util.List} object.
* @return a {@link java.util.List} object.
*/
public List<HRegionLocation> adaptResponse(List<KeyOffset> responses) {
List<HRegionLocation> regions = new ArrayList<>();
// Starting by the first possible row, iterate over the sorted sampled row keys and create
// regions.
byte[] startKey = HConstants.EMPTY_START_ROW;
for (KeyOffset response : responses) {
byte[] endKey = response.getKey().toByteArray();
// Avoid empty regions.
if (Bytes.equals(startKey, endKey)) {
continue;
}
regions.add(createRegionLocation(startKey, endKey));
startKey = endKey;
}
// Create one last region if the last region doesn't reach the end or there are no regions.
byte[] endKey = HConstants.EMPTY_END_ROW;
if (regions.isEmpty() || !Bytes.equals(startKey, endKey)) {
regions.add(createRegionLocation(startKey, endKey));
}
return regions;
}
Aggregations