You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by li...@apache.org on 2021/01/15 02:00:47 UTC

[dubbo-samples] branch master updated: dubbo-samples-ssl module test case (#259)

This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git


The following commit(s) were added to refs/heads/master by this push:
     new 1acf793  dubbo-samples-ssl module test case (#259)
1acf793 is described below

commit 1acf7934ea509ffea0d7f817aa5dc3c4a27cbf22
Author: SSS-K <34...@users.noreply.github.com>
AuthorDate: Fri Jan 15 10:00:40 2021 +0800

    dubbo-samples-ssl module test case (#259)
---
 dubbo-samples-ssl/case-configuration.yml           | 49 +++++++++++++++++
 .../dubbo-samples-ssl-consumer/pom.xml             | 61 ++++------------------
 .../dubbo/samples/basic/SslBasicConsumer.java      |  2 -
 .../dubbo-samples-ssl-provider/pom.xml             | 58 +++-----------------
 .../dubbo/samples/basic/SslBasicProvider.java      |  9 ++--
 .../apache/dubbo/samples/basic/SslServiceIT.java   | 58 ++++++++++++++++++++
 dubbo-samples-ssl/pom.xml                          | 57 ++++++++++++++++++++
 7 files changed, 187 insertions(+), 107 deletions(-)

diff --git a/dubbo-samples-ssl/case-configuration.yml b/dubbo-samples-ssl/case-configuration.yml
new file mode 100644
index 0000000..6c106c5
--- /dev/null
+++ b/dubbo-samples-ssl/case-configuration.yml
@@ -0,0 +1,49 @@
+# 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.
+
+
+services:
+  dubbo-samples-ssl-provider:
+    type: app
+    basedir: dubbo-samples-ssl-provider
+    mainClass: org.apache.dubbo.samples.basic.SslBasicProvider
+    volumes:
+      - ${_basedir}/dubbo-samples-ssl-provider/src/main/resources/certs:/dubbo-samples-ssl-provider/certs
+    systemProps:
+      - zookeeper.address=dubbo-samples-ssl-provider
+      - zookeeper.port=2181
+      - dubbo.ssl.server-key-cert-chain-path=/dubbo-samples-ssl-provider/certs/server0.pem
+      - dubbo.ssl.server-private-key-path=/dubbo-samples-ssl-provider/certs/server0.key
+      - dubbo.ssl.server-trust-cert-collection-path=/dubbo-samples-ssl-provider/certs/ca.pem
+
+  dubbo-samples-ssl-test:
+    type: test
+    basedir: dubbo-samples-ssl-provider
+    tests:
+      - "**/*IT.class"
+    volumes:
+      - ${_basedir}/dubbo-samples-ssl-provider/src/main/resources/certs:/dubbo-samples-ssl-test/certs
+    systemProps:
+      - zookeeper.address=dubbo-samples-ssl-provider
+      - zookeeper.port=2181
+      - dubbo.ssl.client-key-cert-chain-path=/dubbo-samples-ssl-test/certs/client.pem
+      - dubbo.ssl.client-private-key-path=/dubbo-samples-ssl-test/certs/client.key
+      - dubbo.ssl.client-trust-cert-collection-path=/dubbo-samples-ssl-test/certs/ca.pem
+    waitPortsBeforeRun:
+      - dubbo-samples-ssl-provider:2181
+      - dubbo-samples-ssl-provider:20880
+    depends_on:
+      - dubbo-samples-ssl-provider
diff --git a/dubbo-samples-ssl/dubbo-samples-ssl-consumer/pom.xml b/dubbo-samples-ssl/dubbo-samples-ssl-consumer/pom.xml
index 3a80e4b..a2403ca 100644
--- a/dubbo-samples-ssl/dubbo-samples-ssl-consumer/pom.xml
+++ b/dubbo-samples-ssl/dubbo-samples-ssl-consumer/pom.xml
@@ -18,6 +18,12 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>dubbo-samples-ssl</artifactId>
+        <groupId>org.apache.dubbo</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+
     <groupId>org.apache.dubbo</groupId>
     <version>1.0-SNAPSHOT</version>
 
@@ -28,16 +34,6 @@
     <properties>
         <source.level>1.8</source.level>
         <target.level>1.8</target.level>
-        <dubbo.version>2.7.7</dubbo.version>
-        <junit.version>4.12</junit.version>
-        <spring-test.version>4.3.16.RELEASE</spring-test.version>
-        <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
-        <maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
-        <image.name>${artifactId}:${dubbo.version}</image.name>
-        <java-image.name>openjdk:8</java-image.name>
-        <dubbo.port>20880</dubbo.port>
-        <zookeeper.port>2181</zookeeper.port>
-        <main-class>org.apache.dubbo.samples.basic.SslBasicProvider</main-class>
     </properties>
 
     <dependencies>
@@ -45,72 +41,33 @@
         <dependency>
             <groupId>io.netty</groupId>
             <artifactId>netty-tcnative-boringssl-static</artifactId>
-            <version>2.0.26.Final</version> <!-- See table for correct version -->
+            <!-- See table for correct version -->
 <!--            <classifier>${os.detected.classifier}</classifier>-->
 <!--            <scope>runtime</scope>-->
         </dependency>
         <dependency>
             <groupId>io.netty</groupId>
             <artifactId>netty-all</artifactId>
-            <version>4.1.36.Final</version>
         </dependency>
 
         <dependency>
             <groupId>org.apache.dubbo</groupId>
             <artifactId>dubbo</artifactId>
-            <version>${dubbo.version}</version>
         </dependency>
 
         <dependency>
             <groupId>org.apache.dubbo</groupId>
             <artifactId>dubbo-dependencies-zookeeper</artifactId>
-            <version>${dubbo.version}</version>
             <type>pom</type>
         </dependency>
 
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
-            <version>${junit.version}</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.springframework</groupId>
-            <artifactId>spring-test</artifactId>
-            <version>${spring-test.version}</version>
             <scope>test</scope>
         </dependency>
     </dependencies>
 
-    <profiles>
-        <profile>
-            <id>dubbo-integration-test</id>
-            <build>
-                <plugins>
-                    <plugin>
-                        <groupId>org.apache.maven.plugins</groupId>
-                        <artifactId>maven-failsafe-plugin</artifactId>
-                        <version>${maven-failsafe-plugin.version}</version>
-                        <executions>
-                            <execution>
-                                <goals>
-                                    <goal>integration-test</goal>
-                                    <goal>verify</goal>
-                                </goals>
-                                <configuration>
-                                    <includes>
-                                        <include>**/*IT.java</include>
-                                    </includes>
-                                </configuration>
-                            </execution>
-                        </executions>
-                    </plugin>
-                </plugins>
-            </build>
-        </profile>
-    </profiles>
-
     <build>
         <extensions>
             <extension>
@@ -124,7 +81,7 @@
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
-                <version>${maven-compiler-plugin.version}</version>
+                <version>3.7.0</version>
                 <configuration>
                     <source>${source.level}</source>
                     <target>${target.level}</target>
@@ -135,7 +92,7 @@
                 <artifactId>spring-boot-maven-plugin</artifactId>
                 <configuration>
                     <executable>true</executable>
-                    <mainClass>org.apache.dubbo.samples.basic.SslBasicProvider</mainClass>
+                    <mainClass>org.apache.dubbo.samples.basic.SslBasicConsumer</mainClass>
                 </configuration>
                 <executions>
                     <execution>
diff --git a/dubbo-samples-ssl/dubbo-samples-ssl-consumer/src/main/java/org/apache/dubbo/samples/basic/SslBasicConsumer.java b/dubbo-samples-ssl/dubbo-samples-ssl-consumer/src/main/java/org/apache/dubbo/samples/basic/SslBasicConsumer.java
index 1144e94..e88adb5 100644
--- a/dubbo-samples-ssl/dubbo-samples-ssl-consumer/src/main/java/org/apache/dubbo/samples/basic/SslBasicConsumer.java
+++ b/dubbo-samples-ssl/dubbo-samples-ssl-consumer/src/main/java/org/apache/dubbo/samples/basic/SslBasicConsumer.java
@@ -26,8 +26,6 @@ import org.apache.dubbo.config.SslConfig;
 import org.apache.dubbo.config.bootstrap.DubboBootstrap;
 import org.apache.dubbo.samples.basic.api.DemoService;
 
-import org.springframework.context.support.ClassPathXmlApplicationContext;
-
 public class SslBasicConsumer {
 
     private static final String ROOT_DIR = System.getProperty("user.dir");
diff --git a/dubbo-samples-ssl/dubbo-samples-ssl-provider/pom.xml b/dubbo-samples-ssl/dubbo-samples-ssl-provider/pom.xml
index d6592cb..09e8556 100644
--- a/dubbo-samples-ssl/dubbo-samples-ssl-provider/pom.xml
+++ b/dubbo-samples-ssl/dubbo-samples-ssl-provider/pom.xml
@@ -18,6 +18,12 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>dubbo-samples-ssl</artifactId>
+        <groupId>org.apache.dubbo</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+
     <groupId>org.apache.dubbo</groupId>
     <version>1.0-SNAPSHOT</version>
 
@@ -28,16 +34,6 @@
     <properties>
         <source.level>1.8</source.level>
         <target.level>1.8</target.level>
-        <dubbo.version>2.7.7</dubbo.version>
-        <junit.version>4.12</junit.version>
-        <spring-test.version>4.3.16.RELEASE</spring-test.version>
-        <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
-        <maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
-        <image.name>${artifactId}:${dubbo.version}</image.name>
-        <java-image.name>openjdk:8</java-image.name>
-        <dubbo.port>20880</dubbo.port>
-        <zookeeper.port>2181</zookeeper.port>
-        <main-class>org.apache.dubbo.samples.basic.SslBasicProvider</main-class>
     </properties>
 
     <dependencies>
@@ -45,71 +41,33 @@
         <dependency>
             <groupId>io.netty</groupId>
             <artifactId>netty-tcnative-boringssl-static</artifactId>
-            <version>2.0.26.Final</version> <!-- See table for correct version -->
+            <!-- See table for correct version -->
 <!--            <classifier>${os.detected.classifier}</classifier>-->
 <!--            <scope>runtime</scope>-->
         </dependency>
         <dependency>
             <groupId>io.netty</groupId>
             <artifactId>netty-all</artifactId>
-            <version>4.1.36.Final</version>
         </dependency>
 
         <dependency>
             <groupId>org.apache.dubbo</groupId>
             <artifactId>dubbo</artifactId>
-            <version>${dubbo.version}</version>
         </dependency>
 
         <dependency>
             <groupId>org.apache.dubbo</groupId>
             <artifactId>dubbo-dependencies-zookeeper</artifactId>
-            <version>${dubbo.version}</version>
             <type>pom</type>
         </dependency>
 
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
-            <version>${junit.version}</version>
-            <scope>test</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.springframework</groupId>
-            <artifactId>spring-test</artifactId>
-            <version>${spring-test.version}</version>
             <scope>test</scope>
         </dependency>
     </dependencies>
 
-    <profiles>
-        <profile>
-            <id>dubbo-integration-test</id>
-            <build>
-                <plugins>
-                    <plugin>
-                        <groupId>org.apache.maven.plugins</groupId>
-                        <artifactId>maven-failsafe-plugin</artifactId>
-                        <version>${maven-failsafe-plugin.version}</version>
-                        <executions>
-                            <execution>
-                                <goals>
-                                    <goal>integration-test</goal>
-                                    <goal>verify</goal>
-                                </goals>
-                                <configuration>
-                                    <includes>
-                                        <include>**/*IT.java</include>
-                                    </includes>
-                                </configuration>
-                            </execution>
-                        </executions>
-                    </plugin>
-                </plugins>
-            </build>
-        </profile>
-    </profiles>
 
     <build>
         <extensions>
@@ -124,7 +82,7 @@
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
-                <version>${maven-compiler-plugin.version}</version>
+                <version>3.7.0</version>
                 <configuration>
                     <source>${source.level}</source>
                     <target>${target.level}</target>
diff --git a/dubbo-samples-ssl/dubbo-samples-ssl-provider/src/main/java/org/apache/dubbo/samples/basic/SslBasicProvider.java b/dubbo-samples-ssl/dubbo-samples-ssl-provider/src/main/java/org/apache/dubbo/samples/basic/SslBasicProvider.java
index acbf725..f8aaaaf 100644
--- a/dubbo-samples-ssl/dubbo-samples-ssl-provider/src/main/java/org/apache/dubbo/samples/basic/SslBasicProvider.java
+++ b/dubbo-samples-ssl/dubbo-samples-ssl-provider/src/main/java/org/apache/dubbo/samples/basic/SslBasicProvider.java
@@ -32,10 +32,13 @@ import java.util.concurrent.CountDownLatch;
 
 public class SslBasicProvider {
 
-    private static final String ROOT_DIR = System.getProperty("user.dir");
+    private static String zookeeperHost = System.getProperty("zookeeper.address", "127.0.0.1");
+    private static String zookeeperPort = System.getProperty("zookeeper.port", "2181");
+
+    private static String zookeeperAddress = "zookeeper://"+ zookeeperHost +":" + zookeeperPort;
 
     public static void main(String[] args) throws Exception {
-        new EmbeddedZooKeeper(2181, false).start();
+        new EmbeddedZooKeeper(Integer.parseInt(zookeeperPort), false).start();
         // wait for embedded zookeeper start completely.
         Thread.sleep(1000);
 
@@ -62,7 +65,7 @@ public class SslBasicProvider {
 
         DubboBootstrap bootstrap = DubboBootstrap.getInstance();
         bootstrap.application(new ApplicationConfig("ssl-provider"))
-                 .registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
+                 .registry(new RegistryConfig(zookeeperAddress))
                  .protocol(protocolConfig)
                  .ssl(sslConfig);
 
diff --git a/dubbo-samples-ssl/dubbo-samples-ssl-provider/src/test/java/org/apache/dubbo/samples/basic/SslServiceIT.java b/dubbo-samples-ssl/dubbo-samples-ssl-provider/src/test/java/org/apache/dubbo/samples/basic/SslServiceIT.java
new file mode 100644
index 0000000..a10ca7f
--- /dev/null
+++ b/dubbo-samples-ssl/dubbo-samples-ssl-provider/src/test/java/org/apache/dubbo/samples/basic/SslServiceIT.java
@@ -0,0 +1,58 @@
+/*
+ * 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.dubbo.samples.basic;
+
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ReferenceConfig;
+import org.apache.dubbo.config.RegistryConfig;
+import org.apache.dubbo.config.SslConfig;
+import org.apache.dubbo.config.bootstrap.DubboBootstrap;
+import org.apache.dubbo.samples.basic.api.DemoService;
+import org.junit.Assert;
+import org.junit.Test;
+
+
+public class SslServiceIT {
+
+    private static String zookeeperHost = System.getProperty("zookeeper.address", "127.0.0.1");
+    private static String zookeeperPort = System.getProperty("zookeeper.port", "2181");
+
+    private static String zookeeperAddress = "zookeeper://"+ zookeeperHost +":" + zookeeperPort;
+
+    @Test
+    public void test() throws Exception {
+        SslConfig sslConfig = new SslConfig();
+
+        DubboBootstrap bootstrap = DubboBootstrap.getInstance()
+            .application(new ApplicationConfig("dubbo-consumer"))
+            .registry(new RegistryConfig(zookeeperAddress))
+            .ssl(sslConfig);
+
+        ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
+        reference.setInterface(DemoService.class);
+
+        bootstrap.reference(reference);
+
+        bootstrap.start();
+
+        DemoService service = bootstrap.getCache().get(reference);
+        String message = service.sayHello("dubbo");
+        Assert.assertTrue(message.startsWith("Hello dubbo"));
+    }
+
+}
diff --git a/dubbo-samples-ssl/pom.xml b/dubbo-samples-ssl/pom.xml
index 30ed591..5ead506 100644
--- a/dubbo-samples-ssl/pom.xml
+++ b/dubbo-samples-ssl/pom.xml
@@ -30,4 +30,61 @@
        <module>dubbo-samples-ssl-provider</module>
        <module>dubbo-samples-ssl-consumer</module>
    </modules>
+
+    <properties>
+        <dubbo.version>2.7.7</dubbo.version>
+        <junit.version>4.12</junit.version>
+        <spring.version>4.3.16.RELEASE</spring.version>
+    </properties>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework</groupId>
+                <artifactId>spring-framework-bom</artifactId>
+                <version>${spring.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+
+            <!-- It's totally optional, add tcnative with embedded boringSSL support -->
+            <dependency>
+                <groupId>io.netty</groupId>
+                <artifactId>netty-tcnative-boringssl-static</artifactId>
+                <version>2.0.26.Final</version> <!-- See table for correct version -->
+                <!--            <classifier>${os.detected.classifier}</classifier>-->
+                <!--            <scope>runtime</scope>-->
+            </dependency>
+
+            <dependency>
+                <groupId>io.netty</groupId>
+                <artifactId>netty-all</artifactId>
+                <version>4.1.36.Final</version>
+            </dependency>
+
+            <dependency>
+                <groupId>org.apache.dubbo</groupId>
+                <artifactId>dubbo-bom</artifactId>
+                <version>${dubbo.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+
+            <dependency>
+                <groupId>org.apache.dubbo</groupId>
+                <artifactId>dubbo-dependencies-zookeeper</artifactId>
+                <version>${dubbo.version}</version>
+                <type>pom</type>
+            </dependency>
+
+            <dependency>
+                <groupId>junit</groupId>
+                <artifactId>junit</artifactId>
+                <version>${junit.version}</version>
+                <scope>test</scope>
+            </dependency>
+
+        </dependencies>
+    </dependencyManagement>
+
 </project>


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org