Search in sources :

Example 16 with DatabaseName

use of com.google.firestore.admin.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 17 with DatabaseName

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

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

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

Example 20 with DatabaseName

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

the class FirestoreAdminClientTest method importDocumentsTest.

@Test
public void importDocumentsTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    Operation resultOperation = Operation.newBuilder().setName("importDocumentsTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
    mockFirestoreAdmin.addResponse(resultOperation);
    DatabaseName name = DatabaseName.of("[PROJECT]", "[DATABASE]");
    client.importDocumentsAsync(name).get();
    List<AbstractMessage> actualRequests = mockFirestoreAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ImportDocumentsRequest actualRequest = ((ImportDocumentsRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) DatabaseName(com.google.firestore.admin.v1.DatabaseName) ImportDocumentsRequest(com.google.firestore.admin.v1.ImportDocumentsRequest) Operation(com.google.longrunning.Operation) 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 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 Session (com.google.spanner.v1.Session)3 ByteString (com.google.protobuf.ByteString)2 Database (com.google.spanner.admin.database.v1.Database)2 ListSessionsRequest (com.google.spanner.v1.ListSessionsRequest)2 ListSessionsResponse (com.google.spanner.v1.ListSessionsResponse)2 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)1 ServiceOptions (com.google.cloud.ServiceOptions)1 ObservableReactiveUtil (com.google.cloud.spanner.r2dbc.util.ObservableReactiveUtil)1 ListSessionsPagedResponse (com.google.cloud.spanner.v1.SpannerClient.ListSessionsPagedResponse)1