Search in sources :

Example 16 with DatabaseName

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

the class DatabaseAdminClientTest method dropDatabaseExceptionTest.

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

Example 17 with DatabaseName

use of com.google.spanner.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 18 with DatabaseName

use of com.google.spanner.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 19 with DatabaseName

use of com.google.spanner.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 20 with DatabaseName

use of com.google.spanner.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)

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