use of com.google.spanner.admin.database.v1.Database in project java-spanner by googleapis.
the class DatabaseAdminClientTest method updateDatabaseDdlExceptionTest.
@Test
public void updateDatabaseDdlExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockDatabaseAdmin.addException(exception);
try {
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
List<String> statements = new ArrayList<>();
client.updateDatabaseDdlAsync(database, statements).get();
Assert.fail("No exception raised");
} catch (ExecutionException e) {
Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
}
}
use of com.google.spanner.admin.database.v1.Database in project java-spanner by googleapis.
the class DatabaseAdminClientTest method getDatabaseDdlTest.
@Test
public void getDatabaseDdlTest() throws Exception {
GetDatabaseDdlResponse expectedResponse = GetDatabaseDdlResponse.newBuilder().addAllStatements(new ArrayList<String>()).build();
mockDatabaseAdmin.addResponse(expectedResponse);
DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
GetDatabaseDdlResponse actualResponse = client.getDatabaseDdl(database);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetDatabaseDdlRequest actualRequest = ((GetDatabaseDdlRequest) actualRequests.get(0));
Assert.assertEquals(database.toString(), actualRequest.getDatabase());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.admin.database.v1.Database in project java-spanner by googleapis.
the class DatabaseAdminClientTest method restoreDatabaseTest2.
@Test
public void restoreDatabaseTest2() throws Exception {
Database expectedResponse = Database.newBuilder().setName(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString()).setCreateTime(Timestamp.newBuilder().build()).setRestoreInfo(RestoreInfo.newBuilder().build()).setEncryptionConfig(EncryptionConfig.newBuilder().build()).addAllEncryptionInfo(new ArrayList<EncryptionInfo>()).setVersionRetentionPeriod("versionRetentionPeriod-629783929").setEarliestVersionTime(Timestamp.newBuilder().build()).setDefaultLeader("defaultLeader759009962").setDatabaseDialect(DatabaseDialect.forNumber(0)).build();
Operation resultOperation = Operation.newBuilder().setName("restoreDatabaseTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
mockDatabaseAdmin.addResponse(resultOperation);
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
String databaseId = "databaseId1688905718";
String backup = "backup-1396673086";
Database actualResponse = client.restoreDatabaseAsync(parent, databaseId, backup).get();
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
RestoreDatabaseRequest actualRequest = ((RestoreDatabaseRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(databaseId, actualRequest.getDatabaseId());
Assert.assertEquals(backup, actualRequest.getBackup());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.admin.database.v1.Database in project java-spanner by googleapis.
the class DatabaseAdminClientTest method updateDatabaseDdlTest2.
@Test
public void updateDatabaseDdlTest2() throws Exception {
Empty expectedResponse = Empty.newBuilder().build();
Operation resultOperation = Operation.newBuilder().setName("updateDatabaseDdlTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
mockDatabaseAdmin.addResponse(resultOperation);
String database = "database1789464955";
List<String> statements = new ArrayList<>();
client.updateDatabaseDdlAsync(database, statements).get();
List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
UpdateDatabaseDdlRequest actualRequest = ((UpdateDatabaseDdlRequest) actualRequests.get(0));
Assert.assertEquals(database, actualRequest.getDatabase());
Assert.assertEquals(statements, actualRequest.getStatementsList());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.admin.database.v1.Database in project java-spanner by googleapis.
the class DatabaseAdminClientTest method updateBackupTest.
@Test
public void updateBackupTest() throws Exception {
Backup expectedResponse = Backup.newBuilder().setDatabase(DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]").toString()).setVersionTime(Timestamp.newBuilder().build()).setExpireTime(Timestamp.newBuilder().build()).setName(BackupName.of("[PROJECT]", "[INSTANCE]", "[BACKUP]").toString()).setCreateTime(Timestamp.newBuilder().build()).setSizeBytes(-1796325715).addAllReferencingDatabases(new ArrayList<String>()).setEncryptionInfo(EncryptionInfo.newBuilder().build()).setDatabaseDialect(DatabaseDialect.forNumber(0)).build();
mockDatabaseAdmin.addResponse(expectedResponse);
Backup backup = Backup.newBuilder().build();
FieldMask updateMask = FieldMask.newBuilder().build();
Backup actualResponse = client.updateBackup(backup, updateMask);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
UpdateBackupRequest actualRequest = ((UpdateBackupRequest) actualRequests.get(0));
Assert.assertEquals(backup, actualRequest.getBackup());
Assert.assertEquals(updateMask, actualRequest.getUpdateMask());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations