/** 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); } }); }
private void initializePubsub(Description description) throws IOException { pubsub = PubsubGrpcClient.FACTORY.newClient( NO_TIMESTAMP_ATTRIBUTE, NO_ID_ATTRIBUTE, pipelineOptions); TopicPath eventsTopicPathTmp = PubsubClient.topicPathFromName( pipelineOptions.getProject(), createTopicName(description, EVENTS_TOPIC_NAME)); pubsub.createTopic(eventsTopicPathTmp); eventsTopicPath = eventsTopicPathTmp; }
private void initializePubsub(Description description) throws IOException { pubsub = PubsubGrpcClient.FACTORY.newClient( NO_TIMESTAMP_ATTRIBUTE, NO_ID_ATTRIBUTE, pipelineOptions); // Example topic name: // integ-test-TestClassName-testMethodName-2018-12-11-23-32-333-<random-long>-result TopicPath resultTopicPathTmp = PubsubClient.topicPathFromName( pipelineOptions.getProject(), createTopicName(description, RESULT_TOPIC_NAME)); TopicPath startTopicPathTmp = PubsubClient.topicPathFromName( pipelineOptions.getProject(), createTopicName(description, START_TOPIC_NAME)); pubsub.createTopic(resultTopicPathTmp); pubsub.createTopic(startTopicPathTmp); // Set these after successful creation; this signals that they need teardown resultTopicPath = resultTopicPathTmp; startTopicPath = startTopicPathTmp; }