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);
}
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());
}
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());
}
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());
}
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);
});
}
Aggregations