@Experimental public class PubsubTestClient extends PubsubClient implements java.io.Serializable
PubsubClient
for use by unit tests. Only suitable for
testing publish(org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.TopicPath, java.util.List<org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.OutgoingMessage>)
, pull(long, org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.SubscriptionPath, int, boolean)
, acknowledge(org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.SubscriptionPath, java.util.List<java.lang.String>)
and modifyAckDeadline(org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.SubscriptionPath, java.util.List<java.lang.String>, int)
methods. Relies on statics to mimic the Pubsub service, though we try to hide that.Modifier and Type | Class and Description |
---|---|
static interface |
PubsubTestClient.PubsubTestClientFactory
Closing the factory will validate all expected messages were processed.
|
PubsubClient.OutgoingMessage, PubsubClient.ProjectPath, PubsubClient.PubsubClientFactory, PubsubClient.SubscriptionPath, PubsubClient.TopicPath
Constructor and Description |
---|
PubsubTestClient() |
Modifier and Type | Method and Description |
---|---|
int |
ackDeadlineSeconds(PubsubClient.SubscriptionPath subscription)
Return the ack deadline, in seconds, for
subscription . |
void |
acknowledge(PubsubClient.SubscriptionPath subscription,
java.util.List<java.lang.String> ackIds)
Acknowldege messages from
subscription with ackIds . |
void |
advance()
For subscription mode only: Track progression of time according to the
Clock passed . |
void |
close() |
static PubsubTestClient.PubsubTestClientFactory |
createFactoryForCreateSubscription() |
static PubsubTestClient.PubsubTestClientFactory |
createFactoryForPublish(PubsubClient.TopicPath expectedTopic,
java.lang.Iterable<PubsubClient.OutgoingMessage> expectedOutgoingMessages,
java.lang.Iterable<PubsubClient.OutgoingMessage> failingOutgoingMessages)
Return a factory for testing publishers.
|
static PubsubTestClient.PubsubTestClientFactory |
createFactoryForPull(com.google.api.client.util.Clock clock,
PubsubClient.SubscriptionPath expectedSubscription,
int ackTimeoutSec,
java.lang.Iterable<org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.IncomingMessage> expectedIncomingMessages)
Return a factory for testing subscribers.
|
static PubsubTestClient.PubsubTestClientFactory |
createFactoryForPullAndPublish(PubsubClient.SubscriptionPath pullSubscription,
PubsubClient.TopicPath publishTopicPath,
com.google.api.client.util.Clock pullClock,
int pullAckTimeoutSec,
java.lang.Iterable<org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.IncomingMessage> expectedIncomingMessages,
java.lang.Iterable<PubsubClient.OutgoingMessage> expectedOutgoingMessages,
java.lang.Iterable<PubsubClient.OutgoingMessage> failingOutgoingMessages)
Returns a factory for a test that is expected to both publish and pull messages over the course
of the test.
|
void |
createSubscription(PubsubClient.TopicPath topic,
PubsubClient.SubscriptionPath subscription,
int ackDeadlineSeconds)
Create
subscription to topic . |
void |
createTopic(PubsubClient.TopicPath topic)
Create
topic . |
void |
deleteSubscription(PubsubClient.SubscriptionPath subscription)
Delete
subscription . |
void |
deleteTopic(PubsubClient.TopicPath topic) |
boolean |
isEOF()
Return true if
PubsubClient.pull(long, org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.SubscriptionPath, int, boolean) will always return empty list. |
java.util.List<PubsubClient.SubscriptionPath> |
listSubscriptions(PubsubClient.ProjectPath project,
PubsubClient.TopicPath topic)
Return a list of subscriptions for
topic in project . |
java.util.List<PubsubClient.TopicPath> |
listTopics(PubsubClient.ProjectPath project)
Return a list of topics for
project . |
void |
modifyAckDeadline(PubsubClient.SubscriptionPath subscription,
java.util.List<java.lang.String> ackIds,
int deadlineSeconds)
Modify the ack deadline for messages from
subscription with ackIds to be deadlineSeconds from now. |
int |
publish(PubsubClient.TopicPath topic,
java.util.List<PubsubClient.OutgoingMessage> outgoingMessages)
Publish
outgoingMessages to Pubsub topic . |
java.util.List<org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.IncomingMessage> |
pull(long requestTimeMsSinceEpoch,
PubsubClient.SubscriptionPath subscription,
int batchSize,
boolean returnImmediately)
Request the next batch of up to
batchSize messages from subscription . |
createRandomSubscription, extractTimestampAttribute, parseTimestampAsMsSinceEpoch, projectPathFromId, projectPathFromPath, subscriptionPathFromName, subscriptionPathFromPath, topicPathFromName, topicPathFromPath
public static PubsubTestClient.PubsubTestClientFactory createFactoryForPublish(PubsubClient.TopicPath expectedTopic, java.lang.Iterable<PubsubClient.OutgoingMessage> expectedOutgoingMessages, java.lang.Iterable<PubsubClient.OutgoingMessage> failingOutgoingMessages)
public static PubsubTestClient.PubsubTestClientFactory createFactoryForPull(com.google.api.client.util.Clock clock, PubsubClient.SubscriptionPath expectedSubscription, int ackTimeoutSec, java.lang.Iterable<org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.IncomingMessage> expectedIncomingMessages)
public static PubsubTestClient.PubsubTestClientFactory createFactoryForPullAndPublish(PubsubClient.SubscriptionPath pullSubscription, PubsubClient.TopicPath publishTopicPath, com.google.api.client.util.Clock pullClock, int pullAckTimeoutSec, java.lang.Iterable<org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.IncomingMessage> expectedIncomingMessages, java.lang.Iterable<PubsubClient.OutgoingMessage> expectedOutgoingMessages, java.lang.Iterable<PubsubClient.OutgoingMessage> failingOutgoingMessages)
public static PubsubTestClient.PubsubTestClientFactory createFactoryForCreateSubscription()
public void advance()
Clock
passed .
This will simulate Pubsub expiring outstanding ACKs.public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
public int publish(PubsubClient.TopicPath topic, java.util.List<PubsubClient.OutgoingMessage> outgoingMessages) throws java.io.IOException
PubsubClient
outgoingMessages
to Pubsub topic
. Return number of messages published.publish
in class PubsubClient
java.io.IOException
public java.util.List<org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.IncomingMessage> pull(long requestTimeMsSinceEpoch, PubsubClient.SubscriptionPath subscription, int batchSize, boolean returnImmediately) throws java.io.IOException
PubsubClient
batchSize
messages from subscription
. Return
the received messages, or empty collection if none were available. Does not wait for messages
to arrive if returnImmediately
is true. Returned messages will record their
request time as requestTimeMsSinceEpoch
.pull
in class PubsubClient
java.io.IOException
public void acknowledge(PubsubClient.SubscriptionPath subscription, java.util.List<java.lang.String> ackIds) throws java.io.IOException
PubsubClient
subscription
with ackIds
.acknowledge
in class PubsubClient
java.io.IOException
public void modifyAckDeadline(PubsubClient.SubscriptionPath subscription, java.util.List<java.lang.String> ackIds, int deadlineSeconds) throws java.io.IOException
PubsubClient
subscription
with ackIds
to be deadlineSeconds
from now.modifyAckDeadline
in class PubsubClient
java.io.IOException
public void createTopic(PubsubClient.TopicPath topic) throws java.io.IOException
PubsubClient
topic
.createTopic
in class PubsubClient
java.io.IOException
public void deleteTopic(PubsubClient.TopicPath topic) throws java.io.IOException
deleteTopic
in class PubsubClient
java.io.IOException
public java.util.List<PubsubClient.TopicPath> listTopics(PubsubClient.ProjectPath project) throws java.io.IOException
PubsubClient
project
.listTopics
in class PubsubClient
java.io.IOException
public void createSubscription(PubsubClient.TopicPath topic, PubsubClient.SubscriptionPath subscription, int ackDeadlineSeconds) throws java.io.IOException
PubsubClient
subscription
to topic
.createSubscription
in class PubsubClient
java.io.IOException
public void deleteSubscription(PubsubClient.SubscriptionPath subscription) throws java.io.IOException
PubsubClient
subscription
.deleteSubscription
in class PubsubClient
java.io.IOException
public java.util.List<PubsubClient.SubscriptionPath> listSubscriptions(PubsubClient.ProjectPath project, PubsubClient.TopicPath topic) throws java.io.IOException
PubsubClient
topic
in project
.listSubscriptions
in class PubsubClient
java.io.IOException
public int ackDeadlineSeconds(PubsubClient.SubscriptionPath subscription) throws java.io.IOException
PubsubClient
subscription
.ackDeadlineSeconds
in class PubsubClient
java.io.IOException
public boolean isEOF()
PubsubClient
PubsubClient.pull(long, org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.SubscriptionPath, int, boolean)
will always return empty list. Actual clients will
return false. Test clients may return true to signal that all expected
messages have been pulled and the test may complete.isEOF
in class PubsubClient