You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/06/22 14:50:48 UTC

[GitHub] [pulsar] david-streamlio opened a new pull request, #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink

david-streamlio opened a new pull request, #16179:
URL: https://github.com/apache/pulsar/pull/16179

   
   ### Motivation
   
   The current implementation of the Cassandra Sink connector only supported a single schema type (key, string). This is not useful for production. So I modified the code to be able to support any schema type in Cassandra. 
   
   ### Modifications
   
   Added classes that interrogate the database to determine the schema type at runtime. I also added a framework that will extract the values from the supported incoming schema types (GenericRecord, and String) using the table metadata.
   
   ### Verifying this change
   
   - [ x] Make sure that the change passes the CI checks.
   
   *(Please pick either of the following options)*
   
   This change added tests and can be verified as follows:
   
      *Added integration tests for testing against a Cassandra database*
    
   ### Does this pull request potentially affect one of the following parts:
   
   *If `yes` was chosen, please highlight the changes*
   
     - Dependencies (does it add or upgrade a dependency): (yes)
     - The public API: (no)
     - The schema: (yes)
     - The default values of configurations: (no)
     - The wire protocol: (no)
     - The rest endpoints: (no)
     - The admin cli options: ( no)
     - Anything that affects deployment: (no)
   
   ### Documentation
   
   Check the box below or label this PR directly.
   
   Need to update docs? 
   
   - [ x] `doc-required` 
   (Your PR needs to update docs and you will update later)
     


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

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] codecov-commenter commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1277892077

   # [Codecov](https://codecov.io/gh/apache/pulsar/pull/16179?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > :exclamation: No coverage uploaded for pull request base (`master@bff3400`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#section-missing-base-commit).
   > The diff coverage is `n/a`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/pulsar/pull/16179/graphs/tree.svg?width=650&height=150&src=pr&token=acYqCpsK9J&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/pulsar/pull/16179?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@            Coverage Diff            @@
   ##             master   #16179   +/-   ##
   =========================================
     Coverage          ?   70.88%           
     Complexity        ?      438           
   =========================================
     Files             ?       26           
     Lines             ?     2246           
     Branches          ?      245           
   =========================================
     Hits              ?     1592           
     Misses            ?      481           
     Partials          ?      173           
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | unittests | `70.88% <0.00%> (?)` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   


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

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] github-actions[bot] commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1221451899

   The pr had no activity for 30 days, mark with Stale label.


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

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] codelipenghui closed pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink

Posted by GitBox <gi...@apache.org>.
codelipenghui closed pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink
URL: https://github.com/apache/pulsar/pull/16179


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

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] david-streamlio commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink

Posted by GitBox <gi...@apache.org>.
david-streamlio commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1297368527

   @eolivelli , Can you please take a look at this when you get the chance? Thanks again!


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

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] david-streamlio commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink

Posted by GitBox <gi...@apache.org>.
david-streamlio commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1355313812

   /pulsarbot run-failure-checks


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

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] david-streamlio commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink

Posted by GitBox <gi...@apache.org>.
david-streamlio commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1382178440

   @tisonkun @eolivelli I would appreciate another review when you have the time.


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

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] david-streamlio commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink

Posted by GitBox <gi...@apache.org>.
david-streamlio commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1278098298

   /pulsarbot run-failure-checks


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

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] david-streamlio commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink

Posted by GitBox <gi...@apache.org>.
david-streamlio commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1274947370

   /pulsarbot ready-to-test


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

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] david-streamlio commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink

Posted by GitBox <gi...@apache.org>.
david-streamlio commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1289238251

   @eolivelli I have made the requested changes, can you PTAL when you get a chance?  Thank!


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

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] david-streamlio commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink

Posted by GitBox <gi...@apache.org>.
david-streamlio commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1191734946

   @tspannhw  can you review and upvote?


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

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] david-streamlio commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink

