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: fix admin tests to able to run concurrently #3895

Merged
merged 1 commit into from
Nov 2, 2018
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 @@ -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;
}
}