Search in sources :

Example 26 with Table

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);
}
Also used : ListTablesPage(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPage) Table(com.google.cloud.bigtable.admin.v2.models.Table) ByteString(com.google.protobuf.ByteString) ListTablesRequest(com.google.bigtable.admin.v2.ListTablesRequest) ListTablesPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPagedResponse) Test(org.junit.Test)

Example 27 with Table

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);
    }
}
Also used : RestoreTableRequest(com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest) Table(com.google.cloud.bigtable.admin.v2.models.Table) RestoredTableResult(com.google.cloud.bigtable.admin.v2.models.RestoredTableResult) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 28 with Table

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());
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) Test(org.junit.Test)

Example 29 with Table

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]
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) NotFoundException(com.google.api.gax.rpc.NotFoundException) ColumnFamily(com.google.cloud.bigtable.admin.v2.models.ColumnFamily)

Example 30 with Table

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]
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) NotFoundException(com.google.api.gax.rpc.NotFoundException) ColumnFamily(com.google.cloud.bigtable.admin.v2.models.ColumnFamily)

Aggregations

Test (org.junit.Test)17 Table (com.google.cloud.bigtable.admin.v2.models.Table)16 ByteString (com.google.protobuf.ByteString)9 CreateTableRequest (com.google.cloud.bigtable.admin.v2.models.CreateTableRequest)7 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)6 ColumnFamily (com.google.cloud.bigtable.admin.v2.models.ColumnFamily)5 ListTablesRequest (com.google.bigtable.admin.v2.ListTablesRequest)4 Table (com.google.bigtable.admin.v2.Table)4 ListTablesPagedResponse (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPagedResponse)4 NotFoundException (com.google.api.gax.rpc.NotFoundException)3 ModifyColumnFamiliesRequest (com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)3 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)3 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)2 ListTablesResponse (com.google.bigtable.admin.v2.ListTablesResponse)2 ListTablesPage (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPage)2 BigtableInstanceAdminClient (com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient)2 BigtableTableAdminSettings (com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings)2 Instance (com.google.cloud.bigtable.admin.v2.models.Instance)2 RestoreTableRequest (com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest)2 RestoredTableResult (com.google.cloud.bigtable.admin.v2.models.RestoredTableResult)2