diff --git a/bigtable-client-core-parent/bigtable-hbase-integration-tests-common/src/test/java/com/google/cloud/bigtable/hbase/test_env/BigtableEnv.java b/bigtable-client-core-parent/bigtable-hbase-integration-tests-common/src/test/java/com/google/cloud/bigtable/hbase/test_env/BigtableEnv.java index 93b2442fe2..ffe9d89011 100644 --- a/bigtable-client-core-parent/bigtable-hbase-integration-tests-common/src/test/java/com/google/cloud/bigtable/hbase/test_env/BigtableEnv.java +++ b/bigtable-client-core-parent/bigtable-hbase-integration-tests-common/src/test/java/com/google/cloud/bigtable/hbase/test_env/BigtableEnv.java @@ -52,8 +52,7 @@ class BigtableEnv extends SharedTestEnv { "google.bigtable.instance.id", "google.bigtable.use.bulk.api", "google.bigtable.use.plaintext.negotiation", - "google.bigtable.snapshot.cluster.id", - "google.bigtable.use.gcj.client"); + "google.bigtable.snapshot.cluster.id"); @Override protected void setup() throws IOException { diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/BigtableOptionsFactory.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/BigtableOptionsFactory.java index 624a07789f..e80fb7488d 100644 --- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/BigtableOptionsFactory.java +++ b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/BigtableOptionsFactory.java @@ -322,13 +322,6 @@ public class BigtableOptionsFactory { /** Allow namespace methods to be no-ops */ public static final String BIGTABLE_NAMESPACE_WARNING_KEY = "google.bigtable.namespace.warnings"; - /** - * A flag to decide which implementation to use for data & admin operation. - * - *

This will be removed after the transition to java-bigtable. - */ - @BetaApi public static final String BIGTABLE_USE_GCJ_CLIENT = "google.bigtable.use.gcj.client"; - /** Tracing cookie to send in the header with the requests */ @BetaApi("The API for setting tracing cookie is not yet stable and may change in the future") public static final String BIGTABLE_TRACING_COOKIE = "google.bigtable.tracing.cookie.header"; diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/BigtableApi.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/BigtableApi.java index 8289171c07..c62b030f38 100644 --- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/BigtableApi.java +++ b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/BigtableApi.java @@ -16,8 +16,6 @@ package com.google.cloud.bigtable.hbase.wrappers; import com.google.api.core.InternalApi; -import com.google.cloud.bigtable.hbase.wrappers.classic.BigtableClassicApi; -import com.google.cloud.bigtable.hbase.wrappers.classic.BigtableHBaseClassicSettings; import com.google.cloud.bigtable.hbase.wrappers.veneer.BigtableHBaseVeneerSettings; import com.google.cloud.bigtable.hbase.wrappers.veneer.BigtableVeneerApi; import java.io.IOException; @@ -33,11 +31,7 @@ public abstract class BigtableApi implements AutoCloseable { private final BigtableHBaseSettings hBaseSettings; public static BigtableApi create(BigtableHBaseSettings settings) throws IOException { - if (settings instanceof BigtableHBaseVeneerSettings) { - return new BigtableVeneerApi((BigtableHBaseVeneerSettings) settings); - } else { - return new BigtableClassicApi((BigtableHBaseClassicSettings) settings); - } + return new BigtableVeneerApi((BigtableHBaseVeneerSettings) settings); } protected BigtableApi(BigtableHBaseSettings hbaseSettings) { diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/BigtableHBaseSettings.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/BigtableHBaseSettings.java index f6c77814e1..78f28980d9 100644 --- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/BigtableHBaseSettings.java +++ b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/BigtableHBaseSettings.java @@ -15,7 +15,6 @@ */ package com.google.cloud.bigtable.hbase.wrappers; -import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_USE_GCJ_CLIENT; import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.INSTANCE_ID_KEY; import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.PROJECT_ID_KEY; import static com.google.common.base.Strings.isNullOrEmpty; @@ -23,7 +22,6 @@ import com.google.api.core.InternalApi; import com.google.cloud.bigtable.hbase.BigtableOptionsFactory; import com.google.cloud.bigtable.hbase.util.Logger; -import com.google.cloud.bigtable.hbase.wrappers.classic.BigtableHBaseClassicSettings; import com.google.cloud.bigtable.hbase.wrappers.veneer.BigtableHBaseVeneerSettings; import com.google.common.base.Preconditions; import java.io.IOException; @@ -41,11 +39,7 @@ public abstract class BigtableHBaseSettings { private final int ttlSecondsForBackup; public static BigtableHBaseSettings create(Configuration configuration) throws IOException { - if (configuration.getBoolean(BIGTABLE_USE_GCJ_CLIENT, true)) { - return BigtableHBaseVeneerSettings.create(configuration); - } else { - return new BigtableHBaseClassicSettings(configuration); - } + return BigtableHBaseVeneerSettings.create(configuration); } public BigtableHBaseSettings(Configuration configuration) { diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/AdminClientClassicApi.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/AdminClientClassicApi.java deleted file mode 100644 index f5d5fc0104..0000000000 --- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/AdminClientClassicApi.java +++ /dev/null @@ -1,322 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.bigtable.hbase.wrappers.classic; - -import com.google.api.core.ApiFuture; -import com.google.api.core.InternalApi; -import com.google.bigtable.admin.v2.DeleteBackupRequest; -import com.google.bigtable.admin.v2.DeleteTableRequest; -import com.google.bigtable.admin.v2.DropRowRangeRequest; -import com.google.bigtable.admin.v2.GetTableRequest; -import com.google.bigtable.admin.v2.ListBackupsRequest; -import com.google.bigtable.admin.v2.ListBackupsResponse; -import com.google.bigtable.admin.v2.ListClustersRequest; -import com.google.bigtable.admin.v2.ListClustersResponse; -import com.google.bigtable.admin.v2.ListTablesRequest; -import com.google.bigtable.admin.v2.ListTablesResponse; -import com.google.cloud.bigtable.admin.v2.internal.NameUtil; -import com.google.cloud.bigtable.admin.v2.models.Backup; -import com.google.cloud.bigtable.admin.v2.models.Cluster; -import com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest; -import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest; -import com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest; -import com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest; -import com.google.cloud.bigtable.admin.v2.models.RestoredTableResult; -import com.google.cloud.bigtable.admin.v2.models.Table; -import com.google.cloud.bigtable.grpc.BigtableClusterName; -import com.google.cloud.bigtable.grpc.BigtableInstanceClient; -import com.google.cloud.bigtable.grpc.BigtableInstanceName; -import com.google.cloud.bigtable.grpc.BigtableSessionSharedThreadPools; -import com.google.cloud.bigtable.grpc.BigtableTableAdminClient; -import com.google.cloud.bigtable.hbase.wrappers.AdminClientWrapper; -import com.google.cloud.bigtable.util.ApiFutureUtil; -import com.google.common.base.Function; -import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.longrunning.Operation; -import com.google.protobuf.ByteString; -import com.google.protobuf.Empty; -import com.google.protobuf.InvalidProtocolBufferException; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import javax.annotation.Nonnull; - -/** For internal use only - public for technical reasons. */ -@InternalApi("For internal usage only") -public class AdminClientClassicApi implements AdminClientWrapper { - - private final BigtableTableAdminClient tableDelegate; - private final BigtableInstanceClient instanceDelegate; - private final BigtableInstanceName instanceName; - private final ExecutorService batchThreadPool; - - AdminClientClassicApi( - @Nonnull BigtableTableAdminClient tableDelegate, - @Nonnull BigtableInstanceName instanceName, - BigtableInstanceClient instanceDelegate) { - this.tableDelegate = tableDelegate; - this.instanceName = instanceName; - this.batchThreadPool = BigtableSessionSharedThreadPools.getInstance().getBatchThreadPool(); - this.instanceDelegate = instanceDelegate; - } - - @Override - public ApiFuture createTableAsync(CreateTableRequest request) { - com.google.bigtable.admin.v2.CreateTableRequest requestProto = - request.toProto(instanceName.getProjectId(), instanceName.getInstanceId()); - - return ApiFutureUtil.transformAndAdapt( - tableDelegate.createTableAsync(requestProto), - new Function() { - @Override - public Table apply(com.google.bigtable.admin.v2.Table tableProto) { - return Table.fromProto(tableProto); - } - }); - } - - @Override - public ApiFuture
getTableAsync(String tableId) { - GetTableRequest requestProto = - GetTableRequest.newBuilder().setName(instanceName.toTableNameStr(tableId)).build(); - - return ApiFutureUtil.transformAndAdapt( - tableDelegate.getTableAsync(requestProto), - new Function() { - @Override - public Table apply(com.google.bigtable.admin.v2.Table tableProto) { - return Table.fromProto(tableProto); - } - }); - } - - @Override - public ApiFuture> listTablesAsync() { - ListTablesRequest request = - ListTablesRequest.newBuilder().setParent(instanceName.toString()).build(); - ListenableFuture response = tableDelegate.listTablesAsync(request); - - return ApiFutureUtil.transformAndAdapt( - response, - new Function>() { - @Override - public List apply(ListTablesResponse input) { - ImmutableList.Builder tableIdsBuilder = ImmutableList.builder(); - for (com.google.bigtable.admin.v2.Table tableProto : input.getTablesList()) { - tableIdsBuilder.add(instanceName.toTableId(tableProto.getName())); - } - - return tableIdsBuilder.build(); - } - }); - } - - @Override - public ApiFuture deleteTableAsync(String tableId) { - DeleteTableRequest request = - DeleteTableRequest.newBuilder().setName(instanceName.toTableNameStr(tableId)).build(); - - return ApiFutureUtil.transformAndAdapt( - tableDelegate.deleteTableAsync(request), - new Function() { - @Override - public Void apply(Empty empty) { - return null; - } - }); - } - - @Override - public ApiFuture
modifyFamiliesAsync(ModifyColumnFamiliesRequest request) { - com.google.bigtable.admin.v2.ModifyColumnFamiliesRequest modifyColumnRequestProto = - request.toProto(instanceName.getProjectId(), instanceName.getInstanceId()); - - return ApiFutureUtil.transformAndAdapt( - tableDelegate.modifyColumnFamilyAsync(modifyColumnRequestProto), - new Function() { - @Override - public Table apply(com.google.bigtable.admin.v2.Table tableProto) { - return Table.fromProto(tableProto); - } - }); - } - - @Override - public ApiFuture dropRowRangeAsync(String tableId, ByteString rowKeyPrefix) { - Preconditions.checkNotNull(rowKeyPrefix); - DropRowRangeRequest protoRequest = - DropRowRangeRequest.newBuilder() - .setName(instanceName.toTableNameStr(tableId)) - .setDeleteAllDataFromTable(false) - .setRowKeyPrefix(rowKeyPrefix) - .build(); - return ApiFutureUtil.transformAndAdapt( - tableDelegate.dropRowRangeAsync(protoRequest), - new Function() { - @Override - public Void apply(Empty empty) { - return null; - } - }); - } - - @Override - public ApiFuture dropAllRowsAsync(String tableId) { - DropRowRangeRequest protoRequest = - DropRowRangeRequest.newBuilder() - .setName(instanceName.toTableNameStr(tableId)) - .setDeleteAllDataFromTable(true) - .build(); - return ApiFutureUtil.transformAndAdapt( - tableDelegate.dropRowRangeAsync(protoRequest), - new Function() { - @Override - public Void apply(Empty empty) { - return null; - } - }); - } - - @Override - public ApiFuture createBackupAsync(CreateBackupRequest request) { - ListenableFuture backupAsync = - tableDelegate.createBackupAsync( - request.toProto(instanceName.getProjectId(), instanceName.getInstanceId())); - Function function = - new Function() { - @Override - public Backup apply(final Operation operation) { - try { - Future operationFuture = - batchThreadPool.submit( - new Callable() { - @Override - public Operation call() throws Exception { - return tableDelegate.waitForOperation(operation); - } - }); - - return Backup.fromProto( - operationFuture - .get() - .getResponse() - .unpack(com.google.bigtable.admin.v2.Backup.class)); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - throw new RuntimeException("Interrupted while waiting for operation to finish"); - } catch (ExecutionException | InvalidProtocolBufferException e) { - throw new IllegalStateException(e); - } - } - }; - return ApiFutureUtil.transformAndAdapt(backupAsync, function); - } - - @Override - public ApiFuture> listBackupsAsync(String clusterId) { - BigtableClusterName clusterName = instanceName.toClusterName(clusterId); - ListBackupsRequest request = - ListBackupsRequest.newBuilder().setParent(clusterName.getClusterName()).build(); - - // pagination is not required as page_size in the request is not set - everything will be - // returned - return ApiFutureUtil.transformAndAdapt( - tableDelegate.listBackupsAsync(request), - new Function>() { - @Override - public List apply(ListBackupsResponse response) { - List backups = new ArrayList<>(); - for (com.google.bigtable.admin.v2.Backup backup : response.getBackupsList()) { - backups.add(NameUtil.extractBackupIdFromBackupName(backup.getName())); - } - return backups; - } - }); - } - - @Override - public ApiFuture deleteBackupAsync(String clusterId, String backupId) { - BigtableClusterName clusterName = instanceName.toClusterName(clusterId); - DeleteBackupRequest request = - DeleteBackupRequest.newBuilder().setName(clusterName.toBackupName(backupId)).build(); - return ApiFutureUtil.transformAndAdapt( - tableDelegate.deleteBackupAsync(request), - new Function() { - @Override - public Void apply(Empty empty) { - return null; - } - }); - } - - @Override - public ApiFuture restoreTableAsync(RestoreTableRequest request) { - return ApiFutureUtil.transformAndAdapt( - tableDelegate.restoreTableAsync( - request.toProto(instanceName.getProjectId(), instanceName.getInstanceId())), - new Function() { - @Override - public RestoredTableResult apply(final Operation operation) { - try { - Future operationFuture = - batchThreadPool.submit( - new Callable() { - @Override - public Operation call() throws Exception { - return tableDelegate.waitForOperation(operation); - } - }); - - return new RestoredTableResult( - Table.fromProto( - operationFuture - .get() - .getResponse() - .unpack(com.google.bigtable.admin.v2.Table.class)), - operation - .getMetadata() - .unpack(com.google.bigtable.admin.v2.RestoreTableMetadata.class) - .getOptimizeTableOperationName()); - } catch (IOException | InterruptedException | ExecutionException e) { - throw new IllegalStateException(e); - } - } - }); - } - - @Override - public List listClusters(String instanceId) { - ListClustersRequest request = - ListClustersRequest.newBuilder().setParent(instanceName.getInstanceName()).build(); - ListClustersResponse listClustersResponse = instanceDelegate.listCluster(request); - List protoList = listClustersResponse.getClustersList(); - - List clusters = new ArrayList<>(protoList.size()); - for (com.google.bigtable.admin.v2.Cluster value : protoList) { - clusters.add(Cluster.fromProto(value)); - } - return clusters; - } - - @Override - public void close() {} -} diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BigtableClassicApi.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BigtableClassicApi.java deleted file mode 100644 index a0e33d74f0..0000000000 --- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BigtableClassicApi.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.bigtable.hbase.wrappers.classic; - -import com.google.api.core.InternalApi; -import com.google.cloud.bigtable.data.v2.internal.RequestContext; -import com.google.cloud.bigtable.grpc.BigtableInstanceName; -import com.google.cloud.bigtable.grpc.BigtableSession; -import com.google.cloud.bigtable.hbase.wrappers.AdminClientWrapper; -import com.google.cloud.bigtable.hbase.wrappers.BigtableApi; -import com.google.cloud.bigtable.hbase.wrappers.BigtableHBaseSettings; -import com.google.cloud.bigtable.hbase.wrappers.DataClientWrapper; -import java.io.IOException; - -/** For internal use only - public for technical reasons. */ -@InternalApi("For internal usage only") -public class BigtableClassicApi extends BigtableApi { - - private final BigtableSession bigtableSession; - private final DataClientWrapper dataClientWrapper; - private final AdminClientWrapper adminClientWrapper; - - public BigtableClassicApi(BigtableHBaseClassicSettings settings) throws IOException { - this(settings, new BigtableSession(settings.getBigtableOptions())); - } - - // This is a temporary constructor and will be removed once transition over new wrappers - // are completed. - public BigtableClassicApi(BigtableHBaseSettings settings, BigtableSession session) - throws IOException { - super(settings); - this.bigtableSession = session; - - RequestContext requestContext = - RequestContext.create( - settings.getProjectId(), - settings.getInstanceId(), - session.getOptions().getAppProfileId()); - this.dataClientWrapper = new DataClientClassicApi(bigtableSession, requestContext); - - BigtableInstanceName instanceName = - new BigtableInstanceName(settings.getProjectId(), settings.getInstanceId()); - this.adminClientWrapper = - new AdminClientClassicApi( - bigtableSession.getTableAdminClient(), - instanceName, - bigtableSession.getInstanceAdminClient()); - } - - @Override - public AdminClientWrapper getAdminClient() { - return adminClientWrapper; - } - - @Override - public DataClientWrapper getDataClient() { - return dataClientWrapper; - } - - @Override - public void close() throws IOException { - if (adminClientWrapper != null) { - adminClientWrapper.close(); - } - dataClientWrapper.close(); - bigtableSession.close(); - } -} diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BigtableHBaseClassicSettings.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BigtableHBaseClassicSettings.java deleted file mode 100644 index 638345acf3..0000000000 --- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BigtableHBaseClassicSettings.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.bigtable.hbase.wrappers.classic; - -import com.google.api.core.InternalApi; -import com.google.cloud.bigtable.config.BigtableOptions; -import com.google.cloud.bigtable.hbase.BigtableOptionsFactory; -import com.google.cloud.bigtable.hbase.wrappers.BigtableHBaseSettings; -import java.io.IOException; -import org.apache.hadoop.conf.Configuration; - -/** For internal use only - public for technical reasons. */ -@InternalApi("For internal usage only") -public class BigtableHBaseClassicSettings extends BigtableHBaseSettings { - - private final BigtableOptions bigtableOptions; - - public BigtableHBaseClassicSettings(Configuration configuration) throws IOException { - super(configuration); - this.bigtableOptions = BigtableOptionsFactory.fromConfiguration(configuration); - } - - @Override - public String getDataHost() { - return bigtableOptions.getDataHost(); - } - - @Override - public String getAdminHost() { - return bigtableOptions.getAdminHost(); - } - - @Override - public int getPort() { - return bigtableOptions.getPort(); - } - - @Override - public int getBulkMaxRowCount() { - return bigtableOptions.getBulkOptions().getBulkMaxRowKeyCount(); - } - - @Override - public long getBatchingMaxRequestSize() { - return bigtableOptions.getBulkOptions().getMaxMemory(); - } - - @Override - public boolean isRetriesWithoutTimestampAllowed() { - return bigtableOptions.getRetryOptions().allowRetriesWithoutTimestamp(); - } - - public BigtableOptions getBigtableOptions() { - return bigtableOptions; - } -} diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BulkMutationClassicApi.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BulkMutationClassicApi.java deleted file mode 100644 index 5212e0c487..0000000000 --- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BulkMutationClassicApi.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.bigtable.hbase.wrappers.classic; - -import com.google.api.core.ApiFuture; -import com.google.api.core.InternalApi; -import com.google.bigtable.v2.MutateRowResponse; -import com.google.cloud.bigtable.data.v2.models.RowMutationEntry; -import com.google.cloud.bigtable.grpc.async.BulkMutation; -import com.google.cloud.bigtable.hbase.wrappers.BulkMutationWrapper; -import com.google.cloud.bigtable.util.ApiFutureUtil; -import com.google.common.base.Function; -import com.google.common.base.Preconditions; -import java.io.IOException; -import javax.annotation.Nonnull; - -/** For internal use only - public for technical reasons. */ -@InternalApi("For internal usage only") -public class BulkMutationClassicApi implements BulkMutationWrapper { - - private final BulkMutation delegate; - private boolean isClosed = false; - - BulkMutationClassicApi(@Nonnull BulkMutation delegate) { - this.delegate = delegate; - } - - @Override - public ApiFuture add(RowMutationEntry rowMutation) { - Preconditions.checkState(!isClosed, "can't mutate when the bulk mutation is closed."); - return ApiFutureUtil.transformAndAdapt( - delegate.add(rowMutation.toProto()), - new Function() { - @Override - public Void apply(MutateRowResponse response) { - return null; - } - }); - } - - @Override - public void sendUnsent() { - delegate.sendUnsent(); - } - - @Override - public void flush() throws InterruptedException { - delegate.flush(); - } - - @Override - public void close() throws IOException { - isClosed = true; - try { - flush(); - } catch (InterruptedException interruptedException) { - throw new IOException(interruptedException); - } - } -} diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BulkReadClassicApi.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BulkReadClassicApi.java deleted file mode 100644 index 24e94abdf8..0000000000 --- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/BulkReadClassicApi.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.bigtable.hbase.wrappers.classic; - -import com.google.api.core.ApiFunction; -import com.google.api.core.ApiFuture; -import com.google.api.core.ApiFutures; -import com.google.api.core.InternalApi; -import com.google.cloud.bigtable.data.v2.models.Filters; -import com.google.cloud.bigtable.data.v2.models.Query; -import com.google.cloud.bigtable.grpc.async.BulkRead; -import com.google.cloud.bigtable.grpc.scanner.FlatRow; -import com.google.cloud.bigtable.hbase.adapters.Adapters; -import com.google.cloud.bigtable.hbase.wrappers.BulkReadWrapper; -import com.google.common.base.Preconditions; -import com.google.common.util.concurrent.MoreExecutors; -import com.google.protobuf.ByteString; -import javax.annotation.Nonnull; -import org.apache.hadoop.hbase.client.Result; - -/** For internal use only - public for technical reasons. */ -@InternalApi("For internal usage only") -public class BulkReadClassicApi implements BulkReadWrapper { - - private final BulkRead delegate; - private final String tableId; - private boolean isClosed = false; - - BulkReadClassicApi(@Nonnull BulkRead delegate, @Nonnull String tableId) { - this.delegate = delegate; - this.tableId = tableId; - } - - @Override - public void close() { - isClosed = true; - sendOutstanding(); - } - - @Override - public ApiFuture add(ByteString rowKey, Filters.Filter filter) { - Preconditions.checkState(!isClosed, "can't add request when the bulk read is closed."); - Query query = Query.create(tableId).rowKey(rowKey); - if (filter != null) { - query.filter(filter); - } - return ApiFutures.transform( - delegate.add(query), - new ApiFunction() { - @Override - public Result apply(FlatRow flatRow) { - return Adapters.FLAT_ROW_ADAPTER.adaptResponse(flatRow); - } - }, - MoreExecutors.directExecutor()); - } - - @Override - public void sendOutstanding() { - delegate.flush(); - } -} diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/DataClientClassicApi.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/DataClientClassicApi.java deleted file mode 100644 index 33bd2c9e45..0000000000 --- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/classic/DataClientClassicApi.java +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.bigtable.hbase.wrappers.classic; - -import com.google.api.core.ApiFunction; -import com.google.api.core.ApiFuture; -import com.google.api.core.ApiFutures; -import com.google.api.core.InternalApi; -import com.google.bigtable.v2.Cell; -import com.google.bigtable.v2.CheckAndMutateRowRequest; -import com.google.bigtable.v2.CheckAndMutateRowResponse; -import com.google.bigtable.v2.Column; -import com.google.bigtable.v2.Family; -import com.google.bigtable.v2.MutateRowResponse; -import com.google.bigtable.v2.ReadModifyWriteRowResponse; -import com.google.bigtable.v2.Row; -import com.google.bigtable.v2.SampleRowKeysRequest; -import com.google.bigtable.v2.SampleRowKeysResponse; -import com.google.cloud.bigtable.data.v2.internal.NameUtil; -import com.google.cloud.bigtable.data.v2.internal.RequestContext; -import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation; -import com.google.cloud.bigtable.data.v2.models.Filters; -import com.google.cloud.bigtable.data.v2.models.KeyOffset; -import com.google.cloud.bigtable.data.v2.models.Query; -import com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow; -import com.google.cloud.bigtable.data.v2.models.RowMutation; -import com.google.cloud.bigtable.grpc.BigtableDataClient; -import com.google.cloud.bigtable.grpc.BigtableSession; -import com.google.cloud.bigtable.grpc.BigtableTableName; -import com.google.cloud.bigtable.grpc.scanner.FlatRow; -import com.google.cloud.bigtable.grpc.scanner.ResultScanner; -import com.google.cloud.bigtable.hbase.adapters.Adapters; -import com.google.cloud.bigtable.hbase.adapters.read.RowCell; -import com.google.cloud.bigtable.hbase.util.ByteStringer; -import com.google.cloud.bigtable.hbase.util.TimestampConverter; -import com.google.cloud.bigtable.hbase.wrappers.BulkMutationWrapper; -import com.google.cloud.bigtable.hbase.wrappers.BulkReadWrapper; -import com.google.cloud.bigtable.hbase.wrappers.DataClientWrapper; -import com.google.cloud.bigtable.util.ApiFutureUtil; -import com.google.common.base.Function; -import com.google.common.collect.ImmutableList; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.MoreExecutors; -import com.google.protobuf.ByteString; -import io.grpc.stub.StreamObserver; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import javax.annotation.Nullable; -import org.apache.hadoop.hbase.client.AbstractClientScanner; -import org.apache.hadoop.hbase.client.Result; - -/** For internal use only - public for technical reasons. */ -@InternalApi("For internal usage only") -public class DataClientClassicApi implements DataClientWrapper { - - private final BigtableSession session; - private final BigtableDataClient delegate; - private final RequestContext requestContext; - - DataClientClassicApi(BigtableSession session, RequestContext requestContext) { - this.session = session; - this.delegate = session.getDataClient(); - this.requestContext = requestContext; - } - - @Override - public BulkMutationWrapper createBulkMutation(String tableId) { - BigtableTableName tableName = - new BigtableTableName( - NameUtil.formatTableName( - requestContext.getProjectId(), requestContext.getInstanceId(), tableId)); - return new BulkMutationClassicApi(session.createBulkMutation(tableName)); - } - - @Override - public BulkReadWrapper createBulkRead(String tableId) { - BigtableTableName tableName = - new BigtableTableName( - NameUtil.formatTableName( - requestContext.getProjectId(), requestContext.getInstanceId(), tableId)); - return new BulkReadClassicApi(session.createBulkRead(tableName), tableId); - } - - @Override - public ApiFuture mutateRowAsync(RowMutation rowMutation) { - ListenableFuture response = - delegate.mutateRowAsync(rowMutation.toProto(requestContext)); - return ApiFutureUtil.transformAndAdapt( - response, - new Function() { - @Nullable - @Override - public Void apply(@Nullable MutateRowResponse mutateRowResponse) { - return null; - } - }); - } - - @Override - public ApiFuture readModifyWriteRowAsync(ReadModifyWriteRow readModifyWriteRow) { - ListenableFuture response = - delegate.readModifyWriteRowAsync(readModifyWriteRow.toProto(requestContext)); - return ApiFutureUtil.transformAndAdapt( - response, - new Function() { - @Override - public Result apply(ReadModifyWriteRowResponse response) { - return transformRowToResult(response.getRow()); - } - }); - } - - @Override - public ApiFuture checkAndMutateRowAsync(ConditionalRowMutation conditionalRowMutation) { - final CheckAndMutateRowRequest request = conditionalRowMutation.toProto(requestContext); - final ListenableFuture response = - delegate.checkAndMutateRowAsync(request); - return ApiFutureUtil.transformAndAdapt( - response, - new Function() { - @Override - public Boolean apply(CheckAndMutateRowResponse checkAndMutateRowResponse) { - return checkAndMutateRowResponse.getPredicateMatched(); - } - }); - } - - @Override - public ApiFuture> sampleRowKeysAsync(String tableId) { - String fullTableName = - NameUtil.formatTableName( - requestContext.getProjectId(), requestContext.getInstanceId(), tableId); - SampleRowKeysRequest requestProto = - SampleRowKeysRequest.newBuilder().setTableName(fullTableName).build(); - ListenableFuture> responseProto = - delegate.sampleRowKeysAsync(requestProto); - - return ApiFutureUtil.transformAndAdapt( - responseProto, - new Function, List>() { - @Override - public List apply(List rowKeysList) { - ImmutableList.Builder keyOffsetBuilder = ImmutableList.builder(); - for (SampleRowKeysResponse rowKeys : rowKeysList) { - keyOffsetBuilder.add(KeyOffset.create(rowKeys.getRowKey(), rowKeys.getOffsetBytes())); - } - - return keyOffsetBuilder.build(); - } - }); - } - - @Override - public ApiFuture readRowAsync(String tableId, ByteString rowKey, Filters.Filter filter) { - Query request = Query.create(tableId).rowKey(rowKey).limit(1L); - if (filter != null) { - request.filter(filter); - } - - return ApiFutureUtil.transformAndAdapt( - delegate.readFlatRowsAsync(request.toProto(requestContext)), - new Function, Result>() { - @Override - public Result apply(List flatRows) { - if (flatRows.isEmpty()) { - return Result.EMPTY_RESULT; - } - return Adapters.FLAT_ROW_ADAPTER.adaptResponse(flatRows.get(0)); - } - }); - } - - @Override - public org.apache.hadoop.hbase.client.ResultScanner readRows(Query request) { - final ResultScanner bigtableResultScanner = - delegate.readFlatRows(request.toProto(requestContext)); - - return new AbstractClientScanner() { - @Override - public Result next() throws IOException { - FlatRow flatRow = bigtableResultScanner.next(); - if (flatRow == null) { - // Null signals EOF. - return null; - } - return Adapters.FLAT_ROW_ADAPTER.adaptResponse(flatRow); - } - - @Override - public void close() { - try { - bigtableResultScanner.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - // This is copied over form BigtableResultScannerAdapter. - /** - * This is an HBase concept that was added in HBase 1.0.2. It's not relevant for Cloud - * Bigtable. It will not be called from the HBase code and should not be called by the user. - */ - // Developers Note: Do not add @Override so that this can remain backwards compatible with - // 1.0.1. - public boolean renewLease() { - throw new UnsupportedOperationException("renewLease"); - } - }; - } - - @Override - public ApiFuture> readRowsAsync(Query request) { - return ApiFutures.transform( - ApiFutureUtil.adapt(delegate.readFlatRowsAsync(request.toProto(requestContext))), - new ApiFunction, List>() { - @Override - public List apply(List rows) { - ImmutableList.Builder resultList = ImmutableList.builder(); - for (FlatRow flatRow : rows) { - resultList.add(Adapters.FLAT_ROW_ADAPTER.adaptResponse(flatRow)); - } - return resultList.build(); - } - }, - MoreExecutors.directExecutor()); - } - - @Override - public void readRowsAsync(Query request, final StreamObserver observer) { - delegate.readFlatRows( - request.toProto(requestContext), - new StreamObserver() { - @Override - public void onNext(FlatRow flatRow) { - observer.onNext(Adapters.FLAT_ROW_ADAPTER.adaptResponse(flatRow)); - } - - @Override - public void onError(Throwable throwable) { - observer.onError(throwable); - } - - @Override - public void onCompleted() { - observer.onCompleted(); - } - }); - } - - @Override - public void close() throws IOException { - session.close(); - } - - private static Result transformRowToResult(Row row) { - List hbaseCells = new ArrayList<>(); - byte[] rowKeyBytes = ByteStringer.extract(row.getKey()); - - for (Family family : row.getFamiliesList()) { - byte[] familyBytes = ByteStringer.extract(family.getNameBytes()); - - for (Column column : family.getColumnsList()) { - byte[] qualifierBytes = ByteStringer.extract(column.getQualifier()); - - for (Cell cell : column.getCellsList()) { - hbaseCells.add(toRowCell(rowKeyBytes, familyBytes, qualifierBytes, cell)); - } - } - } - return Result.create(hbaseCells); - } - - private static RowCell toRowCell(byte[] rowKey, byte[] family, byte[] qualifier, Cell cell) { - return new RowCell( - rowKey, - family, - qualifier, - TimestampConverter.bigtable2hbase(cell.getTimestampMicros()), - ByteStringer.extract(cell.getValue()), - cell.getLabelsList()); - } -} diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/veneer/metrics/MetricsApiTracerAdapter.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/veneer/metrics/MetricsApiTracerAdapter.java index 8cdbf72192..f333893ed7 100644 --- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/veneer/metrics/MetricsApiTracerAdapter.java +++ b/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/wrappers/veneer/metrics/MetricsApiTracerAdapter.java @@ -16,8 +16,8 @@ package com.google.cloud.bigtable.hbase.wrappers.veneer.metrics; import com.google.api.core.InternalApi; -import com.google.api.gax.tracing.ApiTracer; import com.google.api.gax.tracing.ApiTracerFactory.OperationType; +import com.google.api.gax.tracing.BaseApiTracer; import com.google.cloud.bigtable.metrics.BigtableClientMetrics; import com.google.cloud.bigtable.metrics.BigtableClientMetrics.MetricLevel; import com.google.cloud.bigtable.metrics.Counter; @@ -35,7 +35,7 @@ * its lifecycle. */ @InternalApi -public class MetricsApiTracerAdapter implements ApiTracer { +public class MetricsApiTracerAdapter extends BaseApiTracer { private final Timer firstResponseLatencyTimer = BigtableClientMetrics.timer(MetricLevel.Info, "grpc.method.ReadRows.firstResponse.latency"); diff --git a/bigtable-client-core-parent/bigtable-hbase/src/main/java/org/apache/hadoop/hbase/client/AbstractBigtableConnection.java b/bigtable-client-core-parent/bigtable-hbase/src/main/java/org/apache/hadoop/hbase/client/AbstractBigtableConnection.java index d17632cadc..df2c2a809f 100644 --- a/bigtable-client-core-parent/bigtable-hbase/src/main/java/org/apache/hadoop/hbase/client/AbstractBigtableConnection.java +++ b/bigtable-client-core-parent/bigtable-hbase/src/main/java/org/apache/hadoop/hbase/client/AbstractBigtableConnection.java @@ -27,8 +27,6 @@ import com.google.cloud.bigtable.hbase.util.Logger; import com.google.cloud.bigtable.hbase.wrappers.BigtableApi; import com.google.cloud.bigtable.hbase.wrappers.BigtableHBaseSettings; -import com.google.cloud.bigtable.hbase.wrappers.classic.BigtableHBaseClassicSettings; -import com.google.cloud.bigtable.hbase.wrappers.veneer.BigtableHBaseVeneerSettings; import com.google.common.base.MoreObjects; import java.io.Closeable; import java.io.IOException; @@ -304,10 +302,7 @@ private void shutdownBatchPool() { * @return a {@link com.google.cloud.bigtable.config.BigtableOptions} object. */ public BigtableOptions getOptions() { - if (settings instanceof BigtableHBaseVeneerSettings) { - throw new UnsupportedOperationException("veneer client does not support BigtableOptions"); - } - return ((BigtableHBaseClassicSettings) settings).getBigtableOptions(); + throw new UnsupportedOperationException("veneer client does not support BigtableOptions"); } @Override diff --git a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestAdminClientClassicApi.java b/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestAdminClientClassicApi.java deleted file mode 100644 index 07acbd2c92..0000000000 --- a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestAdminClientClassicApi.java +++ /dev/null @@ -1,282 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.bigtable.hbase.wrappers.classic; - -import static com.google.cloud.bigtable.admin.v2.models.GCRules.GCRULES; -import static com.google.common.util.concurrent.Futures.immediateFuture; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import com.google.bigtable.admin.v2.*; -import com.google.bigtable.admin.v2.Cluster; -import com.google.bigtable.admin.v2.ColumnFamily; -import com.google.bigtable.admin.v2.ListClustersResponse.Builder; -import com.google.cloud.bigtable.admin.v2.internal.NameUtil; -import com.google.cloud.bigtable.admin.v2.models.*; -import com.google.cloud.bigtable.admin.v2.models.Backup; -import com.google.cloud.bigtable.admin.v2.models.CreateBackupRequest; -import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest; -import com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest; -import com.google.cloud.bigtable.admin.v2.models.RestoreTableRequest; -import com.google.cloud.bigtable.admin.v2.models.Table; -import com.google.cloud.bigtable.grpc.BigtableClusterName; -import com.google.cloud.bigtable.grpc.BigtableInstanceClient; -import com.google.cloud.bigtable.grpc.BigtableInstanceName; -import com.google.cloud.bigtable.grpc.BigtableTableAdminClient; -import com.google.cloud.bigtable.hbase.wrappers.AdminClientWrapper; -import com.google.common.collect.ImmutableList; -import com.google.common.util.concurrent.Futures; -import com.google.longrunning.Operation; -import com.google.protobuf.Any; -import com.google.protobuf.ByteString; -import com.google.protobuf.Empty; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.mockito.Mockito; -import org.threeten.bp.Duration; - -@RunWith(JUnit4.class) -public class TestAdminClientClassicApi { - - private static final String PROJECT_ID = "fake-project-id"; - private static final String INSTANCE_ID = "fake-instance-id"; - private static final BigtableInstanceName INSTANCE_NAME = - new BigtableInstanceName(PROJECT_ID, INSTANCE_ID); - - private static final String TABLE_ID = "fake-Table-id"; - private static final String CLUSTER_ID = "fake-cluster-id"; - private static final String TABLE_NAME = - NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID); - - private static final String COLUMN_FAMILY = "myColumnFamily"; - private static final String ROW_KEY_PREFIX = "row-key-val"; - private static final String UPDATE_FAMILY = "update-family"; - private static final String BACKUP_ID = "fake-backup-id"; - private static final BigtableClusterName CLUSTER_NAME = INSTANCE_NAME.toClusterName(CLUSTER_ID); - private static final String BACKUP_NAME = CLUSTER_NAME.toBackupName(BACKUP_ID); - - private BigtableTableAdminClient tableDelegate; - private BigtableInstanceClient instanceDelegate; - - private AdminClientWrapper adminClientWrapper; - - @Before - public void setUp() { - tableDelegate = Mockito.mock(BigtableTableAdminClient.class); - instanceDelegate = Mockito.mock(BigtableInstanceClient.class); - adminClientWrapper = new AdminClientClassicApi(tableDelegate, INSTANCE_NAME, instanceDelegate); - } - - @Test - public void testCreateTableAsync() throws Exception { - CreateTableRequest request = CreateTableRequest.of(TABLE_ID); - - when(tableDelegate.createTableAsync(request.toProto(PROJECT_ID, INSTANCE_ID))) - .thenReturn(immediateFuture(createTableData())); - - assertEquals( - Table.fromProto(createTableData()), adminClientWrapper.createTableAsync(request).get()); - verify(tableDelegate).createTableAsync(request.toProto(PROJECT_ID, INSTANCE_ID)); - } - - @Test - public void testGetTableAsync() throws Exception { - GetTableRequest request = GetTableRequest.newBuilder().setName(TABLE_NAME).build(); - when(tableDelegate.getTableAsync(request)).thenReturn(immediateFuture(createTableData())); - - assertEquals( - Table.fromProto(createTableData()), adminClientWrapper.getTableAsync(TABLE_ID).get()); - verify(tableDelegate).getTableAsync(request); - } - - @Test - public void testListTablesAsync() throws Exception { - ImmutableList tableIdList = - ImmutableList.of("test-table-1", "test-table-2", "test-table-3"); - ListTablesRequest request = - ListTablesRequest.newBuilder().setParent(INSTANCE_NAME.toString()).build(); - ListTablesResponse.Builder builder = ListTablesResponse.newBuilder(); - builder.addTablesBuilder().setName(INSTANCE_NAME.toTableNameStr("test-table-1")).build(); - builder.addTablesBuilder().setName(INSTANCE_NAME.toTableNameStr("test-table-2")).build(); - builder.addTablesBuilder().setName(INSTANCE_NAME.toTableNameStr("test-table-3")).build(); - when(tableDelegate.listTablesAsync(request)).thenReturn(immediateFuture(builder.build())); - - assertEquals(tableIdList, adminClientWrapper.listTablesAsync().get()); - verify(tableDelegate).listTablesAsync(request); - } - - @Test - public void testDeleteTableAsync() throws ExecutionException, InterruptedException { - DeleteTableRequest request = DeleteTableRequest.newBuilder().setName(TABLE_NAME).build(); - when(tableDelegate.deleteTableAsync(request)) - .thenReturn(immediateFuture(Empty.newBuilder().build())); - adminClientWrapper.deleteTableAsync(TABLE_ID).get(); - - verify(tableDelegate).deleteTableAsync(request); - } - - @Test - public void testModifyFamiliesAsync() throws Exception { - ModifyColumnFamiliesRequest request = - ModifyColumnFamiliesRequest.of(TABLE_ID) - .addFamily(COLUMN_FAMILY, GCRULES.maxVersions(1)) - .updateFamily(UPDATE_FAMILY, GCRULES.maxAge(Duration.ofHours(100))); - - when(tableDelegate.modifyColumnFamilyAsync(request.toProto(PROJECT_ID, INSTANCE_ID))) - .thenReturn(immediateFuture(createTableData())); - Future
response = adminClientWrapper.modifyFamiliesAsync(request); - - assertEquals(Table.fromProto(createTableData()), response.get()); - verify(tableDelegate).modifyColumnFamilyAsync(request.toProto(PROJECT_ID, INSTANCE_ID)); - } - - @Test - public void dropRowRangeAsyncForDeleteByPrefix() throws ExecutionException, InterruptedException { - ByteString rowKey = ByteString.copyFrom(new byte[] {0, -32, 122, 13}); - DropRowRangeRequest request = - DropRowRangeRequest.newBuilder() - .setName(TABLE_NAME) - .setDeleteAllDataFromTable(false) - .setRowKeyPrefix(rowKey) - .build(); - - when(tableDelegate.dropRowRangeAsync(request)) - .thenReturn(immediateFuture(Empty.newBuilder().build())); - adminClientWrapper.dropRowRangeAsync(TABLE_ID, rowKey).get(); - - verify(tableDelegate).dropRowRangeAsync(request); - } - - @Test - public void dropRowRangeAsyncForTruncate() throws ExecutionException, InterruptedException { - DropRowRangeRequest request = - DropRowRangeRequest.newBuilder() - .setName(TABLE_NAME) - .setDeleteAllDataFromTable(true) - .build(); - - when(tableDelegate.dropRowRangeAsync(request)) - .thenReturn(immediateFuture(Empty.newBuilder().build())); - adminClientWrapper.dropAllRowsAsync(TABLE_ID).get(); - - verify(tableDelegate).dropRowRangeAsync(request); - } - - @Test - public void listClusters() { - ListClustersRequest request = - ListClustersRequest.newBuilder().setParent(INSTANCE_NAME.getInstanceName()).build(); - Builder builder = ListClustersResponse.newBuilder(); - Cluster cluster = Cluster.newBuilder().setName(CLUSTER_ID).build(); - builder.addClusters(cluster); - ListClustersResponse listClustersResponse = builder.build(); - when(instanceDelegate.listCluster(request)).thenReturn(listClustersResponse); - - List expected = new ArrayList<>(); - expected.add(com.google.cloud.bigtable.admin.v2.models.Cluster.fromProto(cluster)); - - List actual = - adminClientWrapper.listClusters(INSTANCE_ID); - assertEquals(expected, actual); - } - - @Test - public void testCreateBackupAsync() throws Exception { - CreateBackupRequest request = - CreateBackupRequest.of(CLUSTER_ID, BACKUP_ID).setSourceTableId(TABLE_NAME); - com.google.bigtable.admin.v2.CreateBackupRequest requestProto = - request.toProto(PROJECT_ID, INSTANCE_ID); - Operation op = - Operation.newBuilder() - .setMetadata(Any.pack(CreateBackupMetadata.getDefaultInstance())) - .setResponse( - Any.pack( - com.google.bigtable.admin.v2.Backup.newBuilder() - .setName(BACKUP_NAME) - .setSourceTable(TABLE_NAME) - .build())) - .build(); - when(tableDelegate.waitForOperation(op)).thenReturn(op); - when(tableDelegate.createBackupAsync(requestProto)).thenReturn(Futures.immediateFuture(op)); - Future actualResponse = adminClientWrapper.createBackupAsync(request); - assertEquals(BACKUP_ID, actualResponse.get().getId()); - verify(tableDelegate).createBackupAsync(requestProto); - } - - @Test - public void testListBackupsAsync() throws Exception { - ListBackupsRequest request = - ListBackupsRequest.newBuilder().setParent(CLUSTER_NAME.toString()).build(); - ListBackupsResponse response = - ListBackupsResponse.newBuilder() - .addBackups( - com.google.bigtable.admin.v2.Backup.newBuilder() - .setName(BACKUP_NAME) - .setSourceTable(TABLE_NAME) - .build()) - .build(); - when(tableDelegate.listBackupsAsync(request)).thenReturn(Futures.immediateFuture(response)); - Future> actualResponse = adminClientWrapper.listBackupsAsync(CLUSTER_ID); - assertEquals(response.getBackupsCount(), actualResponse.get().size()); - verify(tableDelegate).listBackupsAsync(request); - } - - @Test - public void testDeleteBackupAsync() { - DeleteBackupRequest request = DeleteBackupRequest.newBuilder().setName(BACKUP_NAME).build(); - when(tableDelegate.deleteBackupAsync(request)) - .thenReturn(Futures.immediateFuture(Empty.getDefaultInstance())); - adminClientWrapper.deleteBackupAsync(CLUSTER_ID, BACKUP_ID); - verify(tableDelegate).deleteBackupAsync(request); - } - - @Test - public void testRestoreTableAsync() throws Exception { - RestoreTableRequest request = - RestoreTableRequest.of(CLUSTER_ID, BACKUP_ID).setTableId(TABLE_ID); - com.google.bigtable.admin.v2.RestoreTableRequest requestProto = - request.toProto(PROJECT_ID, INSTANCE_ID); - Operation op = - Operation.newBuilder() - .setMetadata(Any.pack(RestoreTableMetadata.newBuilder().setName(BACKUP_NAME).build())) - .setResponse( - Any.pack( - com.google.bigtable.admin.v2.Table.newBuilder().setName(TABLE_NAME).build())) - .build(); - when(tableDelegate.waitForOperation(op)).thenReturn(op); - when(tableDelegate.restoreTableAsync(requestProto)).thenReturn(Futures.immediateFuture(op)); - Future actualResponse = adminClientWrapper.restoreTableAsync(request); - assertEquals(TABLE_ID, actualResponse.get().getTable().getId()); - verify(tableDelegate).restoreTableAsync(requestProto); - } - - private static com.google.bigtable.admin.v2.Table createTableData() { - GCRules.GCRule gcRule = GCRULES.maxVersions(1); - ColumnFamily columnFamily = ColumnFamily.newBuilder().setGcRule(gcRule.toProto()).build(); - - return com.google.bigtable.admin.v2.Table.newBuilder() - .setName(TABLE_NAME) - .putColumnFamilies(COLUMN_FAMILY, columnFamily) - .build(); - } -} diff --git a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestBigtableClassicApi.java b/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestBigtableClassicApi.java deleted file mode 100644 index 57f009ed98..0000000000 --- a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestBigtableClassicApi.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.bigtable.hbase.wrappers.classic; - -import static com.google.cloud.bigtable.admin.v2.internal.NameUtil.extractTableIdFromTableName; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - -import com.google.bigtable.admin.v2.BigtableTableAdminGrpc; -import com.google.bigtable.admin.v2.DeleteTableRequest; -import com.google.bigtable.v2.BigtableGrpc; -import com.google.bigtable.v2.ReadRowsRequest; -import com.google.bigtable.v2.ReadRowsResponse; -import com.google.cloud.bigtable.data.v2.models.Query; -import com.google.cloud.bigtable.grpc.BigtableSession; -import com.google.cloud.bigtable.hbase.BigtableOptionsFactory; -import com.google.cloud.bigtable.hbase.wrappers.BigtableApi; -import com.google.cloud.bigtable.hbase.wrappers.BigtableHBaseSettings; -import com.google.cloud.bigtable.test.helper.TestServerBuilder; -import com.google.common.collect.Queues; -import com.google.protobuf.Empty; -import io.grpc.Server; -import io.grpc.stub.StreamObserver; -import java.io.IOException; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.TimeUnit; -import org.apache.hadoop.conf.Configuration; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -@RunWith(JUnit4.class) -public class TestBigtableClassicApi { - - private static final String TEST_PROJECT_ID = "fake-project-id"; - private static final String TEST_INSTANCE_ID = "fake-instance-id"; - private static final String ROW_KEY = "test-row-key"; - private static final String TABLE_ID = "test-table-id"; - - private static FakeDataService fakeDataService = new FakeDataService(); - private static FakeAdminService fakeAdminService = new FakeAdminService(); - private static Server server; - - private BigtableHBaseSettings bigtableHBaseSettings; - private BigtableApi bigtableApi; - - @BeforeClass - public static void setUpServer() throws IOException { - server = - TestServerBuilder.newInstance() - .addService(fakeDataService) - .addService(fakeAdminService) - .buildAndStart(); - } - - @AfterClass - public static void tearDownServer() throws InterruptedException { - if (server != null) { - server.shutdownNow(); - server.awaitTermination(); - } - } - - @Before - public void setUp() throws IOException { - Configuration configuration = new Configuration(false); - configuration.set(BigtableOptionsFactory.PROJECT_ID_KEY, TEST_PROJECT_ID); - configuration.set(BigtableOptionsFactory.INSTANCE_ID_KEY, TEST_INSTANCE_ID); - configuration.set(BigtableOptionsFactory.BIGTABLE_NULL_CREDENTIAL_ENABLE_KEY, "true"); - configuration.set(BigtableOptionsFactory.BIGTABLE_DATA_CHANNEL_COUNT_KEY, "1"); - configuration.set( - BigtableOptionsFactory.BIGTABLE_EMULATOR_HOST_KEY, "localhost:" + server.getPort()); - configuration.setBoolean(BigtableOptionsFactory.BIGTABLE_USE_GCJ_CLIENT, false); - bigtableHBaseSettings = BigtableHBaseClassicSettings.create(configuration); - bigtableApi = BigtableApi.create(bigtableHBaseSettings); - } - - @After - public void tearDown() throws Exception { - bigtableApi.close(); - } - - @Test - public void testWithAlreadyBuildBigtableSession() throws Exception { - BigtableHBaseClassicSettings settings = (BigtableHBaseClassicSettings) bigtableHBaseSettings; - - try (BigtableSession session = new BigtableSession(settings.getBigtableOptions()); - BigtableApi bigtableApi = new BigtableClassicApi(settings, session)) { - - assertSame(settings, bigtableApi.getBigtableHBaseSettings()); - - bigtableApi.getAdminClient().deleteTableAsync(TABLE_ID).get(); - DeleteTableRequest deleteTableRequest = fakeAdminService.popLastRequest(); - assertEquals(TABLE_ID, extractTableIdFromTableName(deleteTableRequest.getName())); - - Query query = Query.create(TABLE_ID).rowKey(ROW_KEY); - bigtableApi.getDataClient().readRowsAsync(query); - ReadRowsRequest request = fakeDataService.popLastRequest(); - assertEquals(ROW_KEY, request.getRows().getRowKeys(0).toStringUtf8()); - } - } - - @Test - public void testAdminClient() throws Exception { - assertTrue(bigtableApi.getAdminClient() instanceof AdminClientClassicApi); - - bigtableApi.getAdminClient().deleteTableAsync(TABLE_ID).get(); - DeleteTableRequest deleteTableRequest = fakeAdminService.popLastRequest(); - assertEquals(TABLE_ID, extractTableIdFromTableName(deleteTableRequest.getName())); - } - - @Test - public void testDataClient() throws Exception { - assertTrue(bigtableApi.getDataClient() instanceof DataClientClassicApi); - - Query query = Query.create(TABLE_ID).rowKey(ROW_KEY); - bigtableApi.getDataClient().readRowsAsync(query); - ReadRowsRequest request = fakeDataService.popLastRequest(); - assertEquals(ROW_KEY, request.getRows().getRowKeys(0).toStringUtf8()); - } - - @Test - public void testBigtableHBaseSettings() { - assertSame(bigtableHBaseSettings, bigtableApi.getBigtableHBaseSettings()); - } - - private static class FakeDataService extends BigtableGrpc.BigtableImplBase { - final BlockingQueue requests = Queues.newLinkedBlockingDeque(); - - @SuppressWarnings("unchecked") - T popLastRequest() throws InterruptedException { - return (T) requests.poll(1, TimeUnit.SECONDS); - } - - @Override - public void readRows( - ReadRowsRequest request, StreamObserver responseObserver) { - requests.add(request); - responseObserver.onNext(ReadRowsResponse.getDefaultInstance()); - responseObserver.onCompleted(); - } - } - - private static class FakeAdminService extends BigtableTableAdminGrpc.BigtableTableAdminImplBase { - - final BlockingQueue requests = Queues.newLinkedBlockingDeque(); - - @SuppressWarnings("unchecked") - T popLastRequest() throws InterruptedException { - return (T) requests.poll(1, TimeUnit.SECONDS); - } - - @Override - public void deleteTable(DeleteTableRequest request, StreamObserver responseObserver) { - requests.add(request); - responseObserver.onNext(Empty.getDefaultInstance()); - responseObserver.onCompleted(); - } - } -} diff --git a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestBulkMutationClassicApi.java b/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestBulkMutationClassicApi.java deleted file mode 100644 index 7c5c8f96bd..0000000000 --- a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestBulkMutationClassicApi.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.bigtable.hbase.wrappers.classic; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import com.google.bigtable.v2.MutateRowResponse; -import com.google.bigtable.v2.MutateRowsRequest; -import com.google.cloud.bigtable.data.v2.models.RowMutationEntry; -import com.google.cloud.bigtable.grpc.async.BulkMutation; -import com.google.cloud.bigtable.hbase.wrappers.BulkMutationWrapper; -import com.google.common.util.concurrent.Futures; -import java.io.IOException; -import java.util.concurrent.ExecutionException; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.mockito.Mockito; - -@RunWith(JUnit4.class) -public class TestBulkMutationClassicApi { - - private BulkMutation mockDelegate; - private BulkMutationWrapper bulkMutationWrapper; - - @Before - public void setUp() { - mockDelegate = Mockito.mock(BulkMutation.class); - bulkMutationWrapper = new BulkMutationClassicApi(mockDelegate); - } - - @Test - public void testAddMutate() throws ExecutionException, InterruptedException { - RowMutationEntry rowMutation = RowMutationEntry.create("key"); - MutateRowsRequest.Entry requestProto = rowMutation.toProto(); - when(mockDelegate.add(requestProto)) - .thenReturn(Futures.immediateFuture(MutateRowResponse.getDefaultInstance())); - bulkMutationWrapper.add(rowMutation).get(); - - verify(mockDelegate).add(requestProto); - } - - @Test - public void testFlush() throws InterruptedException { - doNothing().when(mockDelegate).flush(); - bulkMutationWrapper.flush(); - verify(mockDelegate).flush(); - } - - @Test - public void testSendUnsent() { - doNothing().when(mockDelegate).sendUnsent(); - bulkMutationWrapper.sendUnsent(); - verify(mockDelegate).sendUnsent(); - } - - @Test - public void testClose() throws IOException { - bulkMutationWrapper.close(); - try { - bulkMutationWrapper.add(RowMutationEntry.create("key")); - Assert.fail("bulk mutation should be closed"); - } catch (IllegalStateException actualEx) { - assertEquals("can't mutate when the bulk mutation is closed.", actualEx.getMessage()); - } - } -} diff --git a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestBulkReadClassicApi.java b/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestBulkReadClassicApi.java deleted file mode 100644 index 6e0ab92c3b..0000000000 --- a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestBulkReadClassicApi.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.bigtable.hbase.wrappers.classic; - -import static com.google.cloud.bigtable.hbase.adapters.Adapters.FLAT_ROW_ADAPTER; -import static org.junit.Assert.assertArrayEquals; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import com.google.api.core.ApiFutures; -import com.google.cloud.bigtable.data.v2.models.Filters; -import com.google.cloud.bigtable.data.v2.models.Query; -import com.google.cloud.bigtable.grpc.async.BulkRead; -import com.google.cloud.bigtable.grpc.scanner.FlatRow; -import com.google.cloud.bigtable.hbase.wrappers.BulkReadWrapper; -import com.google.protobuf.ByteString; -import java.util.concurrent.ExecutionException; -import org.apache.hadoop.hbase.client.Result; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.mockito.Mockito; - -@RunWith(JUnit4.class) -public class TestBulkReadClassicApi { - - private static final String TABLE_ID = "fake-Table-id"; - private static final FlatRow FLAT_ROW = - FlatRow.newBuilder() - .withRowKey(ByteString.copyFromUtf8("row-key")) - .addCell("cf", ByteString.copyFromUtf8("q1"), 10000L, ByteString.copyFromUtf8("value")) - .build(); - - private BulkRead delegate; - private BulkReadWrapper bulkReadWrapper; - - @Before - public void setUp() { - delegate = Mockito.mock(BulkRead.class); - bulkReadWrapper = new BulkReadClassicApi(delegate, TABLE_ID); - } - - @Test - public void testAdd() throws ExecutionException, InterruptedException { - when(delegate.add(Query.create(TABLE_ID).rowKey("row-key"))) - .thenReturn(ApiFutures.immediateFuture(FLAT_ROW)); - Result result = bulkReadWrapper.add(ByteString.copyFromUtf8("row-key"), null).get(); - assertArrayEquals(FLAT_ROW.getRowKey().toByteArray(), result.getRow()); - assertArrayEquals(FLAT_ROW_ADAPTER.adaptResponse(FLAT_ROW).rawCells(), result.rawCells()); - verify(delegate).add(Query.create(TABLE_ID).rowKey("row-key")); - } - - @Test - public void testAddWithFilter() throws ExecutionException, InterruptedException { - Filters.Filter filter = Filters.FILTERS.family().regex("cf"); - Query query = Query.create(TABLE_ID).rowKey("row-key").filter(filter); - - when(delegate.add(query)).thenReturn(ApiFutures.immediateFuture(FLAT_ROW)); - Result result = bulkReadWrapper.add(ByteString.copyFromUtf8("row-key"), filter).get(); - - assertArrayEquals(FLAT_ROW.getRowKey().toByteArray(), result.getRow()); - assertArrayEquals(FLAT_ROW_ADAPTER.adaptResponse(FLAT_ROW).rawCells(), result.rawCells()); - verify(delegate).add(query); - } - - @Test - public void testSendOutstanding() { - doNothing().when(delegate).flush(); - bulkReadWrapper.sendOutstanding(); - verify(delegate).flush(); - } -} diff --git a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestDataClientClassicApi.java b/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestDataClientClassicApi.java deleted file mode 100644 index 6c945144f2..0000000000 --- a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/classic/TestDataClientClassicApi.java +++ /dev/null @@ -1,461 +0,0 @@ -/* - * Copyright 2020 Google LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.google.cloud.bigtable.hbase.wrappers.classic; - -import static com.google.cloud.bigtable.hbase.adapters.Adapters.FLAT_ROW_ADAPTER; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import com.google.bigtable.v2.Cell; -import com.google.bigtable.v2.CheckAndMutateRowRequest; -import com.google.bigtable.v2.CheckAndMutateRowResponse; -import com.google.bigtable.v2.Column; -import com.google.bigtable.v2.Family; -import com.google.bigtable.v2.MutateRowRequest; -import com.google.bigtable.v2.MutateRowResponse; -import com.google.bigtable.v2.ReadModifyWriteRowRequest; -import com.google.bigtable.v2.ReadModifyWriteRowResponse; -import com.google.bigtable.v2.ReadRowsRequest; -import com.google.bigtable.v2.Row; -import com.google.bigtable.v2.SampleRowKeysRequest; -import com.google.bigtable.v2.SampleRowKeysResponse; -import com.google.cloud.bigtable.data.v2.internal.NameUtil; -import com.google.cloud.bigtable.data.v2.internal.RequestContext; -import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation; -import com.google.cloud.bigtable.data.v2.models.Filters; -import com.google.cloud.bigtable.data.v2.models.KeyOffset; -import com.google.cloud.bigtable.data.v2.models.Mutation; -import com.google.cloud.bigtable.data.v2.models.Query; -import com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow; -import com.google.cloud.bigtable.data.v2.models.RowMutation; -import com.google.cloud.bigtable.grpc.BigtableDataClient; -import com.google.cloud.bigtable.grpc.BigtableSession; -import com.google.cloud.bigtable.grpc.BigtableTableName; -import com.google.cloud.bigtable.grpc.async.BulkMutation; -import com.google.cloud.bigtable.grpc.async.BulkRead; -import com.google.cloud.bigtable.grpc.scanner.FlatRow; -import com.google.cloud.bigtable.grpc.scanner.ResultScanner; -import com.google.cloud.bigtable.grpc.scanner.ScanHandler; -import com.google.cloud.bigtable.hbase.adapters.read.RowCell; -import com.google.cloud.bigtable.hbase.wrappers.DataClientWrapper; -import com.google.common.collect.ImmutableList; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.protobuf.ByteString; -import io.grpc.stub.StreamObserver; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import org.apache.hadoop.hbase.CellUtil; -import org.apache.hadoop.hbase.client.Result; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; -import org.mockito.stubbing.Answer; - -@RunWith(JUnit4.class) -public class TestDataClientClassicApi { - - @Rule public final MockitoRule mockitoRule = MockitoJUnit.rule(); - - private static final String PROJECT_ID = "projectId"; - private static final String INSTANCE_ID = "instanceId"; - private static final String TABLE_ID = "tableId"; - private static final String APP_PROFILE_ID = "appProfileId"; - - private static final ByteString ROW_KEY = ByteString.copyFromUtf8("test-key"); - private static final ByteString QUALIFIER = ByteString.copyFromUtf8("qualifier1"); - private static final int TIMESTAMP = 12345; - private static final ByteString VALUE = ByteString.copyFromUtf8("test-value"); - - private static final FlatRow SAMPLE_FLAT_ROW = - FlatRow.newBuilder() - .withRowKey(ByteString.copyFromUtf8("key")) - .addCell("cf", QUALIFIER, TIMESTAMP, VALUE) - .addCell("cf2", QUALIFIER, TIMESTAMP, VALUE) - .build(); - - private static final RequestContext REQUEST_CONTEXT = - RequestContext.create(PROJECT_ID, INSTANCE_ID, APP_PROFILE_ID); - - @Mock private BigtableDataClient delegate; - - @Mock private BigtableSession bigtableSession; - - @Mock private ResultScanner mockFlatRowScanner; - - private DataClientWrapper dataClientWrapper; - - @Before - public void setUp() { - when(bigtableSession.getDataClient()).thenReturn(delegate); - dataClientWrapper = new DataClientClassicApi(bigtableSession, REQUEST_CONTEXT); - } - - @Test - public void testCreateBulkMutation() { - BulkMutation mockBulkMutation = Mockito.mock(BulkMutation.class); - when(bigtableSession.createBulkMutation(Mockito.any())) - .thenReturn(mockBulkMutation); - assertTrue(dataClientWrapper.createBulkMutation(TABLE_ID) instanceof BulkMutationClassicApi); - verify(bigtableSession).createBulkMutation(Mockito.any()); - } - - @Test - public void testCreateBulkRead() { - BulkRead mockBulkRead = Mockito.mock(BulkRead.class); - when(bigtableSession.createBulkRead(Mockito.any())).thenReturn(mockBulkRead); - assertTrue(dataClientWrapper.createBulkRead(TABLE_ID) instanceof BulkReadClassicApi); - verify(bigtableSession).createBulkRead(Mockito.any()); - } - - @Test - public void testMutateRowAsync() throws Exception { - RowMutation rowMutation = RowMutation.create(TABLE_ID, "key"); - MutateRowRequest request = rowMutation.toProto(REQUEST_CONTEXT); - ListenableFuture response = - Futures.immediateFuture(MutateRowResponse.getDefaultInstance()); - when(delegate.mutateRowAsync(request)).thenReturn(response); - dataClientWrapper.mutateRowAsync(rowMutation).get(); - verify(delegate).mutateRowAsync(request); - } - - @Test - public void testCheckMutateRowAsync() throws Exception { - Mutation mutation = Mutation.create(); - mutation.setCell("family", "qualifier", "some other value"); - ConditionalRowMutation conditionalMutation = - ConditionalRowMutation.create(TABLE_ID, "first" + "-row" + "-key").then(mutation); - CheckAndMutateRowRequest request = conditionalMutation.toProto(REQUEST_CONTEXT); - CheckAndMutateRowResponse response = - CheckAndMutateRowResponse.newBuilder().setPredicateMatched(true).build(); - ListenableFuture future = Futures.immediateFuture(response); - - when(delegate.checkAndMutateRowAsync(request)).thenReturn(future); - Future actual = dataClientWrapper.checkAndMutateRowAsync(conditionalMutation); - verify(delegate).checkAndMutateRowAsync(request); - assertTrue(actual.get()); - } - - @Test - public void testCheckMutateRowAsyncWhenNoPredicateMatch() throws Exception { - Mutation mutation = Mutation.create(); - mutation.setCell("family", "qualifier", "some other value"); - ConditionalRowMutation conditonalMutation = - ConditionalRowMutation.create(TABLE_ID, "first" + "-row" + "-key").then(mutation); - CheckAndMutateRowRequest request = conditonalMutation.toProto(REQUEST_CONTEXT); - CheckAndMutateRowResponse response = - CheckAndMutateRowResponse.newBuilder().setPredicateMatched(false).build(); - ListenableFuture future = Futures.immediateFuture(response); - - when(delegate.checkAndMutateRowAsync(request)).thenReturn(future); - Future actual = dataClientWrapper.checkAndMutateRowAsync(conditonalMutation); - verify(delegate).checkAndMutateRowAsync(request); - assertFalse(actual.get()); - } - - @Test - public void testReadModifyWriteAsyncWithEmptyCell() throws Exception { - ReadModifyWriteRow readModify = ReadModifyWriteRow.create(TABLE_ID, "test-key"); - ReadModifyWriteRowRequest request = readModify.toProto(REQUEST_CONTEXT); - ReadModifyWriteRowResponse response = - ReadModifyWriteRowResponse.newBuilder() - .setRow(Row.newBuilder().setKey(ROW_KEY).build()) - .build(); - ListenableFuture listenableResponse = - Futures.immediateFuture(response); - - when(delegate.readModifyWriteRowAsync(request)).thenReturn(listenableResponse); - Result actualResult = dataClientWrapper.readModifyWriteRowAsync(readModify).get(); - assertNull(actualResult.getRow()); - assertEquals(0, actualResult.rawCells().length); - verify(delegate).readModifyWriteRowAsync(request); - } - - @Test - public void testReadModifyWriteAsyncWithOneRow() throws ExecutionException, InterruptedException { - String family_1 = "col-family-1"; - String family_2 = "col-family-2"; - String family_3 = "col-family-3"; - - ByteString qualifier_1 = ByteString.copyFromUtf8("test-qualifier_1-1"); - ByteString qualifier_2 = ByteString.copyFromUtf8("test-qualifier_1-2"); - ByteString qualifier_3 = ByteString.copyFromUtf8("test-qualifier_1-2"); - - ByteString value_1 = ByteString.copyFromUtf8("test-values-1"); - ByteString value_2 = ByteString.copyFromUtf8("test-values-2"); - ByteString value_3 = ByteString.copyFromUtf8("test-values-3"); - ByteString value_4 = ByteString.copyFromUtf8("test-values-4"); - ByteString value_5 = ByteString.copyFromUtf8("test-values-5"); - ByteString value_6 = ByteString.copyFromUtf8("test-values-6"); - - Row row = - Row.newBuilder() - .setKey(ROW_KEY) - .addFamilies( - Family.newBuilder() - .setName(family_1) - .addColumns( - Column.newBuilder() - .setQualifier(qualifier_1) - // First Cell - .addCells( - Cell.newBuilder() - .setTimestampMicros(11_111L) - .setValue(value_1) - .addLabels("label-1")) - // Same Cell with another timestamp and value - .addCells( - Cell.newBuilder() - .setTimestampMicros(22_222L) - .setValue(value_2) - .addLabels("label-2"))) - .addColumns( - Column.newBuilder() - .setQualifier(qualifier_2) - // With label - .addCells( - Cell.newBuilder() - .setTimestampMicros(11_111L) - .setValue(value_3) - .addLabels("label-3") - .addLabels("label-4")) - // Same family, same timestamp, but different column. - .addCells( - Cell.newBuilder().setTimestampMicros(22_222L).setValue(value_4))) - .build()) - .addFamilies( - Family.newBuilder() - .setName(family_2) - .addColumns( - Column.newBuilder() - .setQualifier(qualifier_1) - // Same column, same timestamp, but different family. - .addCells( - Cell.newBuilder().setTimestampMicros(11_111L).setValue(value_5)))) - .addFamilies( - Family.newBuilder() - .setName(family_3) - .addColumns( - Column.newBuilder() - .setQualifier(qualifier_3) - // Same timestamp, but different family and column. - .addCells(Cell.newBuilder().setValue(value_6).addLabels("label-6")))) - .build(); - - ReadModifyWriteRow readModify = ReadModifyWriteRow.create(TABLE_ID, "test-key"); - ReadModifyWriteRowRequest request = readModify.toProto(REQUEST_CONTEXT); - ReadModifyWriteRowResponse response = - ReadModifyWriteRowResponse.newBuilder().setRow(row).build(); - - ListenableFuture listenableResponse = - Futures.immediateFuture(response); - - when(delegate.readModifyWriteRowAsync(request)).thenReturn(listenableResponse); - Result result = dataClientWrapper.readModifyWriteRowAsync(readModify).get(); - - assertEquals(6, result.rawCells().length); - - List cells1 = - result.getColumnCells(family_1.getBytes(), qualifier_1.toByteArray()); - - assertEquals(2, cells1.size()); - assertEquals(11L, cells1.get(0).getTimestamp()); - assertArrayEquals(value_1.toByteArray(), CellUtil.cloneValue(cells1.get(0))); - assertEquals(Collections.singletonList("label-1"), ((RowCell) cells1.get(0)).getLabels()); - - assertEquals(22L, cells1.get(1).getTimestamp()); - assertArrayEquals(value_2.toByteArray(), CellUtil.cloneValue(cells1.get(1))); - assertEquals(Collections.singletonList("label-2"), ((RowCell) cells1.get(1)).getLabels()); - - List cells2 = - result.getColumnCells(family_1.getBytes(), qualifier_2.toByteArray()); - assertEquals(2, cells2.size()); - assertEquals(11L, cells2.get(0).getTimestamp()); - assertArrayEquals(value_3.toByteArray(), CellUtil.cloneValue(cells2.get(0))); - assertEquals(ImmutableList.of("label-3", "label-4"), ((RowCell) cells2.get(0)).getLabels()); - - assertEquals(22L, cells2.get(1).getTimestamp()); - assertArrayEquals(value_4.toByteArray(), CellUtil.cloneValue(cells2.get(1))); - - List cells3 = - result.getColumnCells(family_2.getBytes(), qualifier_1.toByteArray()); - assertEquals(1, cells3.size()); - assertArrayEquals(value_5.toByteArray(), CellUtil.cloneValue(cells3.get(0))); - - List cells4 = - result.getColumnCells(family_3.getBytes(), qualifier_3.toByteArray()); - assertEquals(1, cells4.size()); - assertArrayEquals(value_6.toByteArray(), CellUtil.cloneValue(cells4.get(0))); - assertEquals(Collections.singletonList("label-6"), ((RowCell) cells4.get(0)).getLabels()); - } - - @Test - public void testSampleRowKeysAsync() throws Exception { - final ByteString ROW_KEY_1 = ByteString.copyFromUtf8("row-key-1"); - final ByteString ROW_KEY_2 = ByteString.copyFromUtf8("row-key-2"); - final ByteString ROW_KEY_3 = ByteString.copyFromUtf8("row-key-3"); - - String tableName = NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID); - SampleRowKeysRequest requestProto = - SampleRowKeysRequest.newBuilder().setTableName(tableName).build(); - List responseProto = - ImmutableList.of( - SampleRowKeysResponse.newBuilder().setRowKey(ROW_KEY_1).setOffsetBytes(11).build(), - SampleRowKeysResponse.newBuilder().setRowKey(ROW_KEY_2).setOffsetBytes(12).build(), - SampleRowKeysResponse.newBuilder().setRowKey(ROW_KEY_3).setOffsetBytes(13).build()); - - when(delegate.sampleRowKeysAsync(requestProto)) - .thenReturn(Futures.immediateFuture(responseProto)); - - List keyOffsetList = dataClientWrapper.sampleRowKeysAsync(TABLE_ID).get(); - assertEquals(keyOffsetList.get(0).getKey(), ROW_KEY_1); - assertEquals(keyOffsetList.get(1).getKey(), ROW_KEY_2); - assertEquals(keyOffsetList.get(2).getKey(), ROW_KEY_3); - verify(delegate).sampleRowKeysAsync(requestProto); - } - - @Test - public void testReadRowAsync() throws Exception { - Query query = Query.create(TABLE_ID).rowKey("non-existent-key").limit(1L); - when(delegate.readFlatRowsAsync(query.toProto(REQUEST_CONTEXT))) - .thenReturn(Futures.immediateFuture(Collections.emptyList())); - - Result result = - dataClientWrapper - .readRowAsync(TABLE_ID, ByteString.copyFromUtf8("non-existent-key"), null) - .get(); - assertEquals(Result.EMPTY_RESULT, result); - - Filters.Filter filter = Filters.FILTERS.family().exactMatch("cf"); - Query queryWithFilter = Query.create(TABLE_ID).rowKey(ROW_KEY).filter(filter).limit(1L); - when(delegate.readFlatRowsAsync(queryWithFilter.toProto(REQUEST_CONTEXT))) - .thenReturn(Futures.immediateFuture(Collections.singletonList(SAMPLE_FLAT_ROW))); - - Result actualResult = dataClientWrapper.readRowAsync(TABLE_ID, ROW_KEY, filter).get(); - assertArrayEquals( - FLAT_ROW_ADAPTER.adaptResponse(SAMPLE_FLAT_ROW).rawCells(), actualResult.rawCells()); - - verify(delegate).readFlatRowsAsync(query.toProto(REQUEST_CONTEXT)); - verify(delegate).readFlatRowsAsync(queryWithFilter.toProto(REQUEST_CONTEXT)); - } - - @Test - public void testReadRows() throws Exception { - Query query = Query.create(TABLE_ID); - when(delegate.readFlatRows(query.toProto(REQUEST_CONTEXT))).thenReturn(mockFlatRowScanner); - when(mockFlatRowScanner.next()) - .thenReturn(SAMPLE_FLAT_ROW) - .thenReturn(SAMPLE_FLAT_ROW) - .thenReturn(SAMPLE_FLAT_ROW) - .thenReturn(null); - doNothing().when(mockFlatRowScanner).close(); - - try (org.apache.hadoop.hbase.client.ResultScanner actualResult = - dataClientWrapper.readRows(query)) { - - assertArrayEquals( - FLAT_ROW_ADAPTER.adaptResponse(SAMPLE_FLAT_ROW).rawCells(), - actualResult.next().rawCells()); - - assertEquals(2, actualResult.next(5).length); - } - - verify(mockFlatRowScanner, times(4)).next(); - verify(mockFlatRowScanner).close(); - verify(delegate).readFlatRows(query.toProto(REQUEST_CONTEXT)); - } - - @Test - public void testReadRowsAsync() throws Exception { - Query query = Query.create(TABLE_ID); - FlatRow anotherFlatRow = FlatRow.newBuilder().withRowKey(ROW_KEY).build(); - List listFlatRows = ImmutableList.of(SAMPLE_FLAT_ROW, anotherFlatRow); - when(delegate.readFlatRowsAsync(query.toProto(REQUEST_CONTEXT))) - .thenReturn(Futures.immediateFuture(listFlatRows)); - - List actualResult = dataClientWrapper.readRowsAsync(query).get(); - assertEquals(listFlatRows.size(), actualResult.size()); - assertArrayEquals( - FLAT_ROW_ADAPTER.adaptResponse(SAMPLE_FLAT_ROW).rawCells(), actualResult.get(0).rawCells()); - assertArrayEquals( - FLAT_ROW_ADAPTER.adaptResponse(anotherFlatRow).rawCells(), actualResult.get(1).rawCells()); - verify(delegate).readFlatRowsAsync(query.toProto(REQUEST_CONTEXT)); - } - - @Test - public void testReadRowsAsyncWithStreamOb() { - final Exception readException = new Exception(); - Query request = Query.create(TABLE_ID).rowKey(ROW_KEY); - StreamObserver resultStreamOb = - new StreamObserver() { - @Override - public void onNext(Result result) { - assertArrayEquals( - FLAT_ROW_ADAPTER.adaptResponse(SAMPLE_FLAT_ROW).rawCells(), result.rawCells()); - } - - @Override - public void onError(Throwable throwable) { - assertEquals(readException, throwable); - } - - @Override - public void onCompleted() {} - }; - when(delegate.readFlatRows( - Mockito.any(), Mockito.>any())) - .thenAnswer( - new Answer() { - @Override - public ScanHandler answer(InvocationOnMock invocationOnMock) { - StreamObserver sb = invocationOnMock.getArgument(1); - sb.onNext(SAMPLE_FLAT_ROW); - sb.onError(readException); - sb.onCompleted(); - return new ScanHandler() { - @Override - public void cancel() {} - }; - } - }); - dataClientWrapper.readRowsAsync(request, resultStreamOb); - verify(delegate) - .readFlatRows(Mockito.any(), Mockito.>any()); - } - - @Test - public void testClose() throws Exception { - doNothing().when(bigtableSession).close(); - dataClientWrapper.close(); - verify(bigtableSession).close(); - } -} diff --git a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/veneer/TestBigtableHBaseVeneerSettings.java b/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/veneer/TestBigtableHBaseVeneerSettings.java index dc77e087a2..9e1f48196a 100644 --- a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/veneer/TestBigtableHBaseVeneerSettings.java +++ b/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/veneer/TestBigtableHBaseVeneerSettings.java @@ -93,7 +93,6 @@ public void setup() { configuration.set(BIGTABLE_ADMIN_HOST_KEY, TEST_HOST); configuration.set(BigtableOptionsFactory.PROJECT_ID_KEY, TEST_PROJECT_ID); configuration.set(BigtableOptionsFactory.INSTANCE_ID_KEY, TEST_INSTANCE_ID); - configuration.set(BigtableOptionsFactory.BIGTABLE_USE_GCJ_CLIENT, "true"); } @Test diff --git a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/veneer/TestBigtableVeneerApi.java b/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/veneer/TestBigtableVeneerApi.java index fa7e8d9cd2..2bb6540c20 100644 --- a/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/veneer/TestBigtableVeneerApi.java +++ b/bigtable-client-core-parent/bigtable-hbase/src/test/java/com/google/cloud/bigtable/hbase/wrappers/veneer/TestBigtableVeneerApi.java @@ -29,7 +29,6 @@ import com.google.cloud.bigtable.hbase.BigtableOptionsFactory; import com.google.cloud.bigtable.hbase.wrappers.BigtableApi; import com.google.cloud.bigtable.hbase.wrappers.BigtableHBaseSettings; -import com.google.cloud.bigtable.hbase.wrappers.classic.BigtableHBaseClassicSettings; import com.google.cloud.bigtable.test.helper.TestServerBuilder; import com.google.common.collect.Queues; import com.google.protobuf.Empty; @@ -74,8 +73,7 @@ public void setUp() throws IOException { configuration.set(BigtableOptionsFactory.BIGTABLE_DATA_CHANNEL_COUNT_KEY, "1"); configuration.set( BigtableOptionsFactory.BIGTABLE_EMULATOR_HOST_KEY, "localhost:" + server.getPort()); - configuration.set(BigtableOptionsFactory.BIGTABLE_USE_GCJ_CLIENT, "true"); - bigtableHBaseSettings = BigtableHBaseClassicSettings.create(configuration); + bigtableHBaseSettings = BigtableHBaseVeneerSettings.create(configuration); bigtableApi = BigtableApi.create(bigtableHBaseSettings); } diff --git a/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-benchmarks/README.md b/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-benchmarks/README.md index 29fa434792..98423a6e45 100644 --- a/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-benchmarks/README.md +++ b/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-benchmarks/README.md @@ -1,7 +1,6 @@ Bigtable Benchmark -This module contains benchmarking test scenarios, which would be idle to check the difference between **bigtable-core** client & **GCJ veneer** client. -after running for one method. +This module contains benchmarking test scenarios, which uses **GCJ veneer** client. It accepts following parameters: @@ -11,6 +10,5 @@ $ java -jar target/benchmarks.jar \ -p projectId=[Project ID] \ -p instanceId=[Instance ID] \ -p rowShape="cellsPerRow/[#]/cellSize/[#]", ... \ - -p useBatch=false \ - -p useGCJ=true,false + -p useBatch=false ``` diff --git a/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-benchmarks/src/main/java/com/google/cloud/bigtable/hbase1_x/BenchmarkSetupUtils.java b/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-benchmarks/src/main/java/com/google/cloud/bigtable/hbase1_x/BenchmarkSetupUtils.java index ca0b1c08ad..8c3da61847 100644 --- a/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-benchmarks/src/main/java/com/google/cloud/bigtable/hbase1_x/BenchmarkSetupUtils.java +++ b/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-benchmarks/src/main/java/com/google/cloud/bigtable/hbase1_x/BenchmarkSetupUtils.java @@ -18,7 +18,6 @@ import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_BULK_AUTOFLUSH_MS_KEY; import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_BULK_MAX_ROW_KEY_COUNT; import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_USE_BATCH; -import static com.google.cloud.bigtable.hbase.BigtableOptionsFactory.BIGTABLE_USE_GCJ_CLIENT; import static com.google.cloud.bigtable.hbase1_x.BigtableBenchmark.COL_FAMILY; import static com.google.cloud.bigtable.hbase1_x.BigtableBenchmark.READ_ROW_PREFIX; import static com.google.cloud.bigtable.hbase1_x.BigtableBenchmark.SAMPLE_TIMESTAMP; @@ -47,13 +46,11 @@ class BenchmarkSetupUtils { private static final Pattern CELL_PATTERN = Pattern.compile("cellsPerRow/(\\d+)/cellSize/(\\d+)"); private static final Random random = new Random(); - static Connection createConnection( - String projectId, String instanceId, boolean useBatch, boolean useGcj) { + static Connection createConnection(String projectId, String instanceId, boolean useBatch) { Configuration config = BigtableConfiguration.configure(projectId, instanceId); config.set(BIGTABLE_USE_BATCH, String.valueOf(useBatch)); config.set(BIGTABLE_BULK_AUTOFLUSH_MS_KEY, String.valueOf(100)); config.set(BIGTABLE_BULK_MAX_ROW_KEY_COUNT, String.valueOf(3000)); - config.set(BIGTABLE_USE_GCJ_CLIENT, String.valueOf(useGcj)); return BigtableConfiguration.connect(config); } diff --git a/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-benchmarks/src/main/java/com/google/cloud/bigtable/hbase1_x/BigtableBenchmark.java b/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-benchmarks/src/main/java/com/google/cloud/bigtable/hbase1_x/BigtableBenchmark.java index 77e771efff..13f23f256d 100644 --- a/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-benchmarks/src/main/java/com/google/cloud/bigtable/hbase1_x/BigtableBenchmark.java +++ b/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-benchmarks/src/main/java/com/google/cloud/bigtable/hbase1_x/BigtableBenchmark.java @@ -91,9 +91,6 @@ public class BigtableBenchmark { }) private String rowShape; - @Param({"true", "false"}) - private boolean useGcj; - @Param("true") private boolean useBatch; @@ -103,7 +100,7 @@ public class BigtableBenchmark { @Setup public void setUp() throws IOException { - connection = BenchmarkSetupUtils.createConnection(projectId, instanceId, useBatch, useGcj); + connection = BenchmarkSetupUtils.createConnection(projectId, instanceId, useBatch); rowShapeParams = new RowShapeParams(rowShape); table = connection.getTable(rowShapeParams.tableName); diff --git a/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-integration-tests/src/test/java/com/google/cloud/bigtable/hbase/TestAuth.java b/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-integration-tests/src/test/java/com/google/cloud/bigtable/hbase/TestAuth.java index 80bb7e6fb7..81d655618e 100644 --- a/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-integration-tests/src/test/java/com/google/cloud/bigtable/hbase/TestAuth.java +++ b/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-integration-tests/src/test/java/com/google/cloud/bigtable/hbase/TestAuth.java @@ -34,9 +34,6 @@ public class TestAuth extends AbstractTest { @Test public void testBatchJwt() throws IOException { Assume.assumeTrue("Batch JWT can only run against Bigtable", sharedTestEnv.isBigtable()); - Assume.assumeFalse( - "GCJ client does not support cachedDataPool", - Boolean.getBoolean("google.bigtable.use.gcj.client")); String currentEndpoint = sharedTestEnv.getConfiguration().get("google.bigtable.endpoint.host"); Assume.assumeTrue( diff --git a/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-integration-tests/src/test/java/com/google/cloud/bigtable/hbase/TestRpcRetryBehavior.java b/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-integration-tests/src/test/java/com/google/cloud/bigtable/hbase/TestRpcRetryBehavior.java index 65d7bac942..4e83e42fd7 100644 --- a/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-integration-tests/src/test/java/com/google/cloud/bigtable/hbase/TestRpcRetryBehavior.java +++ b/bigtable-hbase-1.x-parent/bigtable-hbase-1.x-integration-tests/src/test/java/com/google/cloud/bigtable/hbase/TestRpcRetryBehavior.java @@ -208,7 +208,6 @@ protected Connection makeConnection(Map customConnProps) throws } // retry on aborted to differentiate server hang an explicit server error config.set(BigtableOptionsFactory.ADDITIONAL_RETRY_CODES, "ABORTED"); - config.setBoolean(BigtableOptionsFactory.BIGTABLE_USE_GCJ_CLIENT, true); config.setInt(BigtableOptionsFactory.BIGTABLE_DATA_CHANNEL_COUNT_KEY, 1); return ConnectionFactory.createConnection(config); } diff --git a/bigtable-hbase-1.x-parent/bigtable-hbase-1.x/src/test/java/com/google/cloud/bigtable/hbase1_x/TestMetrics.java b/bigtable-hbase-1.x-parent/bigtable-hbase-1.x/src/test/java/com/google/cloud/bigtable/hbase1_x/TestMetrics.java index f702238f31..ab1ebbf66f 100644 --- a/bigtable-hbase-1.x-parent/bigtable-hbase-1.x/src/test/java/com/google/cloud/bigtable/hbase1_x/TestMetrics.java +++ b/bigtable-hbase-1.x-parent/bigtable-hbase-1.x/src/test/java/com/google/cloud/bigtable/hbase1_x/TestMetrics.java @@ -107,7 +107,6 @@ public void setUp() throws IOException { configuration.set(BigtableOptionsFactory.BIGTABLE_DATA_CHANNEL_COUNT_KEY, "1"); configuration.set( BigtableOptionsFactory.BIGTABLE_EMULATOR_HOST_KEY, "localhost:" + server.getPort()); - configuration.set(BigtableOptionsFactory.BIGTABLE_USE_GCJ_CLIENT, "true"); fakeMetricRegistry = new FakeMetricRegistry(); BigtableClientMetrics.setMetricRegistry(fakeMetricRegistry); @@ -297,7 +296,6 @@ public void testActiveSessionsAndChannels() throws IOException { configuration.set(BigtableOptionsFactory.BIGTABLE_NULL_CREDENTIAL_ENABLE_KEY, "true"); configuration.set( BigtableOptionsFactory.BIGTABLE_DATA_CHANNEL_COUNT_KEY, String.valueOf(connectionCount)); - configuration.set(BigtableOptionsFactory.BIGTABLE_USE_GCJ_CLIENT, "true"); BigtableConnection newConnection = new BigtableConnection(configuration); currentActiveSessions = @@ -325,7 +323,6 @@ public void testChannelPoolCachingActiveChannel() throws Exception { configuration.set(BigtableOptionsFactory.INSTANCE_ID_KEY, TEST_INSTANCE_ID); configuration.set( BigtableOptionsFactory.BIGTABLE_DATA_CHANNEL_COUNT_KEY, String.valueOf(connectionCount)); - configuration.set(BigtableOptionsFactory.BIGTABLE_USE_GCJ_CLIENT, "true"); configuration.set(BigtableOptionsFactory.BIGTABLE_USE_CACHED_DATA_CHANNEL_POOL, "true"); Credentials credentials = NoCredentialsProvider.create().getCredentials(); configuration = BigtableConfiguration.withCredentials(configuration, credentials); diff --git a/bigtable-hbase-2.x-parent/bigtable-hbase-2.x/src/main/java/org/apache/hadoop/hbase/client/BigtableAsyncConnection.java b/bigtable-hbase-2.x-parent/bigtable-hbase-2.x/src/main/java/org/apache/hadoop/hbase/client/BigtableAsyncConnection.java index e32da575b9..daff629133 100644 --- a/bigtable-hbase-2.x-parent/bigtable-hbase-2.x/src/main/java/org/apache/hadoop/hbase/client/BigtableAsyncConnection.java +++ b/bigtable-hbase-2.x-parent/bigtable-hbase-2.x/src/main/java/org/apache/hadoop/hbase/client/BigtableAsyncConnection.java @@ -28,8 +28,6 @@ import com.google.cloud.bigtable.hbase.util.Logger; import com.google.cloud.bigtable.hbase.wrappers.BigtableApi; import com.google.cloud.bigtable.hbase.wrappers.BigtableHBaseSettings; -import com.google.cloud.bigtable.hbase.wrappers.classic.BigtableHBaseClassicSettings; -import com.google.cloud.bigtable.hbase.wrappers.veneer.BigtableHBaseVeneerSettings; import com.google.cloud.bigtable.hbase2_x.BigtableAsyncAdmin; import com.google.cloud.bigtable.hbase2_x.BigtableAsyncBufferedMutator; import com.google.cloud.bigtable.hbase2_x.BigtableAsyncTable; @@ -111,10 +109,7 @@ public BigtableApi getBigtableApi() { } public BigtableOptions getOptions() { - if (settings instanceof BigtableHBaseVeneerSettings) { - throw new UnsupportedOperationException("veneer client does not support BigtableOptions"); - } - return ((BigtableHBaseClassicSettings) this.settings).getBigtableOptions(); + throw new UnsupportedOperationException("veneer client does not support BigtableOptions"); } @Override