Search in sources :

Example 11 with PullRequest

use of com.vmware.connectors.github.pr.v3.PullRequest in project spring-cloud-gcp by spring-cloud.

the class PubSubSampleApplicationTests method getMessagesFromSubscription.

private List<String> getMessagesFromSubscription(String subscriptionName) {
    String projectSubscriptionName = ProjectSubscriptionName.format(projectName, subscriptionName);
    PullRequest pullRequest = PullRequest.newBuilder().setReturnImmediately(true).setMaxMessages(10).setSubscription(projectSubscriptionName).build();
    PullResponse pullResponse = subscriptionAdminClient.getStub().pullCallable().call(pullRequest);
    return pullResponse.getReceivedMessagesList().stream().map((message) -> message.getMessage().getData().toStringUtf8()).collect(Collectors.toList());
}
Also used : Topic(com.google.pubsub.v1.Topic) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Assume.assumeThat(org.junit.Assume.assumeThat) BeforeClass(org.junit.BeforeClass) WebEnvironment(org.springframework.boot.test.context.SpringBootTest.WebEnvironment) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) ListTopicsPagedResponse(com.google.cloud.pubsub.v1.TopicAdminClient.ListTopicsPagedResponse) ServiceOptions(com.google.cloud.ServiceOptions) SubscriptionAdminClient(com.google.cloud.pubsub.v1.SubscriptionAdminClient) StreamSupport(java.util.stream.StreamSupport) ProjectTopicName(com.google.pubsub.v1.ProjectTopicName) SpringRunner(org.springframework.test.context.junit4.SpringRunner) PullResponse(com.google.pubsub.v1.PullResponse) Before(org.junit.Before) AfterClass(org.junit.AfterClass) Awaitility.await(org.awaitility.Awaitility.await) IOException(java.io.IOException) Test(org.junit.Test) PullRequest(com.google.pubsub.v1.PullRequest) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) LocalServerPort(org.springframework.boot.web.server.LocalServerPort) List(java.util.List) Rule(org.junit.Rule) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) OutputCaptureRule(org.springframework.boot.test.system.OutputCaptureRule) TopicAdminClient(com.google.cloud.pubsub.v1.TopicAdminClient) ProjectSubscriptionName(com.google.pubsub.v1.ProjectSubscriptionName) ListSubscriptionsPagedResponse(com.google.cloud.pubsub.v1.SubscriptionAdminClient.ListSubscriptionsPagedResponse) Subscription(com.google.pubsub.v1.Subscription) ResponseEntity(org.springframework.http.ResponseEntity) Matchers.is(org.hamcrest.Matchers.is) PushConfig(com.google.pubsub.v1.PushConfig) TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) ProjectName(com.google.pubsub.v1.ProjectName) PullResponse(com.google.pubsub.v1.PullResponse) PullRequest(com.google.pubsub.v1.PullRequest)

Example 12 with PullRequest

use of com.vmware.connectors.github.pr.v3.PullRequest in project spring-cloud-gcp by spring-cloud.

the class DefaultSubscriberFactoryTests method testCreatePullRequest_nonNullMaxMessages.

@Test
public void testCreatePullRequest_nonNullMaxMessages() {
    DefaultSubscriberFactory factory = new DefaultSubscriberFactory(() -> "project");
    factory.setCredentialsProvider(this.credentialsProvider);
    PullRequest request = factory.createPullRequest("test", null, true);
    assertThat(request.getMaxMessages()).isEqualTo(Integer.MAX_VALUE);
}
Also used : PullRequest(com.google.pubsub.v1.PullRequest) Test(org.junit.Test)

Aggregations

PullRequest (com.google.pubsub.v1.PullRequest)11 PullResponse (com.google.pubsub.v1.PullResponse)5 Test (org.junit.Test)5 PubsubMessage (com.google.pubsub.v1.PubsubMessage)4 ReceivedMessage (com.google.pubsub.v1.ReceivedMessage)4 Timestamp (com.google.protobuf.Timestamp)3 ArrayList (java.util.ArrayList)3 ByteString (com.google.protobuf.ByteString)2 SubscriberGrpc (com.google.pubsub.v1.SubscriberGrpc)2 SubscriberImplBase (com.google.pubsub.v1.SubscriberGrpc.SubscriberImplBase)2 ManagedChannel (io.grpc.ManagedChannel)2 Server (io.grpc.Server)2 StreamObserver (io.grpc.stub.StreamObserver)2 List (java.util.List)2 IncomingMessage (org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.IncomingMessage)2 AcknowledgeablePubsubMessage (org.springframework.cloud.gcp.pubsub.support.AcknowledgeablePubsubMessage)2 BasicAcknowledgeablePubsubMessage (org.springframework.cloud.gcp.pubsub.support.BasicAcknowledgeablePubsubMessage)2 ConvertedAcknowledgeablePubsubMessage (org.springframework.cloud.gcp.pubsub.support.converter.ConvertedAcknowledgeablePubsubMessage)2 ConvertedBasicAcknowledgeablePubsubMessage (org.springframework.cloud.gcp.pubsub.support.converter.ConvertedBasicAcknowledgeablePubsubMessage)2 ServiceOptions (com.google.cloud.ServiceOptions)1