use of com.google.bigtable.v2.TimestampRange in project simple-bigtable by spotify.
the class CellsReadImplTest method testLatest.
@Test
public void testLatest() throws Exception {
// Test Plain Latest
CellWithinCellsRead.ReadImpl cellRead = (CellWithinCellsRead.ReadImpl) this.cellsRead.latest();
ReadRowsRequest.Builder readRequest = cellRead.readRequest();
verifyReadRequest(readRequest);
assertEquals(4, readRequest.getFilter().getChain().getFiltersCount());
assertEquals(1, readRequest.getFilter().getChain().getFilters(3).getCellsPerColumnLimitFilter());
assertEquals(RowFilter.getDefaultInstance(), readRequest.getFilter().toBuilder().clearChain().build());
// Test A Filter Then A Latest
final TimestampRange timestampRange = TimestampRange.newBuilder().setStartTimestampMicros(12345).build();
cellRead = (CellWithinCellsRead.ReadImpl) this.cellsRead.startTimestampMicros(timestampRange.getStartTimestampMicros()).valueRegex(ByteString.copyFromUtf8("regex")).latest();
readRequest = cellRead.readRequest();
verifyReadRequest(readRequest);
assertEquals(6, readRequest.getFilter().getChain().getFiltersCount());
assertEquals(timestampRange, readRequest.getFilter().getChain().getFilters(3).getTimestampRangeFilter());
assertEquals("regex", readRequest.getFilter().getChain().getFilters(4).getValueRegexFilter().toStringUtf8());
assertEquals(1, readRequest.getFilter().getChain().getFilters(5).getCellsPerColumnLimitFilter());
assertEquals(RowFilter.getDefaultInstance(), readRequest.getFilter().toBuilder().clearChain().build());
// Need to make sure that the ColumnRead (CellsRead's parent) did not get the filters added as well.
// This is necessary to reuse the objects.
assertEquals(3, cellsRead.parentRead.readRequest().getFilter().getChain().getFiltersCount());
}
use of com.google.bigtable.v2.TimestampRange in project java-bigtable-hbase by googleapis.
the class TestDeleteAdapter method testDeleteColumnBeforeTimestamp.
@Test
public void testDeleteColumnBeforeTimestamp() {
byte[] rowKey = randomHelper.randomData("rk1-");
byte[] family = randomHelper.randomData("family1-");
byte[] qualifier = randomHelper.randomData("qualifier");
long hbaseTimestamp = 1000L;
long bigtableTimestamp = TimeUnit.MILLISECONDS.toMicros(hbaseTimestamp + 1);
Delete delete = new Delete(rowKey);
delete.addColumns(family, qualifier, hbaseTimestamp);
MutateRowRequest request = adapt(delete);
Assert.assertArrayEquals(rowKey, request.getRowKey().toByteArray());
Assert.assertEquals(1, request.getMutationsCount());
Assert.assertEquals(MutationCase.DELETE_FROM_COLUMN, request.getMutations(0).getMutationCase());
Mutation.DeleteFromColumn deleteFromColumn = request.getMutations(0).getDeleteFromColumn();
Assert.assertArrayEquals(qualifier, deleteFromColumn.getColumnQualifier().toByteArray());
Assert.assertTrue(request.getMutations(0).getDeleteFromColumn().hasTimeRange());
TimestampRange timeRange = deleteFromColumn.getTimeRange();
Assert.assertEquals(0L, timeRange.getStartTimestampMicros());
Assert.assertEquals(bigtableTimestamp, timeRange.getEndTimestampMicros());
}
use of com.google.bigtable.v2.TimestampRange in project java-bigtable-hbase by googleapis.
the class TestDeleteAdapter method testDeleteColumnAtTimestamp.
@Test
public void testDeleteColumnAtTimestamp() {
byte[] rowKey = randomHelper.randomData("rk1-");
byte[] family = randomHelper.randomData("family1-");
byte[] qualifier = randomHelper.randomData("qualifier");
long hbaseTimestamp = 1000L;
long bigtableStartTimestamp = TimeUnit.MILLISECONDS.toMicros(hbaseTimestamp);
long bigtableEndTimestamp = TimeUnit.MILLISECONDS.toMicros(hbaseTimestamp + 1);
Delete delete = new Delete(rowKey);
delete.addColumn(family, qualifier, hbaseTimestamp);
MutateRowRequest request = adapt(delete);
Assert.assertArrayEquals(rowKey, request.getRowKey().toByteArray());
Assert.assertEquals(1, request.getMutationsCount());
MutationCase mutationCase = request.getMutations(0).getMutationCase();
Assert.assertEquals(MutationCase.DELETE_FROM_COLUMN, mutationCase);
Mutation.DeleteFromColumn deleteFromColumn = request.getMutations(0).getDeleteFromColumn();
Assert.assertArrayEquals(family, deleteFromColumn.getFamilyNameBytes().toByteArray());
Assert.assertArrayEquals(qualifier, deleteFromColumn.getColumnQualifier().toByteArray());
Assert.assertTrue(request.getMutations(0).getDeleteFromColumn().hasTimeRange());
TimestampRange timeStampRange = deleteFromColumn.getTimeRange();
Assert.assertEquals(bigtableStartTimestamp, timeStampRange.getStartTimestampMicros());
Assert.assertEquals(bigtableEndTimestamp, timeStampRange.getEndTimestampMicros());
}
use of com.google.bigtable.v2.TimestampRange in project java-bigtable-hbase by googleapis.
the class TestTimestampRangeFilterAdapter method timestampFiltersAreAdapted.
@Test
public void timestampFiltersAreAdapted() {
TimestampRangeFilter filter = new TimestampRangeFilter(10L, 20L);
Filters.Filter expectedFilter = filterAdapter.adapt(emptyScanContext, filter);
TimestampRange expectedTimestampFilter = expectedFilter.toProto().getTimestampRangeFilter();
Assert.assertEquals(10000L, expectedTimestampFilter.getStartTimestampMicros());
Assert.assertEquals(20000L, expectedTimestampFilter.getEndTimestampMicros());
}
use of com.google.bigtable.v2.TimestampRange in project java-bigtable by googleapis.
the class RowMutationTest method toBulkProtoTest.
@Test
public void toBulkProtoTest() {
long timestampMin = System.currentTimeMillis() * 1_000;
RowMutation rowMutation = RowMutation.create("fake-table", "fake-key").setCell("fake-family", "fake-qualifier", "fake-value");
MutateRowsRequest actualRowMutation = rowMutation.toBulkProto(REQUEST_CONTEXT);
com.google.common.collect.Range<Long> timestampRange = com.google.common.collect.Range.closed(timestampMin, System.currentTimeMillis() * 1_000);
assertThat(actualRowMutation.getTableName()).isEqualTo(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID));
assertThat(actualRowMutation.getAppProfileId()).isEqualTo(APP_PROFILE_ID);
assertThat(actualRowMutation.getEntriesList()).hasSize(1);
assertThat(actualRowMutation.getEntries(0).getMutationsList()).hasSize(1);
assertThat(actualRowMutation.getEntries(0).getMutations(0).getSetCell().getValue()).isEqualTo(ByteString.copyFromUtf8("fake-value"));
assertThat(actualRowMutation.getEntries(0).getMutations(0).getSetCell().getTimestampMicros()).isIn(timestampRange);
}
Aggregations