@Override public SubscriptionPath apply(PubsubSubscription from) { return PubsubClient.subscriptionPathFromName(from.project, from.subscription); } }
/** * Create a random subscription for {@code topic}. Return the {@link SubscriptionPath}. It is the * responsibility of the caller to later delete the subscription. */ public SubscriptionPath createRandomSubscription( ProjectPath project, TopicPath topic, int ackDeadlineSeconds) throws IOException { // Create a randomized subscription derived from the topic name. String subscriptionName = topic.getName() + "_beam_" + ThreadLocalRandom.current().nextLong(); SubscriptionPath subscription = PubsubClient.subscriptionPathFromName(project.getId(), subscriptionName); createSubscription(topic, subscription, ackDeadlineSeconds); return subscription; }
/** Wait for a success signal for {@code duration}. */ public void waitForSuccess(Duration duration) throws IOException { SubscriptionPath resultSubscriptionPath = PubsubClient.subscriptionPathFromName( pipelineOptions.getProject(), "result-subscription-" + String.valueOf(ThreadLocalRandom.current().nextLong())); pubsub.createSubscription( resultTopicPath, resultSubscriptionPath, (int) duration.getStandardSeconds()); String result = pollForResultForDuration(resultSubscriptionPath, duration); if (!RESULT_SUCCESS_MESSAGE.equals(result)) { throw new AssertionError(result); } }
/** * Future that waits for a start signal for {@code duration}. * * <p>This future must be created before running the pipeline. A subscription must exist prior to * the start signal being published, which occurs immediately upon pipeline startup. */ public Supplier<Void> waitForStart(Duration duration) throws IOException { SubscriptionPath startSubscriptionPath = PubsubClient.subscriptionPathFromName( pipelineOptions.getProject(), "start-subscription-" + String.valueOf(ThreadLocalRandom.current().nextLong())); pubsub.createSubscription( startTopicPath, startSubscriptionPath, (int) duration.getStandardSeconds()); return Suppliers.memoize( () -> { try { String result = pollForResultForDuration(startSubscriptionPath, duration); checkState(START_SIGNAL_MESSAGE.equals(result)); return null; } catch (IOException e) { throw new RuntimeException(e); } }); }
@Test public void subscriptionPathFromNameWellFormed() { SubscriptionPath path = PubsubClient.subscriptionPathFromName("test", "something"); assertEquals("projects/test/subscriptions/something", path.getPath()); assertEquals("/subscriptions/test/something", path.getV1Beta1Path()); }
private static Subscription buildSubscription(int i) { Subscription subscription = new Subscription(); subscription.setName( PubsubClient.subscriptionPathFromName(PROJECT.getId(), "Subscription" + i).getPath()); subscription.setTopic(PubsubClient.topicPathFromName(PROJECT.getId(), "Topic" + i).getPath()); return subscription; } }