You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by al...@apache.org on 2021/07/02 07:07:57 UTC
[dubbo-samples] branch master updated: Split duplicated reference
configs into several spring xml (#341)
This is an automated email from the ASF dual-hosted git repository.
albumenj 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 c662775 Split duplicated reference configs into several spring xml (#341)
c662775 is described below
commit c662775434170385ae12461adc2cfb21148073d0
Author: Gong Dewei <ky...@qq.com>
AuthorDate: Fri Jul 2 15:07:49 2021 +0800
Split duplicated reference configs into several spring xml (#341)
---
dubbo-samples-multi-registry/pom.xml | 3 +-
.../multi/registry/MultiRegistryConsumer.java | 27 +++-
.../resources/spring/multi-registry-consumer1.xml | 35 +++++
.../resources/spring/multi-registry-consumer2.xml | 34 ++++
.../resources/spring/multi-registry-consumer3.xml | 34 ++++
.../multi/registry/MultiRegistryServiceIT.java | 174 ++++++++++-----------
...iceIT.java => MultiRegistryServiceSplitIT.java} | 62 ++++----
7 files changed, 240 insertions(+), 129 deletions(-)
diff --git a/dubbo-samples-multi-registry/pom.xml b/dubbo-samples-multi-registry/pom.xml
index 8141ee3..26ebfa4 100644
--- a/dubbo-samples-multi-registry/pom.xml
+++ b/dubbo-samples-multi-registry/pom.xml
@@ -29,7 +29,8 @@
<properties>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
- <dubbo.version>2.7.7</dubbo.version>
+ <dubbo.version>2.7.11</dubbo.version>
+<!-- <dubbo.version>3.0.1-SNAPSHOT</dubbo.version>-->
<spring.version>4.3.16.RELEASE</spring.version>
<junit.version>4.12</junit.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
diff --git a/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/MultiRegistryConsumer.java b/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/MultiRegistryConsumer.java
index f34ea1d..89ae451 100644
--- a/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/MultiRegistryConsumer.java
+++ b/dubbo-samples-multi-registry/src/main/java/org/apache/dubbo/samples/multi/registry/MultiRegistryConsumer.java
@@ -28,15 +28,26 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MultiRegistryConsumer {
public static void main(String[] args) throws Exception {
- ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/multi-registry-consumer.xml");
+// ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/multi-registry-consumer.xml");
+// context.start();
+//
+// DemoService demoServiceFormDefault = (DemoService) context.getBean("demoServiceFormDefault");
+// HelloService helloServiceFormShanghai = (HelloService) context.getBean("helloServiceFormShanghai");
+// HelloService helloServiceFormBeijing = (HelloService) context.getBean("helloServiceFormBeijing");
+//
+// System.out.println(demoServiceFormDefault.get("service form default registry"));
+// System.out.println(helloServiceFormShanghai.sayHello("service form shanghai registry"));
+// System.out.println(helloServiceFormBeijing.sayHello("service form beijing registry"));
+
+
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/multi-registry-consumer1.xml");
context.start();
- DemoService demoServiceFormDefault = (DemoService) context.getBean("demoServiceFormDefault");
- HelloService helloServiceFormShanghai = (HelloService) context.getBean("helloServiceFormShanghai");
- HelloService helloServiceFormBeijing = (HelloService) context.getBean("helloServiceFormBeijing");
-
- System.out.println(demoServiceFormDefault.get("service form default registry"));
- System.out.println(helloServiceFormShanghai.sayHello("service form shanghai registry"));
- System.out.println(helloServiceFormBeijing.sayHello("service form beijing registry"));
+ DemoService demoService = context.getBean(DemoService.class);
+ HelloService helloService = context.getBean(HelloService.class);
+ System.out.println(demoService.get("service form default registry"));
+ System.out.println(helloService.sayHello("service form shanghai registry"));
}
+
+
}
diff --git a/dubbo-samples-multi-registry/src/main/resources/spring/multi-registry-consumer1.xml b/dubbo-samples-multi-registry/src/main/resources/spring/multi-registry-consumer1.xml
new file mode 100644
index 0000000..84b1f44
--- /dev/null
+++ b/dubbo-samples-multi-registry/src/main/resources/spring/multi-registry-consumer1.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
+ xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+ <context:property-placeholder/>
+
+ <dubbo:application name="multi-registry-consumer"/>
+
+ <dubbo:registry id="beijingRegistry" address="zookeeper://${zookeeper.address:127.0.0.1}:${zookeeper.port.1:2181}" />
+ <dubbo:registry id="shanghaiRegistry" address="zookeeper://${zookeeper.address:127.0.0.1}:${zookeeper.port.2:2182}" />
+
+ <dubbo:reference id="demoService" registry="beijingRegistry" interface="org.apache.dubbo.samples.multi.registry.api.DemoService"/>
+ <dubbo:reference id="helloService" registry="shanghaiRegistry" interface="org.apache.dubbo.samples.multi.registry.api.HelloService"/>
+
+</beans>
+
diff --git a/dubbo-samples-multi-registry/src/main/resources/spring/multi-registry-consumer2.xml b/dubbo-samples-multi-registry/src/main/resources/spring/multi-registry-consumer2.xml
new file mode 100644
index 0000000..aa252ec
--- /dev/null
+++ b/dubbo-samples-multi-registry/src/main/resources/spring/multi-registry-consumer2.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
+ xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+ <context:property-placeholder/>
+
+ <dubbo:application name="multi-registry-consumer"/>
+
+ <dubbo:registry id="shanghaiRegistry" address="zookeeper://${zookeeper.address:127.0.0.1}:${zookeeper.port.2:2182}" />
+
+ <dubbo:reference id="demoService" interface="org.apache.dubbo.samples.multi.registry.api.DemoService"/>
+ <dubbo:reference id="helloService" interface="org.apache.dubbo.samples.multi.registry.api.HelloService"/>
+
+</beans>
+
diff --git a/dubbo-samples-multi-registry/src/main/resources/spring/multi-registry-consumer3.xml b/dubbo-samples-multi-registry/src/main/resources/spring/multi-registry-consumer3.xml
new file mode 100644
index 0000000..8119df2
--- /dev/null
+++ b/dubbo-samples-multi-registry/src/main/resources/spring/multi-registry-consumer3.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
+ xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+ <context:property-placeholder/>
+
+ <dubbo:application name="multi-registry-consumer"/>
+
+ <dubbo:registry id="beijingRegistry" address="zookeeper://${zookeeper.address:127.0.0.1}:${zookeeper.port.1:2181}" />
+
+ <dubbo:reference id="demoService" interface="org.apache.dubbo.samples.multi.registry.api.DemoService"/>
+ <dubbo:reference id="helloService" interface="org.apache.dubbo.samples.multi.registry.api.HelloService"/>
+
+</beans>
+
diff --git a/dubbo-samples-multi-registry/src/test/java/org/apache/dubbo/samples/multi/registry/MultiRegistryServiceIT.java b/dubbo-samples-multi-registry/src/test/java/org/apache/dubbo/samples/multi/registry/MultiRegistryServiceIT.java
index cdbe0f4..ef587b5 100644
--- a/dubbo-samples-multi-registry/src/test/java/org/apache/dubbo/samples/multi/registry/MultiRegistryServiceIT.java
+++ b/dubbo-samples-multi-registry/src/test/java/org/apache/dubbo/samples/multi/registry/MultiRegistryServiceIT.java
@@ -1,87 +1,87 @@
-/*
- * 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.multi.registry;
-
-import org.apache.dubbo.samples.multi.registry.api.DemoService;
-import org.apache.dubbo.samples.multi.registry.api.HelloService;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-import java.util.List;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = {"classpath:/spring/multi-registry-consumer.xml"})
-public class MultiRegistryServiceIT {
- @Autowired
- @Qualifier("demoServiceFormDefault")
- private DemoService defaultDemoService;
-
- @Autowired
- @Qualifier("demoServiceFormBeijing")
- private DemoService beijingDemoService;
-
- @Autowired
- @Qualifier("helloServiceFormBeijing")
- private HelloService beijingHelloService;
-
- @Autowired
- @Qualifier("helloServiceFormShanghai")
- private HelloService shanghaiHelloService;
-
- @Test
- public void testDefaultDemoService() throws Exception {
- Assert.assertEquals("get: demo", defaultDemoService.get("demo"));
- }
-
- @Test
- public void testBeijingDemoService() throws Exception {
- Assert.assertEquals("get: beijing", beijingDemoService.get("beijing"));
- }
-
- @Test
- public void testBeijingHelloService() throws Exception {
- Assert.assertEquals("sayHello: beijing", beijingHelloService.sayHello("beijing"));
- }
-
- @Test
- public void testShanghaiHelloService() throws Exception {
- Assert.assertEquals("sayHello: shanghai", shanghaiHelloService.sayHello("shanghai"));
- }
-
- @Test
- public void verifyProvidersFromBeijingRegistry() throws Exception {
- List<String> demoServiceProviders = ZKTools.getProviders(DemoService.class, 2181);
- Assert.assertEquals(1, demoServiceProviders.size());
- List<String> helloServiceProviders = ZKTools.getProviders(HelloService.class, 2181);
- Assert.assertEquals(1, helloServiceProviders.size());
- }
-
- @Test
- public void verifyProvidersFromShanghaiRegistry() throws Exception {
- List<String> demoServiceProviders = ZKTools.getProviders(DemoService.class, 2182);
- Assert.assertEquals(1, demoServiceProviders.size());
- List<String> helloServiceProviders = ZKTools.getProviders(HelloService.class, 2182);
- Assert.assertEquals(1, helloServiceProviders.size());
- }
-}
+///*
+// * 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.multi.registry;
+//
+//import org.apache.dubbo.samples.multi.registry.api.DemoService;
+//import org.apache.dubbo.samples.multi.registry.api.HelloService;
+//
+//import org.junit.Assert;
+//import org.junit.Test;
+//import org.junit.runner.RunWith;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.beans.factory.annotation.Qualifier;
+//import org.springframework.test.context.ContextConfiguration;
+//import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+//
+//import java.util.List;
+//
+//@RunWith(SpringJUnit4ClassRunner.class)
+//@ContextConfiguration(locations = {"classpath:/spring/multi-registry-consumer.xml"})
+//public class MultiRegistryServiceIT {
+// @Autowired
+// @Qualifier("demoServiceFormDefault")
+// private DemoService defaultDemoService;
+//
+// @Autowired
+// @Qualifier("demoServiceFormBeijing")
+// private DemoService beijingDemoService;
+//
+// @Autowired
+// @Qualifier("helloServiceFormBeijing")
+// private HelloService beijingHelloService;
+//
+// @Autowired
+// @Qualifier("helloServiceFormShanghai")
+// private HelloService shanghaiHelloService;
+//
+// @Test
+// public void testDefaultDemoService() throws Exception {
+// Assert.assertEquals("get: demo", defaultDemoService.get("demo"));
+// }
+//
+// @Test
+// public void testBeijingDemoService() throws Exception {
+// Assert.assertEquals("get: beijing", beijingDemoService.get("beijing"));
+// }
+//
+// @Test
+// public void testBeijingHelloService() throws Exception {
+// Assert.assertEquals("sayHello: beijing", beijingHelloService.sayHello("beijing"));
+// }
+//
+// @Test
+// public void testShanghaiHelloService() throws Exception {
+// Assert.assertEquals("sayHello: shanghai", shanghaiHelloService.sayHello("shanghai"));
+// }
+//
+// @Test
+// public void verifyProvidersFromBeijingRegistry() throws Exception {
+// List<String> demoServiceProviders = ZKTools.getProviders(DemoService.class, 2181);
+// Assert.assertEquals(1, demoServiceProviders.size());
+// List<String> helloServiceProviders = ZKTools.getProviders(HelloService.class, 2181);
+// Assert.assertEquals(1, helloServiceProviders.size());
+// }
+//
+// @Test
+// public void verifyProvidersFromShanghaiRegistry() throws Exception {
+// List<String> demoServiceProviders = ZKTools.getProviders(DemoService.class, 2182);
+// Assert.assertEquals(1, demoServiceProviders.size());
+// List<String> helloServiceProviders = ZKTools.getProviders(HelloService.class, 2182);
+// Assert.assertEquals(1, helloServiceProviders.size());
+// }
+//}
diff --git a/dubbo-samples-multi-registry/src/test/java/org/apache/dubbo/samples/multi/registry/MultiRegistryServiceIT.java b/dubbo-samples-multi-registry/src/test/java/org/apache/dubbo/samples/multi/registry/MultiRegistryServiceSplitIT.java
similarity index 50%
copy from dubbo-samples-multi-registry/src/test/java/org/apache/dubbo/samples/multi/registry/MultiRegistryServiceIT.java
copy to dubbo-samples-multi-registry/src/test/java/org/apache/dubbo/samples/multi/registry/MultiRegistryServiceSplitIT.java
index cdbe0f4..184c807 100644
--- a/dubbo-samples-multi-registry/src/test/java/org/apache/dubbo/samples/multi/registry/MultiRegistryServiceIT.java
+++ b/dubbo-samples-multi-registry/src/test/java/org/apache/dubbo/samples/multi/registry/MultiRegistryServiceSplitIT.java
@@ -17,56 +17,52 @@
package org.apache.dubbo.samples.multi.registry;
+import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.samples.multi.registry.api.DemoService;
import org.apache.dubbo.samples.multi.registry.api.HelloService;
-
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.List;
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = {"classpath:/spring/multi-registry-consumer.xml"})
-public class MultiRegistryServiceIT {
- @Autowired
- @Qualifier("demoServiceFormDefault")
- private DemoService defaultDemoService;
-
- @Autowired
- @Qualifier("demoServiceFormBeijing")
- private DemoService beijingDemoService;
-
- @Autowired
- @Qualifier("helloServiceFormBeijing")
- private HelloService beijingHelloService;
+public class MultiRegistryServiceSplitIT {
- @Autowired
- @Qualifier("helloServiceFormShanghai")
- private HelloService shanghaiHelloService;
-
- @Test
- public void testDefaultDemoService() throws Exception {
- Assert.assertEquals("get: demo", defaultDemoService.get("demo"));
+ @Before
+ public void setUp() {
+ try {
+ DubboBootstrap.reset();
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
}
@Test
- public void testBeijingDemoService() throws Exception {
- Assert.assertEquals("get: beijing", beijingDemoService.get("beijing"));
+ public void testConsumer1() throws Exception {
+ ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("/spring/multi-registry-consumer1.xml");
+ DemoService demoService = applicationContext.getBean(DemoService.class);
+ HelloService helloService = applicationContext.getBean(HelloService.class);
+ Assert.assertEquals("get: demo", demoService.get("demo"));
+ Assert.assertEquals("sayHello: beijing", helloService.sayHello("beijing"));
}
@Test
- public void testBeijingHelloService() throws Exception {
- Assert.assertEquals("sayHello: beijing", beijingHelloService.sayHello("beijing"));
+ public void testConsumer2() throws Exception {
+ ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("/spring/multi-registry-consumer2.xml");
+ DemoService demoService = applicationContext.getBean(DemoService.class);
+ HelloService helloService = applicationContext.getBean(HelloService.class);
+ Assert.assertEquals("get: demo", demoService.get("demo"));
+ Assert.assertEquals("sayHello: beijing", helloService.sayHello("beijing"));
}
@Test
- public void testShanghaiHelloService() throws Exception {
- Assert.assertEquals("sayHello: shanghai", shanghaiHelloService.sayHello("shanghai"));
+ public void testConsumer3() throws Exception {
+ ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("/spring/multi-registry-consumer3.xml");
+ DemoService demoService = applicationContext.getBean(DemoService.class);
+ HelloService helloService = applicationContext.getBean(HelloService.class);
+ Assert.assertEquals("get: demo", demoService.get("demo"));
+ Assert.assertEquals("sayHello: beijing", helloService.sayHello("beijing"));
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org