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.IncomingMessage, PubsubClient.OutgoingMessage, PubsubClient.ProjectPath, PubsubClient.PubsubClientFactory, PubsubClient.SchemaPath, 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 |
createFactoryForGetSchema(PubsubClient.TopicPath expectedTopic,
@Nullable PubsubClient.SchemaPath expectedSchemaPath,
@Nullable Schema expectedSchema) |
static PubsubTestClient.PubsubTestClientFactory |
createFactoryForPublish(@Nullable 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<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<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 |
createSchema(PubsubClient.SchemaPath schemaPath,
java.lang.String schemaContent,
com.google.pubsub.v1.Schema.Type type)
Create
Schema from Schema definition content. |
void |
createSubscription(PubsubClient.TopicPath topic,
PubsubClient.SubscriptionPath subscription,
int ackDeadlineSeconds)
Create
subscription to topic . |
void |
createTopic(PubsubClient.TopicPath topic)
Create
topic . |
void |
createTopic(PubsubClient.TopicPath topic,
PubsubClient.SchemaPath schema)
Create {link TopicPath} with
PubsubClient.SchemaPath . |
void |
deleteSchema(PubsubClient.SchemaPath schemaPath)
Delete
SchemaPath . |
void |
deleteSubscription(PubsubClient.SubscriptionPath subscription)
Delete
subscription . |
void |
deleteTopic(PubsubClient.TopicPath topic) |
Schema |
getSchema(PubsubClient.SchemaPath schemaPath)
Return a Beam
Schema from the Pub/Sub schema resource, if exists. |
PubsubClient.SchemaPath |
getSchemaPath(PubsubClient.TopicPath topicPath)
Return
PubsubClient.SchemaPath from PubsubClient.TopicPath if exists. |
boolean |
isEOF()
Return true if
PubsubClient.pull(long, org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.SubscriptionPath, int, boolean) will always return empty list. |
boolean |
isTopicExists(PubsubClient.TopicPath topic)
Return true if
topic exists. |
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<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, schemaPathFromId, schemaPathFromPath, subscriptionPathFromName, subscriptionPathFromPath, topicPathFromName, topicPathFromPath
public static PubsubTestClient.PubsubTestClientFactory createFactoryForPublish(@Nullable 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<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<PubsubClient.IncomingMessage> expectedIncomingMessages, java.lang.Iterable<PubsubClient.OutgoingMessage> expectedOutgoingMessages, java.lang.Iterable<PubsubClient.OutgoingMessage> failingOutgoingMessages)
public static PubsubTestClient.PubsubTestClientFactory createFactoryForGetSchema(PubsubClient.TopicPath expectedTopic, @Nullable PubsubClient.SchemaPath expectedSchemaPath, @Nullable Schema expectedSchema)
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<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 createTopic(PubsubClient.TopicPath topic, PubsubClient.SchemaPath schema) throws java.io.IOException
PubsubClient
PubsubClient.SchemaPath
.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 boolean isTopicExists(PubsubClient.TopicPath topic) throws java.io.IOException
PubsubClient
topic
exists.isTopicExists
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
public void createSchema(PubsubClient.SchemaPath schemaPath, java.lang.String schemaContent, com.google.pubsub.v1.Schema.Type type) throws java.io.IOException
PubsubClient
Schema
from Schema definition content.createSchema
in class PubsubClient
java.io.IOException
public void deleteSchema(PubsubClient.SchemaPath schemaPath) throws java.io.IOException
SchemaPath
.deleteSchema
in class PubsubClient
java.io.IOException
public PubsubClient.SchemaPath getSchemaPath(PubsubClient.TopicPath topicPath) throws java.io.IOException
PubsubClient
PubsubClient.SchemaPath
from PubsubClient.TopicPath
if exists.getSchemaPath
in class PubsubClient
java.io.IOException
public Schema getSchema(PubsubClient.SchemaPath schemaPath) throws java.io.IOException
PubsubClient
Schema
from the Pub/Sub schema resource, if exists.getSchema
in class PubsubClient
java.io.IOException