Search in sources :

Example 1 with ListSubscriptionsResponse

use of com.google.pubsub.v1.ListSubscriptionsResponse in project google-cloud-java by GoogleCloudPlatform.

the class SubscriptionAdminClientTest method listSubscriptionsTest.

@Test
@SuppressWarnings("all")
public void listSubscriptionsTest() {
    String nextPageToken = "";
    Subscription subscriptionsElement = Subscription.newBuilder().build();
    List<Subscription> subscriptions = Arrays.asList(subscriptionsElement);
    ListSubscriptionsResponse expectedResponse = ListSubscriptionsResponse.newBuilder().setNextPageToken(nextPageToken).addAllSubscriptions(subscriptions).build();
    mockSubscriber.addResponse(expectedResponse);
    ProjectName project = ProjectName.create("[PROJECT]");
    ListSubscriptionsPagedResponse pagedListResponse = client.listSubscriptions(project);
    List<Subscription> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getSubscriptionsList().get(0), resources.get(0));
    List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListSubscriptionsRequest actualRequest = (ListSubscriptionsRequest) actualRequests.get(0);
    Assert.assertEquals(project, actualRequest.getProjectAsProjectName());
}
Also used : ListSubscriptionsPagedResponse(com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListSubscriptionsPagedResponse) ListSubscriptionsResponse(com.google.pubsub.v1.ListSubscriptionsResponse) ProjectName(com.google.pubsub.v1.ProjectName) ListSubscriptionsRequest(com.google.pubsub.v1.ListSubscriptionsRequest) ByteString(com.google.protobuf.ByteString) Subscription(com.google.pubsub.v1.Subscription) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 2 with ListSubscriptionsResponse

use of com.google.pubsub.v1.ListSubscriptionsResponse in project beam by apache.

the class PubsubGrpcClient method listSubscriptions.

@Override
public List<SubscriptionPath> listSubscriptions(ProjectPath project, TopicPath topic) throws IOException {
    ListSubscriptionsRequest.Builder request = ListSubscriptionsRequest.newBuilder().setProject(project.getPath()).setPageSize(LIST_BATCH_SIZE);
    ListSubscriptionsResponse response = subscriberStub().listSubscriptions(request.build());
    if (response.getSubscriptionsCount() == 0) {
        return ImmutableList.of();
    }
    List<SubscriptionPath> subscriptions = new ArrayList<>(response.getSubscriptionsCount());
    while (true) {
        for (Subscription subscription : response.getSubscriptionsList()) {
            if (subscription.getTopic().equals(topic.getPath())) {
                subscriptions.add(subscriptionPathFromPath(subscription.getName()));
            }
        }
        if (response.getNextPageToken().isEmpty()) {
            break;
        }
        request.setPageToken(response.getNextPageToken());
        response = subscriberStub().listSubscriptions(request.build());
    }
    return subscriptions;
}
Also used : ListSubscriptionsResponse(com.google.pubsub.v1.ListSubscriptionsResponse) ListSubscriptionsRequest(com.google.pubsub.v1.ListSubscriptionsRequest) ArrayList(java.util.ArrayList) Subscription(com.google.pubsub.v1.Subscription)

Aggregations

ListSubscriptionsRequest (com.google.pubsub.v1.ListSubscriptionsRequest)2 ListSubscriptionsResponse (com.google.pubsub.v1.ListSubscriptionsResponse)2 Subscription (com.google.pubsub.v1.Subscription)2 ListSubscriptionsPagedResponse (com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListSubscriptionsPagedResponse)1 ByteString (com.google.protobuf.ByteString)1 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1 ProjectName (com.google.pubsub.v1.ProjectName)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1