Skip to content

Commit

Permalink
system property for tests set up
Browse files Browse the repository at this point in the history
  • Loading branch information
elisheva-qlogic committed Dec 18, 2018
1 parent 670a775 commit 4f35dbf
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,35 @@
import com.google.cloud.bigtable.data.v2.models.RowMutation;
import java.io.IOException;
import org.junit.AfterClass;
import org.junit.AssumptionViolatedException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class HelloWorldTest {

private static final String PROJECT_ID = "test-project"; // Replace with your project ID
private static final String INSTANCE_ID = "test-instance"; // Replace with your instance ID
private static final String INSTANCE_PROPERTY_NAME = "bigtable.instance";
private static final String TABLE_ID = "test-table" + System.currentTimeMillis();
private static final String COLUMN_FAMILY_ID = "test-cf";
private static final String COLUMN_QUALIFIER = "test-greeting";
private static final String ROW_KEY_PREFIX = "test-rowKey";
private static BigtableDataSettings settings;
private static BigtableDataClient dataClient;
private static BigtableTableAdminSettings adminSettings;
private static BigtableTableAdminClient adminClient;

@BeforeClass
public static void beforeClass() throws IOException {
settings =
BigtableDataSettings.newBuilder()
.setInstanceName(InstanceName.of(PROJECT_ID, INSTANCE_ID))
String targetInstance = System.getProperty(INSTANCE_PROPERTY_NAME);
if (targetInstance == null) {
dataClient = null;
adminClient = null;
return;
}
BigtableDataSettings settings =
BigtableDataSettings.newBuilder().setInstanceName(InstanceName.parse(targetInstance))
.build();
dataClient = BigtableDataClient.create(settings);
adminSettings =
BigtableTableAdminSettings.newBuilder()
.setInstanceName(com.google.bigtable.admin.v2.InstanceName.of(PROJECT_ID, INSTANCE_ID))
.build();
BigtableTableAdminSettings adminSettings = BigtableTableAdminSettings.newBuilder()
.setInstanceName(com.google.bigtable.admin.v2.InstanceName.parse(targetInstance)).build();
adminClient = BigtableTableAdminClient.create(adminSettings);
if (!adminClient.exists(TABLE_ID)) {
adminClient.createTable(CreateTableRequest.of(TABLE_ID).addFamily(COLUMN_FAMILY_ID));
Expand All @@ -70,6 +72,14 @@ public static void afterClass() throws Exception {
adminClient.close();
}

@Before
public void setup() {
if (adminClient == null || dataClient == null) {
throw new AssumptionViolatedException(
INSTANCE_PROPERTY_NAME + " property is not set, skipping integration tests.");
}
}

@Test
public void testCreateAndDeleteTable() {
// Create table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.junit.Assert.assertTrue;

import com.google.api.gax.rpc.NotFoundException;
import com.google.bigtable.admin.v2.InstanceName;
import com.google.bigtable.admin.v2.ProjectName;
import com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminClient;
import com.google.cloud.bigtable.admin.v2.BigtableInstanceAdminSettings;
Expand All @@ -30,23 +31,27 @@
import java.io.IOException;
import java.util.List;
import org.junit.AfterClass;
import org.junit.AssumptionViolatedException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class InstanceAdminTest {

private static final String GCLOUD_PROJECT = "test-project"; // Replace with your project ID
private static final String INSTANCE_PROPERTY_NAME = "bigtable.instance";
private static final String PRODUCTION_INSTANCE = "test-instance";
private static final String PRODUCTION_CLUSTER = "test-cluster" + System.currentTimeMillis();
private static BigtableInstanceAdminSettings instanceAdminSettings;
private static BigtableInstanceAdminClient adminClient;

@BeforeClass
public static void beforeClass() throws IOException {
instanceAdminSettings =
BigtableInstanceAdminSettings.newBuilder()
.setProjectName(ProjectName.of(GCLOUD_PROJECT))
.build();
String targetProject = System.getProperty(INSTANCE_PROPERTY_NAME);
ProjectName projectName = ProjectName.of(InstanceName.parse(targetProject).getProject());
if (targetProject == null) {
adminClient = null;
}
BigtableInstanceAdminSettings instanceAdminSettings =
BigtableInstanceAdminSettings.newBuilder().setProjectName(projectName).build();
adminClient = BigtableInstanceAdminClient.create(instanceAdminSettings);
if (!adminClient.exists(PRODUCTION_INSTANCE)) {
adminClient.createInstance(
Expand All @@ -63,6 +68,14 @@ public static void afterClass() {
adminClient.close();
}

@Before
public void setup() {
if (adminClient == null) {
throw new AssumptionViolatedException(
INSTANCE_PROPERTY_NAME + " property is not set, skipping integration tests.");
}
}

@Test
public void testCreateAndDeleteInstance() {
// Create instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import com.google.bigtable.admin.v2.InstanceName;
import com.google.cloud.bigtable.admin.v2.BigtableTableAdminClient;
import com.google.cloud.bigtable.admin.v2.BigtableTableAdminSettings;
import com.google.cloud.bigtable.admin.v2.models.ColumnFamily;
Expand All @@ -27,23 +28,26 @@
import java.util.Collection;
import java.util.List;
import org.junit.AfterClass;
import org.junit.AssumptionViolatedException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class TableAdminTest {

private static final String GCLOUD_PROJECT = "test-project"; // Replace with your project ID
private static final String INSTANCE_ID = "test-instance"; // Replace with your instance ID
private static final String INSTANCE_PROPERTY_NAME = "bigtable.instance";
private static final String TABLE_ID = "test-table" + System.currentTimeMillis();
private static BigtableTableAdminSettings adminSettings;
private static BigtableTableAdminClient adminClient;

@BeforeClass
public static void beforeClass() throws IOException {
adminSettings =
BigtableTableAdminSettings.newBuilder()
.setInstanceName(
com.google.bigtable.admin.v2.InstanceName.of(GCLOUD_PROJECT, INSTANCE_ID))
String targetInstance = System.getProperty(INSTANCE_PROPERTY_NAME);
if (targetInstance == null) {
adminClient = null;
return;
}
BigtableTableAdminSettings adminSettings =
BigtableTableAdminSettings.newBuilder().setInstanceName(InstanceName.parse(targetInstance))
.build();
adminClient = BigtableTableAdminClient.create(adminSettings);
if (!adminClient.exists(TABLE_ID)) {
Expand All @@ -57,6 +61,14 @@ public static void afterClass() {
adminClient.close();
}

@Before
public void setup() {
if (adminClient == null) {
throw new AssumptionViolatedException(
INSTANCE_PROPERTY_NAME + " property is not set, skipping integration tests.");
}
}

@Test
public void testCreateAndDeleteTable() {
// Create table
Expand Down

0 comments on commit 4f35dbf

Please sign in to comment.