Search in sources :

Example 21 with DatabaseName

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

the class SpannerClientTest method batchCreateSessionsExceptionTest.

@Test
public void batchCreateSessionsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockSpanner.addException(exception);
    try {
        DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
        int sessionCount = 185691686;
        client.batchCreateSessions(database, sessionCount);
        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.v1.DatabaseName) Test(org.junit.Test)

Example 22 with DatabaseName

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

the class SpannerClientTest method batchCreateSessionsTest.

@Test
public void batchCreateSessionsTest() throws Exception {
    BatchCreateSessionsResponse expectedResponse = BatchCreateSessionsResponse.newBuilder().addAllSession(new ArrayList<Session>()).build();
    mockSpanner.addResponse(expectedResponse);
    DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
    int sessionCount = 185691686;
    BatchCreateSessionsResponse actualResponse = client.batchCreateSessions(database, sessionCount);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    BatchCreateSessionsRequest actualRequest = ((BatchCreateSessionsRequest) actualRequests.get(0));
    Assert.assertEquals(database.toString(), actualRequest.getDatabase());
    Assert.assertEquals(sessionCount, actualRequest.getSessionCount());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : BatchCreateSessionsResponse(com.google.spanner.v1.BatchCreateSessionsResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) DatabaseName(com.google.spanner.v1.DatabaseName) BatchCreateSessionsRequest(com.google.spanner.v1.BatchCreateSessionsRequest) Test(org.junit.Test)

Example 23 with DatabaseName

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

the class SpannerClientTest method createSessionExceptionTest.

@Test
public void createSessionExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockSpanner.addException(exception);
    try {
        DatabaseName database = DatabaseName.of("[PROJECT]", "[INSTANCE]", "[DATABASE]");
        client.createSession(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.v1.DatabaseName) Test(org.junit.Test)

Example 24 with DatabaseName

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

the class FirestoreAdminClientTest method importDocumentsExceptionTest.

@Test
public void importDocumentsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockFirestoreAdmin.addException(exception);
    try {
        DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
        client.importDocumentsAsync(name).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.firestore.admin.v1.DatabaseName) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 25 with DatabaseName

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

the class FirestoreAdminClientTest method exportDocumentsExceptionTest.

@Test
public void exportDocumentsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockFirestoreAdmin.addException(exception);
    try {
        DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
        client.exportDocumentsAsync(name).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.firestore.admin.v1.DatabaseName) ExecutionException(java.util.concurrent.ExecutionException) 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 Empty (com.google.protobuf.Empty)5 ExecutionException (java.util.concurrent.ExecutionException)5 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)4 DatabaseName (com.google.firestore.admin.v1.DatabaseName)4 Operation (com.google.longrunning.Operation)3 DropDatabaseRequest (com.google.spanner.admin.database.v1.DropDatabaseRequest)3 Session (com.google.spanner.v1.Session)3 ByteString (com.google.protobuf.ByteString)2 Database (com.google.spanner.admin.database.v1.Database)2 GetDatabaseDdlRequest (com.google.spanner.admin.database.v1.GetDatabaseDdlRequest)2 GetDatabaseRequest (com.google.spanner.admin.database.v1.GetDatabaseRequest)2 UpdateDatabaseDdlRequest (com.google.spanner.admin.database.v1.UpdateDatabaseDdlRequest)2 ListSessionsRequest (com.google.spanner.v1.ListSessionsRequest)2