use of com.google.spanner.admin.database.v1.Backup in project java-spanner by googleapis.
the class MockDatabaseAdminServiceImplTest method createBackup.
@Test
public void createBackup() {
createTestDb();
Backup bck = createTestBackup();
assertThat(bck.getName()).isEqualTo(TEST_BCK_NAME);
}
use of com.google.spanner.admin.database.v1.Backup in project java-spanner by googleapis.
the class DatabaseAdminClientTest method deleteBackupExceptionTest.
@Test
public void deleteBackupExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockDatabaseAdmin.addException(exception);
try {
BackupName name = BackupName.of("[PROJECT]", "[INSTANCE]", "[BACKUP]");
client.deleteBackup(name);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.spanner.admin.database.v1.Backup 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()));
}
use of com.google.spanner.admin.database.v1.Backup in project java-spanner by googleapis.
the class DatabaseAdminClientTest method createBackupExceptionTest2.
@Test
public void createBackupExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockDatabaseAdmin.addException(exception);
try {
String parent = "parent-995424086";
Backup backup = Backup.newBuilder().build();
String backupId = "backupId2121930365";
client.createBackupAsync(parent, backup, backupId).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.Backup in project java-spanner by googleapis.
the class DatabaseAdminClientTest method listBackupsTest2.
@Test
public void listBackupsTest2() throws Exception {
Backup responsesElement = Backup.newBuilder().build();
ListBackupsResponse expectedResponse = ListBackupsResponse.newBuilder().setNextPageToken("").addAllBackups(Arrays.asList(responsesElement)).build();
mockDatabaseAdmin.addResponse(expectedResponse);
String parent = "parent-995424086";
ListBackupsPagedResponse pagedListResponse = client.listBackups(parent);
List<Backup> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getBackupsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListBackupsRequest actualRequest = ((ListBackupsRequest) actualRequests.get(0));
Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations