sijie commented on a change in pull request #2504: Add Presto Sql Test
URL: https://github.com/apache/incubator-pulsar/pull/2504#discussion_r219547989
 
 

 ##########
 File path: 
tests/integration/src/test/java/org/apache/pulsar/tests/integration/presto/TestBasicPresto.java
 ##########
 @@ -0,0 +1,123 @@
+/**
+ * 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.tests.integration.presto;
+
+import lombok.Cleanup;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.pulsar.client.api.Producer;
+import org.apache.pulsar.client.api.PulsarClient;
+import org.apache.pulsar.client.impl.schema.JSONSchema;
+import org.apache.pulsar.tests.integration.docker.ContainerExecResult;
+import org.apache.pulsar.tests.integration.topologies.PulsarCluster;
+import org.apache.pulsar.tests.integration.topologies.PulsarClusterSpec;
+import org.apache.pulsar.tests.integration.topologies.PulsarClusterTestBase;
+import org.testng.annotations.AfterSuite;
+import org.testng.annotations.BeforeSuite;
+import org.testng.annotations.Test;
+
+import java.util.stream.Stream;
+
+import static java.util.stream.Collectors.joining;
+import static org.assertj.core.api.Assertions.assertThat;
+
+@Slf4j
+public class TestBasicPresto extends PulsarClusterTestBase {
+
+    @BeforeSuite
+    @Override
+    public void setupCluster() throws Exception {
+        final String clusterName = Stream.of(this.getClass().getSimpleName(), 
randomName(5))
+                .filter(s -> s != null && !s.isEmpty())
+                .collect(joining("-"));
+
+        PulsarClusterSpec spec = PulsarClusterSpec.builder()
+                .numBookies(2)
+                .numBrokers(1)
+                .enablePrestoWorker(true)
+                .clusterName(clusterName)
+                .build();
+
+        log.info("Setting up cluster {} with {} bookies, {} brokers",
+                spec.clusterName(), spec.numBookies(), spec.numBrokers());
+
+        pulsarCluster = PulsarCluster.forSpec(spec);
+        pulsarCluster.start();
+
+        log.info("Cluster {} is setup with presto worker", spec.clusterName());
+    }
+
+    @Test
+    public void testDefaultCatalog() throws Exception {
+        ContainerExecResult containerExecResult = execQuery("show catalogs;");
+        assertThat(containerExecResult.getExitCode()).isEqualTo(0);
+        assertThat(containerExecResult.getStdout()).contains("pulsar", 
"system");
+    }
+
+    @Test
+    public void testSimpleSQLQuery() throws Exception {
+
+        @Cleanup
+        PulsarClient pulsarClient = PulsarClient.builder()
+                                    
.serviceUrl(pulsarCluster.getPlainTextServiceUrl())
+                                    .build();
+
+        final String stocksTopic = "stocks";
+
+        @Cleanup
+        Producer<Stock> producer = 
pulsarClient.newProducer(JSONSchema.of(Stock.class))
+                .topic(stocksTopic)
+                .create();
+
+        final Stock stock1 = new Stock(1,"APPL", 100.0);
+        final Stock stock2 = new Stock(2,"GOOG", 110.0);
+        final Stock stock3 = new Stock(3,"MSFT", 120.0);
+        final Stock stock4 = new Stock(4,"APPL1", 100.0);
+        final Stock stock5 = new Stock(5,"GOOG1", 110.0);
+        final Stock stock6 = new Stock(6,"MSFT1", 120.0);
+
+        producer.send(stock1);
+        producer.send(stock2);
+        producer.send(stock3);
+        producer.send(stock4);
+        producer.send(stock5);
+        producer.send(stock6);
+
+        ContainerExecResult containerExecResult = execQuery("select * from 
pulsar.\"public/default\".stocks order by entryid;");
+        assertThat(containerExecResult.getExitCode()).isEqualTo(0);
+        log.info("select sql query output \n{}", 
containerExecResult.getStdout());
+        
assertThat(containerExecResult.getStdout().split("\n").length).isGreaterThan(4);
 
 Review comment:
   please check the result output as well. checking the number of lines is just 
very meaningless 

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


With regards,
Apache Git Services

Reply via email to