Search in sources :

Example 1 with DropRowRangeRequest

use of com.google.bigtable.admin.v2.DropRowRangeRequest in project java-bigtable by googleapis.

the class BigtableTableAdminClientTest method testDropRowRange.

@Test
public void testDropRowRange() {
    // Setup
    Mockito.when(mockStub.dropRowRangeCallable()).thenReturn(mockDropRowRangeCallable);
    DropRowRangeRequest expectedRequest = DropRowRangeRequest.newBuilder().setName(TABLE_NAME).setRowKeyPrefix(ByteString.copyFromUtf8("rowKeyPrefix")).build();
    final Empty expectedResponse = Empty.getDefaultInstance();
    final AtomicBoolean wasCalled = new AtomicBoolean(false);
    Mockito.when(mockDropRowRangeCallable.futureCall(expectedRequest)).thenAnswer((Answer<ApiFuture<Empty>>) invocationOnMock -> {
        wasCalled.set(true);
        return ApiFutures.immediateFuture(expectedResponse);
    });
    // Execute
    adminClient.dropRowRange(TABLE_ID, "rowKeyPrefix");
    // Verify
    assertThat(wasCalled.get()).isTrue();
}
Also used : ArgumentMatchers(org.mockito.ArgumentMatchers) OperationFuture(com.google.api.gax.longrunning.OperationFuture) NotFoundException(com.google.api.gax.rpc.NotFoundException) CreateBackupMetadata(com.google.bigtable.admin.v2.CreateBackupMetadata) ListTablesRequest(com.google.bigtable.admin.v2.ListTablesRequest) Empty(com.google.protobuf.Empty) Table(com.google.cloud.bigtable.admin.v2.models.Table) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily) Map(java.util.Map) CreateTableRequest(com.google.cloud.bigtable.admin.v2.models.CreateTableRequest) Status(io.grpc.Status) Backup(com.google.cloud.bigtable.admin.v2.models.Backup) GcRule(com.google.bigtable.admin.v2.GcRule) Role(com.google.cloud.Role) ListBackupsPage(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPage) ListTablesPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPagedResponse) ApiFutures(com.google.api.core.ApiFutures) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) Timestamps(com.google.protobuf.util.Timestamps) ClusterState(com.google.bigtable.admin.v2.Table.ClusterState) State(com.google.bigtable.admin.v2.Backup.State) ListTablesPage(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPage) ApiFuture(com.google.api.core.ApiFuture) ByteString(com.google.protobuf.ByteString) EncryptionInfo(com.google.cloud.bigtable.admin.v2.models.EncryptionInfo) List(java.util.List) DeleteTableRequest(com.google.bigtable.admin.v2.DeleteTableRequest) NameUtil(com.google.cloud.bigtable.admin.v2.internal.NameUtil) RestoreTableMetadata(com.google.bigtable.admin.v2.RestoreTableMetadata) DeleteBackupRequest(com.google.bigtable.admin.v2.DeleteBackupRequest) GetTableRequest(com.google.bigtable.admin.v2.GetTableRequest) BackupInfo(com.google.bigtable.admin.v2.BackupInfo) Policy(com.google.cloud.Policy) Mock(org.mockito.Mock) OperationFutures(com.google.api.gax.longrunning.OperationFutures) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Operation(com.google.longrunning.Operation) Timestamp(com.google.protobuf.Timestamp) RestoreSourceType(com.google.bigtable.admin.v2.RestoreSourceType) CreateBackupRequest(com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest) Code(io.grpc.Status.Code) Answer(org.mockito.stubbing.Answer) ListBackupsPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPagedResponse) Lists(com.google.common.collect.Lists) RestoreTableRequest(com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest) ImmutableList(com.google.common.collect.ImmutableList) GrpcStatusCode(com.google.api.gax.grpc.GrpcStatusCode) Instant(org.threeten.bp.Instant) RestoredTableResult(com.google.cloud.bigtable.admin.v2.models.RestoredTableResult) MockitoJUnit(org.mockito.junit.MockitoJUnit) ModifyColumnFamiliesRequest(com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest) Identity(com.google.cloud.Identity) Modification(com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification) Before(org.junit.Before) EnhancedBigtableTableAdminStub(com.google.cloud.bigtable.admin.v2.stub.EnhancedBigtableTableAdminStub) BaseEncoding(com.google.common.io.BaseEncoding) UpdateBackupRequest(com.google.cloud.bigtable.admin.v2.models.UpdateBackupRequest) Test(org.junit.Test) DropRowRangeRequest(com.google.bigtable.admin.v2.DropRowRangeRequest) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) View(com.google.bigtable.admin.v2.Table.View) TableName(com.google.bigtable.admin.v2.TableName) ExecutionException(java.util.concurrent.ExecutionException) OperationCallable(com.google.api.gax.rpc.OperationCallable) UnaryCallable(com.google.api.gax.rpc.UnaryCallable) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) ListBackupsRequest(com.google.bigtable.admin.v2.ListBackupsRequest) MockitoRule(org.mockito.junit.MockitoRule) FakeOperationSnapshot(com.google.api.gax.rpc.testing.FakeOperationSnapshot) GetBackupRequest(com.google.bigtable.admin.v2.GetBackupRequest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ApiFuture(com.google.api.core.ApiFuture) DropRowRangeRequest(com.google.bigtable.admin.v2.DropRowRangeRequest) Empty(com.google.protobuf.Empty) Test(org.junit.Test)

Example 2 with DropRowRangeRequest

use of com.google.bigtable.admin.v2.DropRowRangeRequest in project java-bigtable by googleapis.

the class BaseBigtableTableAdminClientTest method dropRowRangeTest.

@Test
public void dropRowRangeTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockBigtableTableAdmin.addResponse(expectedResponse);
    DropRowRangeRequest request = DropRowRangeRequest.newBuilder().setName(TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]").toString()).build();
    client.dropRowRange(request);
    List<AbstractMessage> actualRequests = mockBigtableTableAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DropRowRangeRequest actualRequest = ((DropRowRangeRequest) actualRequests.get(0));
    Assert.assertEquals(request.getName(), actualRequest.getName());
    Assert.assertEquals(request.getRowKeyPrefix(), actualRequest.getRowKeyPrefix());
    Assert.assertEquals(request.getDeleteAllDataFromTable(), actualRequest.getDeleteAllDataFromTable());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) DropRowRangeRequest(com.google.bigtable.admin.v2.DropRowRangeRequest) AbstractMessage(com.google.protobuf.AbstractMessage) Test(org.junit.Test)

