Search in sources :

Example 1 with ListDatabaseOperationsRequest

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

the class DatabaseAdminClientTest method listDatabaseOperationsTest2.

@Test
public void listDatabaseOperationsTest2() throws Exception {
    Operation responsesElement = Operation.newBuilder().build();
    ListDatabaseOperationsResponse expectedResponse = ListDatabaseOperationsResponse.newBuilder().setNextPageToken("").addAllOperations(Arrays.asList(responsesElement)).build();
    mockDatabaseAdmin.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListDatabaseOperationsPagedResponse pagedListResponse = client.listDatabaseOperations(parent);
    List<Operation> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getOperationsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListDatabaseOperationsRequest actualRequest = ((ListDatabaseOperationsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : ListDatabaseOperationsResponse(com.google.spanner.admin.database.v1.ListDatabaseOperationsResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ListDatabaseOperationsPagedResponse(com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabaseOperationsPagedResponse) ListDatabaseOperationsRequest(com.google.spanner.admin.database.v1.ListDatabaseOperationsRequest) Operation(com.google.longrunning.Operation) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 2 with ListDatabaseOperationsRequest

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

the class GapicSpannerRpc method listDatabaseOperations.

@Override
public Paginated<Operation> listDatabaseOperations(String instanceName, int pageSize, @Nullable String filter, @Nullable String pageToken) {
    acquireAdministrativeRequestsRateLimiter();
    ListDatabaseOperationsRequest.Builder requestBuilder = ListDatabaseOperationsRequest.newBuilder().setParent(instanceName).setPageSize(pageSize);
    if (filter != null) {
        requestBuilder.setFilter(filter);
    }
    if (pageToken != null) {
        requestBuilder.setPageToken(pageToken);
    }
    final ListDatabaseOperationsRequest request = requestBuilder.build();
    final GrpcCallContext context = newCallContext(null, instanceName, request, DatabaseAdminGrpc.getListDatabaseOperationsMethod());
    ListDatabaseOperationsResponse response = runWithRetryOnAdministrativeRequestsExceeded(() -> get(databaseAdminStub.listDatabaseOperationsCallable().futureCall(request, context)));
    return new Paginated<>(response.getOperationsList(), response.getNextPageToken());
}
Also used : ListDatabaseOperationsResponse(com.google.spanner.admin.database.v1.ListDatabaseOperationsResponse) GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) ListDatabaseOperationsRequest(com.google.spanner.admin.database.v1.ListDatabaseOperationsRequest)

Example 3 with ListDatabaseOperationsRequest

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

the class MockDatabaseAdminServiceImpl method listDatabaseOperations.

@Override
public void listDatabaseOperations(ListDatabaseOperationsRequest request, StreamObserver<ListDatabaseOperationsResponse> responseObserver) {
    requests.add(request);
    ListDatabaseOperationsResponse.Builder builder = ListDatabaseOperationsResponse.newBuilder();
    try {
        for (Operation op : operations.iterable()) {
            if (op.getName().matches(".*?/databases\\/.*?/operations/.*?") && op.getName().startsWith(request.getParent())) {
                if (matchesFilter(op, request.getFilter())) {
                    builder.addOperations(op);
                }
            }
        }
        responseObserver.onNext(builder.build());
        responseObserver.onCompleted();
    } catch (Exception e) {
        responseObserver.onError(e);
    }
}
Also used : ListDatabaseOperationsResponse(com.google.spanner.admin.database.v1.ListDatabaseOperationsResponse) Operation(com.google.longrunning.Operation)

Example 4 with ListDatabaseOperationsRequest

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

the class DatabaseAdminClientTest method listDatabaseOperationsTest.

@Test
public void listDatabaseOperationsTest() throws Exception {
    Operation responsesElement = Operation.newBuilder().build();
    ListDatabaseOperationsResponse expectedResponse = ListDatabaseOperationsResponse.newBuilder().setNextPageToken("").addAllOperations(Arrays.asList(responsesElement)).build();
    mockDatabaseAdmin.addResponse(expectedResponse);
    InstanceName parent = InstanceName.of("[PROJECT]", "[INSTANCE]");
    ListDatabaseOperationsPagedResponse pagedListResponse = client.listDatabaseOperations(parent);
    List<Operation> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getOperationsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockDatabaseAdmin.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListDatabaseOperationsRequest actualRequest = ((ListDatabaseOperationsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : InstanceName(com.google.spanner.admin.database.v1.InstanceName) ListDatabaseOperationsResponse(com.google.spanner.admin.database.v1.ListDatabaseOperationsResponse) AbstractMessage(com.google.protobuf.AbstractMessage) ListDatabaseOperationsPagedResponse(com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabaseOperationsPagedResponse) ListDatabaseOperationsRequest(com.google.spanner.admin.database.v1.ListDatabaseOperationsRequest) Operation(com.google.longrunning.Operation) Test(org.junit.Test)

Aggregations

ListDatabaseOperationsResponse (com.google.spanner.admin.database.v1.ListDatabaseOperationsResponse)4 Operation (com.google.longrunning.Operation)3 ListDatabaseOperationsRequest (com.google.spanner.admin.database.v1.ListDatabaseOperationsRequest)3 ListDatabaseOperationsPagedResponse (com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabaseOperationsPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Test (org.junit.Test)2 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)1 ByteString (com.google.protobuf.ByteString)1 InstanceName (com.google.spanner.admin.database.v1.InstanceName)1