-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Bigtable: Decouple TableAdminClient from BigtableTableAdminSettings. #3512
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
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
...d-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/TableAdminSettings.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* 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; | ||
|
||
import com.google.bigtable.admin.v2.InstanceName; | ||
import com.google.cloud.bigtable.admin.v2.stub.BigtableTableAdminStubSettings; | ||
import com.google.common.base.Preconditions; | ||
import com.google.common.base.Verify; | ||
import java.io.IOException; | ||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Settings class to configure an instance of {@link TableAdminClient}. | ||
* | ||
* <p>It must be configured with an {@link InstanceName} and be used to change default RPC settings. | ||
* | ||
* <p>Example usage: | ||
* | ||
* <pre>{@code | ||
* TableAdminSettings.Builder tableAdminSettingsBuilder = TableAdminSettings.newBuilder() | ||
* .setInstanceName(InstanceName.of("my-project", "my-instance"); | ||
* | ||
* tableAdminSettingsBuilder.stubSettings().createTableSettings() | ||
* .setRetrySettings( | ||
* RetrySettings.newBuilder() | ||
* .setTotalTimeout(Duration.ofMinutes(15)) | ||
* .build()); | ||
* | ||
* BigtableTableAdminSettings tableAdminSettings = tableAdminSettingsBuilder.build(); | ||
* }</pre> | ||
*/ | ||
public final class TableAdminSettings { | ||
private final InstanceName instanceName; | ||
private final BigtableTableAdminStubSettings stubSettings; | ||
|
||
private TableAdminSettings(Builder builder) throws IOException { | ||
this.instanceName = Preconditions.checkNotNull(builder.instanceName, "InstanceName must be set"); | ||
this.stubSettings = Verify.verifyNotNull(builder.stubSettings, "stubSettings should never be null").build(); | ||
} | ||
|
||
/** Gets the name of instance whose tables the client will manage. */ | ||
@Nonnull | ||
public InstanceName getInstanceName() { | ||
return instanceName; | ||
} | ||
|
||
/** Gets the underlying RPC settings. */ | ||
public BigtableTableAdminStubSettings getStubSettings() { | ||
return stubSettings; | ||
} | ||
|
||
/** Returns a builder containing all the values of this settings class. */ | ||
public Builder toBuilder() { | ||
return new Builder(this); | ||
} | ||
|
||
/** Returns a new builder for this class. */ | ||
public static Builder newBuilder() { | ||
return new Builder(); | ||
} | ||
|
||
/** Builder for TableAdminSettings. */ | ||
public static final class Builder { | ||
@Nullable | ||
private InstanceName instanceName; | ||
private final BigtableTableAdminStubSettings.Builder stubSettings; | ||
|
||
private Builder() { | ||
stubSettings = BigtableTableAdminStubSettings.newBuilder(); | ||
} | ||
|
||
private Builder(TableAdminSettings settings) { | ||
this.instanceName = settings.instanceName; | ||
this.stubSettings = settings.stubSettings.toBuilder(); | ||
} | ||
|
||
/** Sets the name of instance whose tables the client will manage. */ | ||
public Builder setInstanceName(@Nonnull InstanceName instanceName) { | ||
Preconditions.checkNotNull(instanceName); | ||
this.instanceName = instanceName; | ||
return this; | ||
} | ||
|
||
/** Gets the name of instance whose tables the client will manage. */ | ||
@Nullable | ||
public InstanceName getInstanceName() { | ||
return instanceName; | ||
} | ||
|
||
/** | ||
* Returns the builder for the settings used for all RPCs. | ||
* | ||
* <p>This is meant for advanced usage. The default RPC settings are set to their recommended | ||
* values. | ||
*/ | ||
public BigtableTableAdminStubSettings.Builder stubSettings() { | ||
return stubSettings; | ||
} | ||
|
||
/** Builds an instance of the settings. */ | ||
public TableAdminSettings build() throws IOException { | ||
return new TableAdminSettings(this); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...gtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/TableAdminSettingsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.google.cloud.bigtable.admin.v2; | ||
|
||
import static com.google.common.truth.Truth.*; | ||
|
||
import com.google.api.gax.rpc.StatusCode.Code; | ||
import com.google.bigtable.admin.v2.InstanceName; | ||
import java.io.IOException; | ||
import org.junit.Test; | ||
|
||
public class TableAdminSettingsTest { | ||
|
||
@Test | ||
public void testInstanceName() throws IOException { | ||
InstanceName instanceName = InstanceName.of("my-project", "my-instance"); | ||
|
||
TableAdminSettings.Builder builder = TableAdminSettings.newBuilder() | ||
.setInstanceName(instanceName); | ||
|
||
assertThat(builder.getInstanceName()).isEqualTo(instanceName); | ||
assertThat(builder.build().getInstanceName()).isEqualTo(instanceName); | ||
assertThat(builder.build().toBuilder().getInstanceName()).isEqualTo(instanceName); | ||
} | ||
|
||
@Test | ||
public void testMissingInstanceName() { | ||
Exception actualException = null; | ||
|
||
try { | ||
TableAdminSettings.newBuilder().build(); | ||
} catch (Exception e) { | ||
actualException = e; | ||
} | ||
|
||
assertThat(actualException).isInstanceOf(NullPointerException.class); | ||
} | ||
|
||
@Test | ||
public void testStubSettings() throws IOException { | ||
InstanceName instanceName = InstanceName.of("my-project", "my-instance"); | ||
|
||
TableAdminSettings.Builder builder = TableAdminSettings.newBuilder() | ||
.setInstanceName(instanceName); | ||
|
||
builder.stubSettings().createTableSettings() | ||
.setRetryableCodes(Code.INVALID_ARGUMENT); | ||
|
||
assertThat(builder.build().getStubSettings().createTableSettings().getRetryableCodes()) | ||
.containsExactly(Code.INVALID_ARGUMENT); | ||
|
||
assertThat(builder.build().toBuilder().build().getStubSettings().createTableSettings() | ||
.getRetryableCodes()) | ||
.containsExactly(Code.INVALID_ARGUMENT); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.