KKcorps commented on a change in pull request #7026:
URL: https://github.com/apache/incubator-pinot/pull/7026#discussion_r647520268



##########
File path: pinot-plugins/pinot-stream-ingestion/pinot-pulsar/pom.xml
##########
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0";

Review comment:
       resolved

##########
File path: 
pinot-plugins/pinot-stream-ingestion/pinot-pulsar/src/main/java/org/apache/pinot/plugin/stream/pulsar/PulsarConfig.java
##########
@@ -0,0 +1,102 @@
+/**
+ * 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.pinot.plugin.stream.pulsar;
+
+import com.google.common.base.Preconditions;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pinot.spi.stream.StreamConfigProperties;
+import org.apache.pulsar.client.api.MessageId;
+
+public class PulsarConfig {
+  public static final String STREAM_TYPE = "pulsar";
+  public static final String PULSAR_PROP_PREFIX = "consumer.prop";
+  public static final String BOOTSTRAP_SERVERS = "bootstrap.servers";
+  public static final String START_POSITION = "start_position";
+  public static final String DEFAULT_BOOTSTRAP_BROKERS = 
"pulsar://localhost:6650";
+
+  private String _pulsarTopicName;
+  private String _subscriberId;
+  private String _bootstrapServers;
+  private MessageId _initialMessageId = MessageId.latest;
+  private Map<String, String> _pulsarConsumerProperties;
+
+  public PulsarConfig(StreamConfig streamConfig, String subscriberId){
+    Map<String, String> streamConfigMap = streamConfig.getStreamConfigsMap();
+    _pulsarTopicName = streamConfig.getTopicName();
+    _bootstrapServers = streamConfigMap.getOrDefault(BOOTSTRAP_SERVERS, 
DEFAULT_BOOTSTRAP_BROKERS);
+
+    Preconditions.checkNotNull(_bootstrapServers,

Review comment:
       resolved

##########
File path: 
pinot-plugins/pinot-stream-ingestion/pinot-pulsar/src/test/java/org/apache/pinot/plugin/stream/pulsar/PulsarConsumerTest.java
##########
@@ -0,0 +1,183 @@
+/**
+ * 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.pinot.plugin.stream.pulsar;
+
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.spi.stream.LongMsgOffset;
+import org.apache.pinot.spi.stream.MessageBatch;
+import org.apache.pinot.spi.stream.PartitionLevelConsumer;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pinot.spi.stream.StreamConsumerFactory;
+import org.apache.pinot.spi.stream.StreamConsumerFactoryProvider;
+import org.apache.pulsar.client.admin.PulsarAdmin;
+import org.apache.pulsar.client.api.Message;
+import org.apache.pulsar.client.api.MessageId;
+import org.apache.pulsar.client.api.MessageRouter;
+import org.apache.pulsar.client.api.Producer;
+import org.apache.pulsar.client.api.PulsarClient;
+import org.apache.pulsar.client.api.Schema;
+import org.apache.pulsar.client.api.TopicMetadata;
+import org.apache.pulsar.client.impl.MessageIdImpl;
+import org.apache.pulsar.client.internal.DefaultImplementation;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+
+public class PulsarConsumerTest {
+
+  public static final String TABLE_NAME_WITH_TYPE = "tableName_REALTIME";
+  public static final String TEST_TOPIC = "test-topic";
+  public static final int NUM_PARTITION = 3;
+  public static final String MESSAGE_PREFIX = "sample_msg";
+  public static final int NUM_RECORDS_PER_PARTITION = 1000;
+  public static final String CLIENT_ID = "clientId";
+  private PulsarClient _pulsarClient;
+  private PulsarStandaloneCluster _pulsarStandaloneCluster;
+  private HashMap<Integer, MessageId> _partitionToFirstMessageIdMap = new 
HashMap<>();
+
+  @BeforeClass
+  public void setUp()
+      throws Exception {
+    _pulsarStandaloneCluster = new PulsarStandaloneCluster();
+
+    _pulsarStandaloneCluster.start();
+
+    PulsarAdmin admin =
+        PulsarAdmin.builder().serviceHttpUrl("http://localhost:"; + 
_pulsarStandaloneCluster.getAdminPort()).build();
+
+    String bootstrapServer = "pulsar://localhost:" + 
_pulsarStandaloneCluster.getBrokerPort();
+
+    _pulsarClient = PulsarClient.builder().serviceUrl(bootstrapServer).build();
+
+    admin.topics().createPartitionedTopic(TEST_TOPIC, NUM_PARTITION);
+
+    publishRecords();
+  }
+
+  @AfterClass
+  public void tearDown()
+      throws Exception {
+    _pulsarStandaloneCluster.stop();
+  }
+
+  public void publishRecords()
+      throws Exception {
+    for(int p = 0; p < NUM_PARTITION ; p++) {
+      final int partition = p;
+      Producer<String> producer = 
_pulsarClient.newProducer(Schema.STRING).topic(TEST_TOPIC).messageRouter(new 
MessageRouter() {
+        @Override
+        public int choosePartition(Message<?> msg, TopicMetadata metadata) {
+          return partition;
+        }
+      }).create();
+
+      for (int i = 0; i < NUM_RECORDS_PER_PARTITION; i++) {
+        MessageId messageId = producer.send(MESSAGE_PREFIX + "_" + i);
+        if(!_partitionToFirstMessageIdMap.containsKey(partition)){
+          _partitionToFirstMessageIdMap.put(partition, messageId);
+        }
+      }
+
+    }
+
+    List<String> partitionedTopicList =  
_pulsarClient.getPartitionsForTopic(TEST_TOPIC).get();
+
+    for(String p : partitionedTopicList) {

Review comment:
       done




-- 
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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to