Search in sources :

Example 31 with PubsubMessage

use of com.google.pubsub.v1.PubsubMessage in project spring-cloud-gcp by spring-cloud.

the class JacksonPubSubMessageConverterTests method testToPubSubMessageWithNullPayload.

@Test
public void testToPubSubMessageWithNullPayload() throws JSONException {
    PubsubMessage pubsubMessage = this.converter.toPubSubMessage(null, null);
    Assert.assertNotNull(pubsubMessage);
}
Also used : PubsubMessage(com.google.pubsub.v1.PubsubMessage) Test(org.junit.Test)

Example 32 with PubsubMessage

use of com.google.pubsub.v1.PubsubMessage in project spring-cloud-gcp by spring-cloud.

the class PubSubSubscriberTemplateTests method testPullNextAsync.

@Test
public void testPullNextAsync() throws InterruptedException, ExecutionException, TimeoutException {
    ListenableFuture<PubsubMessage> asyncResult = this.pubSubSubscriberTemplate.pullNextAsync("sub2");
    PubsubMessage message = asyncResult.get(10L, TimeUnit.SECONDS);
    assertThat(asyncResult.isDone()).isTrue();
    assertThat(message).isSameAs(this.pubsubMessage);
    verify(this.subscriberFactory).createPullRequest("sub2", 1, true);
    verify(this.pubSubSubscriberTemplate, times(1)).ack(any());
}
Also used : PubsubMessage(com.google.pubsub.v1.PubsubMessage) ConvertedAcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.converter.ConvertedAcknowledgeablePubsubMessage) AcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.AcknowledgeablePubsubMessage) ConvertedBasicAcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.converter.ConvertedBasicAcknowledgeablePubsubMessage) BasicAcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.BasicAcknowledgeablePubsubMessage) Test(org.junit.Test)

Example 33 with PubsubMessage

use of com.google.pubsub.v1.PubsubMessage in project spring-cloud-gcp by spring-cloud.

the class PubSubSubscriberTemplateTests method testPullAndAck.

@Test
public void testPullAndAck() {
    List<PubsubMessage> result = this.pubSubSubscriberTemplate.pullAndAck("sub2", 1, true);
    assertThat(result.size()).isEqualTo(1);
    PubsubMessage pubsubMessage = result.get(0);
    assertThat(pubsubMessage).isSameAs(this.pubsubMessage);
    verify(this.pubSubSubscriberTemplate, times(1)).ack(any());
}
Also used : PubsubMessage(com.google.pubsub.v1.PubsubMessage) ConvertedAcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.converter.ConvertedAcknowledgeablePubsubMessage) AcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.AcknowledgeablePubsubMessage) ConvertedBasicAcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.converter.ConvertedBasicAcknowledgeablePubsubMessage) BasicAcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.BasicAcknowledgeablePubsubMessage) Test(org.junit.Test)

Example 34 with PubsubMessage

use of com.google.pubsub.v1.PubsubMessage in project spring-cloud-gcp by spring-cloud.

the class PubSubSubscriberTemplateTests method testPullNextAsync_NoMessages.

@Test
public void testPullNextAsync_NoMessages() throws InterruptedException, ExecutionException, TimeoutException {
    when(this.pullApiFuture.get()).thenReturn(PullResponse.newBuilder().build());
    ListenableFuture<PubsubMessage> asyncResult = this.pubSubSubscriberTemplate.pullNextAsync("sub2");
    PubsubMessage message = asyncResult.get(10L, TimeUnit.SECONDS);
    assertThat(asyncResult.isDone()).isTrue();
    assertThat(message).isNull();
    verify(this.subscriberFactory).createPullRequest("sub2", 1, true);
    verify(this.pubSubSubscriberTemplate, never()).ack(any());
}
Also used : PubsubMessage(com.google.pubsub.v1.PubsubMessage) ConvertedAcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.converter.ConvertedAcknowledgeablePubsubMessage) AcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.AcknowledgeablePubsubMessage) ConvertedBasicAcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.converter.ConvertedBasicAcknowledgeablePubsubMessage) BasicAcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.BasicAcknowledgeablePubsubMessage) Test(org.junit.Test)

Example 35 with PubsubMessage

use of com.google.pubsub.v1.PubsubMessage in project spring-cloud-gcp by spring-cloud.

the class PubSubTemplateIntegrationTests method testCreatePublishPullNextAndDelete.

