use of com.google.spanner.admin.database.v1.RestoreDatabaseRequest in project java-spanner by googleapis.
the class MockDatabaseAdminServiceImplTest method restoreDatabaseAlreadyExists.
@Test
public void restoreDatabaseAlreadyExists() throws InterruptedException, ExecutionException {
createTestDb();
createTestBackup();
RestoreDatabaseRequest request = RestoreDatabaseRequest.newBuilder().setBackup(TEST_BCK_NAME).setDatabaseId("test-db").setParent(TEST_PARENT).build();
OperationFuture<Database, RestoreDatabaseMetadata> op = client.restoreDatabaseOperationCallable().futureCall(request);
exception.expect(ApiExceptionMatcher.forCode(StatusCode.Code.ALREADY_EXISTS));
op.get();
}
use of com.google.spanner.admin.database.v1.RestoreDatabaseRequest 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.RestoreDatabaseRequest 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.RestoreDatabaseRequest in project java-spanner by googleapis.
the class DatabaseAdminClientTest method restoreDatabaseTest3.
@Test
public void restoreDatabaseTest3() 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);
String parent = "parent-995424086";
String databaseId = "databaseId1688905718";
BackupName backup = BackupName.of("[PROJECT]", "[INSTANCE]", "[BACKUP]");
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, actualRequest.getParent());
Assert.assertEquals(databaseId, actualRequest.getDatabaseId());
Assert.assertEquals(backup.toString(), actualRequest.getBackup());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.spanner.admin.database.v1.RestoreDatabaseRequest in project java-spanner by googleapis.
the class MockDatabaseAdminServiceImpl method restoreDatabase.
@Override
public void restoreDatabase(RestoreDatabaseRequest request, StreamObserver<Operation> responseObserver) {
requests.add(request);
try {
restoreDatabaseStartupExecutionTime.simulateExecutionTime(exceptions, false, freezeLock);
MockBackup bck = backups.get(request.getBackup());
if (bck != null) {
String name = String.format("%s/databases/%s", request.getParent(), request.getDatabaseId());
MockDatabase db = new MockDatabase(name, bck.ddl, RestoreInfo.newBuilder().setBackupInfo(bck.toBackupInfo()).setSourceType(RestoreSourceType.BACKUP).build());
if (databases.putIfAbsent(name, db) == null) {
bck.referencingDatabases.add(db.name);
Operation optimizeOperation = Operation.newBuilder().setDone(false).setName(operations.generateOperationName(name)).setMetadata(Any.pack(OptimizeRestoredDatabaseMetadata.newBuilder().setName(name).setProgress(OperationProgress.newBuilder().setStartTime(currentTime()).setProgressPercent(0).build()).build())).setResponse(Any.pack(db.toProto())).build();
RestoreDatabaseMetadata metadata = RestoreDatabaseMetadata.newBuilder().setBackupInfo(bck.toBackupInfo()).setName(name).setProgress(OperationProgress.newBuilder().setStartTime(currentTime()).setProgressPercent(0).build()).setOptimizeDatabaseOperationName(optimizeOperation.getName()).setSourceType(RestoreSourceType.BACKUP).build();
Operation operation = Operation.newBuilder().setMetadata(Any.pack(metadata)).setResponse(Any.pack(db.toProto())).setDone(false).setName(operations.generateOperationName(name)).build();
operations.addOperation(operation, new RestoreDatabaseCallable(operation.getName(), name));
operations.addOperation(optimizeOperation, new OptimizeDatabaseCallable(optimizeOperation.getName(), operation.getName(), name));
restoreDatabaseResponseExecutionTime.simulateExecutionTime(exceptions, false, freezeLock);
responseObserver.onNext(operation);
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.ALREADY_EXISTS.asRuntimeException());
}
} else {
responseObserver.onError(Status.NOT_FOUND.asRuntimeException());
}
} catch (Throwable t) {
responseObserver.onError(t);
}
}
Aggregations