Example 3 with DropRowRangeRequest

use of com.google.bigtable.admin.v2.DropRowRangeRequest in project java-bigtable by googleapis.

the class BaseBigtableTableAdminClientTest method dropRowRangeExceptionTest.

@Test
public void dropRowRangeExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockBigtableTableAdmin.addException(exception);
    try {
        DropRowRangeRequest request = DropRowRangeRequest.newBuilder().setName(TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]").toString()).build();
        client.dropRowRange(request);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : DropRowRangeRequest(com.google.bigtable.admin.v2.DropRowRangeRequest) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 4 with DropRowRangeRequest

use of com.google.bigtable.admin.v2.DropRowRangeRequest in project java-bigtable by googleapis.

the class BigtableTableAdminClientTests method testDropRowRange.

@Test
public void testDropRowRange() {
    // Setup
    Mockito.when(mockStub.dropRowRangeCallable()).thenReturn(mockDropRowRangeCallable);
    DropRowRangeRequest expectedRequest = DropRowRangeRequest.newBuilder().setName(TABLE_NAME).setRowKeyPrefix(ByteString.copyFromUtf8("rowKeyPrefix")).build();
    final Empty expectedResponse = Empty.getDefaultInstance();
    final AtomicBoolean wasCalled = new AtomicBoolean(false);
    Mockito.when(mockDropRowRangeCallable.futureCall(expectedRequest)).thenAnswer((Answer<ApiFuture<Empty>>) invocationOnMock -> {
        wasCalled.set(true);
        return ApiFutures.immediateFuture(expectedResponse);
    });
    // Execute
    adminClient.dropRowRange(TABLE_ID, "rowKeyPrefix");
    // Verify
    assertThat(wasCalled.get()).isTrue();
}
Also used : ArgumentMatchers(org.mockito.ArgumentMatchers) OperationFuture(com.google.api.gax.longrunning.OperationFuture) NotFoundException(com.google.api.gax.rpc.NotFoundException) CreateBackupMetadata(com.google.bigtable.admin.v2.CreateBackupMetadata) ListTablesRequest(com.google.bigtable.admin.v2.ListTablesRequest) Empty(com.google.protobuf.Empty) Table(com.google.cloud.bigtable.admin.v2.models.Table) ColumnFamily(com.google.bigtable.admin.v2.ColumnFamily) Map(java.util.Map) CreateTableRequest(com.google.cloud.bigtable.admin.v2.models.CreateTableRequest) Status(io.grpc.Status) Backup(com.google.cloud.bigtable.admin.v2.models.Backup) GcRule(com.google.bigtable.admin.v2.GcRule) Role(com.google.cloud.Role) ListBackupsPage(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPage) ListTablesPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPagedResponse) ApiFutures(com.google.api.core.ApiFutures) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) Timestamps(com.google.protobuf.util.Timestamps) ClusterState(com.google.bigtable.admin.v2.Table.ClusterState) State(com.google.bigtable.admin.v2.Backup.State) ListTablesPage(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListTablesPage) ApiFuture(com.google.api.core.ApiFuture) ByteString(com.google.protobuf.ByteString) EncryptionInfo(com.google.cloud.bigtable.admin.v2.models.EncryptionInfo) List(java.util.List) DeleteTableRequest(com.google.bigtable.admin.v2.DeleteTableRequest) NameUtil(com.google.cloud.bigtable.admin.v2.internal.NameUtil) RestoreTableMetadata(com.google.bigtable.admin.v2.RestoreTableMetadata) DeleteBackupRequest(com.google.bigtable.admin.v2.DeleteBackupRequest) GetTableRequest(com.google.bigtable.admin.v2.GetTableRequest) BackupInfo(com.google.bigtable.admin.v2.BackupInfo) Policy(com.google.cloud.Policy) Mock(org.mockito.Mock) OperationFutures(com.google.api.gax.longrunning.OperationFutures) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Operation(com.google.longrunning.Operation) Timestamp(com.google.protobuf.Timestamp) RestoreSourceType(com.google.bigtable.admin.v2.RestoreSourceType) CreateBackupRequest(com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest) Code(io.grpc.Status.Code) Answer(org.mockito.stubbing.Answer) ListBackupsPagedResponse(com.google.cloud.bigtable.admin.v2.BaseBigtableTableAdminClient.ListBackupsPagedResponse) Lists(com.google.common.collect.Lists) RestoreTableRequest(com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest) ImmutableList(com.google.common.collect.ImmutableList) GrpcStatusCode(com.google.api.gax.grpc.GrpcStatusCode) Instant(org.threeten.bp.Instant) RestoredTableResult(com.google.cloud.bigtable.admin.v2.models.RestoredTableResult) MockitoJUnit(org.mockito.junit.MockitoJUnit) ModifyColumnFamiliesRequest(com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest) Identity(com.google.cloud.Identity) Modification(com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest.Modification) Before(org.junit.Before) EnhancedBigtableTableAdminStub(com.google.cloud.bigtable.admin.v2.stub.EnhancedBigtableTableAdminStub) BaseEncoding(com.google.common.io.BaseEncoding) UpdateBackupRequest(com.google.cloud.bigtable.admin.v2.models.UpdateBackupRequest) Test(org.junit.Test) DropRowRangeRequest(com.google.bigtable.admin.v2.DropRowRangeRequest) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) View(com.google.bigtable.admin.v2.Table.View) TableName(com.google.bigtable.admin.v2.TableName) ExecutionException(java.util.concurrent.ExecutionException) OperationCallable(com.google.api.gax.rpc.OperationCallable) UnaryCallable(com.google.api.gax.rpc.UnaryCallable) Mockito(org.mockito.Mockito) Rule(org.junit.Rule) ListBackupsRequest(com.google.bigtable.admin.v2.ListBackupsRequest) MockitoRule(org.mockito.junit.MockitoRule) FakeOperationSnapshot(com.google.api.gax.rpc.testing.FakeOperationSnapshot) GetBackupRequest(com.google.bigtable.admin.v2.GetBackupRequest) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ApiFuture(com.google.api.core.ApiFuture) DropRowRangeRequest(com.google.bigtable.admin.v2.DropRowRangeRequest) Empty(com.google.protobuf.Empty) Test(org.junit.Test)