@Test
public void testCreatePublishPullNextAndDelete() {
    this.contextRunner.run((context) -> {
        PubSubAdmin pubSubAdmin = context.getBean(PubSubAdmin.class);
        PubSubTemplate pubSubTemplate = context.getBean(PubSubTemplate.class);
        String topicName = "tarkus_" + UUID.randomUUID();
        String subscriptionName = "zatoichi_" + UUID.randomUUID();
        assertThat(pubSubAdmin.getTopic(topicName)).isNull();
        assertThat(pubSubAdmin.getSubscription(subscriptionName)).isNull();
        pubSubAdmin.createTopic(topicName);
        pubSubAdmin.createSubscription(subscriptionName, topicName);
        Map<String, String> headers = new HashMap<>();
        headers.put("cactuar", "tonberry");
        headers.put("fujin", "raijin");
        pubSubTemplate.publish(topicName, "tatatatata", headers).get();
        // get message
        AtomicReference<PubsubMessage> pubsubMessageRef = new AtomicReference<>();
        Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> {
            pubsubMessageRef.set(pubSubTemplate.pullNext(subscriptionName));
            return pubsubMessageRef.get() != null;
        });
        PubsubMessage pubsubMessage = pubsubMessageRef.get();
        assertThat(pubsubMessage.getData()).isEqualTo(ByteString.copyFromUtf8("tatatatata"));
        assertThat(pubsubMessage.getAttributesCount()).isEqualTo(2);
        assertThat(pubsubMessage.getAttributesOrThrow("cactuar")).isEqualTo("tonberry");
        assertThat(pubsubMessage.getAttributesOrThrow("fujin")).isEqualTo("raijin");
        assertThat(pubSubAdmin.getTopic(topicName)).isNotNull();
        assertThat(pubSubAdmin.getSubscription(subscriptionName)).isNotNull();
        assertThat(pubSubAdmin.listTopics().stream().filter((topic) -> topic.getName().endsWith(topicName)).toArray().length).isEqualTo(1);
        assertThat(pubSubAdmin.listSubscriptions().stream().filter((subscription) -> subscription.getName().endsWith(subscriptionName)).toArray().length).isEqualTo(1);
        pubSubAdmin.deleteSubscription(subscriptionName);
        pubSubAdmin.deleteTopic(topicName);
        assertThat(pubSubAdmin.getTopic(topicName)).isNull();
        assertThat(pubSubAdmin.getSubscription(subscriptionName)).isNull();
        assertThat(pubSubAdmin.listTopics().stream().filter((topic) -> topic.getName().endsWith(topicName)).toArray().length).isEqualTo(0);
        assertThat(pubSubAdmin.listSubscriptions().stream().filter((subscription) -> subscription.getName().endsWith(subscriptionName)).toArray().length).isEqualTo(0);
    });
}
Also used : HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteString(com.google.protobuf.ByteString) PubSubTemplate(org.springframework.cloud.gcp.pubsub.core.PubSubTemplate) PubsubMessage(com.google.pubsub.v1.PubsubMessage) ConvertedAcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.converter.ConvertedAcknowledgeablePubsubMessage) AcknowledgeablePubsubMessage(org.springframework.cloud.gcp.pubsub.support.AcknowledgeablePubsubMessage) PubSubAdmin(org.springframework.cloud.gcp.pubsub.PubSubAdmin) Test(org.junit.Test)

Aggregations

PubsubMessage (com.google.pubsub.v1.PubsubMessage)51 ByteString (com.google.protobuf.ByteString)28 Test (org.junit.Test)26 ArrayList (java.util.ArrayList)15 Subscriber (com.google.cloud.pubsub.v1.Subscriber)12 List (java.util.List)12 AcknowledgeablePubsubMessage (org.springframework.cloud.gcp.pubsub.support.AcknowledgeablePubsubMessage)12 Publisher (com.google.cloud.pubsub.v1.Publisher)11 ConvertedAcknowledgeablePubsubMessage (org.springframework.cloud.gcp.pubsub.support.converter.ConvertedAcknowledgeablePubsubMessage)11 ProjectTopicName (com.google.pubsub.v1.ProjectTopicName)10 ProjectSubscriptionName (com.google.pubsub.v1.ProjectSubscriptionName)9 BasicAcknowledgeablePubsubMessage (org.springframework.cloud.gcp.pubsub.support.BasicAcknowledgeablePubsubMessage)9 ConvertedBasicAcknowledgeablePubsubMessage (org.springframework.cloud.gcp.pubsub.support.converter.ConvertedBasicAcknowledgeablePubsubMessage)9 SettableApiFuture (com.google.api.core.SettableApiFuture)8 ServiceOptions (com.google.cloud.ServiceOptions)8 DlpServiceClient (com.google.cloud.dlp.v2.DlpServiceClient)8 Action (com.google.privacy.dlp.v2.Action)8 BigQueryTable (com.google.privacy.dlp.v2.BigQueryTable)8 CreateDlpJobRequest (com.google.privacy.dlp.v2.CreateDlpJobRequest)8 DlpJob (com.google.privacy.dlp.v2.DlpJob)8