Xeli commented on a change in pull request #6594: [FLINK-9311] [pubsub] Added 
PubSub source connector with support for checkpointing (ATLEAST_ONCE)
URL: https://github.com/apache/flink/pull/6594#discussion_r271056321
 
 

 ##########
 File path: 
flink-end-to-end-tests/flink-connector-gcp-pubsub-emulator-tests/src/test/java/org/apache/flink/streaming/connectors/gcp/pubsub/emulator/PubsubHelper.java
 ##########
 @@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.streaming.connectors.gcp.pubsub.emulator;
+
+import com.google.api.gax.core.NoCredentialsProvider;
+import com.google.api.gax.rpc.NotFoundException;
+import com.google.api.gax.rpc.TransportChannelProvider;
+import com.google.cloud.pubsub.v1.MessageReceiver;
+import com.google.cloud.pubsub.v1.Publisher;
+import com.google.cloud.pubsub.v1.Subscriber;
+import com.google.cloud.pubsub.v1.SubscriptionAdminClient;
+import com.google.cloud.pubsub.v1.SubscriptionAdminSettings;
+import com.google.cloud.pubsub.v1.TopicAdminClient;
+import com.google.cloud.pubsub.v1.TopicAdminSettings;
+import com.google.cloud.pubsub.v1.stub.GrpcSubscriberStub;
+import com.google.cloud.pubsub.v1.stub.SubscriberStub;
+import com.google.cloud.pubsub.v1.stub.SubscriberStubSettings;
+import com.google.pubsub.v1.AcknowledgeRequest;
+import com.google.pubsub.v1.ProjectSubscriptionName;
+import com.google.pubsub.v1.ProjectTopicName;
+import com.google.pubsub.v1.PullRequest;
+import com.google.pubsub.v1.PullResponse;
+import com.google.pubsub.v1.PushConfig;
+import com.google.pubsub.v1.ReceivedMessage;
+import com.google.pubsub.v1.Topic;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A helper class to make managing the testing topics a bit easier.
+ */
+public class PubsubHelper {
+
+       private static final Logger LOG = 
LoggerFactory.getLogger(PubsubHelper.class);
+
+       private TransportChannelProvider channelProvider = null;
+
+       private TopicAdminClient topicClient;
+       private SubscriptionAdminClient subscriptionAdminClient;
+
+       public PubsubHelper(TransportChannelProvider channelProvider) {
+               this.channelProvider = channelProvider;
+       }
+
+       public TransportChannelProvider getChannelProvider() {
+               return channelProvider;
+       }
+
+       public TopicAdminClient getTopicAdminClient() throws IOException {
+               if (topicClient == null) {
+                       TopicAdminSettings topicAdminSettings = 
TopicAdminSettings.newBuilder()
+                               .setTransportChannelProvider(channelProvider)
+                               
.setCredentialsProvider(NoCredentialsProvider.create())
+                               .build();
+                       topicClient = 
TopicAdminClient.create(topicAdminSettings);
+               }
+               return topicClient;
+       }
+
+       public Topic createTopic(String project, String topic) throws 
IOException {
+               deleteTopic(project, topic);
+               ProjectTopicName topicName = ProjectTopicName.of(project, 
topic);
+               TopicAdminClient adminClient = getTopicAdminClient();
+               LOG.info("CreateTopic {}", topicName);
+               return adminClient.createTopic(topicName);
+       }
+
+       public void deleteTopic(String project, String topic) throws 
IOException {
+               deleteTopic(ProjectTopicName.of(project, topic));
+       }
+
+       public void deleteTopic(ProjectTopicName topicName) throws IOException {
+//        LOG.info("CreateTopic {}", topicName);
+               TopicAdminClient adminClient = getTopicAdminClient();
+               try {
+                       Topic existingTopic = adminClient.getTopic(topicName);
 
 Review comment:
   Fixed!

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to