use of com.google.cloud.bigtable.admin.v2.models.Table in project java-bigtable by googleapis.
the class BigtableTableAdminClientTest method testListTables.
@Test
public void testListTables() {
// Setup
Mockito.when(mockStub.listTablesPagedCallable()).thenReturn(mockListTableCallable);
com.google.bigtable.admin.v2.ListTablesRequest expectedRequest = com.google.bigtable.admin.v2.ListTablesRequest.newBuilder().setParent(INSTANCE_NAME).build();
// 3 Tables spread across 2 pages
List<com.google.bigtable.admin.v2.Table> expectedProtos = Lists.newArrayList();
for (int i = 0; i < 3; i++) {
expectedProtos.add(com.google.bigtable.admin.v2.Table.newBuilder().setName(TABLE_NAME + i).build());
}
// 2 on the first page
ListTablesPage page0 = Mockito.mock(ListTablesPage.class);
Mockito.when(page0.getValues()).thenReturn(expectedProtos.subList(0, 2));
Mockito.when(page0.hasNextPage()).thenReturn(true);
// 1 on the last page
ListTablesPage page1 = Mockito.mock(ListTablesPage.class);
Mockito.when(page1.getValues()).thenReturn(expectedProtos.subList(2, 3));
// Link page0 to page1
Mockito.when(page0.getNextPageAsync()).thenReturn(ApiFutures.immediateFuture(page1));
// Link page to the response
ListTablesPagedResponse response0 = Mockito.mock(ListTablesPagedResponse.class);
Mockito.when(response0.getPage()).thenReturn(page0);
Mockito.when(mockListTableCallable.futureCall(expectedRequest)).thenReturn(ApiFutures.immediateFuture(response0));
// Execute
List<String> actualResults = adminClient.listTables();
// Verify
List<String> expectedResults = Lists.newArrayList();
for (com.google.bigtable.admin.v2.Table expectedProto : expectedProtos) {
expectedResults.add(TableName.parse(expectedProto.getName()).getTable());
}
assertThat(actualResults).containsExactlyElementsIn(expectedResults);
}
use of com.google.cloud.bigtable.admin.v2.models.Table in project java-bigtable by googleapis.
the class BigtableBackupIT method restoreTableTest.
@Test
public void restoreTableTest() throws InterruptedException, ExecutionException {
String backupId = prefixGenerator.newPrefix();
String restoredTableId = prefixGenerator.newPrefix();
tableAdmin.createBackup(createBackupRequest(backupId));
// Wait 2 minutes so that the RestoreTable API will trigger an optimize restored
// table operation.
Thread.sleep(120 * 1000);
try {
RestoreTableRequest req = RestoreTableRequest.of(targetCluster, backupId).setTableId(restoredTableId);
RestoredTableResult result = tableAdmin.restoreTable(req);
assertWithMessage("Incorrect restored table id").that(result.getTable().getId()).isEqualTo(restoredTableId);
if (result.getOptimizeRestoredTableOperationToken() != null) {
// The assertion might be missing if the test is running against a HDD cluster or an
// optimization is not necessary.
tableAdmin.awaitOptimizeRestoredTable(result.getOptimizeRestoredTableOperationToken());
Table restoredTable = tableAdmin.getTable(restoredTableId);
assertWithMessage("Incorrect restored table id").that(restoredTable.getId()).isEqualTo(restoredTableId);
}
} finally {
tableAdmin.deleteBackup(targetCluster, backupId);
tableAdmin.deleteTable(restoredTableId);
}
}
use of com.google.cloud.bigtable.admin.v2.models.Table in project java-bigtable by googleapis.
the class BigtableTableAdminClientIT method getTable.
@Test
public void getTable() {
tableAdmin.createTable(CreateTableRequest.of(tableId));
Table tableResponse = tableAdmin.getTable(tableId);
assertNotNull(tableResponse);
assertEquals(tableId, tableResponse.getId());
}
use of com.google.cloud.bigtable.admin.v2.models.Table in project java-bigtable by googleapis.
the class TableAdminExample method listColumnFamilies.
/**
* Demonstrates how to list a table's column families.
*/
public void listColumnFamilies() {
System.out.println("\nPrinting ID and GC Rule for all column families");
// Lists all families in the table with GC rules.
try {
Table table = adminClient.getTable(tableId);
Collection<ColumnFamily> columnFamilies = table.getColumnFamilies();
for (ColumnFamily columnFamily : columnFamilies) {
System.out.printf("Column family: %s%nGC Rule: %s%n", columnFamily.getId(), columnFamily.getGCRule().toString());
}
} catch (NotFoundException e) {
System.err.println("Failed to list column families from a non-existent table: " + e.getMessage());
}
// [END bigtable_list_column_families]
}
use of com.google.cloud.bigtable.admin.v2.models.Table in project java-bigtable by googleapis.
the class TableAdminExample method printModifiedColumnFamily.
/**
* Demonstrates how to print the modified column family.
*/
public void printModifiedColumnFamily() {
System.out.printf("%nPrint updated GC rule for column family %s%n", COLUMN_FAMILY_1);
// [START bigtable_family_get_gc_rule]
try {
Table table = adminClient.getTable(tableId);
Collection<ColumnFamily> columnFamilies = table.getColumnFamilies();
for (ColumnFamily columnFamily : columnFamilies) {
if (columnFamily.getId().equals(COLUMN_FAMILY_1)) {
System.out.printf("Column family: %s%nGC Rule: %s%n", columnFamily.getId(), columnFamily.getGCRule().toString());
}
}
} catch (NotFoundException e) {
System.err.println("Failed to print a non-existent column family: " + e.getMessage());
}
// [END bigtable_family_get_gc_rule]
}
Aggregations