Search in sources :

Example 1 with org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database

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);
    }
}
Also used : Database(com.google.spanner.admin.database.v1.Database) Operation(com.google.longrunning.Operation) CreateDatabaseMetadata(com.google.spanner.admin.database.v1.CreateDatabaseMetadata)

Example 2 with org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database

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);
}
Also used : ListDatabasesPagedResponse(com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabasesPagedResponse) ArrayList(java.util.ArrayList) Database(com.google.spanner.admin.database.v1.Database) Test(org.junit.Test)

Example 3 with org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database

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();
}
Also used : RestoreDatabaseRequest(com.google.spanner.admin.database.v1.RestoreDatabaseRequest) Database(com.google.spanner.admin.database.v1.Database) RestoreDatabaseMetadata(com.google.spanner.admin.database.v1.RestoreDatabaseMetadata) Test(org.junit.Test)

Example 4 with org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database

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);
}
Also used : Database(com.google.spanner.admin.database.v1.Database) Test(org.junit.Test)

Example 5 with org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database

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();
}
Also used : RestoreDatabaseRequest(com.google.spanner.admin.database.v1.RestoreDatabaseRequest) Database(com.google.spanner.admin.database.v1.Database) RestoreDatabaseMetadata(com.google.spanner.admin.database.v1.RestoreDatabaseMetadata) Test(org.junit.Test)

Aggregations

Database (com.google.spanner.admin.database.v1.Database)21 Test (org.junit.Test)20 Database (org.molgenis.emx2.Database)12 ArrayList (java.util.ArrayList)11 AbstractMessage (com.google.protobuf.AbstractMessage)10 ByteString (com.google.protobuf.ByteString)8 Operation (com.google.longrunning.Operation)7 RestoreDatabaseRequest (com.google.spanner.admin.database.v1.RestoreDatabaseRequest)7 BeforeClass (org.junit.BeforeClass)6 CreateDatabaseRequest (com.google.spanner.admin.database.v1.CreateDatabaseRequest)4 InstanceName (com.google.spanner.admin.database.v1.InstanceName)4 Schema (org.molgenis.emx2.Schema)4 ListDatabasesPagedResponse (com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabasesPagedResponse)3 CreateDatabaseMetadata (com.google.spanner.admin.database.v1.CreateDatabaseMetadata)3 RestoreDatabaseMetadata (com.google.spanner.admin.database.v1.RestoreDatabaseMetadata)3 BackupName (com.google.spanner.admin.database.v1.BackupName)2 DatabaseName (com.google.spanner.admin.database.v1.DatabaseName)2 GetDatabaseRequest (com.google.spanner.admin.database.v1.GetDatabaseRequest)2 ListDatabasesRequest (com.google.spanner.admin.database.v1.ListDatabasesRequest)2 ListDatabasesResponse (com.google.spanner.admin.database.v1.ListDatabasesResponse)2