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

Cloud Bigtable: InstanceAdmin sample update #4346

Merged
Merged
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 @@ -20,7 +20,6 @@
import static org.junit.Assert.assertTrue;

import com.google.api.gax.rpc.NotFoundException;
import com.google.bigtable.admin.v2.InstanceName;
import com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient;
import com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminSettings;
import com.google.cloud.bigtable.admin.v2.models.Cluster;
Expand All @@ -42,25 +41,24 @@
/** Integration tests for {@link InstanceAdminExample} */
public class ITInstanceAdminExample {

private static final String INSTANCE_PROPERTY_NAME = "bigtable.instance";
private static final String PROJECT_PROPERTY_NAME = "bigtable.project";
private static final String ID_PREFIX = "instanceadmin";
private static final String CLUSTER = "cluster";
private static String projectName;
private static String projectId;
private static BigtableInstanceAdminClient adminClient;
private String clusterId;
private String instanceId;
private InstanceAdminExample instanceAdmin;

@BeforeClass
public static void beforeClass() throws IOException {
String targetProject = System.getProperty(INSTANCE_PROPERTY_NAME);
if (targetProject == null) {
projectId = System.getProperty(PROJECT_PROPERTY_NAME);
if (projectId == null) {
adminClient = null;
return;
}
projectName = InstanceName.parse(targetProject).getProject();
BigtableInstanceAdminSettings instanceAdminSettings =
BigtableInstanceAdminSettings.newBuilder().setProjectId(projectName).build();
BigtableInstanceAdminSettings.newBuilder().setProjectId(projectId).build();
adminClient = BigtableInstanceAdminClient.create(instanceAdminSettings);
}

Expand All @@ -74,11 +72,11 @@ public static void afterClass() {
public void setup() throws IOException {
if (adminClient == null) {
throw new AssumptionViolatedException(
INSTANCE_PROPERTY_NAME + " property is not set, skipping integration tests.");
PROJECT_PROPERTY_NAME + " property is not set, skipping integration tests.");
}
instanceId = generateId();
clusterId = generateId();
instanceAdmin = new InstanceAdminExample(projectName, instanceId, clusterId);
instanceAdmin = new InstanceAdminExample(projectId, instanceId, clusterId);
adminClient.createInstance(
CreateInstanceRequest.of(instanceId)
.addCluster(clusterId, "us-central1-f", 3, StorageType.SSD)
Expand All @@ -99,7 +97,7 @@ public void testCreateAndDeleteInstance() throws IOException {
String testInstance = generateId();
String testCluster = generateId();
InstanceAdminExample testInstanceAdmin =
new InstanceAdminExample(projectName, testInstance, testCluster);
new InstanceAdminExample(projectId, testInstance, testCluster);
testInstanceAdmin.createProdInstance();
assertTrue(adminClient.exists(testInstance));

Expand Down