Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bigtable: add enhanced stub for bigtable table admin client #3691

Merged
merged 2 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
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.Table;
import com.google.cloud.bigtable.admin.v2.stub.BigtableTableAdminStub;
import com.google.cloud.bigtable.admin.v2.stub.EnhancedBigtableTableAdminStub;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -97,7 +97,7 @@
* }</pre>
*/
public final class BigtableTableAdminClient implements AutoCloseable {
private final BigtableTableAdminStub stub;
private final EnhancedBigtableTableAdminStub stub;
private final InstanceName instanceName;

/** Constructs an instance of BigtableTableAdminClient with the given instanceName. */
Expand All @@ -109,17 +109,19 @@ public static BigtableTableAdminClient create(@Nonnull InstanceName instanceName
/** Constructs an instance of BigtableTableAdminClient with the given settings. */
public static BigtableTableAdminClient create(@Nonnull BigtableTableAdminSettings settings)
throws IOException {
return create(settings.getInstanceName(), settings.getStubSettings().createStub());
EnhancedBigtableTableAdminStub stub = EnhancedBigtableTableAdminStub
.createEnhanced(settings.getStubSettings());
return create(settings.getInstanceName(), stub);
}

/** Constructs an instance of BigtableTableAdminClient with the given instanceName and stub. */
public static BigtableTableAdminClient create(@Nonnull InstanceName instanceName,
@Nonnull BigtableTableAdminStub stub) {
@Nonnull EnhancedBigtableTableAdminStub stub) {
return new BigtableTableAdminClient(instanceName, stub);
}

private BigtableTableAdminClient(@Nonnull InstanceName instanceName,
@Nonnull BigtableTableAdminStub stub) {
@Nonnull EnhancedBigtableTableAdminStub stub) {
Preconditions.checkNotNull(instanceName);
Preconditions.checkNotNull(stub);
this.instanceName = instanceName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2018 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
*
* https://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.admin.v2.stub;

import com.google.api.core.InternalApi;
import com.google.api.gax.rpc.ClientContext;
import java.io.IOException;

/**
* Extension of the autogenerated {@link GrpcBigtableTableAdminStub}. It acts as a decorator to add
* enhanced abilities to the autogenerated stub.
*
* <p>This class is considered an internal implementation detail and not meant to be used by
* applications.
*/
@InternalApi
public class EnhancedBigtableTableAdminStub extends GrpcBigtableTableAdminStub {
private final BigtableTableAdminStubSettings settings;
private final ClientContext clientContext;

public static EnhancedBigtableTableAdminStub createEnhanced(
BigtableTableAdminStubSettings settings)
throws IOException {
return new EnhancedBigtableTableAdminStub(settings, ClientContext.create(settings));
}

private EnhancedBigtableTableAdminStub(BigtableTableAdminStubSettings settings,
ClientContext clientContext) throws IOException {
super(settings, clientContext);

this.settings = settings;
this.clientContext = clientContext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest;
import com.google.cloud.bigtable.admin.v2.models.Table;
import com.google.cloud.bigtable.admin.v2.stub.BigtableTableAdminStub;
import com.google.cloud.bigtable.admin.v2.stub.EnhancedBigtableTableAdminStub;
import com.google.common.collect.Lists;
import com.google.protobuf.ByteString;
import com.google.protobuf.Empty;
Expand All @@ -63,7 +64,7 @@ public class BigtableTableAdminClientTest {

private BigtableTableAdminClient adminClient;
@Mock
private BigtableTableAdminStub mockStub;
private EnhancedBigtableTableAdminStub mockStub;

@Mock
private UnaryCallable<com.google.bigtable.admin.v2.CreateTableRequest, com.google.bigtable.admin.v2.Table> mockCreateTableCallable;
Expand Down