Search in sources :

Example 21 with Table

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

the class BaseBigtableTableAdminClientTest method listTablesTest.

@Test
public void listTablesTest() throws Exception {
    Table responsesElement = Table.newBuilder().build();
    ListTablesResponse expectedResponse = ListTablesResponse.newBuilder().setNextPageToken("").addAllTables(Arrays.asList(responsesElement)).build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
    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.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : InstanceName(com.google.bigtable.admin.v2.InstanceName) 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) ListTablesPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPagedResponse) Test(org.junit.Test)

Example 22 with Table

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

the class BigtableTableAdminClientTest 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 23 with Table

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

the class BigtableTableAdminClientTest 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 24 with Table

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

the class BigtableTableAdminClientTest 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 25 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)

Aggregations

Test (org.junit.Test)17 Table (com.google.cloud.bigtable.admin.v2.models.Table)16 ByteString (com.google.protobuf.ByteString)9 ColumnFamily (com.google.cloud.bigtable.admin.v2.models.ColumnFamily)5 CreateTableRequest (com.google.cloud.bigtable.admin.v2.models.CreateTableRequest)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 BigtableTableAdminClient (com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient)4 NotFoundException (com.google.api.gax.rpc.NotFoundException)3 ModifyColumnFamiliesRequest (com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest)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 AbstractMessage (com.google.protobuf.AbstractMessage)2