From 0838e549eef75bed5378d75ba63952d950eddc13 Mon Sep 17 00:00:00 2001 From: fyf <2569548856@qq.com> Date: Fri, 3 Mar 2023 14:32:34 +0800 Subject: [PATCH 1/9] refactor dubbo-samples-local --- .../case-configuration.yml | 20 +++- .../dubbo-samples-local-consumer/pom.xml | 70 ++++++++++++++ .../dubbo/samples/local/LocalConsumer.java} | 26 ++--- .../org/apache/dubbo/samples/local/Task.java | 52 ++++++++++ .../src/main/resources/application.yml | 27 ++++++ .../src/main/resources/log4j.properties | 0 .../dubbo/samples/local/LocalServiceIT.java | 25 +++++ .../dubbo-samples-local-interface/pom.xml | 35 +++++++ .../samples/local/api/LocalService.java} | 2 +- .../dubbo-samples-local-provider/pom.xml | 65 +++++++++++++ .../samples/local/EmbeddedZooKeeper.java | 0 .../dubbo/samples/local/LocalProvider.java | 32 +++++++ .../samples/local/impl/LocalServiceImpl.java} | 8 +- .../src/main/resources/application.yml | 26 +++++ .../src/main/resources/log4j.properties | 23 +++++ 2-advanced/dubbo-samples-local/pom.xml | 96 +++++++++++++------ .../src/main/resources/spring/dubbo-demo.xml | 38 -------- .../dubbo/samples/local/DemoServiceIT.java | 53 ---------- 18 files changed, 454 insertions(+), 144 deletions(-) create mode 100644 2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml rename 2-advanced/dubbo-samples-local/{src/main/java/org/apache/dubbo/samples/local/LocalDemo.java => dubbo-samples-local-consumer/src/main/java/org/apache/dubbo/samples/local/LocalConsumer.java} (54%) create mode 100644 2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/java/org/apache/dubbo/samples/local/Task.java create mode 100644 2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/application.yml rename 2-advanced/dubbo-samples-local/{ => dubbo-samples-local-consumer}/src/main/resources/log4j.properties (100%) create mode 100644 2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java create mode 100644 2-advanced/dubbo-samples-local/dubbo-samples-local-interface/pom.xml rename 2-advanced/dubbo-samples-local/{src/main/java/org/apache/dubbo/samples/local/api/DemoService.java => dubbo-samples-local-interface/src/main/java/org/apache/dubbo/samples/local/api/LocalService.java} (96%) create mode 100644 2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml rename 2-advanced/dubbo-samples-local/{ => dubbo-samples-local-provider}/src/main/java/org/apache/dubbo/samples/local/EmbeddedZooKeeper.java (100%) create mode 100644 2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/LocalProvider.java rename 2-advanced/dubbo-samples-local/{src/main/java/org/apache/dubbo/samples/local/impl/DemoServiceImpl.java => dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/impl/LocalServiceImpl.java} (90%) create mode 100644 2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/application.yml create mode 100644 2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/log4j.properties delete mode 100644 2-advanced/dubbo-samples-local/src/main/resources/spring/dubbo-demo.xml delete mode 100644 2-advanced/dubbo-samples-local/src/test/java/org/apache/dubbo/samples/local/DemoServiceIT.java diff --git a/2-advanced/dubbo-samples-local/case-configuration.yml b/2-advanced/dubbo-samples-local/case-configuration.yml index b23ab56d6c..f722aa995f 100644 --- a/2-advanced/dubbo-samples-local/case-configuration.yml +++ b/2-advanced/dubbo-samples-local/case-configuration.yml @@ -17,8 +17,22 @@ # local call through injvm, start test container only services: - dubbo-samples-local-test: + local-provider: + type: app + basedir: dubbo-samples-local-provider + mainClass: org.apache.dubbo.samples.local.LocalProvider + local-consumer: type: test - basedir: . + basedir: dubbo-samples-local-consumer tests: - - "**/*IT.class" \ No newline at end of file + - "**/*IT.class" + systemProps: + - zookeeper.address=local-provider + - zookeeper.port=2181 + - dubbo.address=local-provider + - dubbo.port=20880 + waitPortsBeforeRun: + - local-provider:2181 + - local-provider:20880 + depends_on: + - local-provider \ No newline at end of file diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml new file mode 100644 index 0000000000..73addeffe7 --- /dev/null +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml @@ -0,0 +1,70 @@ + + + + + dubbo-samples-local + org.apache.dubbo + 1.0-SNAPSHOT + + 4.0.0 + + dubbo-samples-local-consumer + + + 8 + 8 + + + + + org.apache.dubbo + dubbo-samples-local-interface + ${project.parent.version} + + + + + org.apache.dubbo + dubbo-spring-boot-starter + + + org.apache.dubbo + dubbo-dependencies-zookeeper-curator5 + pom + + + slf4j-reload4j + org.slf4j + + + + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-test + test + + + \ No newline at end of file diff --git a/2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/LocalDemo.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/java/org/apache/dubbo/samples/local/LocalConsumer.java similarity index 54% rename from 2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/LocalDemo.java rename to 2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/java/org/apache/dubbo/samples/local/LocalConsumer.java index 94ea847d4c..d4cb42fa50 100644 --- a/2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/LocalDemo.java +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/java/org/apache/dubbo/samples/local/LocalConsumer.java @@ -16,26 +16,16 @@ * limitations under the License. * */ - package org.apache.dubbo.samples.local; -import org.apache.dubbo.samples.local.api.DemoService; - -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import java.util.concurrent.CountDownLatch; - -public class LocalDemo { - - public static void main(String[] args) throws InterruptedException { - new EmbeddedZooKeeper(2181, true).start(); - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo.xml"); - context.start(); - System.out.println("dubbo service started"); +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; - DemoService demoService = context.getBean("demoService", DemoService.class); - String hello = demoService.sayHello("world"); - System.out.println(hello); - new CountDownLatch(1).await(); +@SpringBootApplication +@EnableDubbo +public class LocalConsumer { + public static void main(String[] args) { + SpringApplication.run(LocalConsumer.class, args); } } diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/java/org/apache/dubbo/samples/local/Task.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/java/org/apache/dubbo/samples/local/Task.java new file mode 100644 index 0000000000..dfe8fcbab6 --- /dev/null +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/java/org/apache/dubbo/samples/local/Task.java @@ -0,0 +1,52 @@ +/* + * + * 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.local; + +import org.apache.dubbo.config.annotation.DubboReference; +import org.apache.dubbo.samples.local.api.LocalService; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +import java.util.Date; + +@Component +public class Task implements CommandLineRunner { + + @DubboReference + private LocalService localService; + + @Override + public void run(String... args) throws Exception { + String result = localService.sayHello("world"); + System.out.println("Receive result ======> " + result); + + new Thread(()->{ + while (true) { + try { + Thread.sleep(1000); + System.out.println(new Date() + " Receive result ======> " + localService.sayHello("world")); + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); + } + } + }).start(); + } +} diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/application.yml b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/application.yml new file mode 100644 index 0000000000..d64dfe674e --- /dev/null +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/application.yml @@ -0,0 +1,27 @@ +# +# +# 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. +# +# + +dubbo: + application: + name: local-consumer + protocol: + name: dubbo + port: 20880 + registry: + address: zookeeper://${zookeeper.address:127.0.0.1}:2181 \ No newline at end of file diff --git a/2-advanced/dubbo-samples-local/src/main/resources/log4j.properties b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/log4j.properties similarity index 100% rename from 2-advanced/dubbo-samples-local/src/main/resources/log4j.properties rename to 2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/log4j.properties diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java new file mode 100644 index 0000000000..3dd6c29699 --- /dev/null +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java @@ -0,0 +1,25 @@ +package org.apache.dubbo.samples.local; + +import org.apache.dubbo.config.annotation.DubboReference; +import org.apache.dubbo.samples.local.api.LocalService; +import org.apache.dubbo.spring.boot.autoconfigure.DubboAutoConfiguration; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@SpringBootTest(classes = {DubboAutoConfiguration.class}) +@RunWith(SpringRunner.class) +public class LocalServiceIT { + @DubboReference + private LocalService localService; + + @Test + public void test() throws Exception { + String result = localService.sayHello("world"); + Assert.assertEquals(result, "Hello world, response from provider: 10.193.180.32:20880"); + result = localService.sayHelloAsync("world"); + Assert.assertEquals(result, "Hello world, response from provider: 10.193.180.32:20880"); + } +} diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-interface/pom.xml b/2-advanced/dubbo-samples-local/dubbo-samples-local-interface/pom.xml new file mode 100644 index 0000000000..36fa691bcf --- /dev/null +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-interface/pom.xml @@ -0,0 +1,35 @@ + + + + + dubbo-samples-local + org.apache.dubbo + 1.0-SNAPSHOT + + 4.0.0 + + dubbo-samples-local-interface + + + 8 + 8 + + + \ No newline at end of file diff --git a/2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/api/DemoService.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-interface/src/main/java/org/apache/dubbo/samples/local/api/LocalService.java similarity index 96% rename from 2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/api/DemoService.java rename to 2-advanced/dubbo-samples-local/dubbo-samples-local-interface/src/main/java/org/apache/dubbo/samples/local/api/LocalService.java index 7492773e04..3d272d4bc4 100644 --- a/2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/api/DemoService.java +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-interface/src/main/java/org/apache/dubbo/samples/local/api/LocalService.java @@ -19,7 +19,7 @@ package org.apache.dubbo.samples.local.api; -public interface DemoService { +public interface LocalService { String sayHello(String name); diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml new file mode 100644 index 0000000000..bbcd7d489a --- /dev/null +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml @@ -0,0 +1,65 @@ + + + + + dubbo-samples-local + org.apache.dubbo + 1.0-SNAPSHOT + + 4.0.0 + + dubbo-samples-local-provider + + + 8 + 8 + + + + + org.apache.dubbo + dubbo-samples-local-interface + ${project.parent.version} + + + + + org.apache.dubbo + dubbo-spring-boot-starter + + + org.apache.dubbo + dubbo-dependencies-zookeeper-curator5 + pom + + + slf4j-reload4j + org.slf4j + + + + + + + org.springframework.boot + spring-boot-starter + + + \ No newline at end of file diff --git a/2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/EmbeddedZooKeeper.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/EmbeddedZooKeeper.java similarity index 100% rename from 2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/EmbeddedZooKeeper.java rename to 2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/EmbeddedZooKeeper.java diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/LocalProvider.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/LocalProvider.java new file mode 100644 index 0000000000..31b1165b17 --- /dev/null +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/LocalProvider.java @@ -0,0 +1,32 @@ +/* + * + * 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.local; + +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@EnableDubbo +public class LocalProvider { + public static void main(String[] args) { +// new EmbeddedZooKeeper(2181, false).start(); + SpringApplication.run(LocalProvider.class, args); + } +} diff --git a/2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/impl/DemoServiceImpl.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/impl/LocalServiceImpl.java similarity index 90% rename from 2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/impl/DemoServiceImpl.java rename to 2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/impl/LocalServiceImpl.java index da897ca7ab..faea68d968 100644 --- a/2-advanced/dubbo-samples-local/src/main/java/org/apache/dubbo/samples/local/impl/DemoServiceImpl.java +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/impl/LocalServiceImpl.java @@ -16,19 +16,21 @@ * limitations under the License. * */ - package org.apache.dubbo.samples.local.impl; +import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.rpc.AsyncContext; import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.rpc.RpcServiceContext; -import org.apache.dubbo.samples.local.api.DemoService; +import org.apache.dubbo.samples.local.api.LocalService; import java.text.SimpleDateFormat; import java.util.Date; -public class DemoServiceImpl implements DemoService { +@DubboService +public class LocalServiceImpl implements LocalService { + @Override public String sayHello(String name) { System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress()); diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/application.yml b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/application.yml new file mode 100644 index 0000000000..04bc500c29 --- /dev/null +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/application.yml @@ -0,0 +1,26 @@ +# +# +# 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. +# +# +dubbo: + application: + name: local-provider + protocol: + name: dubbo + port: 20880 + registry: + address: zookeeper://${zookeeper.address:127.0.0.1}:2181 \ No newline at end of file diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/log4j.properties b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/log4j.properties new file mode 100644 index 0000000000..2e299bbb25 --- /dev/null +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/log4j.properties @@ -0,0 +1,23 @@ +# +# +# 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. +# +# +log4j.rootLogger=info, stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy hh:mm:ss:sss z}] %t %5p %c{2}: %m%n diff --git a/2-advanced/dubbo-samples-local/pom.xml b/2-advanced/dubbo-samples-local/pom.xml index 4712d95893..b238cf0161 100644 --- a/2-advanced/dubbo-samples-local/pom.xml +++ b/2-advanced/dubbo-samples-local/pom.xml @@ -19,7 +19,13 @@ 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"> org.apache.dubbo + pom 1.0-SNAPSHOT + + dubbo-samples-local-provider + dubbo-samples-local-consumer + dubbo-samples-local-interface + 4.0.0 @@ -28,23 +34,47 @@ Dubbo Samples Local - 1.8 - 1.8 - 3.1.6 - 4.3.29.RELEASE + 3.2.0-beta.4 + 2.7.8 4.13.1 3.7.0 + 1.8 + 1.8 + UTF-8 + + + + + + + + + + + + + + + + + + + + + + - org.springframework - spring-framework-bom - ${spring.version} + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} pom import + org.apache.dubbo dubbo-bom @@ -52,9 +82,10 @@ pom import + org.apache.dubbo - dubbo-dependencies-zookeeper + dubbo-dependencies-zookeeper-curator5 ${dubbo.version} pom @@ -62,16 +93,16 @@ - - org.apache.dubbo - dubbo - + + + + - - org.apache.dubbo - dubbo-dependencies-zookeeper - pom - + + + + + junit @@ -105,16 +136,25 @@ - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${source.level} - ${target.level} - - - + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + + + + + + + + + + + + + diff --git a/2-advanced/dubbo-samples-local/src/main/resources/spring/dubbo-demo.xml b/2-advanced/dubbo-samples-local/src/main/resources/spring/dubbo-demo.xml deleted file mode 100644 index 6f33dbf3b5..0000000000 --- a/2-advanced/dubbo-samples-local/src/main/resources/spring/dubbo-demo.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - - diff --git a/2-advanced/dubbo-samples-local/src/test/java/org/apache/dubbo/samples/local/DemoServiceIT.java b/2-advanced/dubbo-samples-local/src/test/java/org/apache/dubbo/samples/local/DemoServiceIT.java deleted file mode 100644 index a865062d76..0000000000 --- a/2-advanced/dubbo-samples-local/src/test/java/org/apache/dubbo/samples/local/DemoServiceIT.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.local; - -import org.apache.dubbo.samples.local.api.DemoService; - -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = {"classpath:/spring/dubbo-demo.xml"}) -public class DemoServiceIT { - @Autowired - private DemoService demoService; - - @BeforeClass - public static void setUp() throws Exception { - new EmbeddedZooKeeper(2181, false).start(); - } - - @Test - public void test() throws Exception { - // see also: org.apache.dubbo.rpc.protocol.injvm.InjvmInvoker.doInvoke - // InjvmInvoker set remote address to 127.0.0.1:0 - String result = demoService.sayHello("world"); - Assert.assertEquals(result, "Hello world, response from provider: 127.0.0.1:0"); - - result = demoService.sayHelloAsync("world"); - Assert.assertEquals(result, "Hello world, response from provider: 127.0.0.1:0"); - - } - -} From a2a7352b9c3544e769b704db9bb1ba4417c47767 Mon Sep 17 00:00:00 2001 From: fyf <2569548856@qq.com> Date: Fri, 3 Mar 2023 14:59:01 +0800 Subject: [PATCH 2/9] refactor dubbo-samples-local --- .../dubbo-samples-local-provider/pom.xml | 1 - .../dubbo/samples/local/LocalProvider.java | 1 - 2-advanced/dubbo-samples-local/pom.xml | 43 ------------------- 3 files changed, 45 deletions(-) diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml index bbcd7d489a..5a77d59754 100644 --- a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml @@ -38,7 +38,6 @@ dubbo-samples-local-interface ${project.parent.version} - org.apache.dubbo diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/LocalProvider.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/LocalProvider.java index 31b1165b17..7faf9ff74a 100644 --- a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/LocalProvider.java +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/LocalProvider.java @@ -26,7 +26,6 @@ @EnableDubbo public class LocalProvider { public static void main(String[] args) { -// new EmbeddedZooKeeper(2181, false).start(); SpringApplication.run(LocalProvider.class, args); } } diff --git a/2-advanced/dubbo-samples-local/pom.xml b/2-advanced/dubbo-samples-local/pom.xml index b238cf0161..10a2129635 100644 --- a/2-advanced/dubbo-samples-local/pom.xml +++ b/2-advanced/dubbo-samples-local/pom.xml @@ -45,27 +45,6 @@ - - - - - - - - - - - - - - - - - - - - - org.springframework.boot @@ -93,17 +72,6 @@ - - - - - - - - - - - junit junit @@ -146,15 +114,4 @@ - - - - - - - - - - - From ee33bb588531814b144835fad1ff1d049562e786 Mon Sep 17 00:00:00 2001 From: fyf <2569548856@qq.com> Date: Fri, 3 Mar 2023 17:40:39 +0800 Subject: [PATCH 3/9] modify application.yml --- .../dubbo-samples-local-consumer/pom.xml | 26 ++++++++++---- .../dubbo/samples/local/LocalServiceIT.java | 19 +++++++++++ .../dubbo-samples-local-interface/pom.xml | 6 +--- .../dubbo-samples-local-provider/pom.xml | 25 ++++++++++---- 2-advanced/dubbo-samples-local/pom.xml | 34 +++++++------------ 5 files changed, 70 insertions(+), 40 deletions(-) diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml index 73addeffe7..c53024848d 100644 --- a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml @@ -22,28 +22,25 @@ dubbo-samples-local org.apache.dubbo 1.0-SNAPSHOT + ../pom.xml 4.0.0 dubbo-samples-local-consumer - - 8 - 8 - - + org.apache.dubbo dubbo-samples-local-interface ${project.parent.version} - org.apache.dubbo dubbo-spring-boot-starter + org.apache.dubbo dubbo-dependencies-zookeeper-curator5 @@ -55,16 +52,31 @@ - org.springframework.boot spring-boot-starter + org.springframework.boot spring-boot-test test + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + \ No newline at end of file diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java index 3dd6c29699..e1fae07b32 100644 --- a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java @@ -1,3 +1,22 @@ +/* + * + * 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.local; import org.apache.dubbo.config.annotation.DubboReference; diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-interface/pom.xml b/2-advanced/dubbo-samples-local/dubbo-samples-local-interface/pom.xml index 36fa691bcf..80054da76d 100644 --- a/2-advanced/dubbo-samples-local/dubbo-samples-local-interface/pom.xml +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-interface/pom.xml @@ -22,14 +22,10 @@ dubbo-samples-local org.apache.dubbo 1.0-SNAPSHOT + ../pom.xml 4.0.0 dubbo-samples-local-interface - - 8 - 8 - - \ No newline at end of file diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml index 5a77d59754..e09a81a319 100644 --- a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml @@ -22,17 +22,14 @@ dubbo-samples-local org.apache.dubbo 1.0-SNAPSHOT + ../pom.xml 4.0.0 dubbo-samples-local-provider - - 8 - 8 - - + org.apache.dubbo dubbo-samples-local-interface @@ -43,6 +40,7 @@ org.apache.dubbo dubbo-spring-boot-starter + org.apache.dubbo dubbo-dependencies-zookeeper-curator5 @@ -54,11 +52,26 @@ - org.springframework.boot spring-boot-starter + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + \ No newline at end of file diff --git a/2-advanced/dubbo-samples-local/pom.xml b/2-advanced/dubbo-samples-local/pom.xml index 10a2129635..8b71b06629 100644 --- a/2-advanced/dubbo-samples-local/pom.xml +++ b/2-advanced/dubbo-samples-local/pom.xml @@ -18,9 +18,6 @@ - org.apache.dubbo - pom - 1.0-SNAPSHOT dubbo-samples-local-provider dubbo-samples-local-consumer @@ -29,15 +26,18 @@ 4.0.0 + org.apache.dubbo dubbo-samples-local + 1.0-SNAPSHOT + pom + Dubbo Samples Local Dubbo Samples Local - 3.2.0-beta.4 + 3.2.0-beta.6-SNAPSHOT 2.7.8 4.13.1 - 3.7.0 1.8 1.8 UTF-8 @@ -68,6 +68,13 @@ ${dubbo.version} pom + + + junit + junit + ${junit.version} + test + @@ -86,23 +93,6 @@ - - - - javax.annotation - - [1.11,) - - - - javax.annotation - javax.annotation-api - 1.3.2 - - - - - From fed17c963e99c06e95300deb8e1f4285e9e39200 Mon Sep 17 00:00:00 2001 From: fyf <2569548856@qq.com> Date: Tue, 7 Mar 2023 08:44:04 +0800 Subject: [PATCH 4/9] add zookeeper related config --- .../case-configuration.yml | 2 + .../dubbo-samples-local-consumer/pom.xml | 26 +++++++ .../src/main/resources/application.yml | 2 +- .../dubbo-samples-local-provider/pom.xml | 67 +++++++++++++++++++ .../dubbo/samples/local/LocalProvider.java | 2 + 2-advanced/dubbo-samples-local/pom.xml | 2 +- 6 files changed, 99 insertions(+), 2 deletions(-) diff --git a/2-advanced/dubbo-samples-local/case-configuration.yml b/2-advanced/dubbo-samples-local/case-configuration.yml index f722aa995f..b564475e64 100644 --- a/2-advanced/dubbo-samples-local/case-configuration.yml +++ b/2-advanced/dubbo-samples-local/case-configuration.yml @@ -17,6 +17,8 @@ # local call through injvm, start test container only services: + zookeeper: + image: zookeeper:latest local-provider: type: app basedir: dubbo-samples-local-provider diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml index c53024848d..5b403e0b40 100644 --- a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml @@ -63,7 +63,33 @@ spring-boot-test test + + + junit + junit + 4.13.1 + test + + + + + + + javax.annotation + + [1.11,) + + + + javax.annotation + javax.annotation-api + 1.3.2 + + + + + diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/application.yml b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/application.yml index d64dfe674e..e3a0ddf195 100644 --- a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/application.yml +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/application.yml @@ -22,6 +22,6 @@ dubbo: name: local-consumer protocol: name: dubbo - port: 20880 + port: -1 registry: address: zookeeper://${zookeeper.address:127.0.0.1}:2181 \ No newline at end of file diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml index e09a81a319..24655c0133 100644 --- a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml @@ -28,6 +28,10 @@ dubbo-samples-local-provider + + 3.8.0 + + @@ -57,8 +61,71 @@ org.springframework.boot spring-boot-starter + + + org.apache.zookeeper + zookeeper + ${zookeeper.version} + + + netty-handler + io.netty + + + netty-transport-native-epoll + io.netty + + + + + commons-cli + commons-cli + 1.4 + + + org.eclipse.jetty + jetty-server + + + org.eclipse.jetty + jetty-servlet + + + org.eclipse.jetty + jetty-client + + + jline + jline + 2.14.6 + + + io.dropwizard.metrics + metrics-core + + + org.xerial.snappy + snappy-java + + + + + javax.annotation + + [1.11,) + + + + javax.annotation + javax.annotation-api + 1.3.2 + + + + + diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/LocalProvider.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/LocalProvider.java index 7faf9ff74a..42c320ecfd 100644 --- a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/LocalProvider.java +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/java/org/apache/dubbo/samples/local/LocalProvider.java @@ -26,6 +26,8 @@ @EnableDubbo public class LocalProvider { public static void main(String[] args) { + // Start the registry + new EmbeddedZooKeeper(2181, false).start(); SpringApplication.run(LocalProvider.class, args); } } diff --git a/2-advanced/dubbo-samples-local/pom.xml b/2-advanced/dubbo-samples-local/pom.xml index 8b71b06629..5c7dfe4aad 100644 --- a/2-advanced/dubbo-samples-local/pom.xml +++ b/2-advanced/dubbo-samples-local/pom.xml @@ -35,7 +35,7 @@ Dubbo Samples Local - 3.2.0-beta.6-SNAPSHOT + 3.2.0-beta.4 2.7.8 4.13.1 1.8 From 7a28f77169a73e6f64dc366f601ba7d86d3b2aa4 Mon Sep 17 00:00:00 2001 From: fyf <2569548856@qq.com> Date: Tue, 7 Mar 2023 11:06:22 +0800 Subject: [PATCH 5/9] modify pom.xml config --- .../case-configuration.yml | 19 +- .../dubbo-samples-local/case-versions.conf | 2 +- .../dubbo-samples-local-consumer/pom.xml | 11 +- .../src/main/resources/application.yml | 1 + .../samples/local/EmbeddedZooKeeper.java | 255 ++++++++++++++++++ .../dubbo/samples/local/LocalServiceIT.java | 10 +- .../dubbo-samples-local-provider/pom.xml | 67 ----- .../src/main/resources/application.yml | 1 + 2-advanced/dubbo-samples-local/pom.xml | 8 +- 9 files changed, 295 insertions(+), 79 deletions(-) create mode 100644 2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/EmbeddedZooKeeper.java diff --git a/2-advanced/dubbo-samples-local/case-configuration.yml b/2-advanced/dubbo-samples-local/case-configuration.yml index b564475e64..db73bf9dc9 100644 --- a/2-advanced/dubbo-samples-local/case-configuration.yml +++ b/2-advanced/dubbo-samples-local/case-configuration.yml @@ -19,22 +19,31 @@ services: zookeeper: image: zookeeper:latest + local-provider: type: app basedir: dubbo-samples-local-provider mainClass: org.apache.dubbo.samples.local.LocalProvider + systemProps: + - zookeeper.address=zookeeper + waitPortsBeforeRun: + - zookeeper:2181 + checkPorts: + - 20880 + checkLog: "Current Spring Boot Application is await" + depends_on: + - zookeeper + local-consumer: type: test basedir: dubbo-samples-local-consumer tests: - "**/*IT.class" systemProps: - - zookeeper.address=local-provider - - zookeeper.port=2181 - - dubbo.address=local-provider - - dubbo.port=20880 + - zookeeper.address=zookeeper waitPortsBeforeRun: - - local-provider:2181 + - zookeeper:2181 - local-provider:20880 depends_on: + - zookeeper - local-provider \ No newline at end of file diff --git a/2-advanced/dubbo-samples-local/case-versions.conf b/2-advanced/dubbo-samples-local/case-versions.conf index 9a2ae82744..20c45c863f 100644 --- a/2-advanced/dubbo-samples-local/case-versions.conf +++ b/2-advanced/dubbo-samples-local/case-versions.conf @@ -20,6 +20,6 @@ # Supported component versions of the test case # Spring app -dubbo.version=3.* +dubbo.version=2.7*, 3.* spring.version=4.*, 5.* java.version= [<= 11] diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml index 5b403e0b40..d561d25a0d 100644 --- a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml @@ -40,10 +40,10 @@ org.apache.dubbo dubbo-spring-boot-starter - + org.apache.dubbo - dubbo-dependencies-zookeeper-curator5 + dubbo-dependencies-zookeeper pom @@ -70,7 +70,12 @@ 4.13.1 test - + + org.apache.dubbo + embedded-zookeeper + 1.0-SNAPSHOT + test + diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/application.yml b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/application.yml index e3a0ddf195..52e00981c1 100644 --- a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/application.yml +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/main/resources/application.yml @@ -20,6 +20,7 @@ dubbo: application: name: local-consumer + logger: slf4j protocol: name: dubbo port: -1 diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/EmbeddedZooKeeper.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/EmbeddedZooKeeper.java new file mode 100644 index 0000000000..b1e8539d7a --- /dev/null +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/EmbeddedZooKeeper.java @@ -0,0 +1,255 @@ +/* + * Copyright 2014 the original author or authors. + * + * Licensed 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.local; + +import org.apache.zookeeper.server.ServerConfig; +import org.apache.zookeeper.server.ZooKeeperServerMain; +import org.apache.zookeeper.server.quorum.QuorumPeerConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.SmartLifecycle; +import org.springframework.util.ErrorHandler; +import org.springframework.util.SocketUtils; + +import java.io.File; +import java.lang.reflect.Method; +import java.util.Properties; +import java.util.UUID; + +/** + * from: https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java + * + * Helper class to start an embedded instance of standalone (non clustered) ZooKeeper. + * + * NOTE: at least an external standalone server (if not an ensemble) are recommended, even for + * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication} + * + * @author Patrick Peralta + * @author Mark Fisher + * @author David Turanski + */ +public class EmbeddedZooKeeper implements SmartLifecycle { + + /** + * Logger. + */ + private static final Logger logger = LoggerFactory.getLogger(EmbeddedZooKeeper.class); + + /** + * ZooKeeper client port. This will be determined dynamically upon startup. + */ + private final int clientPort; + + /** + * Whether to auto-start. Default is true. + */ + private boolean autoStartup = true; + + /** + * Lifecycle phase. Default is 0. + */ + private int phase = 0; + + /** + * Thread for running the ZooKeeper server. + */ + private volatile Thread zkServerThread; + + /** + * ZooKeeper server. + */ + private volatile ZooKeeperServerMain zkServer; + + /** + * {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread. + */ + private ErrorHandler errorHandler; + + private boolean daemon = true; + + /** + * Construct an EmbeddedZooKeeper with a random port. + */ + public EmbeddedZooKeeper() { + clientPort = SocketUtils.findAvailableTcpPort(); + } + + /** + * Construct an EmbeddedZooKeeper with the provided port. + * + * @param clientPort port for ZooKeeper server to bind to + */ + public EmbeddedZooKeeper(int clientPort, boolean daemon) { + this.clientPort = clientPort; + this.daemon = daemon; + } + + /** + * Returns the port that clients should use to connect to this embedded server. + * + * @return dynamically determined client port + */ + public int getClientPort() { + return this.clientPort; + } + + /** + * Specify whether to start automatically. Default is true. + * + * @param autoStartup whether to start automatically + */ + public void setAutoStartup(boolean autoStartup) { + this.autoStartup = autoStartup; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isAutoStartup() { + return this.autoStartup; + } + + /** + * Specify the lifecycle phase for the embedded server. + * + * @param phase the lifecycle phase + */ + public void setPhase(int phase) { + this.phase = phase; + } + + /** + * {@inheritDoc} + */ + @Override + public int getPhase() { + return this.phase; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isRunning() { + return (zkServerThread != null); + } + + /** + * Start the ZooKeeper server in a background thread. + *

