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/10/12 23:02:31 UTC

[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

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