Class PubSubTestClients
java.lang.Object
io.github.flink.gcp.connector.testutils.pubsub.PubSubTestClients
- All Implemented Interfaces:
AutoCloseable
The Pub/Sub admin, publish and pull machinery every integration-test harness needs, parameterised
over the transport: a plaintext channel with no credentials against the emulator, or
application-default credentials against the real service. The harnesses in the connector modules
keep their connector-typed conveniences and delegate the client work here; everything on this
class is stock
com.google.* types, which is what lets the SQL module's smoke test drive
the emulator with these clients while the connector under test uses its relocated copies.
Subscriptions are addressed by their full resource path (
projects/<p>/subscriptions/<s>) so no connector destination type crosses the module boundary.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static PubSubTestClientsforEmulator(String endpoint) Clients over one plaintext channel to the emulator, with no credentials.voidpublishOrdered(com.google.pubsub.v1.TopicName topic, String orderingKey, String publishEndpoint, String... payloads) Publishes the payloads, optionally under one ordering key, and waits for the acknowledgements so the messages are durable before a source starts.pullAndAckUntil(String subscriptionPath, int expected, Duration timeout) Pulls and acknowledges untilexpecteddistinct payloads have arrived or the deadline passes, returning what did arrive.List<com.google.pubsub.v1.PubsubMessage>pullMessages(String subscriptionPath, int maxMessages) Pulls up tomaxMessageswithout acknowledging, returning the messages — for tests that must leave the subscription's state untouched, at the cost of the next pull waiting out the acknowledgement deadline before a redelivery.List<com.google.pubsub.v1.PubsubMessage>pullMessagesAndAck(String subscriptionPath, int maxMessages) Pulls up tomaxMessagesand acknowledges them, returning the messages.List<com.google.pubsub.v1.PubsubMessage>pullMessagesUntil(String subscriptionPath, int expected, Duration timeout) Pulls and acknowledges untilexpecteddistinct messages have arrived or the deadline passes, returning them whole — attributes, publish time and ordering key included, whichpullAndAckUntil(java.lang.String, int, java.time.Duration)discards.com.google.cloud.pubsub.v1.SubscriptionAdminClientcom.google.cloud.pubsub.v1.TopicAdminClientstatic PubSubTestClientsClients on the SDK's defaults: application-default credentials, real service.
-
Method Details
-
forEmulator
Clients over one plaintext channel to the emulator, with no credentials. The returned instance owns the channel and shuts it down onclose().- Throws:
IOException
-
withApplicationDefaultCredentials
Clients on the SDK's defaults: application-default credentials, real service. The poll interval is looser than the emulator transport's because every pull is a network round trip.- Throws:
IOException
-
topicAdmin
public com.google.cloud.pubsub.v1.TopicAdminClient topicAdmin() -
subscriptionAdmin
public com.google.cloud.pubsub.v1.SubscriptionAdminClient subscriptionAdmin() -
publishOrdered
public void publishOrdered(com.google.pubsub.v1.TopicName topic, String orderingKey, String publishEndpoint, String... payloads) throws IOException, InterruptedException, ExecutionException Publishes the payloads, optionally under one ordering key, and waits for the acknowledgements so the messages are durable before a source starts.- Parameters:
orderingKey- the ordering key, or null for unordered publishingpublishEndpoint- overrides the publisher's endpoint, or null for the transport's default — the real-service ordering tests pass their regional endpoint here, because ordered publishing is only guaranteed through one- Throws:
IOExceptionInterruptedExceptionExecutionException
-
pullAndAckUntil
public Set<String> pullAndAckUntil(String subscriptionPath, int expected, Duration timeout) throws InterruptedException Pulls and acknowledges untilexpecteddistinct payloads have arrived or the deadline passes, returning what did arrive.A single pull is not guaranteed to return everything outstanding even when more is available, so an exact-count assertion on one pull would be flaky.
- Throws:
InterruptedException
-
pullMessagesUntil
public List<com.google.pubsub.v1.PubsubMessage> pullMessagesUntil(String subscriptionPath, int expected, Duration timeout) throws InterruptedException Pulls and acknowledges untilexpecteddistinct messages have arrived or the deadline passes, returning them whole — attributes, publish time and ordering key included, whichpullAndAckUntil(java.lang.String, int, java.time.Duration)discards.Distinct by message id, for the same reason
pullAndAckUntil(java.lang.String, int, java.time.Duration)collects into a set: an acknowledgement is not necessarily applied before the next pull is served, and the sinks are at-least-once, so the same message can come back. Counting redeliveries would make every exact-count assertion a coin flip.- Throws:
InterruptedException
-
pullMessagesAndAck
public List<com.google.pubsub.v1.PubsubMessage> pullMessagesAndAck(String subscriptionPath, int maxMessages) Pulls up tomaxMessagesand acknowledges them, returning the messages. One pull only — usepullMessagesUntil(java.lang.String, int, java.time.Duration)to assert on a known count. -
pullMessages
public List<com.google.pubsub.v1.PubsubMessage> pullMessages(String subscriptionPath, int maxMessages) Pulls up tomaxMessageswithout acknowledging, returning the messages — for tests that must leave the subscription's state untouched, at the cost of the next pull waiting out the acknowledgement deadline before a redelivery. -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-