use of com.google.pubsub.v1.Subscription in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method createSnapshotExceptionTest.
@Test
@SuppressWarnings("all")
public void createSnapshotExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockSubscriber.addException(exception);
try {
SnapshotName name = SnapshotName.create("[PROJECT]", "[SNAPSHOT]");
SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
client.createSnapshot(name, subscription);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of com.google.pubsub.v1.Subscription in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method modifyAckDeadlineExceptionTest.
@Test
@SuppressWarnings("all")
public void modifyAckDeadlineExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockSubscriber.addException(exception);
try {
SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
List<String> ackIds = new ArrayList<>();
int ackDeadlineSeconds = 2135351438;
client.modifyAckDeadline(subscription, ackIds, ackDeadlineSeconds);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of com.google.pubsub.v1.Subscription in project google-cloud-java by GoogleCloudPlatform.
the class SubscriptionAdminClientTest method acknowledgeTest.
@Test
@SuppressWarnings("all")
public void acknowledgeTest() {
Empty expectedResponse = Empty.newBuilder().build();
mockSubscriber.addResponse(expectedResponse);
SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
List<String> ackIds = new ArrayList<>();
client.acknowledge(subscription, ackIds);
List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
Assert.assertEquals(1, actualRequests.size());
AcknowledgeRequest actualRequest = (AcknowledgeRequest) actualRequests.get(0);
Assert.assertEquals(subscription, actualRequest.getSubscriptionAsSubscriptionName());
Assert.assertEquals(ackIds, actualRequest.getAckIdsList());
}
use of com.google.pubsub.v1.Subscription in project google-cloud-java by GoogleCloudPlatform.
the class ITSubscriptionAdminClientSnippets method createSubscription.
private Subscription createSubscription(String topicName, String subscriptionName) throws Exception {
createTopic(topicName);
Subscription subscription = subscriptionAdminClientSnippets.createSubscription(topicName, subscriptionName);
assertNotNull(subscription);
Subscription retrievedSubscription = subscriptionAdminClientSnippets.getSubscription(subscriptionName);
assertNotNull(retrievedSubscription);
assertEquals(subscription.getName(), retrievedSubscription.getName());
return subscription;
}
use of com.google.pubsub.v1.Subscription in project google-cloud-java by GoogleCloudPlatform.
the class ITSubscriptionAdminClientSnippets method listSubscriptionsRetrievesAllAddedSubscriptions.
@Test
public void listSubscriptionsRetrievesAllAddedSubscriptions() throws Exception {
List<Subscription> addedSubscriptions = new ArrayList<>();
String topicName1 = topics[0];
String subscriptionName1 = subscriptions[0];
String topicName2 = topics[1];
String subscriptionName2 = subscriptions[1];
addedSubscriptions.add(createSubscription(topicName1, subscriptionName1));
addedSubscriptions.add(createSubscription(topicName2, subscriptionName2));
boolean[] subFound = { false, false };
ListSubscriptionsPagedResponse response = subscriptionAdminClientSnippets.listSubscriptions();
assertNotNull(response);
Iterable<Subscription> subscriptions = response.iterateAll();
for (int i = 0; i < 2; i++) {
if (!subFound[i]) {
subFound[i] = Iterables.contains(subscriptions, addedSubscriptions.get(i));
}
}
assertTrue(subFound[0] && subFound[1]);
}
Aggregations