use of com.google.spanner.admin.database.v1.Database in project java-spanner by googleapis.
the class MockDatabaseAdminServiceImplTest method getDatabase.
@Test
public void getDatabase() {
createTestDb();
Database db = client.getDatabase(TEST_DB_NAME);
assertThat(db.getName()).isEqualTo(TEST_DB_NAME);
}
use of com.google.spanner.admin.database.v1.Database in project java-spanner by googleapis.
the class MockDatabaseAdminServiceImplTest method restoreDatabaseNotFound.
@Test
public void restoreDatabaseNotFound() throws InterruptedException, ExecutionException {
createTestDb();
RestoreDatabaseRequest request = RestoreDatabaseRequest.newBuilder().setBackup(TEST_BCK_NAME).setDatabaseId("restored-db").setParent(TEST_PARENT).build();
OperationFuture<Database, RestoreDatabaseMetadata> op = client.restoreDatabaseOperationCallable().futureCall(request);
exception.expect(ApiExceptionMatcher.forCode(StatusCode.Code.NOT_FOUND));
op.get();
}
use of com.google.spanner.admin.database.v1.Database in project java-spanner by googleapis.
the class SpannerThreadsTest method mockGetDatabaseResponse.
private void mockGetDatabaseResponse() {
DatabaseName name2 = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
Database expectedResponse = Database.newBuilder().setName(name2.toString()).build();
mockDatabaseAdmin.addResponse(expectedResponse);
}
use of com.google.spanner.admin.database.v1.Database in project java-spanner by googleapis.
the class DatabaseAdminClientTest method listDatabasesTest2.
@Test
public void listDatabasesTest2() throws Exception {
Database responsesElement = Database.newBuilder().build();
ListDatabasesResponse expectedResponse = ListDatabasesResponse.newBuilder().setNextPageToken("").addAllDatabases(Arrays.asList(responsesElement)).build();
mockDatabaseAdmin.addResponse(expectedResponse);
String parent = "parent-995424086";
ListDatabasesPagedResponse pagedListResponse = client.listDatabases(parent);
List<Database> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getDatabasesList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListDatabasesRequest actualRequest = ((ListDatabasesRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
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 createBackupTest.
@Test
public void createBackupTest() 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();
Operation resultOperation = Operation.newBuilder().setName("createBackupTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
mockDatabaseAdmin.addResponse(resultOperation);
InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
Backup backup = Backup.newBuilder().build();
String backupId = "backupId2121930365";
Backup actualResponse = client.createBackupAsync(parent, backup, backupId).get();
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateBackupRequest actualRequest = ((CreateBackupRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(backup, actualRequest.getBackup());
Assert.assertEquals(backupId, actualRequest.getBackupId());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations