pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] sijie closed pull request #2072: Integration test coverage on python functions
Date Tue, 03 Jul 2018 07:24:11 GMT
sijie closed pull request #2072: Integration test coverage on python functions
URL: https://github.com/apache/incubator-pulsar/pull/2072
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/distribution/server/src/assemble/bin.xml b/distribution/server/src/assemble/bin.xml
index ff7c1a3a00..61178bfe4f 100644
--- a/distribution/server/src/assemble/bin.xml
+++ b/distribution/server/src/assemble/bin.xml
@@ -47,6 +47,10 @@
       <directory>${basedir}/../../pulsar-functions/runtime/target/python-instance</directory>
       <outputDirectory>instances/python-instance</outputDirectory>
     </fileSet>
+    <fileSet>
+      <directory>${basedir}/../../pulsar-functions/python-examples</directory>
+      <outputDirectory>examples/python-examples</outputDirectory>
+    </fileSet>
   </fileSets>
   <files>
     <file>
diff --git a/pom.xml b/pom.xml
index 1c7f899742..862a29d020 100644
--- a/pom.xml
+++ b/pom.xml
@@ -166,6 +166,7 @@ flexible messaging model and an intuitive client API.</description>
 
     <!-- Plugin dependencies -->
     <protobuf-maven-plugin.version>0.5.0</protobuf-maven-plugin.version>
+    <exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
   </properties>
 
   <dependencyManagement>
diff --git a/pulsar-client-cpp/docker/build-wheels.sh b/pulsar-client-cpp/docker/build-wheels.sh
index 2146869449..ebbb441cac 100755
--- a/pulsar-client-cpp/docker/build-wheels.sh
+++ b/pulsar-client-cpp/docker/build-wheels.sh
@@ -35,6 +35,34 @@ PYTHON_VERSIONS=(
    '3.6 cp36-cp36m'
 )
 
