Search in sources :

Example 46 with Subscription

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

the class SubscriptionAdminClientTest method streamingPullTest.

@Test
@SuppressWarnings("all")
public void streamingPullTest() throws Exception {
    StreamingPullResponse expectedResponse = StreamingPullResponse.newBuilder().build();
    mockSubscriber.addResponse(expectedResponse);
    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);
    requestObserver.onCompleted();
    List<StreamingPullResponse> actualResponses = responseObserver.future().get();
    Assert.assertEquals(1, actualResponses.size());
    Assert.assertEquals(expectedResponse, actualResponses.get(0));
}
Also used : StreamingPullResponse(com.google.pubsub.v1.StreamingPullResponse) SubscriptionName(com.google.pubsub.v1.SubscriptionName) MockStreamObserver(com.google.api.gax.grpc.testing.MockStreamObserver) StreamingPullRequest(com.google.pubsub.v1.StreamingPullRequest) Test(org.junit.Test)

Example 47 with Subscription

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

the class SubscriptionAdminClientTest method modifyPushConfigTest.

@Test
@SuppressWarnings("all")
public void modifyPushConfigTest() {
    Empty expectedResponse = Empty.newBuilder().build();
    mockSubscriber.addResponse(expectedResponse);
    SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
    PushConfig pushConfig = PushConfig.newBuilder().build();
    client.modifyPushConfig(subscription, pushConfig);
    List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ModifyPushConfigRequest actualRequest = (ModifyPushConfigRequest) actualRequests.get(0);
    Assert.assertEquals(subscription, actualRequest.getSubscriptionAsSubscriptionName());
    Assert.assertEquals(pushConfig, actualRequest.getPushConfig());
}
Also used : PushConfig(com.google.pubsub.v1.PushConfig) Empty(com.google.protobuf.Empty) SubscriptionName(com.google.pubsub.v1.SubscriptionName) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) ModifyPushConfigRequest(com.google.pubsub.v1.ModifyPushConfigRequest) Test(org.junit.Test)

Example 48 with Subscription

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

the class SubscriptionAdminClientTest method modifyPushConfigExceptionTest.

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

Example 49 with Subscription

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

the class SubscriptionAdminClientTest method getSubscriptionTest.

@Test
@SuppressWarnings("all")
public void getSubscriptionTest() {
    SubscriptionName name = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
    TopicNameOneof topic = TopicNameOneof.from(TopicName.create("[PROJECT]", "[TOPIC]"));
    int ackDeadlineSeconds = 2135351438;
    boolean retainAckedMessages = false;
    Subscription expectedResponse = Subscription.newBuilder().setNameWithSubscriptionName(name).setTopicWithTopicNameOneof(topic).setAckDeadlineSeconds(ackDeadlineSeconds).setRetainAckedMessages(retainAckedMessages).build();
    mockSubscriber.addResponse(expectedResponse);
    SubscriptionName subscription = SubscriptionName.create("[PROJECT]", "[SUBSCRIPTION]");
    Subscription actualResponse = client.getSubscription(subscription);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockSubscriber.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    GetSubscriptionRequest actualRequest = (GetSubscriptionRequest) actualRequests.get(0);
    Assert.assertEquals(subscription, actualRequest.getSubscriptionAsSubscriptionName());
}
Also used : TopicNameOneof(com.google.pubsub.v1.TopicNameOneof) GetSubscriptionRequest(com.google.pubsub.v1.GetSubscriptionRequest) SubscriptionName(com.google.pubsub.v1.SubscriptionName) Subscription(com.google.pubsub.v1.Subscription) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 50 with Subscription

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

the class PubsubGrpcClient method acknowledge.

@Override
public void acknowledge(SubscriptionPath subscription, List<String> ackIds) throws IOException {
    AcknowledgeRequest request = AcknowledgeRequest.newBuilder().setSubscription(subscription.getPath()).addAllAckIds(ackIds).build();
    // ignore Empty result.
    subscriberStub().acknowledge(request);
}
Also used : AcknowledgeRequest(com.google.pubsub.v1.AcknowledgeRequest)

Aggregations

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