Search in sources :

Example 36 with SubscriptionName

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

the class TopicAdminClientTest method listTopicSubscriptionsTest.

@Test
@SuppressWarnings("all")
public void listTopicSubscriptionsTest() {
    String nextPageToken = "";
    SubscriptionName subscriptionsElement = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
    List<SubscriptionName> subscriptions = Arrays.asList(subscriptionsElement);
    ListTopicSubscriptionsResponse expectedResponse = ListTopicSubscriptionsResponse.newBuilder().setNextPageToken(nextPageToken).addAllSubscriptionsWithSubscriptionNameList(subscriptions).build();
    mockPublisher.addResponse(expectedResponse);
    TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
    ListTopicSubscriptionsPagedResponse pagedListResponse = client.listTopicSubscriptions(topic);
    List<String> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getSubscriptionsList().get(0), resources.get(0));
    List<SubscriptionName> resourceNames = Lists.newArrayList(pagedListResponse.iterateAllAsSubscriptionName());
    Assert.assertEquals(1, resourceNames.size());
    Assert.assertEquals(expectedResponse.getSubscriptionsListAsSubscriptionNameList().get(0), resourceNames.get(0));
    List<GeneratedMessageV3> actualRequests = mockPublisher.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListTopicSubscriptionsRequest actualRequest = (ListTopicSubscriptionsRequest) actualRequests.get(0);
    Assert.assertEquals(topic, actualRequest.getTopicAsTopicName());
}
Also used : ListTopicSubscriptionsPagedResponse(com.google.cloud.pubsub.spi.v1.PagedResponseWrappers.ListTopicSubscriptionsPagedResponse) ListTopicSubscriptionsRequest(com.google.pubsub.v1.ListTopicSubscriptionsRequest) ByteString(com.google.protobuf.ByteString) SubscriptionName(com.google.pubsub.v1.SubscriptionName) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) ListTopicSubscriptionsResponse(com.google.pubsub.v1.ListTopicSubscriptionsResponse) TopicName(com.google.pubsub.v1.TopicName) Test(org.junit.Test)

Example 37 with SubscriptionName

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

the class SubscriptionAdminClientTest method streamingPullExceptionTest.

@Test
@SuppressWarnings("all")
public void streamingPullExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockSubscriber.addException(exception);
    SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
    int streamAckDeadlineSeconds = 1875467245;
    StreamingPullRequest request = StreamingPullRequest.newBuilder().setSubscriptionWithSubscriptionName(subscription).setStreamAckDeadlineSeconds(streamAckDeadlineSeconds).build();
    MockStreamObserver<StreamingPullResponse> responseObserver = new MockStreamObserver<>();
    StreamingCallable<StreamingPullRequest, StreamingPullResponse> callable = client.streamingPullCallable();
    ApiStreamObserver<StreamingPullRequest> requestObserver = callable.bidiStreamingCall(responseObserver);
    requestObserver.onNext(request);
    try {
        List<StreamingPullResponse> actualResponses = responseObserver.future().get();
        Assert.fail("No exception thrown");
    } catch (ExecutionException e) {
        Assert.assertTrue(e.getCause() instanceof StatusRuntimeException);
        StatusRuntimeException statusException = (StatusRuntimeException) e.getCause();
        Assert.assertEquals(Status.INVALID_ARGUMENT, statusException.getStatus());
    }
}
Also used : StreamingPullResponse(com.google.pubsub.v1.StreamingPullResponse) StatusRuntimeException(io.grpc.StatusRuntimeException) SubscriptionName(com.google.pubsub.v1.SubscriptionName) MockStreamObserver(com.google.api.gax.grpc.testing.MockStreamObserver) ExecutionException(java.util.concurrent.ExecutionException) StreamingPullRequest(com.google.pubsub.v1.StreamingPullRequest) Test(org.junit.Test)

Example 38 with SubscriptionName

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

the class SubscriptionAdminClientTest method deleteSubscriptionExceptionTest.

@Test
@SuppressWarnings("all")
public void deleteSubscriptionExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockSubscriber.addException(exception);
    try {
        SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
        client.deleteSubscription(subscription);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) SubscriptionName(com.google.pubsub.v1.SubscriptionName) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 39 with SubscriptionName

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

the class SubscriptionAdminClientTest method createSnapshotTest.

@Test
@SuppressWarnings("all")
public void createSnapshotTest() {
    SnapshotName name2 = SnapshotName.create("[PROJECT]", "[SNAPSHOT]");
    TopicName topic = TopicName.create("[PROJECT]", "[TOPIC]");
    Snapshot expectedResponse = Snapshot.newBuilder().setNameWithSnapshotName(name2).setTopicWithTopicName(topic).build();
    mockSubscriber.addResponse(expectedResponse);
    SnapshotName name = SnapshotName.create("[PROJECT]", "[SNAPSHOT]");
    SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
    Snapshot actualResponse = client.createSnapshot(name, subscription);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateSnapshotRequest actualRequest = (CreateSnapshotRequest) actualRequests.get(0);
    Assert.assertEquals(name, actualRequest.getNameAsSnapshotName());
    Assert.assertEquals(subscription, actualRequest.getSubscriptionAsSubscriptionName());
}
Also used : Snapshot(com.google.pubsub.v1.Snapshot) CreateSnapshotRequest(com.google.pubsub.v1.CreateSnapshotRequest) SubscriptionName(com.google.pubsub.v1.SubscriptionName) SnapshotName(com.google.pubsub.v1.SnapshotName) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) TopicName(com.google.pubsub.v1.TopicName) Test(org.junit.Test)

Example 40 with SubscriptionName

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

the class SubscriptionAdminClientTest method getSubscriptionExceptionTest.

@Test
@SuppressWarnings("all")
public void getSubscriptionExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockSubscriber.addException(exception);
    try {
        SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
        client.getSubscription(subscription);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) SubscriptionName(com.google.pubsub.v1.SubscriptionName) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Aggregations

SubscriptionName (com.google.pubsub.v1.SubscriptionName)31 Test (org.junit.Test)24 TopicName (com.google.pubsub.v1.TopicName)11 Subscription (com.google.pubsub.v1.Subscription)10 SubscriptionAdminClient (com.google.cloud.pubsub.spi.v1.SubscriptionAdminClient)9 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)9 StatusRuntimeException (io.grpc.StatusRuntimeException)9 ApiException (com.google.api.gax.grpc.ApiException)8 ProjectSubscriptionName (com.google.pubsub.v1.ProjectSubscriptionName)8 PushConfig (com.google.pubsub.v1.PushConfig)8 ByteString (com.google.protobuf.ByteString)7 Subscriber (com.google.cloud.pubsub.v1.Subscriber)5 PubsubMessage (com.google.pubsub.v1.PubsubMessage)5 Empty (com.google.protobuf.Empty)4 ArrayList (java.util.ArrayList)4 AckReplyConsumer (com.google.cloud.pubsub.spi.v1.AckReplyConsumer)3 MessageReceiver (com.google.cloud.pubsub.spi.v1.MessageReceiver)3 Subscriber (com.google.cloud.pubsub.spi.v1.Subscriber)3 TopicAdminClient (com.google.cloud.pubsub.spi.v1.TopicAdminClient)3 SubscriptionAdminClient (com.google.cloud.pubsub.v1.SubscriptionAdminClient)3