Posted by GitBox <gi...@apache.org>.
david-streamlio commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1312147210

   @eolivelli Can I please get some feedback on these changes I made in response to your initial feedback? Thanks again for the review, I really appreciated it.


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

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] david-streamlio commented on pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink

Posted by GitBox <gi...@apache.org>.
david-streamlio commented on PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#issuecomment-1273812855

   /pulsarbot run-failure-checks


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

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] eolivelli commented on a diff in pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink

Posted by GitBox <gi...@apache.org>.
eolivelli commented on code in PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#discussion_r993261206


##########
pulsar-io/cassandra/src/main/java/org/apache/pulsar/io/cassandra/util/CassandraConnector.java:
##########
@@ -0,0 +1,135 @@
+/**
+ * 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.pulsar.io.cassandra.util;
+
+import com.datastax.driver.core.*;
+import com.datastax.driver.core.Session;
+import org.apache.pulsar.io.cassandra.CassandraSinkConfig;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CassandraConnector {
+
+    private Cluster cluster;
+    private Session session;

Review Comment:
   we have to handle concurrent access properly to these fields



##########
pulsar-io/cassandra/pom.xml:
##########
@@ -51,6 +51,39 @@
     <dependency>
       <groupId>com.datastax.cassandra</groupId>
       <artifactId>cassandra-driver-core</artifactId>
+      <version>${cassandra.version}</version>
+      <exclusions>
+        <exclusion>
+          <groupId>io.dropwizard.metrics</groupId>
+          <artifactId>metrics-core</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+
+    <dependency>
+      <groupId>commons-beanutils</groupId>
+      <artifactId>commons-beanutils</artifactId>
+      <version>1.9.4</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.pulsar</groupId>
+      <artifactId>pulsar-functions-local-runner-original</artifactId>
+      <version>2.11.0-SNAPSHOT</version>

Review Comment:
   please use project.version



##########
pulsar-io/cassandra/src/main/java/org/apache/pulsar/io/cassandra/util/TableMetadataProvider.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.pulsar.io.cassandra.util;
+
+import com.datastax.driver.core.*;

Review Comment:
   please do not use star imports



##########
pulsar-io/cassandra/src/main/java/org/apache/pulsar/io/cassandra/util/StringRecordWrapper.java:
##########
@@ -0,0 +1,47 @@
+/**
+ * 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.pulsar.io.cassandra.util;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class StringRecordWrapper extends RecordWrapper<String> {
+
+    private Map<String, Object> valuesMap;
+
+    public StringRecordWrapper(String jsonString) {
+        super(jsonString);
+        valuesMap = new Gson().fromJson(jsonString,

Review Comment:
   I think that we can cache this "new Gson()" instance in a static field



##########
pulsar-io/cassandra/src/test/java/org/apache/pulsar/io/cassandra/producers/InputTopicProducerThread.java:
##########
@@ -0,0 +1,83 @@
+/**
+ * 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.pulsar.io.cassandra.producers;
+
+import org.apache.pulsar.client.api.Producer;
+import org.apache.pulsar.client.api.PulsarClient;
+import org.apache.pulsar.client.api.PulsarClientException;
+import org.apache.pulsar.client.api.Schema;
+
+import java.util.Random;
+
+public abstract class InputTopicProducerThread<T> implements Runnable {
+
+    private Random rnd = new Random();
+
+    final String inputTopic;
+    final String brokerUrl;
+    PulsarClient client;
+    Producer<T> producer;
+
+    public InputTopicProducerThread(String brokerUrl, String inputTopic) {
+        this.brokerUrl = brokerUrl;
+        this.inputTopic = inputTopic;
+    }
+
+    @Override
+    public void run() {
+        for (int idx = 0; idx < 100; idx++) {
+            try {
+                getProducer().newMessage().key(getKey()).value(getValue()).send();
+            } catch (PulsarClientException e) {
+                e.printStackTrace();

Review Comment:
   please use logger



##########
pulsar-io/cassandra/src/test/java/org/apache/pulsar/io/cassandra/CassandraSinkExec.java:
##########
@@ -0,0 +1,98 @@
+/**
+ * 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.pulsar.io.cassandra;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.pulsar.common.io.SinkConfig;
+import org.apache.pulsar.functions.LocalRunner;
+import org.apache.pulsar.io.cassandra.producers.InputTopicProducerThread;
+import org.apache.pulsar.io.cassandra.producers.InputTopicStringProducer;
+import org.apache.pulsar.io.cassandra.producers.ReadingSchemaRecordProducer;
+import org.yaml.snakeyaml.Yaml;
+
+/**
+ * Useful for testing within IDE.
+ *
+ */
+public class CassandraSinkExec {
+
+    public static final String BROKER_URL = "pulsar://localhost:6650";
+    public static final String INPUT_TOPIC = "persistent://public/default/air-quality-reading-generic";
+    // public static final String INPUT_TOPIC = "persistent://public/default/air-quality-reading-string";
+    public static final String CONFIG_FILE = "cassandra-sink-config.yaml";
+
+    public static void main(String[] args) throws Exception {
+
+        SinkConfig config = getSinkConfig();
+
+        final LocalRunner localRunner =
+                LocalRunner.builder()
+                        .brokerServiceUrl(BROKER_URL)
+                        .sinkConfig(config)
+                        .build();
+
+        localRunner.start(false);
+
+        sendData();
+        TimeUnit.MINUTES.sleep(10);
+
+        localRunner.stop();
+
+        System.exit(0);
+    }
+
+    private static SinkConfig getSinkConfig() throws FileNotFoundException {
+        SinkConfig sinkConfig = SinkConfig.builder()
+                .autoAck(true)
+                .cleanupSubscription(Boolean.TRUE)
+                .configs(getConfigs())
+                .className(CassandraGenericRecordSink.class.getName())
+                .inputs(Collections.singletonList(INPUT_TOPIC))
+                .name("CassandraSink")
+                .build();
+
+        return sinkConfig;
+    }
+
+    private static Map<String, Object> getConfigs() throws FileNotFoundException {
+        Map<String, Object> configs = new HashMap<String, Object>();
+
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        File file = new File(classLoader.getResource(CONFIG_FILE).getFile());
+
+        Yaml yaml = new Yaml();
+        configs = yaml.load(new FileInputStream(file));
+
+        return configs;
+    }
+
+    private static final void sendData() throws InterruptedException {
+        TimeUnit.SECONDS.sleep(10);

Review Comment:
   do we need to sleep a fixed amount of time ?



##########
pulsar-io/cassandra/src/test/java/org/apache/pulsar/io/cassandra/CassandraSinkExec.java:
##########
@@ -0,0 +1,98 @@
+/**
+ * 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.pulsar.io.cassandra;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.pulsar.common.io.SinkConfig;
+import org.apache.pulsar.functions.LocalRunner;
+import org.apache.pulsar.io.cassandra.producers.InputTopicProducerThread;
+import org.apache.pulsar.io.cassandra.producers.InputTopicStringProducer;
+import org.apache.pulsar.io.cassandra.producers.ReadingSchemaRecordProducer;
+import org.yaml.snakeyaml.Yaml;
+
+/**
+ * Useful for testing within IDE.
+ *
+ */
+public class CassandraSinkExec {
+
+    public static final String BROKER_URL = "pulsar://localhost:6650";
+    public static final String INPUT_TOPIC = "persistent://public/default/air-quality-reading-generic";
+    // public static final String INPUT_TOPIC = "persistent://public/default/air-quality-reading-string";
+    public static final String CONFIG_FILE = "cassandra-sink-config.yaml";
+
+    public static void main(String[] args) throws Exception {
+
+        SinkConfig config = getSinkConfig();
+
+        final LocalRunner localRunner =
+                LocalRunner.builder()
+                        .brokerServiceUrl(BROKER_URL)
+                        .sinkConfig(config)
+                        .build();
+
+        localRunner.start(false);
+
+        sendData();
+        TimeUnit.MINUTES.sleep(10);
+
+        localRunner.stop();
+
+        System.exit(0);
+    }
+
+    private static SinkConfig getSinkConfig() throws FileNotFoundException {
+        SinkConfig sinkConfig = SinkConfig.builder()
+                .autoAck(true)
+                .cleanupSubscription(Boolean.TRUE)
+                .configs(getConfigs())
+                .className(CassandraGenericRecordSink.class.getName())
+                .inputs(Collections.singletonList(INPUT_TOPIC))
+                .name("CassandraSink")
+                .build();
+
+        return sinkConfig;
+    }
+
+    private static Map<String, Object> getConfigs() throws FileNotFoundException {
+        Map<String, Object> configs = new HashMap<String, Object>();
+
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        File file = new File(classLoader.getResource(CONFIG_FILE).getFile());
+
+        Yaml yaml = new Yaml();
+        configs = yaml.load(new FileInputStream(file));

Review Comment:
   please close the stream



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

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [pulsar] david-streamlio commented on a diff in pull request #16179: [improve][pulsar-io] Added support for generic record and raw JSON string schemas to CassandraSink

Posted by GitBox <gi...@apache.org>.
david-streamlio commented on code in PR #16179:
URL: https://github.com/apache/pulsar/pull/16179#discussion_r993962325


##########
pulsar-io/cassandra/src/test/java/org/apache/pulsar/io/cassandra/CassandraSinkExec.java:
##########
@@ -0,0 +1,98 @@
+/**
+ * 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.pulsar.io.cassandra;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.pulsar.common.io.SinkConfig;
+import org.apache.pulsar.functions.LocalRunner;
+import org.apache.pulsar.io.cassandra.producers.InputTopicProducerThread;
+import org.apache.pulsar.io.cassandra.producers.InputTopicStringProducer;
+import org.apache.pulsar.io.cassandra.producers.ReadingSchemaRecordProducer;
+import org.yaml.snakeyaml.Yaml;
+
+/**
+ * Useful for testing within IDE.
+ *
+ */
+public class CassandraSinkExec {
+
+    public static final String BROKER_URL = "pulsar://localhost:6650";
+    public static final String INPUT_TOPIC = "persistent://public/default/air-quality-reading-generic";
+    // public static final String INPUT_TOPIC = "persistent://public/default/air-quality-reading-string";
+    public static final String CONFIG_FILE = "cassandra-sink-config.yaml";
+
+    public static void main(String[] args) throws Exception {
+
+        SinkConfig config = getSinkConfig();
+
+        final LocalRunner localRunner =
+                LocalRunner.builder()
+                        .brokerServiceUrl(BROKER_URL)
+                        .sinkConfig(config)
+                        .build();
+
+        localRunner.start(false);
+
+        sendData();
+        TimeUnit.MINUTES.sleep(10);
+
+        localRunner.stop();
+
+        System.exit(0);
+    }
+
+    private static SinkConfig getSinkConfig() throws FileNotFoundException {
+        SinkConfig sinkConfig = SinkConfig.builder()
+                .autoAck(true)
+                .cleanupSubscription(Boolean.TRUE)
+                .configs(getConfigs())
+                .className(CassandraGenericRecordSink.class.getName())
+                .inputs(Collections.singletonList(INPUT_TOPIC))
+                .name("CassandraSink")
+                .build();
+
+        return sinkConfig;
+    }
+
+    private static Map<String, Object> getConfigs() throws FileNotFoundException {
+        Map<String, Object> configs = new HashMap<String, Object>();
+
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        File file = new File(classLoader.getResource(CONFIG_FILE).getFile());
+
+        Yaml yaml = new Yaml();
+        configs = yaml.load(new FileInputStream(file));
+
+        return configs;
+    }
+
+    private static final void sendData() throws InterruptedException {
+        TimeUnit.SECONDS.sleep(10);

Review Comment:
   The only reason I sleep 10 seconds, is so I can easily visualize the data as it is published to the system. The delay allows me time to execute a query against Cassandra in order to detect the new records.



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

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org