use of com.google.api.services.pubsub.model.ListSubscriptionsResponse in project beam by apache.
the class PubsubJsonClient method listSubscriptions.
@Override
public List<SubscriptionPath> listSubscriptions(ProjectPath project, TopicPath topic) throws IOException {
Subscriptions.List request = pubsub.projects().subscriptions().list(project.getPath());
ListSubscriptionsResponse response = request.execute();
if (response.getSubscriptions() == null || response.getSubscriptions().isEmpty()) {
return ImmutableList.of();
}
List<SubscriptionPath> subscriptions = new ArrayList<>(response.getSubscriptions().size());
while (true) {
for (Subscription subscription : response.getSubscriptions()) {
if (subscription.getTopic().equals(topic.getPath())) {
subscriptions.add(subscriptionPathFromPath(subscription.getName()));
}
}
if (Strings.isNullOrEmpty(response.getNextPageToken())) {
break;
}
request.setPageToken(response.getNextPageToken());
response = request.execute();
}
return subscriptions;
}
use of com.google.api.services.pubsub.model.ListSubscriptionsResponse in project beam by apache.
the class PubsubJsonClientTest method listSubscriptions.
@Test
public void listSubscriptions() throws Exception {
ListSubscriptionsResponse expectedResponse1 = new ListSubscriptionsResponse();
expectedResponse1.setSubscriptions(Collections.singletonList(buildSubscription(1)));
expectedResponse1.setNextPageToken("AVgJH3Z7aHxiDBs");
ListSubscriptionsResponse expectedResponse2 = new ListSubscriptionsResponse();
expectedResponse2.setSubscriptions(Collections.singletonList(buildSubscription(2)));
Subscriptions.List request = mockPubsub.projects().subscriptions().list(PROJECT.getPath());
when((Object) request.execute()).thenReturn(expectedResponse1, expectedResponse2);
final TopicPath topic101 = PubsubClient.topicPathFromName("testProject", "Topic2");
List<SubscriptionPath> subscriptionPaths = client.listSubscriptions(PROJECT, topic101);
assertEquals(1, subscriptionPaths.size());
}
Aggregations