temp test
This commit is contained in:
parent
dc15a8db6c
commit
b87b9a2ff9
|
|
@ -114,5 +114,15 @@
|
|||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* 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.demo.consumer;
|
||||
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.CuratorFrameworkFactory;
|
||||
import org.apache.curator.retry.ExponentialBackoffRetry;
|
||||
|
||||
public class ZKTools {
|
||||
private static String zookeeperHost = System.getProperty("zookeeper.address", "127.0.0.1");
|
||||
private static CuratorFramework client;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
initClient();
|
||||
generateAppevelRouter();
|
||||
}
|
||||
|
||||
public static void initClient() {
|
||||
client = CuratorFrameworkFactory.newClient(zookeeperHost + ":2181", 60 * 1000, 60 * 1000,
|
||||
new ExponentialBackoffRetry(1000, 3));
|
||||
client.start();
|
||||
}
|
||||
|
||||
public static void generateAppevelRouter() {
|
||||
String str = "" +
|
||||
"---\n" +
|
||||
"scope: application\n" +
|
||||
"force: true\n" +
|
||||
"runtime: true\n" +
|
||||
"enabled: true\n" +
|
||||
"priority: 2\n" +
|
||||
"key: demo-consumer\n" +
|
||||
"conditions:\n" +
|
||||
" - interface=org.apache.dubbo.demo.GreetingService=>address=*:20880\n" +
|
||||
" - interface=org.apache.dubbo.demo.DemoService=>address=*:20881\n" +
|
||||
"...";
|
||||
|
||||
System.out.println(str);
|
||||
|
||||
try {
|
||||
String path = "/dubbo/config/dubbo/demo-consumer.condition-router";
|
||||
if (client.checkExists().forPath(path) == null) {
|
||||
client.create().creatingParentsIfNeeded().forPath(path);
|
||||
}
|
||||
setData(path, str);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void setData(String path, String data) throws Exception {
|
||||
client.setData().forPath(path, data.getBytes());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import org.apache.dubbo.demo.DemoService;
|
||||
import org.apache.dubbo.demo.GreetingService;
|
||||
import org.apache.dubbo.demo.consumer.ZKTools;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.jupiter.api.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-consumer.xml"})
|
||||
public class DemoServiceIT {
|
||||
@Autowired
|
||||
private DemoService demoService;
|
||||
|
||||
@Autowired
|
||||
private GreetingService greetingService;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception {
|
||||
ZKTools.initClient();
|
||||
ZKTools.generateAppevelRouter();
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDemoService() throws Exception {
|
||||
String result = demoService.sayHello("world");
|
||||
Assert.assertTrue(result.contains("20880"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDemoService2() throws Exception {
|
||||
String result = greetingService.hello();
|
||||
Assert.assertTrue(result.contains("20881"));
|
||||
}
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@ public class DemoServiceImpl implements DemoService {
|
|||
e.printStackTrace();
|
||||
}
|
||||
return "Hello " + name + ", response from provider: "
|
||||
+ RpcContext.getServiceContext().getLocalAddress();
|
||||
+ RpcContext.getServiceContext().getLocalAddress() + RpcContext.getServiceContext().getLocalPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.dubbo.demo.provider;
|
||||
|
||||
import org.apache.dubbo.demo.GreetingService;
|
||||
import org.apache.dubbo.rpc.RpcContext;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -24,6 +25,6 @@ import org.apache.dubbo.demo.GreetingService;
|
|||
public class GreetingServiceImpl implements GreetingService {
|
||||
@Override
|
||||
public String hello() {
|
||||
return "Greetings!";
|
||||
return "Greetings!" + RpcContext.getServiceContext().getLocalPort();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,10 @@
|
|||
<dubbo:protocol name="rest" port="-1"/>
|
||||
<dubbo:protocol name="tri" port="-1"/>
|
||||
|
||||
<!-- <dubbo:protocol name="dubbo" port="28081"/>-->
|
||||
<!-- <dubbo:protocol name="rest" port="28081"/>-->
|
||||
<!-- <dubbo:protocol name="tri" port="28081"/>-->
|
||||
|
||||
<bean id="demoService" class="org.apache.dubbo.demo.provider.DemoServiceImpl"/>
|
||||
<bean id="greetingService" class="org.apache.dubbo.demo.provider.GreetingServiceImpl"/>
|
||||
<bean id="restDemoService" class="org.apache.dubbo.demo.provider.RestDemoServiceImpl"/>
|
||||
|
|
|
|||
Loading…
Reference in New Issue