Skip to content

Commit

Permalink
Bigtable: fix admin tests to able to run concurrently (#3895)
Browse files Browse the repository at this point in the history
  • Loading branch information
igorbernstein2 authored and chingor13 committed Nov 2, 2018
1 parent 9dcd23b commit 9c111f4
Showing 1 changed file with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.AssumptionViolatedException;
import org.junit.Before;
Expand All @@ -48,6 +49,7 @@ public class BigtableTableAdminClientIT {
private static final String INSTANCE_PROPERTY_NAME = "bigtable.instance";

private static BigtableTableAdminClient tableAdmin;
private static String prefix;

@BeforeClass
public static void createClient() throws IOException {
Expand All @@ -60,6 +62,17 @@ public static void createClient() throws IOException {

InstanceName instanceName = InstanceName.parse(targetInstance);
tableAdmin = BigtableTableAdminClient.create(instanceName);

// Setup a prefix to avoid collisions between concurrent test runs
prefix = String.format("020%d", System.currentTimeMillis());

// Cleanup old tables, under normal circumstances this will do nothing
String stalePrefix = String.format("020%d", System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1));
for (TableName tableName : tableAdmin.listTables()) {
if (stalePrefix.compareTo(tableName.getTable()) > 0) {
tableAdmin.deleteTable(tableName.getTable());
}
}
}

@AfterClass
Expand All @@ -79,7 +92,7 @@ public void setup() {

@Test
public void createTable() {
String tableId = "adminCreateTest";
String tableId = getTableId("adminCreateTest");
CreateTableRequest createTableReq =
CreateTableRequest.of(tableId)
.addFamily("cf1")
Expand Down Expand Up @@ -110,7 +123,7 @@ public void createTable() {

@Test
public void modifyFamilies() {
String tableId = "adminModifyFamTest";
String tableId = getTableId("adminModifyFamTest");
ModifyColumnFamiliesRequest modifyFamiliesReq = ModifyColumnFamiliesRequest.of(tableId);

modifyFamiliesReq
Expand Down Expand Up @@ -179,14 +192,14 @@ public void modifyFamilies() {

@Test
public void deleteTable() {
String tableId = "adminDeleteTest";
String tableId = getTableId("adminDeleteTest");
tableAdmin.createTable(CreateTableRequest.of(tableId));
tableAdmin.deleteTable(tableId);
}

@Test
public void getTable() {
String tableId = "adminGetTest";
String tableId = getTableId("adminGetTest");

try {
tableAdmin.createTable(CreateTableRequest.of(tableId));
Expand All @@ -200,7 +213,7 @@ public void getTable() {

@Test
public void listTables() {
String tableId = "adminListTest";
String tableId = getTableId("adminListTest");

try {
tableAdmin.createTable(CreateTableRequest.of(tableId));
Expand All @@ -214,7 +227,7 @@ public void listTables() {

@Test
public void listTablesAsync() throws Exception {
String tableId = "adminListTest";
String tableId = getTableId("adminListTest");

try {
tableAdmin.createTable(CreateTableRequest.of(tableId));
Expand All @@ -228,7 +241,7 @@ public void listTablesAsync() throws Exception {

@Test
public void dropRowRange() {
String tableId = "adminDropRowrangeTest";
String tableId = getTableId("adminDropRowrangeTest");

try {
tableAdmin.createTable(CreateTableRequest.of(tableId));
Expand All @@ -241,7 +254,7 @@ public void dropRowRange() {

@Test
public void awaitReplication() {
String tableId = "adminConsistencyTest";
String tableId = getTableId("adminConsistencyTest");

try {
tableAdmin.createTable(CreateTableRequest.of(tableId));
Expand All @@ -250,4 +263,8 @@ public void awaitReplication() {
tableAdmin.deleteTable(tableId);
}
}

private static String getTableId(String name) {
return prefix + "-" + name;
}
}

0 comments on commit 9c111f4

Please sign in to comment.