use of org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database in project java-spanner by googleapis.
the class MockDatabaseAdminServiceImpl method createDatabase.
@Override
public void createDatabase(CreateDatabaseRequest request, StreamObserver<Operation> responseObserver) {
requests.add(request);
try {
createDatabaseStartupExecutionTime.simulateExecutionTime(exceptions, false, freezeLock);
String id = request.getCreateStatement().replace("CREATE DATABASE ", "");
if (id.startsWith("`") && id.endsWith("`")) {
id = id.substring(1, id.length() - 1);
}
String name = String.format("%s/databases/%s", request.getParent(), id);
MockDatabase db = new MockDatabase(name, request.getExtraStatementsList(), null);
if (databases.putIfAbsent(name, db) == null) {
CreateDatabaseMetadata metadata = CreateDatabaseMetadata.newBuilder().setDatabase(name).build();
Database database = Database.newBuilder().setName(name).setState(db.state).build();
Operation operation = Operation.newBuilder().setMetadata(Any.pack(metadata)).setResponse(Any.pack(database)).setDone(false).setName(operations.generateOperationName(name)).build();
operations.addOperation(operation, new CreateDatabaseCallable(operation.getName(), name));
createDatabaseResponseExecutionTime.simulateExecutionTime(exceptions, false, freezeLock);
responseObserver.onNext(operation);
responseObserver.onCompleted();
} else {
responseObserver.onError(Status.ALREADY_EXISTS.withDescription(String.format("Database with name %s already exists", name)).asRuntimeException());
}
} catch (Throwable t) {
responseObserver.onError(t);
}
}
use of org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database in project java-spanner by googleapis.
the class MockDatabaseAdminServiceImplTest method listDatabases.
@Test
public void listDatabases() {
createTestDb();
ListDatabasesPagedResponse response = client.listDatabases(TEST_PARENT);
List<String> databases = new ArrayList<>();
for (Database db : response.iterateAll()) {
databases.add(db.getName());
}
assertThat(databases).containsExactly(TEST_DB_NAME);
}
use of org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database 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 org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$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 org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$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();
}
Aggregations