use of com.google.spanner.admin.database.v1.CreateDatabaseMetadata in project google-cloud-java by GoogleCloudPlatform.
the class ITDatabaseAdminTest method databaseOperations.
@Test
public void databaseOperations() throws Exception {
String dbId = testHelper.getUniqueDatabaseId();
String instanceId = testHelper.getInstanceId().getInstance();
String statement1 = "CREATE TABLE T (\n" + " K STRING(MAX),\n" + ") PRIMARY KEY(K)";
Operation<Database, CreateDatabaseMetadata> op = dbAdminClient.createDatabase(instanceId, dbId, ImmutableList.of(statement1));
op = op.waitFor();
Database db = op.getResult();
dbs.add(db);
assertThat(db.getId().getDatabase()).isEqualTo(dbId);
db = dbAdminClient.getDatabase(instanceId, dbId);
assertThat(db.getId().getDatabase()).isEqualTo(dbId);
boolean foundDb = false;
for (Database dbInList : Iterators.toArray(dbAdminClient.listDatabases(instanceId).iterateAll().iterator(), Database.class)) {
if (dbInList.getId().getDatabase().equals(dbId)) {
foundDb = true;
break;
}
}
assertThat(foundDb).isTrue();
String statement2 = "CREATE TABLE T2 (\n" + " K2 STRING(MAX),\n" + ") PRIMARY KEY(K2)";
Operation<?, ?> op2 = dbAdminClient.updateDatabaseDdl(instanceId, dbId, ImmutableList.of(statement2), null);
op2.waitFor();
List<String> statementsInDb = dbAdminClient.getDatabaseDdl(instanceId, dbId);
assertThat(statementsInDb).containsExactly(statement1, statement2);
dbAdminClient.dropDatabase(instanceId, dbId);
dbs.clear();
expectedException.expect(isSpannerException(ErrorCode.NOT_FOUND));
db = dbAdminClient.getDatabase(testHelper.getInstanceId().getInstance(), dbId);
}
use of com.google.spanner.admin.database.v1.CreateDatabaseMetadata in project google-cloud-java by GoogleCloudPlatform.
the class RemoteSpannerHelper method createTestDatabase.
/**
* Creates a test database defined by {@code statements} in the test instance. A {@code CREATE
* DATABASE ...} statement should not be included; an appropriate name will be chosen and the
* statement generated accordingly.
*/
public Database createTestDatabase(Iterable<String> statements) throws SpannerException {
String dbId = getUniqueDatabaseId();
Operation<Database, CreateDatabaseMetadata> op = client.getDatabaseAdminClient().createDatabase(instanceId.getInstance(), dbId, statements);
op = op.waitFor();
Database db = op.getResult();
logger.log(Level.FINE, "Created test database {0}", db.getId());
dbs.add(db);
return db;
}
use of com.google.spanner.admin.database.v1.CreateDatabaseMetadata in project google-cloud-java by GoogleCloudPlatform.
the class ITDatabaseAdminTest method databaseOperationsViaEntity.
@Test
public void databaseOperationsViaEntity() throws Exception {
String dbId = testHelper.getUniqueDatabaseId();
String instanceId = testHelper.getInstanceId().getInstance();
String statement1 = "CREATE TABLE T (\n" + " K STRING(MAX),\n" + ") PRIMARY KEY(K)";
Operation<Database, CreateDatabaseMetadata> op = dbAdminClient.createDatabase(instanceId, dbId, ImmutableList.of(statement1));
op = op.waitFor();
Database db = op.getResult();
dbs.add(db);
assertThat(db.getId().getDatabase()).isEqualTo(dbId);
db = db.reload();
assertThat(db.getId().getDatabase()).isEqualTo(dbId);
String statement2 = "CREATE TABLE T2 (\n" + " K2 STRING(MAX),\n" + ") PRIMARY KEY(K2)";
Operation<?, ?> op2 = db.updateDdl(ImmutableList.of(statement2), null);
op2.waitFor();
Iterable<String> statementsInDb = db.getDdl();
assertThat(statementsInDb).containsExactly(statement1, statement2);
db.drop();
dbs.clear();
expectedException.expect(isSpannerException(ErrorCode.NOT_FOUND));
db.reload();
}
use of com.google.spanner.admin.database.v1.CreateDatabaseMetadata in project google-cloud-java by GoogleCloudPlatform.
the class ITDatabaseAdminTest method updateDdlRetry.
@Test
public void updateDdlRetry() throws Exception {
String dbId = testHelper.getUniqueDatabaseId();
String instanceId = testHelper.getInstanceId().getInstance();
String statement1 = "CREATE TABLE T (\n" + " K STRING(MAX),\n" + ") PRIMARY KEY(K)";
Operation<Database, CreateDatabaseMetadata> op = dbAdminClient.createDatabase(instanceId, dbId, ImmutableList.of(statement1));
op = op.waitFor();
Database db = op.getResult();
dbs.add(db);
String statement2 = "CREATE TABLE T2 (\n" + " K2 STRING(MAX),\n" + ") PRIMARY KEY(K2)";
Operation<Void, UpdateDatabaseDdlMetadata> op1 = dbAdminClient.updateDatabaseDdl(instanceId, dbId, ImmutableList.of(statement2), "myop");
Operation<Void, UpdateDatabaseDdlMetadata> op2 = dbAdminClient.updateDatabaseDdl(instanceId, dbId, ImmutableList.of(statement2), "myop");
op1 = op1.waitFor();
op2 = op2.waitFor();
assertThat(op1.getMetadata()).isEqualTo(op2.getMetadata());
}
Aggregations