@Override public TopicPath apply(PubsubTopic from) { return PubsubClient.topicPathFromName(from.project, from.topic); } }
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; }
private static Topic buildTopic(int i) { Topic topic = new Topic(); topic.setName(PubsubClient.topicPathFromName(PROJECT.getId(), "Topic" + i).getPath()); return topic; }
@Test public void topicPathFromNameWellFormed() { TopicPath path = PubsubClient.topicPathFromName("test", "something"); assertEquals("projects/test/topics/something", path.getPath()); assertEquals("/topics/test/something", path.getV1Beta1Path()); } }
@Test public void listSubscriptions() throws Exception { ListSubscriptionsResponse expectedResponse1 = new ListSubscriptionsResponse(); expectedResponse1.setSubscriptions(Collections.singletonList(buildSubscription(1))); expectedResponse1.setNextPageToken("AVgJH3Z7aHxiDBs"); ListSubscriptionsResponse expectedResponse2 = new ListSubscriptionsResponse(); expectedResponse2.setSubscriptions(Collections.singletonList(buildSubscription(2))); Subscriptions.List request = mockPubsub.projects().subscriptions().list(PROJECT.getPath()); when((Object) (request.execute())).thenReturn(expectedResponse1, expectedResponse2); final TopicPath topic101 = PubsubClient.topicPathFromName("testProject", "Topic2"); List<SubscriptionPath> subscriptionPaths = client.listSubscriptions(PROJECT, topic101); assertEquals(1, subscriptionPaths.size()); }
@Test public void noSubscriptionSplitGeneratesSubscription() throws Exception { TopicPath topicPath = PubsubClient.topicPathFromName("my_project", "my_topic"); factory = PubsubTestClient.createFactoryForCreateSubscription(); PubsubUnboundedSource source = new PubsubUnboundedSource( factory, StaticValueProvider.of(PubsubClient.projectPathFromId("my_project")), StaticValueProvider.of(topicPath), null /* subscription */, null /* timestampLabel */, null /* idLabel */, false /* needsAttributes */); assertThat(source.getSubscription(), nullValue()); assertThat(source.getSubscription(), nullValue()); PipelineOptions options = PipelineOptionsFactory.create(); List<PubsubSource> splits = (new PubsubSource(source)).split(3, options); // We have at least one returned split assertThat(splits, hasSize(greaterThan(0))); for (PubsubSource split : splits) { // Each split is equal assertThat(split, equalTo(splits.get(0))); } assertThat(splits.get(0).subscriptionPath, not(nullValue())); }
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; } }
@Test public void noSubscriptionNoSplitGeneratesSubscription() throws Exception { TopicPath topicPath = PubsubClient.topicPathFromName("my_project", "my_topic"); factory = PubsubTestClient.createFactoryForCreateSubscription(); PubsubUnboundedSource source =