Search in sources :

Example 1 with DatabaseName

use of com.google.spanner.v1.DatabaseName 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);
}
Also used : DatabaseName(com.google.spanner.admin.database.v1.DatabaseName) Database(com.google.spanner.admin.database.v1.Database)

Example 2 with DatabaseName

use of com.google.spanner.v1.DatabaseName in project java-spanner by googleapis.

the class DatabaseAdminClientTest method updateDatabaseDdlExceptionTest.

@Test
public void updateDatabaseDdlExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDatabaseAdmin.addException(exception);
    try {
        DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
        List<String> statements = new ArrayList<>();
        client.updateDatabaseDdlAsync(database, statements).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());
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) DatabaseName(com.google.spanner.admin.database.v1.DatabaseName) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 3 with DatabaseName

use of com.google.spanner.v1.DatabaseName in project java-spanner by googleapis.

the class DatabaseAdminClientTest method getDatabaseDdlTest.

@Test
public void getDatabaseDdlTest() throws Exception {
    GetDatabaseDdlResponse expectedResponse = GetDatabaseDdlResponse.newBuilder().addAllStatements(new ArrayList<String>()).build();
    mockDatabaseAdmin.addResponse(expectedResponse);
    DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
    GetDatabaseDdlResponse actualResponse = client.getDatabaseDdl(database);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetDatabaseDdlRequest actualRequest = ((GetDatabaseDdlRequest) actualRequests.get(0));
    Assert.assertEquals(database.toString(), actualRequest.getDatabase());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) DatabaseName(com.google.spanner.admin.database.v1.DatabaseName) GetDatabaseDdlResponse(com.google.spanner.admin.database.v1.GetDatabaseDdlResponse) GetDatabaseDdlRequest(com.google.spanner.admin.database.v1.GetDatabaseDdlRequest) Test(org.junit.Test)

Example 4 with DatabaseName

use of com.google.spanner.v1.DatabaseName in project java-spanner by googleapis.

the class DatabaseAdminClientTest method updateDatabaseDdlTest.

@Test
public void updateDatabaseDdlTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    Operation resultOperation = Operation.newBuilder().setName("updateDatabaseDdlTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockDatabaseAdmin.addResponse(resultOperation);
    DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
    List<String> statements = new ArrayList<>();
    client.updateDatabaseDdlAsync(database, statements).get();
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    UpdateDatabaseDdlRequest actualRequest = ((UpdateDatabaseDdlRequest) actualRequests.get(0));
    Assert.assertEquals(database.toString(), actualRequest.getDatabase());
    Assert.assertEquals(statements, actualRequest.getStatementsList());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) DatabaseName(com.google.spanner.admin.database.v1.DatabaseName) ArrayList(java.util.ArrayList) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) UpdateDatabaseDdlRequest(com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest) Test(org.junit.Test)

Example 5 with DatabaseName

use of com.google.spanner.v1.DatabaseName in project java-spanner by googleapis.

the class DatabaseAdminClientTest method getDatabaseDdlExceptionTest.

@Test
public void getDatabaseDdlExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockDatabaseAdmin.addException(exception);
    try {
        DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
        client.getDatabaseDdl(database);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) StatusRuntimeException(io.grpc.StatusRuntimeException) DatabaseName(com.google.spanner.admin.database.v1.DatabaseName) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)19 AbstractMessage (com.google.protobuf.AbstractMessage)10 DatabaseName (com.google.spanner.admin.database.v1.DatabaseName)10 StatusRuntimeException (io.grpc.StatusRuntimeException)10 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)9 DatabaseName (com.google.spanner.v1.DatabaseName)7 ArrayList (java.util.ArrayList)6 Session (com.google.spanner.v1.Session)5 DatabaseName (com.google.firestore.admin.v1.DatabaseName)4 Empty (com.google.protobuf.Empty)4 ExecutionException (java.util.concurrent.ExecutionException)4 Operation (com.google.longrunning.Operation)3 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)2 ByteString (com.google.protobuf.ByteString)2 Database (com.google.spanner.admin.database.v1.Database)2 BatchCreateSessionsRequest (com.google.spanner.v1.BatchCreateSessionsRequest)2 CreateSessionRequest (com.google.spanner.v1.CreateSessionRequest)2 ListSessionsRequest (com.google.spanner.v1.ListSessionsRequest)2 ListSessionsResponse (com.google.spanner.v1.ListSessionsResponse)2 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)1