Skip to content

Commit

Permalink
Add some checks to debug test flakiness..
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerjou Cheng committed Mar 22, 2017
1 parent 0f1a308 commit e51fe6e
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.cloud.spanner.DatabaseAdminClient;
import com.google.cloud.spanner.DatabaseClient;
import com.google.cloud.spanner.DatabaseId;
import com.google.cloud.spanner.DatabaseInfo;
// [START transaction_import]
import com.google.cloud.spanner.Key;
// [END transaction_import]
Expand Down Expand Up @@ -57,6 +58,8 @@
// [END write_import]
import java.util.Arrays;
import java.util.List;
import com.google.cloud.WaitForOption;
import java.util.concurrent.TimeUnit;

/**
* Example code for using the Cloud Spanner API. This example demonstrates all the common
Expand Down Expand Up @@ -132,8 +135,15 @@ static void createDatabase(DatabaseAdminClient dbAdminClient, DatabaseId id) {
+ " AlbumTitle STRING(MAX)\n"
+ ") PRIMARY KEY (SingerId, AlbumId),\n"
+ " INTERLEAVE IN PARENT Singers ON DELETE CASCADE"));
Database db = op.waitFor().getResult();
System.out.println("Created database [" + db.getId() + "]");
op = op.waitFor(WaitForOption.timeout(2, TimeUnit.MINUTES));
Database db = op.getResult();
if (op.isSuccessful() && db.getState() == DatabaseInfo.State.READY) {
System.out.println("Created database [" + db.getId() + "]");
} else {
throw new RuntimeException(String.format(
"Error creating database: {successful: %b, state: %s}",
op.isSuccessful(), db.getState()));
}
}

// [START write]
Expand Down Expand Up @@ -198,10 +208,14 @@ static void read(DatabaseClient dbClient) {

// [START add_marketing_budget]
static void addMarketingBudget(DatabaseAdminClient adminClient, DatabaseId dbId) {
adminClient.updateDatabaseDdl(dbId.getInstanceId().getInstance(),
Operation op = adminClient.updateDatabaseDdl(
dbId.getInstanceId().getInstance(),
dbId.getDatabase(),
Arrays.asList("ALTER TABLE Albums ADD COLUMN MarketingBudget INT64"),
null).waitFor();
if (!op.isSuccessful()) {
throw new RuntimeException("ALTER TABLE operation unsuccessful");
}
System.out.println("Added MarketingBudget column");
}
// [END add_marketing_budget]
Expand Down

0 comments on commit e51fe6e

Please sign in to comment.