+function contains() {
+    local n=$#
+    local value=${!n}
+    for ((i=1;i < $#;i++)) {
+        if [ "${!i}" == "${value}" ]; then
+            echo "y"
+            return 0
+        fi
+    }
+    echo "n"
+    return 1
+}
+
+
+if [ $# -ge 1 ]; then
+    build_version=$@
+    if [ $(contains "${PYTHON_VERSIONS[@]}" "${build_version}") == "y" ]; then
+        PYTHON_VERSIONS=(
+            "${build_version}"
+        )
+    else
+        echo "Unknown build version : ${build_version}"
+        echo "Supported python build versions are :"
+        echo ${PYTHON_VERSIONS[@]}
+        exit 1
+    fi
+fi
+
 for line in "${PYTHON_VERSIONS[@]}"; do
     read -r -a PY <<< "$line"
     PYTHON_VERSION=${PY[0]}
diff --git a/tests/docker-images/latest-version-image/Dockerfile b/tests/docker-images/latest-version-image/Dockerfile
index e638ba0851..bcc2b539d9 100644
--- a/tests/docker-images/latest-version-image/Dockerfile
+++ b/tests/docker-images/latest-version-image/Dockerfile
@@ -19,7 +19,7 @@
 
 FROM apachepulsar/pulsar:latest
 
-RUN apt-get update && apt-get install -y supervisor
+RUN apt-get update && apt-get install -y supervisor python-pip
 
 RUN mkdir -p /var/log/pulsar && mkdir -p /var/run/supervisor/ && mkdir -p
/pulsar/ssl
 
@@ -31,5 +31,9 @@ COPY ssl/ca.cert.pem ssl/broker.key-pk8.pem ssl/broker.cert.pem \
      ssl/admin.key-pk8.pem ssl/admin.cert.pem /pulsar/ssl/
 
 COPY scripts/init-cluster.sh scripts/run-global-zk.sh scripts/run-local-zk.sh \
-     scripts/run-bookie.sh scripts/run-broker.sh scripts/run-functions-worker.sh scripts/run-proxy.sh
/pulsar/bin/
+     scripts/run-bookie.sh scripts/run-broker.sh scripts/run-functions-worker.sh scripts/run-proxy.sh
\
+     scripts/install-pulsar-client.sh /pulsar/bin/
+
+ADD target/python-client/ /pulsar/pulsar-client
+RUN /pulsar/bin/install-pulsar-client.sh
 
diff --git a/tests/docker-images/latest-version-image/pom.xml b/tests/docker-images/latest-version-image/pom.xml
index 232312f13d..5094f89e41 100644
--- a/tests/docker-images/latest-version-image/pom.xml
+++ b/tests/docker-images/latest-version-image/pom.xml
@@ -48,7 +48,51 @@
         </dependency>
       </dependencies>
       <build>
+        <!-- build cpp client, copy the wheel file and then build docker image -->
         <plugins>
+          <plugin>
+            <groupId>org.codehaus.mojo</groupId>
+            <artifactId>exec-maven-plugin</artifactId>
+            <version>${exec-maven-plugin.version}</version>
+            <executions>
+              <execution>
+                <id>build-pulsar-clients</id>
+                <phase>compile</phase>
+                <goals>
+                  <goal>exec</goal>
+                </goals>
+                <configuration>
+                  <skip>${skipBuildPythonClient}</skip>
+                  <workingDirectory>${project.basedir}/target</workingDirectory>
+                  <executable>${project.basedir}/../../../pulsar-client-cpp/docker/build-wheels.sh</executable>
+                  <arguments>
+                    <!-- build python 2.7 -->
+                    <argument>2.7 cp27-cp27mu</argument>
+                  </arguments>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-antrun-plugin</artifactId>
+            <executions>
+              <execution>
+                <phase>compile</phase>
+                <goals>
+                  <goal>run</goal>
+                </goals>
+                <configuration>
+                  <skip>${skipBuildPythonClient}</skip>
+                  <tasks>
+                    <echo>copy python wheel file</echo>
+                    <mkdir dir="${basedir}/target/python-client"/>
+                    <copydir src="${basedir}/../../../pulsar-client-cpp/python/wheelhouse"
dest="${basedir}/target/python-client"/>
+                  </tasks>
+                </configuration>
+              </execution>
+            </executions>
+          </plugin>
           <plugin>
             <groupId>com.spotify</groupId>
             <artifactId>dockerfile-maven-plugin</artifactId>
@@ -56,12 +100,14 @@
             <executions>
               <execution>
                 <id>default</id>
+                <phase>package</phase>
                 <goals>
                   <goal>build</goal>
                 </goals>
               </execution>
               <execution>
                 <id>add-latest-tag</id>
+                <phase>package</phase>
                 <goals>
                   <goal>tag</goal>
                 </goals>
diff --git a/tests/docker-images/latest-version-image/scripts/install-pulsar-client.sh b/tests/docker-images/latest-version-image/scripts/install-pulsar-client.sh
new file mode 100755
index 0000000000..2e048c1c20
--- /dev/null
+++ b/tests/docker-images/latest-version-image/scripts/install-pulsar-client.sh
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+#
+# 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.
+#
+
+set -x
+
+WHEEL_FILE=`ls /pulsar/pulsar-client`
+pip install /pulsar/pulsar-client/${WHEEL_FILE}
diff --git a/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/PulsarFunctionsTestBase.java
b/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/PulsarFunctionsTestBase.java
index dc2e290e5a..b8ffc7cf09 100644
--- a/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/PulsarFunctionsTestBase.java
+++ b/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/PulsarFunctionsTestBase.java
@@ -31,9 +31,24 @@
 @Slf4j
 public abstract class PulsarFunctionsTestBase extends PulsarClusterTestBase  {
 
-    public static final String EXCLAMATION_FUNC_CLASS =
+    public static final String EXCLAMATION_JAVA_CLASS =
         "org.apache.pulsar.functions.api.examples.ExclamationFunction";
 
+    public static final String EXCLAMATION_PYTHON_CLASS =
+        "exclamation.Exclamation";
+
+    public static final String EXCLAMATION_PYTHON_FILE = "exclamation.py";
+
+    protected static String getExclamationClass(Runtime runtime) {
+        if (Runtime.JAVA == runtime) {
+            return EXCLAMATION_JAVA_CLASS;
+        } else if (Runtime.PYTHON == runtime) {
+            return EXCLAMATION_PYTHON_CLASS;
+        } else {
+            throw new IllegalArgumentException("Unsupported runtime : " + runtime);
+        }
+    }
+
     @BeforeClass
     public static void setupCluster() throws Exception {
         PulsarClusterTestBase.setupCluster();
@@ -47,7 +62,8 @@ public static void setupCluster() throws Exception {
     @DataProvider(name = "FunctionRuntimes")
     public static Object[][] functionRuntimes() {
         return new Object[][] {
-            new Object[] { Runtime.JAVA }
+            new Object[] { Runtime.JAVA },
+            new Object[] { Runtime.PYTHON }
         };
     }
 
diff --git a/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/runtime/PulsarFunctionsProcessRuntimeTest.java
b/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/runtime/PulsarFunctionsProcessRuntimeTest.java
index 7c4033f07c..83edac8523 100644
--- a/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/runtime/PulsarFunctionsProcessRuntimeTest.java
+++ b/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/runtime/PulsarFunctionsProcessRuntimeTest.java
@@ -22,4 +22,7 @@
  * Run runtime tests in process mode.
  */
 public class PulsarFunctionsProcessRuntimeTest extends PulsarFunctionsRuntimeTest {
+    public PulsarFunctionsProcessRuntimeTest() {
+        super(ContainerFactory.PROCESS);
+    }
 }
diff --git a/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/runtime/PulsarFunctionsRuntimeTest.java
b/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/runtime/PulsarFunctionsRuntimeTest.java
index e816f70c80..41be67f114 100644
--- a/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/runtime/PulsarFunctionsRuntimeTest.java
+++ b/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/runtime/PulsarFunctionsRuntimeTest.java
@@ -40,12 +40,28 @@
  */
 public abstract class PulsarFunctionsRuntimeTest extends PulsarFunctionsTestBase {
 
+    protected enum ContainerFactory {
+        PROCESS,
+        THREAD
+    }
+
+    private final ContainerFactory containerFactory;
+
+    public PulsarFunctionsRuntimeTest(ContainerFactory containerFactory) {
+        this.containerFactory = containerFactory;
+    }
+
     //
     // Test CRUD functions on different runtimes.
     //
 
     @Test(dataProvider = "FunctionRuntimes")
     public void testExclamationFunction(Runtime runtime) throws Exception {
+        if (ContainerFactory.THREAD == containerFactory && Runtime.PYTHON == runtime)
{
+            // python can only run on process mode
+            return;
+        }
+
         String inputTopicName = "test-exclamation-" + runtime + "-input-" + randomName(8);
         String outputTopicName = "test-exclamation-" + runtime + "-output-" + randomName(8);
         String functionName = "test-exclamation-fn-" + randomName(8);
@@ -53,7 +69,7 @@ public void testExclamationFunction(Runtime runtime) throws Exception {
 
         // submit the exclamation function
         submitExclamationFunction(
-            inputTopicName, outputTopicName, functionName);
+            runtime, inputTopicName, outputTopicName, functionName);
 
         // get function info
         getFunctionInfoSuccess(functionName);
@@ -71,13 +87,23 @@ public void testExclamationFunction(Runtime runtime) throws Exception
{
         getFunctionInfoNotFound(functionName);
     }
 
-    private static void submitExclamationFunction(String inputTopicName,
+    private static void submitExclamationFunction(Runtime runtime,
+                                                  String inputTopicName,
                                                   String outputTopicName,
                                                   String functionName) throws Exception {
-        CommandGenerator generator = CommandGenerator.createDefaultGenerator(inputTopicName,
EXCLAMATION_FUNC_CLASS);
+        CommandGenerator generator;
+        generator = CommandGenerator.createDefaultGenerator(inputTopicName, getExclamationClass(runtime));
         generator.setSinkTopic(outputTopicName);
         generator.setFunctionName(functionName);
-        String command = generator.generateCreateFunctionCommand();
+        String command;
+        if (Runtime.JAVA == runtime) {
+            command = generator.generateCreateFunctionCommand();
+        } else if (Runtime.PYTHON == runtime) {
+            generator.setRuntime(runtime);
+            command = generator.generateCreateFunctionCommand(EXCLAMATION_PYTHON_FILE);
+        } else {
+            throw new IllegalArgumentException("Unsupported runtime : " + runtime);
+        }
         String[] commands = {
             "sh", "-c", command
         };
diff --git a/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/runtime/PulsarFunctionsThreadRuntimeTest.java
b/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/runtime/PulsarFunctionsThreadRuntimeTest.java
index 61ddba3704..7ca9931b0c 100644
--- a/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/runtime/PulsarFunctionsThreadRuntimeTest.java
+++ b/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/runtime/PulsarFunctionsThreadRuntimeTest.java
@@ -29,6 +29,10 @@
 @Slf4j
 public class PulsarFunctionsThreadRuntimeTest extends PulsarFunctionsRuntimeTest {
 
+    public PulsarFunctionsThreadRuntimeTest() {
+        super(ContainerFactory.THREAD);
+    }
+
     @BeforeClass
     public static void setupCluster() throws Exception {
         PulsarClusterTestBase.setupCluster();
diff --git a/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/utils/CommandGenerator.java
b/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/utils/CommandGenerator.java
index 12225fec10..71466160fe 100644
--- a/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/utils/CommandGenerator.java
+++ b/tests/integration/semantics/src/test/java/org/apache/pulsar/tests/integration/functions/utils/CommandGenerator.java
@@ -54,7 +54,7 @@
 
     private Map<String, String> userConfig = new HashMap<>();
     private static final String JAVAJAR = "/pulsar/examples/api-examples.jar";
-    private static final String PYTHONBASE = "/pulsar/examples/python";
+    private static final String PYTHONBASE = "/pulsar/examples/python-examples/";
 
     public static CommandGenerator createDefaultGenerator(String sourceTopic, String functionClassName)
{
         CommandGenerator generator = new CommandGenerator();


 

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message