Example 5 with DropRowRangeRequest

use of com.google.bigtable.admin.v2.DropRowRangeRequest in project java-bigtable-hbase by googleapis.

the class BigtableAdminTest method testDeleteRowRangeByPrefixNonUtf8.

@Test
public void testDeleteRowRangeByPrefixNonUtf8() throws IOException, InterruptedException {
    TableName tableName = TableName.valueOf(TABLE_ID);
    ByteString expectedKey = ByteString.copyFrom(new byte[] { 0, 0, 0, (byte) 128 });
    DropRowRangeRequest expectedRequest = DropRowRangeRequest.newBuilder().setName(TABLE_NAME).setRowKeyPrefix(expectedKey).build();
    responseQueue.put(Empty.getDefaultInstance());
    admin.deleteRowRangeByPrefix(tableName, expectedKey.toByteArray());
    assertEquals(expectedRequest, requestQueue.take());
}
Also used : TableName(org.apache.hadoop.hbase.TableName) DropRowRangeRequest(com.google.bigtable.admin.v2.DropRowRangeRequest) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Aggregations

DropRowRangeRequest (com.google.bigtable.admin.v2.DropRowRangeRequest)6 Test (org.junit.Test)6 ByteString (com.google.protobuf.ByteString)3 ApiFuture (com.google.api.core.ApiFuture)2 ApiFutures (com.google.api.core.ApiFutures)2 GrpcStatusCode (com.google.api.gax.grpc.GrpcStatusCode)2 OperationFuture (com.google.api.gax.longrunning.OperationFuture)2 OperationFutures (com.google.api.gax.longrunning.OperationFutures)2 OperationSnapshot (com.google.api.gax.longrunning.OperationSnapshot)2 NotFoundException (com.google.api.gax.rpc.NotFoundException)2 OperationCallable (com.google.api.gax.rpc.OperationCallable)2 UnaryCallable (com.google.api.gax.rpc.UnaryCallable)2 FakeOperationSnapshot (com.google.api.gax.rpc.testing.FakeOperationSnapshot)2 State (com.google.bigtable.admin.v2.Backup.State)2 BackupInfo (com.google.bigtable.admin.v2.BackupInfo)2 ColumnFamily (com.google.bigtable.admin.v2.ColumnFamily)2 CreateBackupMetadata (com.google.bigtable.admin.v2.CreateBackupMetadata)2 DeleteBackupRequest (com.google.bigtable.admin.v2.DeleteBackupRequest)2 DeleteTableRequest (com.google.bigtable.admin.v2.DeleteTableRequest)2 GcRule (com.google.bigtable.admin.v2.GcRule)2