Search in sources :

Example 21 with DatabaseName

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

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

Example 23 with DatabaseName

use of com.google.spanner.v1.DatabaseName in project cloud-spanner-r2dbc by GoogleCloudPlatform.

the class SessionCleanupUtils method getSessionNames.

private static List<String> getSessionNames() throws Exception {
    String databaseName = DatabaseName.format(ServiceOptions.getDefaultProjectId(), DatabaseProperties.INSTANCE, DatabaseProperties.DATABASE);
    String nextPageToken = null;
    List<String> sessionNames = new ArrayList<>();
    do {
        ListSessionsRequest.Builder requestBuilder = ListSessionsRequest.newBuilder().setDatabase(databaseName);
        if (nextPageToken != null) {
            requestBuilder.setPageToken(nextPageToken);
        }
        ListSessionsResponse listSessionsResponse = ObservableReactiveUtil.<ListSessionsResponse>unaryCall(obs -> spannerStub.listSessions(requestBuilder.build(), obs)).block();
        nextPageToken = listSessionsResponse.getNextPageToken();
        sessionNames.addAll(listSessionsResponse.getSessionsList().stream().map(Session::getName).collect(Collectors.toList()));
    } while (nextPageToken != null && !"".equals(nextPageToken));
    return sessionNames;
}
Also used : ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) Session(com.google.spanner.v1.Session) SpannerStub(com.google.spanner.v1.SpannerGrpc.SpannerStub) ManagedChannel(io.grpc.ManagedChannel) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) DeleteSessionRequest(com.google.spanner.v1.DeleteSessionRequest) ListSessionsResponse(com.google.spanner.v1.ListSessionsResponse) MoreCallCredentials(io.grpc.auth.MoreCallCredentials) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ObservableReactiveUtil(com.google.cloud.spanner.r2dbc.util.ObservableReactiveUtil) Empty(com.google.protobuf.Empty) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) ListSessionsRequest(com.google.spanner.v1.ListSessionsRequest) List(java.util.List) StreamObserver(io.grpc.stub.StreamObserver) ServiceOptions(com.google.cloud.ServiceOptions) DatabaseName(com.google.spanner.v1.DatabaseName) SpannerGrpc(com.google.spanner.v1.SpannerGrpc) ArrayList(java.util.ArrayList) ListSessionsRequest(com.google.spanner.v1.ListSessionsRequest) Session(com.google.spanner.v1.Session)

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