| Modifier and Type | Class and Description |
|---|---|
static interface |
TestPubsub.PollingAssertion |
| Modifier and Type | Method and Description |
|---|---|
Statement |
apply(Statement base,
Description description) |
TestPubsub.PollingAssertion |
assertThatTopicEventuallyReceives(Matcher<PubsubMessage>... matchers)
Repeatedly pull messages from
subscriptionPath() until receiving one for each matcher
(or timeout is reached), then assert that the received messages match the expectations. |
void |
checkIfAnySubscriptionExists(java.lang.String project,
Duration timeoutDuration)
Check if topics exist.
|
static TestPubsub |
create()
Creates an instance of this rule.
|
void |
publish(java.util.List<PubsubMessage> messages)
Publish messages to
topicPath(). |
java.util.List<PubsubMessage> |
pull()
Pull up to 100 messages from
subscriptionPath(). |
java.util.List<PubsubMessage> |
pull(int maxBatchSize)
Pull up to
maxBatchSize messages from subscriptionPath(). |
PubsubClient.SubscriptionPath |
subscriptionPath()
Subscription path used to listen for messages on
topicPath(). |
PubsubClient.TopicPath |
topicPath()
Topic path where events will be published to.
|
java.util.List<PubsubMessage> |
waitForNMessages(int n,
Duration timeoutDuration)
Repeatedly pull messages from
subscriptionPath(), returns after receiving n
messages or after waiting for timeoutDuration. |
public static TestPubsub create()
Loads GCP configuration from TestPipelineOptions.
public Statement apply(Statement base, Description description)
public PubsubClient.TopicPath topicPath()
public PubsubClient.SubscriptionPath subscriptionPath()
topicPath().public void publish(java.util.List<PubsubMessage> messages) throws java.io.IOException
topicPath().java.io.IOExceptionpublic java.util.List<PubsubMessage> pull() throws java.io.IOException
subscriptionPath().java.io.IOExceptionpublic java.util.List<PubsubMessage> pull(int maxBatchSize) throws java.io.IOException
maxBatchSize messages from subscriptionPath().java.io.IOExceptionpublic java.util.List<PubsubMessage> waitForNMessages(int n, Duration timeoutDuration) throws java.io.IOException, java.lang.InterruptedException
subscriptionPath(), returns after receiving n
messages or after waiting for timeoutDuration.java.io.IOExceptionjava.lang.InterruptedExceptionpublic TestPubsub.PollingAssertion assertThatTopicEventuallyReceives(Matcher<PubsubMessage>... matchers)
subscriptionPath() until receiving one for each matcher
(or timeout is reached), then assert that the received messages match the expectations.
Example usage:
{@code
testTopic
.assertThatTopicEventuallyReceives(
hasProperty("payload", equalTo("hello".getBytes(StandardCharsets.US_ASCII))),
hasProperty("payload", equalTo("world".getBytes(StandardCharsets.US_ASCII))))
.waitForUpTo(Duration.standardSeconds(20));
public void checkIfAnySubscriptionExists(java.lang.String project,
Duration timeoutDuration)
throws java.lang.InterruptedException,
java.lang.IllegalArgumentException,
java.io.IOException,
java.util.concurrent.TimeoutException
project - GCP project identifier.timeoutDuration - Joda duration that sets a period of time before checking times out.java.lang.InterruptedExceptionjava.lang.IllegalArgumentExceptionjava.io.IOExceptionjava.util.concurrent.TimeoutException