Search in sources :

Example 6 with Table

use of com.google.cloud.bigtable.admin.v2.models.Table in project java-bigtable by googleapis.

the class BigtableTableAdminClientTests method testModifyFamilies.

@Test
public void testModifyFamilies() {
    // Setup
    Mockito.when(mockStub.modifyColumnFamiliesCallable()).thenReturn(mockModifyTableCallable);
    com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest expectedRequest = com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.newBuilder().setName(TABLE_NAME).addModifications(Modification.newBuilder().setId("cf").setCreate(ColumnFamily.newBuilder().setGcRule(GcRule.getDefaultInstance()))).build();
    com.google.bigtable.admin.v2.Table fakeResponse = com.google.bigtable.admin.v2.Table.newBuilder().setName(TABLE_NAME).putColumnFamilies("cf", ColumnFamily.newBuilder().setGcRule(GcRule.getDefaultInstance()).build()).build();
    Mockito.when(mockModifyTableCallable.futureCall(expectedRequest)).thenReturn(ApiFutures.immediateFuture(fakeResponse));
    // Execute
    Table actualResult = adminClient.modifyFamilies(ModifyColumnFamiliesRequest.of(TABLE_ID).addFamily("cf"));
    // Verify
    assertThat(actualResult).isEqualTo(Table.fromProto(fakeResponse));
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) Test(org.junit.Test)

Example 7 with Table

use of com.google.cloud.bigtable.admin.v2.models.Table in project java-bigtable by googleapis.

the class BigtableTableAdminClientTests method testCreateTable.

@Test
public void testCreateTable() {
    // Setup
    Mockito.when(mockStub.createTableCallable()).thenReturn(mockCreateTableCallable);
    com.google.bigtable.admin.v2.CreateTableRequest expectedRequest = com.google.bigtable.admin.v2.CreateTableRequest.newBuilder().setParent(INSTANCE_NAME).setTableId(TABLE_ID).build();
    com.google.bigtable.admin.v2.Table expectedResponse = com.google.bigtable.admin.v2.Table.newBuilder().setName(TABLE_NAME).build();
    Mockito.when(mockCreateTableCallable.futureCall(expectedRequest)).thenReturn(ApiFutures.immediateFuture(expectedResponse));
    // Execute
    Table result = adminClient.createTable(CreateTableRequest.of(TABLE_ID));
    // Verify
    assertThat(result).isEqualTo(Table.fromProto(expectedResponse));
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) Test(org.junit.Test)

Example 8 with Table

use of com.google.cloud.bigtable.admin.v2.models.Table in project java-bigtable by googleapis.

the class BigtableTableAdminClientTests method testGetTable.

@Test
public void testGetTable() {
    // Setup
    Mockito.when(mockStub.getTableCallable()).thenReturn(mockGetTableCallable);
    GetTableRequest expectedRequest = GetTableRequest.newBuilder().setName(TABLE_NAME).setView(View.SCHEMA_VIEW).build();
    com.google.bigtable.admin.v2.Table expectedResponse = com.google.bigtable.admin.v2.Table.newBuilder().setName(TABLE_NAME).build();
    Mockito.when(mockGetTableCallable.futureCall(expectedRequest)).thenReturn(ApiFutures.immediateFuture(expectedResponse));
    // Execute
    Table actualResult = adminClient.getTable(TABLE_ID);
    // Verify
    assertThat(actualResult).isEqualTo(Table.fromProto(expectedResponse));
}
Also used : GetTableRequest(com.google.bigtable.admin.v2.GetTableRequest) Table(com.google.cloud.bigtable.admin.v2.models.Table) Test(org.junit.Test)

Example 9 with Table

use of com.google.cloud.bigtable.admin.v2.models.Table in project java-bigtable by googleapis.

the class BaseBigtableTableAdminClientTest method listTablesTest2.

@Test
public void listTablesTest2() throws Exception {
    Table responsesElement = Table.newBuilder().build();
    ListTablesResponse expectedResponse = ListTablesResponse.newBuilder().setNextPageToken("").addAllTables(Arrays.asList(responsesElement)).build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListTablesPagedResponse pagedListResponse = client.listTables(parent);
    List<Table> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getTablesList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListTablesRequest actualRequest = ((ListTablesRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Table(com.google.bigtable.admin.v2.Table) AbstractMessage(com.google.protobuf.AbstractMessage) ListTablesRequest(com.google.bigtable.admin.v2.ListTablesRequest) ListTablesResponse(com.google.bigtable.admin.v2.ListTablesResponse) ByteString(com.google.protobuf.ByteString) ListTablesPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPagedResponse) Test(org.junit.Test)

Example 10 with Table

use of com.google.cloud.bigtable.admin.v2.models.Table in project java-bigtable by googleapis.

the class BigtableBackupIT method createAndPopulateTestTable.

private static Table createAndPopulateTestTable(BigtableTableAdminClient tableAdmin, BigtableDataClient dataClient) throws InterruptedException {
    String tableId = PrefixGenerator.newPrefix("BigtableBackupIT#createAndPopulateTestTable");
    Table testTable = tableAdmin.createTable(CreateTableRequest.of(tableId).addFamily("cf1"));
    // Populate test data.
    byte[] rowBytes = new byte[1024];
    Random random = new Random();
    random.nextBytes(rowBytes);
    try (Batcher<RowMutationEntry, Void> batcher = dataClient.newBulkMutationBatcher(tableId)) {
        for (int i = 0; i < 10; i++) {
            batcher.add(RowMutationEntry.create("test-row-" + i).setCell("cf1", ByteString.EMPTY, ByteString.copyFrom(rowBytes)));
        }
    }
    return testTable;
}
Also used : Table(com.google.cloud.bigtable.admin.v2.models.Table) Random(java.util.Random) RowMutationEntry(com.google.cloud.bigtable.data.v2.models.RowMutationEntry) ByteString(com.google.protobuf.ByteString)

Aggregations

Test (org.junit.Test)21 Table (com.google.cloud.bigtable.admin.v2.models.Table)20 ByteString (com.google.protobuf.ByteString)10 CreateTableRequest (com.google.cloud.bigtable.admin.v2.models.CreateTableRequest)7 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)6 ListTablesRequest (com.google.bigtable.admin.v2.ListTablesRequest)5 ListTablesPagedResponse (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPagedResponse)5 ColumnFamily (com.google.cloud.bigtable.admin.v2.models.ColumnFamily)5 Table (com.google.bigtable.admin.v2.Table)4 NotFoundException (com.google.api.gax.rpc.NotFoundException)3 ListTablesPage (com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPage)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 GetTableRequest (com.google.bigtable.admin.v2.GetTableRequest)2 ListTablesResponse (com.google.bigtable.admin.v2.ListTablesResponse)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