Modifier and Type | Class and Description |
---|---|
static interface |
TestPubsub.PollingAssertion |
Modifier and Type | Method and Description |
---|---|
Statement |
apply(Statement base,
Description description) |
void |
assertSubscriptionEventuallyCreated(java.lang.String project,
Duration timeoutDuration)
Block until a subscription is created for this test topic in the specified project.
|
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)
|
static TestPubsub |
create()
Creates an instance of this rule using options provided by
TestPipeline.testingPipelineOptions() . |
static TestPubsub |
fromOptions(PipelineOptions options)
Creates an instance of this rule using provided options.
|
void |
publish(java.util.List<PubsubMessage> messages)
Publish messages to
topicPath() . |
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()
TestPipeline.testingPipelineOptions()
.
Loads GCP configuration from TestPipelineOptions
.
public static TestPubsub fromOptions(PipelineOptions options)
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)
topicPath()
.public 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.IOException
java.lang.InterruptedException
public 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));
@Deprecated 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.InterruptedException
java.lang.IllegalArgumentException
java.io.IOException
java.util.concurrent.TimeoutException
public void assertSubscriptionEventuallyCreated(java.lang.String project, Duration timeoutDuration) throws java.lang.InterruptedException, java.lang.IllegalArgumentException, java.io.IOException
AssertionError
if timeoutDuration
is reached before a subscription is created.project
- GCP project identifier.timeoutDuration
- Joda duration before timeout occurs.java.lang.InterruptedException
java.lang.IllegalArgumentException
java.io.IOException