+ * Register an error handler via {@link #setErrorHandler} in order to handle + * any exceptions thrown during startup or execution. + */ + @Override + public synchronized void start() { + if (zkServerThread == null) { + zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper Server Starter"); + zkServerThread.setDaemon(daemon); + zkServerThread.start(); + } + } + + /** + * Shutdown the ZooKeeper server. + */ + @Override + public synchronized void stop() { + if (zkServerThread != null) { + // The shutdown method is protected...thus this hack to invoke it. + // This will log an exception on shutdown; see + // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for details. + try { + Method shutdown = ZooKeeperServerMain.class.getDeclaredMethod("shutdown"); + shutdown.setAccessible(true); + shutdown.invoke(zkServer); + } + + catch (Exception e) { + throw new RuntimeException(e); + } + + // It is expected that the thread will exit after + // the server is shutdown; this will block until + // the shutdown is complete. + try { + zkServerThread.join(5000); + zkServerThread = null; + } + catch (InterruptedException e) { + Thread.currentThread().interrupt(); + logger.warn("Interrupted while waiting for embedded ZooKeeper to exit"); + // abandoning zk thread + zkServerThread = null; + } + } + } + + /** + * Stop the server if running and invoke the callback when complete. + */ + @Override + public void stop(Runnable callback) { + stop(); + callback.run(); + } + + /** + * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread. If none + * is provided, only error-level logging will occur. + * + * @param errorHandler the {@link ErrorHandler} to be invoked + */ + public void setErrorHandler(ErrorHandler errorHandler) { + this.errorHandler = errorHandler; + } + + /** + * Runnable implementation that starts the ZooKeeper server. + */ + private class ServerRunnable implements Runnable { + + @Override + public void run() { + try { + Properties properties = new Properties(); + File file = new File(System.getProperty("java.io.tmpdir") + + File.separator + UUID.randomUUID()); + file.deleteOnExit(); + properties.setProperty("dataDir", file.getAbsolutePath()); + properties.setProperty("clientPort", String.valueOf(clientPort)); + + QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig(); + quorumPeerConfig.parseProperties(properties); + + zkServer = new ZooKeeperServerMain(); + ServerConfig configuration = new ServerConfig(); + configuration.readFrom(quorumPeerConfig); + + zkServer.runFromConfig(configuration); + } + catch (Exception e) { + if (errorHandler != null) { + errorHandler.handleError(e); + } + else { + logger.error("Exception running embedded ZooKeeper", e); + } + } + } + } + +} \ No newline at end of file diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java index e1fae07b32..c5a2d6a61b 100644 --- a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java @@ -23,6 +23,7 @@ import org.apache.dubbo.samples.local.api.LocalService; import org.apache.dubbo.spring.boot.autoconfigure.DubboAutoConfiguration; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; @@ -34,11 +35,16 @@ public class LocalServiceIT { @DubboReference private LocalService localService; + @BeforeClass + public static void setUp() throws Exception { + new EmbeddedZooKeeper(2181, false).start(); + } + @Test public void test() throws Exception { String result = localService.sayHello("world"); - Assert.assertEquals(result, "Hello world, response from provider: 10.193.180.32:20880"); + Assert.assertEquals(result, "Hello world, response from provider: 127.0.0.1:0"); result = localService.sayHelloAsync("world"); - Assert.assertEquals(result, "Hello world, response from provider: 10.193.180.32:20880"); + Assert.assertEquals(result, "Hello world, response from provider: 127.0.0.1:0"); } } diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml index 24655c0133..e09a81a319 100644 --- a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/pom.xml @@ -28,10 +28,6 @@ dubbo-samples-local-provider - - 3.8.0 - - @@ -61,71 +57,8 @@ org.springframework.boot spring-boot-starter - - - org.apache.zookeeper - zookeeper - ${zookeeper.version} - - - netty-handler - io.netty - - - netty-transport-native-epoll - io.netty - - - - - commons-cli - commons-cli - 1.4 - - - org.eclipse.jetty - jetty-server - - - org.eclipse.jetty - jetty-servlet - - - org.eclipse.jetty - jetty-client - - - jline - jline - 2.14.6 - - - io.dropwizard.metrics - metrics-core - - - org.xerial.snappy - snappy-java - - - - - javax.annotation - - [1.11,) - - - - javax.annotation - javax.annotation-api - 1.3.2 - - - - - diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/application.yml b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/application.yml index 04bc500c29..37e8f056d5 100644 --- a/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/application.yml +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-provider/src/main/resources/application.yml @@ -19,6 +19,7 @@ dubbo: application: name: local-provider + logger: slf4j protocol: name: dubbo port: 20880 diff --git a/2-advanced/dubbo-samples-local/pom.xml b/2-advanced/dubbo-samples-local/pom.xml index 5c7dfe4aad..a682fe0696 100644 --- a/2-advanced/dubbo-samples-local/pom.xml +++ b/2-advanced/dubbo-samples-local/pom.xml @@ -18,6 +18,13 @@ + + org.apache + apache + 23 + + + dubbo-samples-local-provider dubbo-samples-local-consumer @@ -37,7 +44,6 @@ 3.2.0-beta.4 2.7.8 - 4.13.1 1.8 1.8 UTF-8 From b13707af30744c8be189f7630283091005a97860 Mon Sep 17 00:00:00 2001 From: fyf <2569548856@qq.com> Date: Tue, 7 Mar 2023 11:10:57 +0800 Subject: [PATCH 6/9] add junit version --- 2-advanced/dubbo-samples-local/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/2-advanced/dubbo-samples-local/pom.xml b/2-advanced/dubbo-samples-local/pom.xml index a682fe0696..3f1226ab9d 100644 --- a/2-advanced/dubbo-samples-local/pom.xml +++ b/2-advanced/dubbo-samples-local/pom.xml @@ -44,6 +44,7 @@ 3.2.0-beta.4 2.7.8 + 4.13.1 1.8 1.8 UTF-8 From f04281297912f1ac49a3cbc2b4e1c470498a66f4 Mon Sep 17 00:00:00 2001 From: fyf <2569548856@qq.com> Date: Tue, 7 Mar 2023 11:54:38 +0800 Subject: [PATCH 7/9] remove embedded-zookeeper module --- .../dubbo-samples-local-consumer/pom.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml index d561d25a0d..acd99609a4 100644 --- a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/pom.xml @@ -70,12 +70,6 @@ 4.13.1 test - - org.apache.dubbo - embedded-zookeeper - 1.0-SNAPSHOT - test - From b27ca6932311d177239ab7d31146aac3e76d6c41 Mon Sep 17 00:00:00 2001 From: fyf <2569548856@qq.com> Date: Tue, 7 Mar 2023 17:08:35 +0800 Subject: [PATCH 8/9] add localAddress --- .../org/apache/dubbo/samples/local/LocalServiceIT.java | 8 ++++++-- nacos-mysql/Dockerfile | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 nacos-mysql/Dockerfile diff --git a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java index c5a2d6a61b..9fee0fad74 100644 --- a/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java +++ b/2-advanced/dubbo-samples-local/dubbo-samples-local-consumer/src/test/java/org/apache/dubbo/samples/local/LocalServiceIT.java @@ -20,6 +20,7 @@ package org.apache.dubbo.samples.local; import org.apache.dubbo.config.annotation.DubboReference; +import org.apache.dubbo.rpc.RpcContext; import org.apache.dubbo.samples.local.api.LocalService; import org.apache.dubbo.spring.boot.autoconfigure.DubboAutoConfiguration; import org.junit.Assert; @@ -29,6 +30,8 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import java.net.InetSocketAddress; + @SpringBootTest(classes = {DubboAutoConfiguration.class}) @RunWith(SpringRunner.class) public class LocalServiceIT { @@ -42,9 +45,10 @@ public static void setUp() throws Exception { @Test public void test() throws Exception { + InetSocketAddress localAddress = RpcContext.getContext().getLocalAddress(); String result = localService.sayHello("world"); - Assert.assertEquals(result, "Hello world, response from provider: 127.0.0.1:0"); + Assert.assertEquals(result, "Hello world, response from provider: " + localAddress); result = localService.sayHelloAsync("world"); - Assert.assertEquals(result, "Hello world, response from provider: 127.0.0.1:0"); + Assert.assertEquals(result, "Hello world, response from provider: " + localAddress); } } diff --git a/nacos-mysql/Dockerfile b/nacos-mysql/Dockerfile new file mode 100644 index 0000000000..d520f38a1e --- /dev/null +++ b/nacos-mysql/Dockerfile @@ -0,0 +1,5 @@ +FROM mysql:5.7.40 +ADD https://raw.githubusercontent.com/alibaba/nacos/develop/distribution/conf/mysql-schema.sql /docker-entrypoint-initdb.d/nacos-mysql.sql +RUN chown -R mysql:mysql /docker-entrypoint-initdb.d/nacos-mysql.sql +EXPOSE 3306 +CMD ["mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"] \ No newline at end of file From b45fd1e0d1741cd996fa027dcd378bdc8f991320 Mon Sep 17 00:00:00 2001 From: fyf <2569548856@qq.com> Date: Tue, 7 Mar 2023 17:27:18 +0800 Subject: [PATCH 9/9] remove useless dir --- nacos-mysql/Dockerfile | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 nacos-mysql/Dockerfile diff --git a/nacos-mysql/Dockerfile b/nacos-mysql/Dockerfile deleted file mode 100644 index d520f38a1e..0000000000 --- a/nacos-mysql/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM mysql:5.7.40 -ADD https://raw.githubusercontent.com/alibaba/nacos/develop/distribution/conf/mysql-schema.sql /docker-entrypoint-initdb.d/nacos-mysql.sql -RUN chown -R mysql:mysql /docker-entrypoint-initdb.d/nacos-mysql.sql -EXPOSE 3306 -CMD ["mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"] \ No newline at end of file