com.google.pubsub.v1.GetSubscriptionRequest Java Examples

The following examples show how to use com.google.pubsub.v1.GetSubscriptionRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SubscriberServiceTest.java    From kafka-pubsub-emulator with Apache License 2.0 6 votes vote down vote up
@Test
public void deleteSubscription() {
  String subscriptionName = TestHelpers.PROJECT1_SUBSCRIPTION1;
  DeleteSubscriptionRequest request =
      DeleteSubscriptionRequest.newBuilder().setSubscription(subscriptionName).build();

  assertThat(fakeSubscriptionManager1.isRunning(), Matchers.is(true));
  blockingStub.deleteSubscription(request);
  assertThat(fakeSubscriptionManager1.isRunning(), Matchers.is(false));

  expectedException.expect(StatusRuntimeException.class);
  expectedException.expectMessage(Status.NOT_FOUND.getCode().toString());

  blockingStub.getSubscription(
      GetSubscriptionRequest.newBuilder().setSubscription(subscriptionName).build());
}
 
Example #2
Source File: SubscriberServiceTest.java    From kafka-pubsub-emulator with Apache License 2.0 6 votes vote down vote up
@Test
public void getSubscription() {
  GetSubscriptionRequest request =
      GetSubscriptionRequest.newBuilder()
          .setSubscription(TestHelpers.PROJECT1_SUBSCRIPTION1)
          .build();
  Subscription response = blockingStub.getSubscription(request);
  assertThat(
      response,
      Matchers.equalTo(
          Subscription.newBuilder()
              .setName(TestHelpers.PROJECT1_SUBSCRIPTION1)
              .setTopic(TestHelpers.PROJECT1_TOPIC1)
              .putLabels(KAFKA_TOPIC, "kafka-topic-1")
              .setPushConfig(PushConfig.getDefaultInstance())
              .setAckDeadlineSeconds(10)
              .build()));
}
 
Example #3
Source File: CloudPubSubSourceConnector.java    From pubsub with Apache License 2.0 6 votes vote down vote up
/**
 * Check whether the user provided Cloud Pub/Sub subscription name specified by {@link
 * #CPS_SUBSCRIPTION_CONFIG} exists or not.
 */
@VisibleForTesting
public void verifySubscription(String cpsProject, String cpsSubscription, CredentialsProvider credentialsProvider) {
  try {
    SubscriberStubSettings subscriberStubSettings =
    SubscriberStubSettings.newBuilder()
      .setTransportChannelProvider(
          SubscriberStubSettings.defaultGrpcTransportProviderBuilder()
              .setMaxInboundMessageSize(20 << 20) // 20MB
              .build())
      .setCredentialsProvider(credentialsProvider)
      .build();
    GrpcSubscriberStub stub = GrpcSubscriberStub.create(subscriberStubSettings);
    GetSubscriptionRequest request =
        GetSubscriptionRequest.newBuilder()
            .setSubscription(
                String.format(
                    ConnectorUtils.CPS_SUBSCRIPTION_FORMAT, cpsProject, cpsSubscription))
            .build();
    stub.getSubscriptionCallable().call(request);
  } catch (Exception e) {
    throw new ConnectException(
        "Error verifying the subscription " + cpsSubscription + " for project " + cpsProject, e);
  }
}
 
Example #4
Source File: SubscriberService.java    From kafka-pubsub-emulator with Apache License 2.0 5 votes vote down vote up
@Override
public void getSubscription(
    GetSubscriptionRequest request, StreamObserver<Subscription> responseObserver) {
  logger.atFine().log("Getting Subscription %s", request);
  Optional<Subscription> subscription =
      configurationManager.getSubscriptionByName(request.getSubscription());
  if (!subscription.isPresent()) {
    String message = request.getSubscription() + " is not a valid Subscription";
    logger.atWarning().log(message);
    responseObserver.onError(Status.NOT_FOUND.withDescription(message).asException());
  } else {
    responseObserver.onNext(subscription.get());
    responseObserver.onCompleted();
  }
}
 
Example #5
Source File: SubscriberServiceTest.java    From kafka-pubsub-emulator with Apache License 2.0 5 votes vote down vote up
@Test
public void getSubscription_subscriptionDoesNotExist() {
  expectedException.expect(StatusRuntimeException.class);
  expectedException.expectMessage(Status.NOT_FOUND.getCode().toString());

  GetSubscriptionRequest request =
      GetSubscriptionRequest.newBuilder()
          .setSubscription("projects/project-1/subscriptions/unknown-subscription")
          .build();
  blockingStub.getSubscription(request);
}
 
Example #6
Source File: PubsubGrpcClient.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public int ackDeadlineSeconds(SubscriptionPath subscription) throws IOException {
  GetSubscriptionRequest request =
      GetSubscriptionRequest.newBuilder().setSubscription(subscription.getPath()).build();
  Subscription response = subscriberStub().getSubscription(request);
  return response.getAckDeadlineSeconds();
}