迁移config中的集成测试和性能测试。

git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@211 1a56cb94-b969-4eaa-88fa-be21384802f2
This commit is contained in:
tony.chenl 2011-11-08 08:17:48 +00:00
parent 4c49d48949
commit 70d24893eb
83 changed files with 40 additions and 4783 deletions

View File

@ -1,98 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.callback.explicit.test;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.alibaba.dubbo.registry.support.SimpleRegistryExporter;
/**
* @author chao.liuc
*
*/
public class CallbackTest {
//test 开关
private boolean test = true ;
@Before
public void setUp() throws Exception {
test = false;
SimpleRegistryExporter.exportIfAbsent(9234);
}
@Test
public void startProvider() throws InterruptedException{
if (!test) return;
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"classpath:com/alibaba/dubbo/callback/explicit/provider.xml");
context.start();
synchronized (CallbackTest.class) {
CallbackTest.class.wait();
}
}
@Test
public void startConsumer() throws InterruptedException{
if (!test) return;
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"classpath:com/alibaba/dubbo/callback/explicit/consumer.xml");
context.start();
IDemoService demoService = (IDemoService)context.getBean("demoService");
IDemoCallback callback = new IDemoCallback(){
public String yyy(String msg) {
System.out.println("callback1:"+msg);
return "callback1 onChanged ,"+msg;
}
};
IDemoCallback callback2 = new IDemoCallback(){
public String yyy(String msg) {
System.out.println("callback2:"+msg);
return "callback2 onChanged ,"+msg;
}
};
int i = 1;
long time = System.currentTimeMillis();
System.out.println("cient request id:"+time);
demoService.xxx(callback,"time:"+(i++) +",client request id:"+time);
Thread.sleep(2500);
// demoService.unxxx(callback,"unxxx");
System.out.println("");
time = System.currentTimeMillis();
System.out.println("cient request id:"+time);
demoService.xxx(callback2,"time:"+(i++) +",client request id:"+time);
Thread.sleep(2500);
// demoService.unxxx(callback2,"unxxx2");
System.out.println("");
time = System.currentTimeMillis();
System.out.println("cient request id:"+time);
demoService.xxx(callback,"time:"+(i++) +",client request id:"+time);
Thread.sleep(2500);
// demoService.unxxx(callback,"unxxx");
synchronized (CallbackTest.class) {
CallbackTest.class.wait();
}
}
}

View File

@ -1,53 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.callback.explicit.test;
import com.alibaba.dubbo.common.ExtensionLoader;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.ProxyFactory;
public class Client {
private static ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
private static Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
/**
* @param args
*/
public static void main(String[] args) throws Exception {
URL consumerUrl = Server.serviceURL
// .removeParameter("yyy."+Constants.ASYNC_KEY)
;
//refer client
Invoker<IDemoService> reference = protocol.refer(IDemoService.class, consumerUrl);
IDemoService demoProxy = (IDemoService)proxyFactory.getProxy(reference);
//registry callback
demoProxy.xxx(new IDemoCallback() {
public String yyy(String msg) {
System.out.println("Recived callback: " + msg);
return "ok";
}
},"other custom args");
System.out.println("Async...");
synchronized (Client.class) {
Client.class.wait();
}
}
}

View File

@ -1,53 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.callback.explicit.test;
/**
* @author chao.liuc
*/
public class DemoServiceImpl implements IDemoService {
public String get(){
return "ok" ;
}
public void xxx(final IDemoCallback callback ,String arg1) {
callback.yyy("Sync callback msg .This is callback data. arg1:"+arg1);
Thread t = new Thread(new Runnable() {
public void run() {
for(int i = 0 ;i< 10;i++){
String ret = callback.yyy("server invoke callback : arg:"+System.currentTimeMillis());
System.out.println("callback result is :"+ret);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
t.setDaemon(true);
t.start();
System.out.println("xxx invoke complete");
}
public void unxxx(IDemoCallback callback, String arg1) {
}
public void xxx2(IDemoCallback callback, IDemoCallback callback2, String arg1) {
}
}

View File

@ -1,27 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.callback.explicit.test;
/**
* @author liuchao
*
*/
public interface IDemoCallback{
String yyy(String msg);
}

View File

@ -1,31 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.callback.explicit.test;
/**
* @author chao.liuc
*/
public interface IDemoService{
public String get();
public void xxx(IDemoCallback callback,String arg1);
public void xxx2(IDemoCallback callback,IDemoCallback callback2,String arg1);
public void unxxx(IDemoCallback callback,String arg1);
}

View File

@ -1,49 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.callback.explicit.test;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.ExtensionLoader;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.ProxyFactory;
public class Server {
private static ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
private static Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
public final static URL serviceURL = URL.valueOf("dubbo://127.0.0.1:20880/"+IDemoService.class.getName()+"?group=test"
+"&"+Constants.CODEC_KEY+"=dubbo"
+"&"+Constants.DOWNSTREAM_CODEC_KEY+"=dubbo"
+"&xxx.0.callback=true"
+"&timeout="+Integer.MAX_VALUE
// uncomment is unblock invoking
+"&yyy."+Constants.ASYNC_KEY+"=true"
);
/**
* @param args
*/
public static void main(String[] args) throws Exception {
//export
Invoker<IDemoService> invoker = proxyFactory.getInvoker(new DemoServiceImpl(), IDemoService.class, serviceURL);
protocol.export(invoker);
synchronized (Server.class) {
Server.class.wait();
}
}
}

View File

@ -1,126 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.callback.implicit.test;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.alibaba.dubbo.registry.support.SimpleRegistryExporter;
import com.alibaba.dubbo.rpc.RpcContext;
/**
* @author chao.liuc
*/
public class CallbackTest {
@Before
public void setUp() throws Exception {
SimpleRegistryExporter.exportIfAbsent(9234);
}
public static void main(String[] args) throws InterruptedException {
startProvider();
synchronized (CallbackTest.class) {
CallbackTest.class.wait();
}
}
public static AbstractApplicationContext startProvider() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"classpath:com/alibaba/dubbo/callback/implicit/provider.xml");
context.start();
return context ;
}
@Test
public void TestCallback_Close() throws Exception {
AbstractApplicationContext providerContext = startProvider();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"classpath:com/alibaba/dubbo/callback/implicit/consumer2.xml");
context.start();
IDemoService demoService = (IDemoService) context.getBean("demoService");
int requestId = 2;
Person ret = demoService.get(requestId);
Assert.assertEquals(requestId, ret.getId());
context.destroy();
providerContext.destroy();
}
@Test
public void TestCallback_Open() throws Exception {
AbstractApplicationContext providerContext = startProvider();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"classpath:com/alibaba/dubbo/callback/implicit/consumer.xml");
context.start();
IDemoService demoService = (IDemoService) context.getBean("demoService");
NofifyImpl notify = (NofifyImpl) context.getBean("demoCallback");
int requestId = 2;
Person ret = demoService.get(requestId);
Assert.assertEquals(null, ret);
for (int i = 0; i < 10; i++) {
if (!notify.ret.containsKey(requestId)) {
Thread.sleep(200);
} else {
break;
}
}
Assert.assertEquals(requestId, notify.ret.get(requestId).getId());
context.destroy();
providerContext.destroy();
}
@Test
public void Test_Async_Call() throws Exception {
AbstractApplicationContext providerContext = startProvider();
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"classpath:com/alibaba/dubbo/callback/implicit/consumer_async.xml");
context.start();
IDemoService demoService = (IDemoService) context.getBean("demoService");
int requestId1 = 1;
Person ret = demoService.get(requestId1);
Assert.assertEquals(null, ret);
Future<Person> p1Future = RpcContext.getContext().getFuture();
int requestId2 = 2;
Person ret2 = demoService.get(requestId2);
Assert.assertEquals(null, ret2);
Future<Person> p2Future = RpcContext.getContext().getFuture();
ret = p1Future.get(1000, TimeUnit.MICROSECONDS);
ret2 = p2Future.get(1000, TimeUnit.MICROSECONDS);
Assert.assertEquals(requestId1, ret.getId());
Assert.assertEquals(requestId2, ret2.getId());
context.destroy();
providerContext.destroy();
}
}

View File

@ -1,22 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.callback.implicit.test;
class ExceptionDemoExService implements IDemoService {
public Person get(int id) {
throw new RuntimeException("args is :" + id);
}
}

View File

@ -1,20 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.callback.implicit.test;
interface IDemoService {
public Person get(int id);
}

View File

@ -1,21 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.callback.implicit.test;
interface Nofify {
public void onreturn(Person msg, Integer id);
public void onthrow(Throwable ex, Integer id);
}

View File

@ -1,31 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.callback.implicit.test;
import java.util.HashMap;
import java.util.Map;
class NofifyImpl implements Nofify {
public Map<Integer, Person> ret = new HashMap<Integer, Person>();
public Map<Integer, Throwable> errors = new HashMap<Integer, Throwable>();
public void onreturn(Person msg, Integer id) {
System.out.println("onreturn:" + msg);
ret.put(id, msg);
}
public void onthrow(Throwable ex, Integer id) {
errors.put(id, ex);
}
}

View File

@ -1,22 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.callback.implicit.test;
class NormalDemoService implements IDemoService {
public Person get(int id) {
return new Person(id, "charles`son", 4);
}
}

View File

@ -1,52 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.callback.implicit.test;
import java.io.Serializable;
public class Person implements Serializable{
private static final long serialVersionUID = 1L;
public Person(int id, String name, int age) {
this.id = id;
this.name = name;
this.age = age;
}
private int id;
private String name ;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Override
public String toString() {
return "Person [name=" + name + ", age=" + age + "]";
}
}

View File

@ -13,15 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.demo.api;
/**
* IWelcome
*
* @author william.liangf
*/
public interface IWelcome {
User getUser();
package com.alibaba.dubbo.config.api;
/**
* DemoService
*
* @author william.liangf
*/
public interface DemoService {
String sayName(String name);
}

View File

@ -13,15 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.demo.api;
package com.alibaba.dubbo.config.provider.impl;
import com.alibaba.dubbo.config.api.DemoService;
/**
* Role
* DemoServiceImpl
*
* @author william.liangf
*/
public enum Role {
GUEST, MEMBER, ADMINISTRATOR
public class DemoServiceImpl implements DemoService {
public String sayName(String name) {
return "say:" + name;
}
}

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.config.test;
package com.alibaba.dubbo.config.support;
import com.alibaba.dubbo.common.Extension;
import com.alibaba.dubbo.common.URL;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.config.test;
package com.alibaba.dubbo.config.support;
import java.util.ArrayList;
import java.util.List;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.config.test;
package com.alibaba.dubbo.config.support;
import com.alibaba.dubbo.common.Extension;
import com.alibaba.dubbo.common.URL;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.rpc.util;
package com.alibaba.dubbo.config.support;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

View File

@ -1,133 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.config.test;
import java.util.Date;
import org.junit.Test;
import com.alibaba.dubbo.common.ExtensionLoader;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ConsumerConfig;
import com.alibaba.dubbo.config.ProviderConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;
import com.alibaba.dubbo.rpc.Protocol;
import com.alibaba.dubbo.rpc.ProxyFactory;
import com.alibaba.dubbo.rpc.util.MyException;
import com.alibaba.dubbo.rpc.util.MyService;
import com.alibaba.dubbo.rpc.util.MyServiceImpl;
/**
* User: heyman
* Date: 5/18/11
* Time: 4:20 PM
*/
@SuppressWarnings({"deprecation","rawtypes","unchecked"})
public class ExceptionTest {
private Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
private ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
@Test(expected = RuntimeException.class)
public void testException() {
URL url = URL.valueOf("dubbo://127.0.0.1:9010/TestService?codec=dubbo");
protocol.export(proxy.getInvoker(new MyServiceImpl(), MyService.class, url));
MyService service = proxy.getProxy(protocol.refer(MyService.class, url));
try {
service.throwException();
} catch (MyException e) {
//success
}
service.throwSystemException();
}
@Test
public void testMultiClients() {
URL url1 = URL.valueOf("dubbo://127.0.0.1:9010/TestService?codec=dubbo&channels=3");
URL url2 = URL.valueOf("dubbo://127.0.0.1:9010/TestService2?codec=dubbo&channels=3");
protocol.export(proxy.getInvoker(new MyServiceImpl(), MyService.class, url1));
protocol.export(proxy.getInvoker(new MyServiceImpl(), MyService.class, url2));
MyService service = proxy.getProxy(protocol.refer(MyService.class, url1));
MyService service2 = proxy.getProxy(protocol.refer(MyService.class, url2));
service.echo("test");
/*service.echo("test");
service.echo("test");*/
service2.echo("test");
}
@Test
public void multiContect() {
ApplicationConfig application = new ApplicationConfig();
application.setName("TestServiceServer");
RegistryConfig registry = new RegistryConfig();
registry.setAddress("N/A");
/*List<RegistryConfig> rcList = new ArrayList<RegistryConfig>();
rcList.add(registry);*/
// 服务提供者全局配置
ProviderConfig provider = new ProviderConfig();
provider.setPort(9091);
provider.setThreads(10);
provider.setRegistry(registry);
// provider.setCodec("java");
//provider.setPayload(32 * 1024 * 1024); // 32m max databuffer
// 服务提供者暴露服务配置
ServiceConfig<MyService> service = new ServiceConfig<MyService>();
service.setProvider(provider); // 多个提供者可以用setProviders()
service.setApplication(application);
//service.setRegistry(null);
service.setInterfaceClass(MyService.class);
service.setRef(new MyServiceImpl());
service.setVersion("1.0.0");
service.setPath("testService");
service.export(); // 注意此调用必需将触发服务注册
ApplicationConfig applicationc = new ApplicationConfig();
applicationc.setName("TestServiceServer");
// 服务消费者全局配置
ConsumerConfig consumer = new ConsumerConfig();
consumer.setTimeout(5000);
consumer.setRetries(0);
// 引用远程服务
ReferenceConfig reference = new ReferenceConfig();
//reference.setRegistry(registry); // 多个注册中心可以用setRegistries()
reference.setApplication(application);
reference.setConsumer(consumer);
reference.setInterfaceClass(MyService.class);
reference.setVersion("1.0.0");
//reference.setMethods(methods);
reference.setTimeout(60 * 1000); //超时60秒
reference.setCheck(false);
/*Map<String, String> parameters = new HashMap<String, String>();
parameters.put("codec", "hessian2");
reference.setParameters(parameters);*/
reference.setUrl("dubbo://127.0.0.1:9091/testService");
reference.get();
}
@Test
public void test() {
System.out.println((new Date()).getTime());
}
}

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.config.test;
package com.alibaba.dubbo.config.url.test;
import java.io.UnsupportedEncodingException;

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.config.test;
package com.alibaba.dubbo.config.url.test;
import java.util.Arrays;
@ -30,7 +30,8 @@ import com.alibaba.dubbo.config.ConsumerConfig;
import com.alibaba.dubbo.config.MethodConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.demo.api.DemoService;
import com.alibaba.dubbo.config.api.DemoService;
import com.alibaba.dubbo.config.support.MockRegistry;
/**
@ -201,11 +202,11 @@ public class InvokerSideConfigUrlTest extends UrlTestBase {
refConf.setMethods(Arrays.asList(new MethodConfig[]{methodConfForReference}));
methodConfForReference.setName("sayHello");
methodConfForReference.setName("sayName");
regConfForReference.setAddress("127.0.0.1:9090");
regConfForReference.setProtocol("mockregistry");
appConfForReference.setName("ConfigTests");
refConf.setInterface("com.alibaba.dubbo.demo.api.DemoService");
refConf.setInterface("com.alibaba.dubbo.config.api.DemoService");
}
private <T> void verifyInvokerUrlGeneration(T config, Object[][] dataTable){

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.dubbo.config.test;
package com.alibaba.dubbo.config.url.test;
import java.util.Arrays;
@ -28,9 +28,9 @@ import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.ProviderConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;
import com.alibaba.dubbo.demo.api.DemoService;
import com.alibaba.dubbo.demo.provider.impl.DemoServiceImpl;
import com.alibaba.dubbo.rpc.util.RpcConfigGetSetProxy;
import com.alibaba.dubbo.config.api.DemoService;
import com.alibaba.dubbo.config.provider.impl.DemoServiceImpl;
import com.alibaba.dubbo.config.support.RpcConfigGetSetProxy;
/**
* @author haomin.liuhm
@ -116,11 +116,11 @@ public class UrlTestBase {
};
protected Object methodConfForServiceTable[][] = {
{"actives", "sayHello.actives", "int", 0, 90, "", "", "", "", ""},
{"executes", "sayHello.executes", "int", 0, 90, "", "", "", "", ""},
{"deprecated", "sayHello.deprecated", "boolean", false, true, "", "", "", "", ""},
{"async", "sayHello.async", "boolean", false, true, "", "", "", "", ""},
{"timeout", "sayHello.timeout", "int", 0, 90, "", "", "", "", ""},
{"actives", "sayName.actives", "int", 0, 90, "", "", "", "", ""},
{"executes", "sayName.executes", "int", 0, 90, "", "", "", "", ""},
{"deprecated", "sayName.deprecated", "boolean", false, true, "", "", "", "", ""},
{"async", "sayName.async", "boolean", false, true, "", "", "", "", ""},
{"timeout", "sayName.timeout", "int", 0, 90, "", "", "", "", ""},
};
protected DemoService demoService = new DemoServiceImpl();
@ -174,7 +174,7 @@ public class UrlTestBase {
servConf.setRef(demoService);
servConf.setInterfaceClass(DemoService.class);
methodConfForService.setName("sayHello");
methodConfForService.setName("sayName");
regConfForService.setAddress("127.0.0.1:9090");
regConfForService.setProtocol("mockregistry");
appConfForService.setName("ConfigTests");

View File

@ -1,73 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.api;
import java.io.Serializable;
/**
* Address
*
* @author william.liangf
*/
public class Address implements Serializable {
private static final long serialVersionUID = 2472090310183915884L;
private String city;
private String street;
private String code;
public Address() {
}
public Address(String city, String street, String code) {
this.city = city;
this.street = street;
this.code = code;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
@Override
public String toString() {
return "Address [city=" + city + ", code=" + code + ", street=" + street + "]";
}
}

View File

@ -1,81 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.api;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* DemoService
*
* @author william.liangf
*/
public interface DemoService extends MapService<Map<Object, Object>> {
List<String> getEnvironment();
List<String> getScene();
Welcome sayHello(User user);
String sayOK();
void say();
String sayName(String name);
String sayParams(String name, String parentId, Role[] roles);
long sayLong(long id);
float sayFloat(float id);
short sayShort(short id);
Role sayRole(Role role);
Role[] sayRoles(Role[] role);
List<User> sayList(List<User> users);
Welcome sayTwoHello(User user, User user2);
String sayTwoName(String name1, String name2);
HashSet<String> sayTwoParam(String name1, HashSet<String> name2);
String sayQuery(IndexQueryParameter param);
Map<Object, Object> sayMap(Map<Object, Object> map);
HashMap<Object, Object> sayHashMap(HashMap<Object, Object> map);
LinkedHashMap<Object, Object> sayLinkedHashMap(LinkedHashMap<Object, Object> map);
void throwException();
List<Person> listPerson(Person person);
Person showPerson(Person person);
void subscribe(IDemoCallback callback,String arg1);
void unsubscribe(IDemoCallback callback);
}

View File

@ -1,146 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.api;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* DemoServiceMock
*
* @author william.liangf
*/
public class DemoServiceMock implements DemoService {
public Welcome sayHello(User user) {
System.out.println("-------------Mock");
return null;
}
public String sayOK() {
return "ERR";
}
public void say() {
}
public String sayName(String name) {
return null;
}
public Role sayRole(Role role) {
return null;
}
public Role[] sayRoles(Role[] role) {
return null;
}
public List<User> sayList(List<User> role) {
return null;
}
public Welcome sayTwoHello(User user, User user2) {
return null;
}
public String sayTwoName(String name1, String name2) {
return null;
}
public String sayQuery(IndexQueryParameter param) {
return null;
}
public Map<Object, Object> sayMap(Map<Object, Object> map) {
return null;
}
public HashMap<Object, Object> sayHashMap(HashMap<Object, Object> map) {
return null;
}
public LinkedHashMap<Object, Object> sayLinkedHashMap(LinkedHashMap<Object, Object> map) {
return null;
}
public void throwException() {
}
public long sayLong(long id) {
return 0;
}
public short sayShort(short id) {
return 0;
}
public HashSet<String> sayTwoParam(String name1, HashSet<String> name2) {
return null;
}
public float sayFloat(float id) {
return 0;
}
public List<String> getEnvironment() {
return null;
}
public List<String> getScene() {
return null;
}
public List<Person> listPerson(Person person) {
return null;
}
public Person showPerson(Person person) {
return null;
}
public void subscribe(IDemoCallback callback, String arg1) {
}
public void unsubscribe(IDemoCallback callback) {
}
public String sayParams(String name, String parentId, Role[] roles) {
return null;
}
}

View File

@ -1,135 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.api;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* DemoServiceMock
*
* @author william.liangf
*/
public class DemoServiceStub implements DemoService {
private DemoService demoService;
public DemoServiceStub(DemoService demoService){
this.demoService = demoService;
}
public Welcome sayHello(User user) {
System.out.println("-----------------Stub");
return demoService.sayHello(user);
}
public String sayOK() {
return demoService.sayOK();
}
public void say() {
demoService.say();
}
public String sayName(String name) {
return demoService.sayName(name);
}
public long sayLong(long id) {
return demoService.sayLong(id);
}
public float sayFloat(float id) {
return demoService.sayFloat(id);
}
public short sayShort(short id) {
return demoService.sayShort(id);
}
public Role sayRole(Role role) {
return demoService.sayRole(role);
}
public Role[] sayRoles(Role[] role) {
return demoService.sayRoles(role);
}
public List<User> sayList(List<User> role) {
return demoService.sayList(role);
}
public Welcome sayTwoHello(User user, User user2) {
return demoService.sayTwoHello(user, user2);
}
public String sayTwoName(String name1, String name2) {
return demoService.sayTwoName(name1, name2);
}
public HashSet<String> sayTwoParam(String name1, HashSet<String> name2) {
return demoService.sayTwoParam(name1, name2);
}
public String sayQuery(IndexQueryParameter param) {
return demoService.sayQuery(param);
}
public Map<Object, Object> sayMap(Map<Object, Object> map) {
return demoService.sayMap(map);
}
public HashMap<Object, Object> sayHashMap(HashMap<Object, Object> map) {
return demoService.sayHashMap(map);
}
public LinkedHashMap<Object, Object> sayLinkedHashMap(LinkedHashMap<Object, Object> map) {
return demoService.sayLinkedHashMap(map);
}
public void throwException() {
demoService.throwException();
}
public List<String> getEnvironment() {
return demoService.getEnvironment();
}
public List<String> getScene() {
return demoService.getScene();
}
public List<Person> listPerson(Person person) {
return demoService.listPerson(person);
}
public Person showPerson(Person person) {
return demoService.showPerson(person);
}
public void subscribe(IDemoCallback callback,String arg1) {
}
public void unsubscribe(IDemoCallback callback) {
}
public String sayParams(String name, String parentId, Role[] roles) {
return null;
}
}

View File

@ -1,204 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.api;
import java.io.Serializable;
/**
* @author xk1430
*/
public class FullAddress implements Serializable {
private static final long serialVersionUID = 5163979984269419831L;
private String countryId;
private String countryName;
private String provinceName;
private String cityId;
private String cityName;
private String streetAddress;
private String zipCode;
public void setCountryId(String countryId) {
this.countryId = countryId;
}
public void setCountryName(String countryName) {
this.countryName = countryName;
}
public void setProvinceName(String provinceName) {
this.provinceName = provinceName;
}
public void setCityId(String cityId) {
this.cityId = cityId;
}
public void setCityName(String cityName) {
this.cityName = cityName;
}
public void setStreetAddress(String streetAddress) {
this.streetAddress = streetAddress;
}
public void setZipCode(String zipCode) {
this.zipCode = zipCode;
}
public String getCountryId() {
return countryId;
}
public String getCountryName() {
return countryName;
}
public String getProvinceName() {
return provinceName;
}
public String getCityId() {
return cityId;
}
public String getCityName() {
return cityName;
}
public String getStreetAddress() {
return streetAddress;
}
public String getZipCode() {
return zipCode;
}
public FullAddress() {
}
public FullAddress(String countryId, String provinceName, String cityId, String streetAddress,
String zipCode) {
this.countryId = countryId;
this.countryName = countryId;
this.provinceName = provinceName;
this.cityId = cityId;
this.cityName = cityId;
this.streetAddress = streetAddress;
this.zipCode = zipCode;
}
public FullAddress(String countryId, String countryName, String provinceName, String cityId,
String cityName, String streetAddress, String zipCode) {
this.countryId = countryId;
this.countryName = countryName;
this.provinceName = provinceName;
this.cityId = cityId;
this.cityName = cityName;
this.streetAddress = streetAddress;
this.zipCode = zipCode;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((cityId == null) ? 0 : cityId.hashCode());
result = prime * result + ((cityName == null) ? 0 : cityName.hashCode());
result = prime * result + ((countryId == null) ? 0 : countryId.hashCode());
result = prime * result + ((countryName == null) ? 0 : countryName.hashCode());
result = prime * result + ((provinceName == null) ? 0 : provinceName.hashCode());
result = prime * result + ((streetAddress == null) ? 0 : streetAddress.hashCode());
result = prime * result + ((zipCode == null) ? 0 : zipCode.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
FullAddress other = (FullAddress) obj;
if (cityId == null) {
if (other.cityId != null)
return false;
} else if (!cityId.equals(other.cityId))
return false;
if (cityName == null) {
if (other.cityName != null)
return false;
} else if (!cityName.equals(other.cityName))
return false;
if (countryId == null) {
if (other.countryId != null)
return false;
} else if (!countryId.equals(other.countryId))
return false;
if (countryName == null) {
if (other.countryName != null)
return false;
} else if (!countryName.equals(other.countryName))
return false;
if (provinceName == null) {
if (other.provinceName != null)
return false;
} else if (!provinceName.equals(other.provinceName))
return false;
if (streetAddress == null) {
if (other.streetAddress != null)
return false;
} else if (!streetAddress.equals(other.streetAddress))
return false;
if (zipCode == null) {
if (other.zipCode != null)
return false;
} else if (!zipCode.equals(other.zipCode))
return false;
return true;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (countryName != null && countryName.length() > 0) {
sb.append(countryName);
}
if (provinceName != null && provinceName.length() > 0) {
sb.append(" ");
sb.append(provinceName);
}
if (cityName != null && cityName.length() > 0) {
sb.append(" ");
sb.append(cityName);
}
if (streetAddress != null && streetAddress.length() > 0) {
sb.append(" ");
sb.append(streetAddress);
}
return sb.toString();
}
}

View File

@ -1,27 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.api;
/**
* @author liuchao
*
*/
public interface IDemoCallback{
String onChanged(String msg);
}

View File

@ -1,138 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.api;
import java.io.Serializable;
import java.util.HashMap;
/**
* IndexQueryParameter
*
* @author william.liangf
*/
public class IndexQueryParameter implements Serializable {
private static final long serialVersionUID = 5035064961368369616L;
/**
* 开始的查询页码
*/
private int pageNo = 1;
/**
* 本次操作的最大返回记录数
*/
private int pageSize = 24;
/**
* 用户查询参数
*/
private HashMap<String, Object> parameters;
public static IndexQueryParameter create() {
return new IndexQueryParameter();
}
public IndexQueryParameter() {
this(new HashMap<String, Object>());
}
public IndexQueryParameter(HashMap<String, Object> parameters) {
this.parameters = parameters;
}
public int getPageNo() {
return pageNo;
}
public IndexQueryParameter setPageNo(int pageNo) {
this.pageNo = pageNo;
if (this.pageNo < 1) {
this.pageNo = 1;
}
return this;
}
public int getPageSize() {
return pageSize;
}
public IndexQueryParameter setPageSize(int pageSize) {
this.pageSize = pageSize;
if (this.pageSize < 0) {
this.pageSize = 0;
}
return this;
}
public HashMap<String, Object> getParameters() {
return parameters;
}
public void setParameters(HashMap<String, Object> parameters) {
this.parameters = parameters;
}
public IndexQueryParameter setParameter(String name, String value) {
this.parameters.put(name, value);
return this;
}
public int getRecordCount() {
return this.pageNo * this.pageSize;
}
}

View File

@ -1,22 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.api;
public interface MapService<T> {
T sayMap(T map);
}

View File

@ -1,151 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.api;
import java.io.Serializable;
/**
*
* @author tony.chenl
*/
public class Person implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
String personId;
String loginName;
PersonStatus status;
String email;
String penName;
PersonInfo infoProfile;
public Person() {
}
public Person(String id) {
this.personId = id;
}
public String getPersonId() {
return personId;
}
public void setPersonId(String personId) {
this.personId = personId;
}
public PersonInfo getInfoProfile() {
return infoProfile;
}
public void setInfoProfile(PersonInfo infoProfile) {
this.infoProfile = infoProfile;
}
public void setLoginName(String loginName) {
this.loginName = loginName;
}
public void setStatus(PersonStatus status) {
this.status = status;
}
public void setEmail(String email) {
this.email = email;
}
public void setPenName(String penName) {
this.penName = penName;
}
public String getEmail() {
return this.email;
}
public String getLoginName() {
return this.loginName;
}
public PersonStatus getStatus() {
return this.status;
}
public String getPenName() {
return penName;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((email == null) ? 0 : email.hashCode());
result = prime * result + ((infoProfile == null) ? 0 : infoProfile.hashCode());
result = prime * result + ((loginName == null) ? 0 : loginName.hashCode());
result = prime * result + ((penName == null) ? 0 : penName.hashCode());
result = prime * result + ((personId == null) ? 0 : personId.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Person other = (Person) obj;
if (email == null) {
if (other.email != null)
return false;
} else if (!email.equals(other.email))
return false;
if (infoProfile == null) {
if (other.infoProfile != null)
return false;
} else if (!infoProfile.equals(other.infoProfile))
return false;
if (loginName == null) {
if (other.loginName != null)
return false;
} else if (!loginName.equals(other.loginName))
return false;
if (penName == null) {
if (other.penName != null)
return false;
} else if (!penName.equals(other.penName))
return false;
if (personId == null) {
if (other.personId != null)
return false;
} else if (!personId.equals(other.personId))
return false;
if (status != other.status)
return false;
return true;
}
}

View File

@ -1,201 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.api;
import java.io.Serializable;
import java.util.List;
/**
*
* @author tony.chenl
*/
public class PersonInfo implements Serializable {
private static final long serialVersionUID = 7443011149612231882L;
List<Phone> phones;
Phone fax;
FullAddress fullAddress;
String mobileNo;
String name;
boolean male;
boolean female;
String department;
String jobTitle;
String homepageUrl;
public List<Phone> getPhones() {
return phones;
}
public void setPhones(List<Phone> phones) {
this.phones = phones;
}
public boolean isMale() {
return male;
}
public void setMale(boolean male) {
this.male = male;
}
public boolean isFemale() {
return female;
}
public void setFemale(boolean female) {
this.female = female;
}
public void setFax(Phone fax) {
this.fax = fax;
}
public void setFullAddress(FullAddress fullAddress) {
this.fullAddress = fullAddress;
}
public void setMobileNo(String mobileNo) {
this.mobileNo = mobileNo;
}
public void setName(String name) {
this.name = name;
}
public void setDepartment(String department) {
this.department = department;
}
public void setJobTitle(String jobTitle) {
this.jobTitle = jobTitle;
}
public void setHomepageUrl(String homepageUrl) {
this.homepageUrl = homepageUrl;
}
public String getDepartment() {
return department;
}
public Phone getFax() {
return fax;
}
public FullAddress getFullAddress() {
return fullAddress;
}
public String getHomepageUrl() {
return homepageUrl;
}
public String getJobTitle() {
return jobTitle;
}
public String getMobileNo() {
return mobileNo;
}
public String getName() {
return name;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((department == null) ? 0 : department.hashCode());
result = prime * result + ((fax == null) ? 0 : fax.hashCode());
result = prime * result + (female ? 1231 : 1237);
result = prime * result + ((fullAddress == null) ? 0 : fullAddress.hashCode());
result = prime * result + ((homepageUrl == null) ? 0 : homepageUrl.hashCode());
result = prime * result + ((jobTitle == null) ? 0 : jobTitle.hashCode());
result = prime * result + (male ? 1231 : 1237);
result = prime * result + ((mobileNo == null) ? 0 : mobileNo.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((phones == null) ? 0 : phones.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PersonInfo other = (PersonInfo) obj;
if (department == null) {
if (other.department != null)
return false;
} else if (!department.equals(other.department))
return false;
if (fax == null) {
if (other.fax != null)
return false;
} else if (!fax.equals(other.fax))
return false;
if (female != other.female)
return false;
if (fullAddress == null) {
if (other.fullAddress != null)
return false;
} else if (!fullAddress.equals(other.fullAddress))
return false;
if (homepageUrl == null) {
if (other.homepageUrl != null)
return false;
} else if (!homepageUrl.equals(other.homepageUrl))
return false;
if (jobTitle == null) {
if (other.jobTitle != null)
return false;
} else if (!jobTitle.equals(other.jobTitle))
return false;
if (male != other.male)
return false;
if (mobileNo == null) {
if (other.mobileNo != null)
return false;
} else if (!mobileNo.equals(other.mobileNo))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (phones == null) {
if (other.phones != null)
return false;
} else if (!phones.equals(other.phones))
return false;
return true;
}
}

View File

@ -1,25 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.api;
/**
*
* @author tony.chenl
*/
public enum PersonStatus {
ENABLED,
DISABLED
}

View File

@ -1,143 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.api;
import java.io.Serializable;
/**
* 电话号码
*
* @author xk1430
*/
public class Phone implements Serializable {
private static final long serialVersionUID = 4399060521859707703L;
private String country;
private String area;
private String number;
private String extensionNumber;
public Phone() {
}
public Phone(String country, String area, String number, String extensionNumber) {
this.country = country;
this.area = area;
this.number = number;
this.extensionNumber = extensionNumber;
}
public void setCountry(String country) {
this.country = country;
}
public void setArea(String area) {
this.area = area;
}
public void setNumber(String number) {
this.number = number;
}
public void setExtensionNumber(String extensionNumber) {
this.extensionNumber = extensionNumber;
}
public String getCountry() {
return country;
}
public String getArea() {
return area;
}
public String getNumber() {
return number;
}
public String getExtensionNumber() {
return extensionNumber;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((area == null) ? 0 : area.hashCode());
result = prime * result + ((country == null) ? 0 : country.hashCode());
result = prime * result + ((extensionNumber == null) ? 0 : extensionNumber.hashCode());
result = prime * result + ((number == null) ? 0 : number.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Phone other = (Phone) obj;
if (area == null) {
if (other.area != null)
return false;
} else if (!area.equals(other.area))
return false;
if (country == null) {
if (other.country != null)
return false;
} else if (!country.equals(other.country))
return false;
if (extensionNumber == null) {
if (other.extensionNumber != null)
return false;
} else if (!extensionNumber.equals(other.extensionNumber))
return false;
if (number == null) {
if (other.number != null)
return false;
} else if (!number.equals(other.number))
return false;
return true;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
if (country != null && country.length() > 0) {
sb.append(country);
sb.append("-");
}
if (area != null && area.length() > 0) {
sb.append(area);
sb.append("-");
}
if (number != null && number.length() > 0) {
sb.append(number);
}
if (extensionNumber != null && extensionNumber.length() > 0) {
sb.append("-");
sb.append(extensionNumber);
}
return sb.toString();
}
}

View File

@ -1,99 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.api;
import java.io.Serializable;
import java.util.Arrays;
/**
* User
*
* @author william.liangf
*/
public class User implements Serializable {
private static final long serialVersionUID = 5840134024756337246L;
private String name;
private int age;
private String[] phones;
private Address address;
private Role role;
public User() {
}
public User(String name, int age, String[] phones, Address address, Role role) {
super();
this.name = name;
this.age = age;
this.phones = phones;
this.address = address;
this.role = role;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String[] getPhones() {
return phones;
}
public void setPhones(String[] phones) {
this.phones = phones;
}
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
public Role getRole() {
return role;
}
public void setRole(Role role) {
this.role = role;
}
@Override
public String toString() {
return "User [address=" + address + ", age=" + age + ", name=" + name + ", phones="
+ Arrays.toString(phones) + "]" + ", role="
+ role + "]";
}
}

View File

@ -1,80 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.api;
import java.io.Serializable;
/**
* Hello
*
* @author william.liangf
*/
public class Welcome implements IWelcome, Serializable {
private static final long serialVersionUID = 1L;
private String salutatory;
private User user;
private User user2;
public Welcome() {
}
public Welcome(String salutatory, User user) {
super();
this.salutatory = salutatory;
this.user = user;
}
public Welcome(String salutatory, User user, User user2) {
super();
this.salutatory = salutatory;
this.user = user;
this.user2 = user2;
}
public String getSalutatory() {
return salutatory;
}
public void setSalutatory(String salutatory) {
this.salutatory = salutatory;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public User getUser2() {
return user2;
}
public void setUser2(User user2) {
this.user2 = user2;
}
@Override
public String toString() {
return "Welcome [salutatory=" + salutatory + ", user=" + user + ", user2=" + user2 + "]";
}
}

View File

@ -1,75 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.consumer;
import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.demo.api.Address;
import com.alibaba.dubbo.demo.api.DemoService;
import com.alibaba.dubbo.demo.api.Role;
import com.alibaba.dubbo.demo.api.User;
import com.alibaba.dubbo.demo.api.Welcome;
import com.alibaba.dubbo.rpc.RpcContext;
/**
* CodeProvider
*
* @author william.liangf
*/
public class CodeConsumer {
@SuppressWarnings("deprecation")
public static void main(String[] args) throws Exception {
ApplicationConfig application = new ApplicationConfig();
application.setName("code-consumer");
RegistryConfig registry = new RegistryConfig();
registry.setAddress("10.20.153.28:9090");
registry.setUsername("admin");
registry.setPassword("hello1234");
ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
reference.setApplication(application);
reference.setRegistry(registry);
reference.setInterfaceClass(DemoService.class);
reference.setVersion("1.0.0");
DemoService demoService = reference.get();
User user = new User("liangfei", 25, new String[]{"13012345678", "1308654321"}, new Address("hangzhou", "wangshang", "310052"), Role.MEMBER);
for (int i = 0; i < 1; i ++) {
try {
RpcContext.getContext().setAttachment("i", String.valueOf(i));
Welcome result = demoService.sayHello(user);
System.out.println("-------- (" + i + ") " + result);
} catch (Exception e) {
e.printStackTrace();
}
}
reference.destroy();
synchronized (CodeConsumer.class) {
while (true) {
try {
CodeConsumer.class.wait();
} catch (InterruptedException e) {
}
}
}
}
}

View File

@ -1,57 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.consumer;
import java.util.ArrayList;
import java.util.List;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.alibaba.dubbo.demo.api.Address;
import com.alibaba.dubbo.demo.api.DemoService;
import com.alibaba.dubbo.demo.api.Role;
import com.alibaba.dubbo.demo.api.User;
import com.alibaba.dubbo.demo.api.Welcome;
/**
* SimpleConsumer
*
* @author william.liangf
*/
public class ComplexConsumer {
public static void main(String[] args) throws Throwable {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:complex_consumer.xml");
context.start();
DemoService demoService = (DemoService)context.getBean("demoService");
User user = new User("liangfei", 25, new String[]{"13012345678", "1308654321"}, new Address("hangzhou", "wangshang", "310052"), Role.MEMBER);
List<User> users = new ArrayList<User>();
users.add(user);
for (int i = 0; i < Integer.MAX_VALUE; i ++) {
Thread.sleep(2000);
try {
long start = System.currentTimeMillis();
Welcome result = demoService.sayHello(user);
List<User> us = demoService.sayList(users);
User u = us.get(0);
System.out.println("--------elapsed: " + (System.currentTimeMillis() - start) + "ms, result: " + result + ", list: " + u);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

View File

@ -1,30 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.consumer;
import com.alibaba.dubbo.demo.api.IDemoCallback;
/**
* @author chao.liuc
*
*/
public class DemoCallBackImpl implements IDemoCallback{
public String onChanged(String msg) {
System.out.println("Recived callback: " + msg);
return "onChanged";
}
}

View File

@ -1,51 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.consumer;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.alibaba.dubbo.demo.api.Address;
import com.alibaba.dubbo.demo.api.DemoService;
import com.alibaba.dubbo.demo.api.Role;
import com.alibaba.dubbo.demo.api.User;
import com.alibaba.dubbo.demo.api.Welcome;
import com.alibaba.dubbo.rpc.RpcContext;
/**
* DirectConsumer
*
* @author william.liangf
*/
public class DirectConsumer {
public static void main(String[] args) throws Throwable {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:direct_consumer.xml");
context.start();
DemoService demoService = (DemoService)context.getBean("demoService");
User user = new User("liangfei", 25, new String[]{"13012345678", "1308654321"}, new Address("hangzhou", "wangshang", "310052"), Role.MEMBER);
for (int i = 0; i < Integer.MAX_VALUE; i ++) {
Thread.sleep(2000);
try {
RpcContext.getContext().setAttachment("i", String.valueOf(i));
Welcome result = demoService.sayHello(user);
System.out.println("-------- (" + i + ") " + result);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

View File

@ -1,54 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.consumer;
import java.util.HashMap;
import java.util.Map;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.alibaba.dubbo.rpc.service.GenericService;
public class GenericConsumer {
public static void main(String[] args) throws Throwable {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:generic_consumer.xml");
context.start();
GenericService service = (GenericService)context.getBean("demoService");
Map<Object, Object> address = new HashMap<Object, Object>();
address.put("class", "com.alibaba.dubbo.demo.api.Address");
address.put("city", "hangzhou");
address.put("street", "wangshang");
address.put("code", "310052");
Map<Object, Object> user = new HashMap<Object, Object>();
user.put("class", "com.alibaba.dubbo.demo.api.User");
user.put("name", "liangfei");
user.put("age", 25);
user.put("role", "MEMBER");
user.put("address", address);
user.put("phones", new String[]{"13012345678", "1308654321"});
for (int i = 0; i < Integer.MAX_VALUE; i ++) {
Thread.sleep(2000);
try {
Object result = service.$invoke("sayHello", new String[]{"com.alibaba.dubbo.demo.api.User"}, new Object[]{user});
System.out.println("-------- (" + i + ") " + result);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

View File

@ -1,51 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.consumer;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.alibaba.dubbo.demo.api.Address;
import com.alibaba.dubbo.demo.api.DemoService;
import com.alibaba.dubbo.demo.api.Role;
import com.alibaba.dubbo.demo.api.User;
import com.alibaba.dubbo.demo.api.Welcome;
import com.alibaba.dubbo.rpc.RpcContext;
/**
* SimpleConsumer
*
* @author william.liangf
*/
public class InjvmConsumer {
public static void main(String[] args) throws Throwable {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:injvm_consumer.xml");
context.start();
DemoService demoService = (DemoService)context.getBean("demoService");
User user = new User("liangfei", 25, new String[]{"13012345678", "1308654321"}, new Address("hangzhou", "wangshang", "310052"), Role.MEMBER);
for (int i = 0; i < Integer.MAX_VALUE; i ++) {
Thread.sleep(2000);
try {
RpcContext.getContext().setAttachment("i", String.valueOf(i));
Welcome result = demoService.sayHello(user);
System.out.println("-------- (" + i + ") " + result);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

View File

@ -1,72 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.consumer;
import java.util.concurrent.atomic.AtomicInteger;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.alibaba.dubbo.demo.api.Address;
import com.alibaba.dubbo.demo.api.DemoService;
import com.alibaba.dubbo.demo.api.Role;
import com.alibaba.dubbo.demo.api.User;
import com.alibaba.dubbo.demo.api.Welcome;
import com.alibaba.dubbo.rpc.RpcContext;
/**
* SimpleConsumer
*
* @author william.liangf
*/
public class PerformanceConsumer {
public static void main(String[] args) throws Throwable {
final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:performance_consumer.xml");
context.start();
final DemoService demoService = (DemoService)context.getBean("demoService");
final User user = new User("liangfei", 25, new String[]{"13012345678", "1308654321"}, new Address("hangzhou", "wangshang", "310052"), Role.MEMBER);
final AtomicInteger count = new AtomicInteger();
final AtomicInteger error = new AtomicInteger();
for (int n = 0; n < 11; n ++) {
new Thread(new Runnable() {
public void run() {
for (int i = 0; i < Integer.MAX_VALUE; i ++) {
try {
int c = count.incrementAndGet();
if (c % 100 == 0) {
System.out.println("count: " + count.get() + ", error: " + error.get());
}
RpcContext.getContext().setAttachment("i", String.valueOf(i));
Welcome result = demoService.sayHello(user);
// System.out.println(result);
User user = result.getUser();
if (! "liangfei".equals(user.getName())) {
throw new IllegalStateException("Invalid result " + user.getName());
}
} catch (Exception e) {
error.incrementAndGet();
//if (e.getMessage().contains("ExecutionException")) {
e.printStackTrace();
//}
System.out.println("count: " + count.get() + ", error: " + error.get());
}
}
}
}).start();
}
}
}

View File

@ -1,54 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.consumer;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.alibaba.dubbo.demo.api.Address;
import com.alibaba.dubbo.demo.api.DemoService;
import com.alibaba.dubbo.demo.api.Role;
import com.alibaba.dubbo.demo.api.User;
import com.alibaba.dubbo.demo.api.Welcome;
import com.alibaba.dubbo.rpc.RpcContext;
/**
* SimpleConsumer
*
* @author william.liangf
*/
public class SimpleConsumer {
public static void main(String[] args) throws Throwable {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:simple_consumer.xml");
context.start();
DemoService demoService = (DemoService)context.getBean("demoService");
User user = new User("liang\nfei", 25, new String[]{"13012345678", "1308654321"}, new Address("hangzhou", "wangshang", "310052"), Role.MEMBER);
for (int i = 0; i < Integer.MAX_VALUE; i ++) {
try {
RpcContext.getContext().setAttachment("i", String.valueOf(i));
Welcome result = demoService.sayHello(user);
System.out.println("-------- (" + i + ") " + result);
} catch (Exception e) {
e.printStackTrace();
}
Thread.sleep(3000);
}
synchronized (SimpleConsumer.class) {
SimpleConsumer.class.wait();
}
}
}

View File

@ -1,33 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.monitor;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* SimpleMonitor
*
* @author william.liangf
*/
public class SimpleMonitor {
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:simple_monitor.xml");
context.start();
System.in.read(); // 输入任意键退出
}
}

View File

@ -1,60 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.provider;
import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;
import com.alibaba.dubbo.demo.api.DemoService;
import com.alibaba.dubbo.demo.provider.impl.DemoServiceImpl;
/**
* CodeProvider
*
* @author william.liangf
*/
public class CodeProvider {
@SuppressWarnings("deprecation")
public static void main(String[] args) throws Exception {
DemoService demoService = new DemoServiceImpl();
ApplicationConfig application = new ApplicationConfig();
application.setName("code-provider");
RegistryConfig registry = new RegistryConfig();
registry.setAddress("10.20.153.28:9090");
registry.setUsername("admin");
registry.setPassword("hello1234");
ProtocolConfig protocol = new ProtocolConfig();
protocol.setName("dubbo");
protocol.setPort(20883);
ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
service.setApplication(application);
service.setRegistry(registry);
service.setProtocol(protocol);
service.setInterfaceClass(DemoService.class);
service.setVersion("1.0.0");
service.setRef(demoService);
service.export();
System.in.read(); // 输入任意键退出
}
}

View File

@ -1,33 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.provider;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* ComplexProvider
*
* @author william.liangf
*/
public class ComplexProvider {
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:complex_provider.xml");
context.start();
System.in.read(); // 输入任意键退出
}
}

View File

@ -1,33 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.provider;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* SimpleProvider
*
* @author william.liangf
*/
public class DirectProvider {
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:direct_provider.xml");
context.start();
System.in.read(); // 输入任意键退出
}
}

View File

@ -1,33 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.provider;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* GenericProvider
*
* @author william.liangf
*/
public class GenericProvider {
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:generic_provider.xml");
context.start();
System.in.read(); // 输入任意键退出
}
}

View File

@ -1,33 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.provider;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* SimpleProvider
*
* @author william.liangf
*/
public class SimpleProvider {
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:simple_provider.xml");
context.start();
System.in.read(); // 输入任意键退出
}
}

View File

@ -1,43 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.provider.impl;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.dubbo.rpc.RpcContext;
import com.alibaba.dubbo.rpc.service.GenericException;
import com.alibaba.dubbo.rpc.service.GenericService;
/**
* DemoServiceGenericeImpl
*
* @author william.liangf
*/
public class DemoServiceGenericImpl implements GenericService {
public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException {
if ("sayHello".equals(method)) {
System.out.println(">>>>>>DemoServiceGenericImpl: " + args[0]);
Map<String, Object> map = new HashMap<String, Object>();
map.put("salutatory", "generic provider: " + RpcContext.getContext().getLocalAddress());
map.put("user", args[0]);
return map;
}
return null;
}
}

View File

@ -1,192 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.provider.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import com.alibaba.dubbo.demo.api.DemoService;
import com.alibaba.dubbo.demo.api.IDemoCallback;
import com.alibaba.dubbo.demo.api.IndexQueryParameter;
import com.alibaba.dubbo.demo.api.Person;
import com.alibaba.dubbo.demo.api.Role;
import com.alibaba.dubbo.demo.api.User;
import com.alibaba.dubbo.demo.api.Welcome;
import com.alibaba.dubbo.performance.PerformanceUtils;
import com.alibaba.dubbo.rpc.RpcContext;
/**
* DemoServiceImpl
*
* @author william.liangf
*/
public class DemoServiceImpl implements DemoService {
public Welcome sayHello(User user) {
// throw new RuntimeException();
System.out.println("(" + RpcContext.getContext().getAttachment("i")
+ ") >>>>>>DemoServiceImpl: " + user);
return new Welcome("provider: " + RpcContext.getContext().getLocalAddress(), user);
}
public void say() {
System.out.println(">>>>>>>>>>>>>>>>>>>say()");
}
public String sayOK() {
return "OK";
}
public String sayName(String name) {
return "say:" + name;
}
public Welcome sayTwoHello(User user, User user2) {
return new Welcome("Hello", user, user2);
}
public String sayTwoName(String name1, String name2) {
return name1 + " and " + name2;
}
public String sayQuery(IndexQueryParameter param) {
return param.getParameters().toString();
}
public Role sayRole(Role role) {
return role;
}
public Role[] sayRoles(Role[] roles) {
return roles;
}
public Map<Object, Object> sayMap(Map<Object, Object> map) {
map.put("xx", "yy");
return map;
}
public void throwException() {
throw new RuntimeException("OK");
}
public LinkedHashMap<Object, Object> sayLinkedHashMap(LinkedHashMap<Object, Object> map) {
return map;
}
public HashMap<Object, Object> sayHashMap(HashMap<Object, Object> map) {
return map;
}
public long sayLong(long id) {
return id;
}
public short sayShort(short id) {
return id;
}
public List<User> sayList(List<User> roles) {
return roles;
}
public HashSet<String> sayTwoParam(String name1, HashSet<String> name2) {
name2.add(name1);
return name2;
}
public float sayFloat(float id) {
return id;
}
public List<String> getEnvironment() {
return PerformanceUtils.getEnvironment();
}
public List<String> getScene() {
return PerformanceUtils.getScene();
}
public List<Person> listPerson(Person person) {
List<Person> list = new ArrayList<Person>();
for (int i = 0; i < 10; i++) {
list.add(person);
}
return list;
}
public Person showPerson(Person person) {
return person;
}
private volatile Thread t;
private Vector<IDemoCallback> callbacks = new Vector<IDemoCallback>();
public void subscribe(final IDemoCallback callback, final String arg1) {
System.out.println("+++subscribe callback id is:" + System.identityHashCode(callback) +arg1);
// callback.onChanged("This is callback data.");
synchronized (callbacks) {
if(!callbacks.contains(callback))
callbacks.add(callback);
}
if (t == null) {
t = new Thread(new Runnable() {
public void run() {
for (int i = 0; i < 1000; i++) {
Vector<IDemoCallback> callbacks2 = new Vector<IDemoCallback>(callbacks);
Iterator<IDemoCallback> iter = callbacks2.iterator();
while(iter != null && iter.hasNext()){
//有并发修改问题.
IDemoCallback callback = iter.next();
long time = System.currentTimeMillis();
System.out.print(" server request id: "+time);
String ret = callback.onChanged("server request id:"+ time);
System.out.println(",client callback :" + ret);
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
}
});
t.start();
}
System.out.println("+++server side subscribe ok");
}
public void unsubscribe(final IDemoCallback callback) {
synchronized (callbacks) {
int size = callbacks.size();
callbacks.remove(callback);
System.out.println("---unsubscribe callback id is:" + System.identityHashCode(callback)+",callback list size("+size+"->"+callbacks.size()+")");
}
}
public String sayParams(String name, String parentId, Role[] roles) {
return "Name:" + name + ", ParentId: " + parentId + ", Roles: " + Arrays.toString(roles);
}
}

View File

@ -1,162 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.provider.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.dubbo.demo.api.DemoService;
import com.alibaba.dubbo.demo.api.IDemoCallback;
import com.alibaba.dubbo.demo.api.IndexQueryParameter;
import com.alibaba.dubbo.demo.api.Person;
import com.alibaba.dubbo.demo.api.Role;
import com.alibaba.dubbo.demo.api.User;
import com.alibaba.dubbo.demo.api.Welcome;
import com.alibaba.dubbo.performance.PerformanceUtils;
import com.alibaba.dubbo.rpc.RpcContext;
/**
* DemoServiceImpl
*
* @author william.liangf
*/
public class DemoServiceImpl2 implements DemoService {
public Welcome sayHello(User user) {
System.out.println(">>>>>>DemoServiceImpl2: " + user);
return new Welcome("provider2: " + RpcContext.getContext().getLocalAddress(), user);
}
public void say() {
System.out.println(">>>>>>>>>>>>>>>>>>>say()");
}
public String sayOK() {
return "OK";
}
public String sayName(String name) {
return "say:" + name;
}
public Welcome sayTwoHello(User user, User user2) {
return new Welcome("Hello", user, user2);
}
public String sayTwoName(String name1, String name2) {
return name1 + " and " + name2;
}
public String sayQuery(IndexQueryParameter param) {
return param.getParameters().toString();
}
public Role sayRole(Role role) {
return role;
}
public Role[] sayRoles(Role[] roles) {
return roles;
}
public Map<Object, Object> sayMap(Map<Object, Object> map) {
map.put("xx", "yy");
return map;
}
public void throwException() {
throw new RuntimeException("OK");
}
public LinkedHashMap<Object, Object> sayLinkedHashMap(
LinkedHashMap<Object, Object> map) {
return map;
}
public HashMap<Object, Object> sayHashMap(HashMap<Object, Object> map) {
return map;
}
public long sayLong(long id) {
return id;
}
public short sayShort(short id) {
return id;
}
public List<User> sayList(List<User> roles) {
return roles;
}
public HashSet<String> sayTwoParam(String name1, HashSet<String> name2) {
name2.add(name1);
return name2;
}
public float sayFloat(float id) {
return id;
}
public List<String> getEnvironment() {
return PerformanceUtils.getEnvironment();
}
public List<String> getScene() {
return PerformanceUtils.getScene();
}
public List<Person> listPerson(Person person) {
List<Person> list = new ArrayList<Person>();
for (int i = 0; i < 10; i ++) {
list.add(person);
}
return list;
}
public Person showPerson(Person person) {
return person;
}
public void subscribe(IDemoCallback callback,String arg1) {
}
public void unsubscribe(IDemoCallback callback) {
}
public String sayParams(String name, String parentId, Role[] roles) {
return "Name:" + name + ", ParentId: " + parentId + ", Roles: " + Arrays.toString(roles);
}
}

View File

@ -1,61 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.registry;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.registry.NotifyListener;
import com.alibaba.dubbo.registry.RegistryService;
public class RegistryServiceLocal implements RegistryService {
RegistryService registryService;
ConcurrentMap<URL, NotifyListener> listeners = new ConcurrentHashMap<URL, NotifyListener>();
public RegistryServiceLocal(RegistryService registryService) {
this.registryService = registryService;
}
public void register(URL url) {
registryService.register(url);
}
public void unregister(URL url) {
registryService.unregister(url);
}
public void subscribe(URL url, NotifyListener listener) {
registryService.subscribe(url, listener);
listeners.put(url, listener);
}
public void unsubscribe(URL url, NotifyListener listener) {
registryService.unsubscribe(url, listener);
}
public List<URL> lookup(URL url) {
return registryService.lookup(url);
}
public void ondisconnect(){
for(URL url : listeners.keySet()){
registryService.subscribe(url, listeners.get(url));
}
}
}

View File

@ -1,34 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.demo.registry;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* TODO Comment of SimpleRegistry
* @author william.liangf
*
*/
public class SimpleRegistry {
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:simple_registry.xml");
context.start();
System.in.read(); // 输入任意键退出
}
}

View File

@ -1,262 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.performance;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicLong;
import junit.framework.TestCase;
import org.junit.Test;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.demo.api.DemoService;
import com.alibaba.dubbo.demo.api.FullAddress;
import com.alibaba.dubbo.demo.api.Person;
import com.alibaba.dubbo.demo.api.PersonInfo;
import com.alibaba.dubbo.demo.api.PersonStatus;
import com.alibaba.dubbo.demo.api.Phone;
import com.alibaba.dubbo.remoting.Channel;
import com.alibaba.dubbo.remoting.RemotingException;
import com.alibaba.dubbo.remoting.exchange.support.ExchangeHandlerAdapter;
/**
* PerformanceClientTest
*
* mvn clean test -Dtest=*PerformanceConsumerTest -Dserver=10.20.153.187:9911
*
* @author william.liangf
*/
public class PerformanceConsumerTest extends TestCase {
private static final Logger logger = LoggerFactory.getLogger(PerformanceConsumerTest.class);
@SuppressWarnings("deprecation")
@Test
public void testClient() throws Throwable {
// 读取参数
if (PerformanceUtils.getProperty("server", null) == null) {
logger.warn("Please set -Dserver=127.0.0.1:9911");
return;
}
final String server = System.getProperty("server", "127.0.0.1:9911");
final String transporter = PerformanceUtils.getProperty(Constants.TRANSPORTER_KEY, Constants.DEFAULT_TRANSPORTER);
final int timeout = PerformanceUtils.getIntProperty(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
final int length = PerformanceUtils.getIntProperty("length", 1024);
final int connections = PerformanceUtils.getIntProperty(Constants.CONNECTIONS_KEY, 1);
final int concurrent = PerformanceUtils.getIntProperty("concurrent", 100);
int r = PerformanceUtils.getIntProperty("runs", 1000);
final int runs = r > 0 ? r : Integer.MAX_VALUE;
final String onerror = PerformanceUtils.getProperty("onerror", "continue");
ApplicationConfig application = new ApplicationConfig();
application.setName("code-consumer");
RegistryConfig registry = new RegistryConfig();
registry.setAddress(RegistryConfig.NO_AVAILABLE);
ReferenceConfig<DemoService> reference = new ReferenceConfig<DemoService>();
reference.setApplication(application);
reference.setRegistry(registry);
reference.setInterfaceClass(DemoService.class);
reference.setVersion("1.0.0");
reference.setConnections(connections);
reference.setTimeout(timeout);
reference.setClient(transporter);
reference.setUrl("dubbo://" + server + "/" + DemoService.class.getName());
final DemoService demoService = reference.get();
List<String> serverEnvironment = demoService.getEnvironment();
List<String> serverScene = demoService.getScene();
// 制造数据
StringBuilder buf = new StringBuilder(length);
for (int i = 0; i < length; i ++) {
buf.append("A");
}
final String data = buf.toString();
Person person = new Person();
person.setPersonId("superman111");
person.setLoginName("superman");
person.setEmail("sm@1.com");
person.setPenName("pname");
person.setStatus(PersonStatus.ENABLED);
ArrayList<Phone> phones = new ArrayList<Phone>();
Phone phone1 = new Phone("86", "0571", "87654321", "001");
Phone phone2 = new Phone("86", "0571", "87654322", "002");
phones.add(phone1);
phones.add(phone2);
PersonInfo pi = new PersonInfo();
pi.setPhones(phones);
Phone fax = new Phone("86", "0571", "87654321", null);
pi.setFax(fax);
FullAddress addr = new FullAddress("CN", "zj", "3480", "wensanlu", "315000");
pi.setFullAddress(addr);
pi.setMobileNo("13584652131");
pi.setMale(true);
pi.setDepartment("b2b");
pi.setHomepageUrl("www.capcom.com");
pi.setJobTitle("qa");
pi.setName("superman");
person.setInfoProfile(pi);
// 计数器
final AtomicLong count = new AtomicLong();
final AtomicLong error = new AtomicLong();
final AtomicLong time = new AtomicLong();
final AtomicLong all = new AtomicLong();
// 并发调用
final CountDownLatch latch = new CountDownLatch(concurrent);
for (int i = 0; i < concurrent; i ++) {
new Thread(new Runnable() {
public void run() {
try {
long init = System.currentTimeMillis();
for (int i = 0; i < runs; i++) {
try {
count.incrementAndGet();
long start = System.currentTimeMillis();
String result = demoService.sayName(data);
long end = System.currentTimeMillis();
if (! result.endsWith(data)) {
throw new IllegalStateException("Invalid result " + result);
}
time.addAndGet(end - start);
} catch (Exception e) {
error.incrementAndGet();
e.printStackTrace();
if ("exit".equals(onerror)) {
System.exit(-1);
} else if ("break".equals(onerror)) {
break;
} else if ("sleep".equals(onerror)) {
try {
Thread.sleep(30000);
} catch (InterruptedException e1) {
}
}
}
}
all.addAndGet(System.currentTimeMillis() - init);
} finally {
latch.countDown();
}
}
}).start();
}
// 输出tps不精确但大概反映情况
new Thread(new Runnable() {
public void run() {
try{
SimpleDateFormat dateFormat = new SimpleDateFormat ("HH:mm:ss");
long lastCount = count.get();
long sleepTime = 2000;
long elapsd = sleepTime/1000;
boolean bfirst = true;
while (latch.getCount() > 0) {
long c = count.get()-lastCount ;
if(! bfirst)//第一次不准
System.out.println("["+dateFormat.format(new Date()) +"] count: " + count.get() + ", error: " + error.get() + ",tps:"+(c/elapsd));
bfirst = false;
lastCount = count.get();
Thread.sleep(sleepTime);
}
} catch(Exception e) {
e.printStackTrace();
}
}
}).start();
latch.await();
long total = count.get();
long failed = error.get();
long succeeded = total - failed;
long elapsed = time.get();
long allElapsed = all.get();
long clientElapsed = allElapsed - elapsed;
long art = 0;
long qps = 0;
long throughput = 0;
if (elapsed > 0) {
art = elapsed / succeeded;
qps = concurrent * succeeded * 1000 / elapsed;
throughput = concurrent * succeeded * length * 2 * 1000 / elapsed;
}
PerformanceUtils.printBorder();
PerformanceUtils.printHeader("Dubbo Remoting Performance Test Report");
PerformanceUtils.printBorder();
PerformanceUtils.printHeader("Test Environment");
PerformanceUtils.printSeparator();
for (String item: serverEnvironment) {
PerformanceUtils.printBody("Server " + item);
}
PerformanceUtils.printSeparator();
List<String> clientEnvironment = PerformanceUtils.getEnvironment();
for (String item: clientEnvironment) {
PerformanceUtils.printBody("Client " + item);
}
PerformanceUtils.printSeparator();
PerformanceUtils.printHeader("Test Scene");
PerformanceUtils.printSeparator();
for (String item: serverScene) {
PerformanceUtils.printBody("Server " + item);
}
PerformanceUtils.printBody("Client Transporter: " + transporter);
PerformanceUtils.printBody("Response Timeout: " + timeout + " ms");
PerformanceUtils.printBody("Data Length: " + length + " bytes");
PerformanceUtils.printBody("Client Shared Connections: " + connections);
PerformanceUtils.printBody("Client Concurrent Threads: " + concurrent);
PerformanceUtils.printBody("Run Times Per Thread: " + runs);
PerformanceUtils.printSeparator();
PerformanceUtils.printHeader("Test Result");
PerformanceUtils.printSeparator();
PerformanceUtils.printBody("Succeeded Requests: " + DecimalFormat.getIntegerInstance().format(succeeded));
PerformanceUtils.printBody("Failed Requests: " + failed);
PerformanceUtils.printBody("Client Elapsed Time: " + clientElapsed + " ms");
PerformanceUtils.printBody("Average Response Time: " + art + " ms");
PerformanceUtils.printBody("Requests Per Second: " + qps + "/s");
PerformanceUtils.printBody("Throughput Per Second: " + DecimalFormat.getIntegerInstance().format(throughput) + " bytes/s");
PerformanceUtils.printBorder();
}
static class PeformanceTestHandler extends ExchangeHandlerAdapter{
public void connected(Channel channel) throws RemotingException {
System.out.println("connected event,chanel;"+channel);
}
public void disconnected(Channel channel) throws RemotingException {
System.out.println("disconnected event,chanel;"+channel);
}
}
}

View File

@ -1,187 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.performance;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.junit.Test;
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.ExtensionLoader;
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;
import com.alibaba.dubbo.demo.api.DemoService;
import com.alibaba.dubbo.demo.provider.impl.DemoServiceImpl;
import com.alibaba.dubbo.remoting.Channel;
import com.alibaba.dubbo.remoting.RemotingException;
import com.alibaba.dubbo.remoting.exchange.ExchangeServer;
import com.alibaba.dubbo.remoting.exchange.Exchangers;
import com.alibaba.dubbo.remoting.exchange.support.ExchangeHandlerAdapter;
import com.alibaba.dubbo.rpc.Protocol;
/**
* PerformanceServer
*
* mvn clean test -Dtest=*PerformanceProviderTest -Dport=9911
*
* @author william.liangf
*/
public class PerformanceProviderTest extends TestCase {
private static final Logger logger = LoggerFactory.getLogger(PerformanceProviderTest.class);
private static ServiceConfig<DemoService> service = null;
@Test
public void testServer() throws Exception {
// 读取参数
if (PerformanceUtils.getProperty("port", null) == null) {
logger.warn("Please set -Dport=9911");
return;
}
final int port = PerformanceUtils.getIntProperty("port", 9911);
final boolean telnet = PerformanceUtils.getBooleanProperty("telnet", true);
if(telnet) {
statTelnetServer(port+1);
}
service = statServer();
synchronized (PerformanceProviderTest.class) {
while (true) {
try {
PerformanceProviderTest.class.wait();
} catch (InterruptedException e) {
}
}
}
}
private static void restartServer(int times, int wait, int sleep) throws Exception{
if (service != null) {
service.unexport();
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension("dubbo").destroy();
Thread.sleep(100);
}
for (int i = 0; i < times; i++) {
logger.info("restart times:" + i);
service = statServer();
if (wait > 0) {
Thread.sleep(wait);
}
service.unexport();
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension("dubbo").destroy();
if (sleep > 0) {
Thread.sleep(sleep);
}
}
service = statServer();
}
@SuppressWarnings("deprecation")
private static ServiceConfig<DemoService> statServer() throws Exception{
final int port = PerformanceUtils.getIntProperty("port", 9911);
final String transporter = PerformanceUtils.getProperty(Constants.TRANSPORTER_KEY, Constants.DEFAULT_TRANSPORTER);
final String serialization = PerformanceUtils.getProperty(Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION);
final String threadpool = PerformanceUtils.getProperty(Constants.THREADPOOL_KEY, Constants.DEFAULT_THREADPOOL);
final int threads = PerformanceUtils.getIntProperty(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
final int iothreads = PerformanceUtils.getIntProperty(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS);
final int buffer = PerformanceUtils.getIntProperty(Constants.BUFFER_KEY, Constants.DEFAULT_BUFFER_SIZE);
List<String> scene = new ArrayList<String>();
scene.add("Transporter: " + transporter);
scene.add("Service Threads: " + threads);
PerformanceUtils.setScene(scene);
DemoService demoService = new DemoServiceImpl();
ApplicationConfig application = new ApplicationConfig();
application.setName("performance-provider");
RegistryConfig registry = new RegistryConfig();
registry.setAddress(RegistryConfig.NO_AVAILABLE);
ProtocolConfig protocol = new ProtocolConfig();
protocol.setName("dubbo");
protocol.setPort(port);
protocol.setTransporter(transporter);
protocol.setSerialization(serialization);
protocol.setThreadpool(threadpool);
protocol.setThreads(threads);
protocol.setIothreads(iothreads);
protocol.setBuffer(buffer);
ServiceConfig<DemoService> service = new ServiceConfig<DemoService>();
service.setApplication(application);
service.setRegistry(registry);
service.setProtocol(protocol);
service.setInterfaceClass(DemoService.class);
service.setVersion("1.0.0");
service.setRef(demoService);
service.export();
return service;
}
private static ExchangeServer statTelnetServer(int port) throws Exception{
// 启动服务器
ExchangeServer telnetserver = Exchangers.bind("exchange://0.0.0.0:" + port , new ExchangeHandlerAdapter() {
public String telnet(Channel channel, String message) throws RemotingException {
if(message.equals("help")){
return "support cmd: \r\n\tstart \r\n\tstop \r\n\tshutdown \r\n\trestart times [alive] [sleep] \r\ntelnet>";
} else if(message.equals("stop")){
if (service != null) {
logger.info("server closed:" + service);
service.unexport();
ExtensionLoader.getExtensionLoader(Protocol.class).getExtension("dubbo").destroy();
}
return "stop server\r\ntelnet>";
} else if(message.startsWith("start")){
try {
restartServer(0, 0, 0);
} catch (Exception e) {
e.printStackTrace();
}
return "start server\r\ntelnet>";
} else if(message.startsWith("shutdown")){
System.exit(0);
return "start server\r\ntelnet>";
} else if(message.startsWith("restart ")){ //r times [sleep] r 10 or r 10 100
String[] args = message.split(" ");
int times = args.length > 1 ? Integer.parseInt(args[1]) : 1;
int alive = args.length > 2 ? Integer.parseInt(args[2]) : 0;
int sleep = args.length > 3 ? Integer.parseInt(args[3]) : 100;
try {
restartServer(times, alive, sleep);
} catch (Exception e) {
e.printStackTrace();
}
return "restart server,times:"+times+" stop wait time: "+alive+",sleep time: " + sleep+" usage:restart [times] [wait] [sleep] \r\ntelnet>";
} else{
return "echo: " + message + "\r\ntelnet> ";
}
}
});
return telnetserver;
}
}

View File

@ -1,136 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.performance;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
/**
* PerformanceUtils
*
* @author william.liangf
*/
public class PerformanceUtils {
public static String getProperty(String key, String defaultValue) {
String value = System.getProperty(key);
if (value == null || value.trim().length() == 0 || value.startsWith("$")) {
return defaultValue;
}
return value.trim();
}
public static int getIntProperty(String key, int defaultValue) {
String value = System.getProperty(key);
if (value == null || value.trim().length() == 0 || value.startsWith("$")) {
return defaultValue;
}
return Integer.parseInt(value.trim());
}
public static boolean getBooleanProperty(String key, boolean defaultValue) {
String value = System.getProperty(key);
if (value == null || value.trim().length() == 0 || value.startsWith("$")) {
return defaultValue;
}
return Boolean.parseBoolean(value.trim());
}
public static List<String> getEnvironment() {
List<String> environment = new ArrayList<String>();
environment.add("OS: " + System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch", ""));
environment.add("CPU: " + Runtime.getRuntime().availableProcessors() + " cores");
environment.add("JVM: " + System.getProperty("java.vm.name") + " " + System.getProperty("java.runtime.version"));
environment.add("Memory: " + DecimalFormat.getIntegerInstance().format(Runtime.getRuntime().totalMemory())
+ " bytes (Max: " + DecimalFormat.getIntegerInstance().format(Runtime.getRuntime().maxMemory()) + " bytes)");
NetworkInterface ni = PerformanceUtils.getNetworkInterface();
if (ni != null) {
environment.add("Network: " + ni.getDisplayName());
}
return environment;
}
private static List<String> scene = new ArrayList<String>();
public static List<String> getScene() {
return scene;
}
public static void setScene(List<String> scene) {
PerformanceUtils.scene = scene;
}
private static final int WIDTH = 64;
public static void printSeparator() {
StringBuilder pad = new StringBuilder();
for (int i = 0; i < WIDTH; i ++) {
pad.append("-");
}
System.out.println("+" + pad + "+");
}
public static void printBorder() {
StringBuilder pad = new StringBuilder();
for (int i = 0; i < WIDTH; i ++) {
pad.append("=");
}
System.out.println("+" + pad + "+");
}
public static void printBody(String msg) {
StringBuilder pad = new StringBuilder();
int len = WIDTH - msg.length() - 1;
if (len > 0) {
for (int i = 0; i < len; i ++) {
pad.append(" ");
}
}
System.out.println("| " + msg + pad + "|");
}
public static void printHeader(String msg) {
StringBuilder pad = new StringBuilder();
int len = WIDTH - msg.length();
if (len > 0) {
int half = len / 2;
for (int i = 0; i < half; i ++) {
pad.append(" ");
}
}
System.out.println("|" + pad + msg + pad + ((len % 2 == 0) ? "" : " ") + "|");
}
public static NetworkInterface getNetworkInterface() {
try {
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
if (interfaces != null) {
while (interfaces.hasMoreElements()) {
try {
return interfaces.nextElement();
} catch (Throwable e) {
}
}
}
} catch (SocketException e) {
}
return null;
}
}

View File

@ -1,41 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.rpc.util;
/**
* User: heyman
* Date: 5/18/11
* Time: 9:07 PM
*/
public class MyException extends Exception {
private static final long serialVersionUID = 1L;
public MyException() {
super();
}
public MyException(String message, Throwable cause) {
super(message, cause);
}
public MyException(String message) {
super(message);
}
public MyException(Throwable cause) {
super(cause);
}
}

View File

@ -1,41 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.rpc.util;
/**
* User: heyman
* Date: 5/18/11
* Time: 9:09 PM
*/
public class MyRuntimeException extends RuntimeException {
private static final long serialVersionUID = 1L;
public MyRuntimeException() {
super();
}
public MyRuntimeException(String message, Throwable cause) {
super(message, cause);
}
public MyRuntimeException(String message) {
super(message);
}
public MyRuntimeException(Throwable cause) {
super(cause);
}
}

View File

@ -1,28 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.rpc.util;
/**
* User: heyman
* Date: 5/18/11
* Time: 4:10 PM
*/
public interface MyService {
public String echo(String input);
public void noReturn (String input);
public String throwException() throws MyException;
public String throwSystemException();
}

View File

@ -1,40 +0,0 @@
/*
* Copyright 1999-2011 Alibaba Group.
*
* 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 com.alibaba.dubbo.rpc.util;
import org.apache.commons.logging.LogConfigurationException;
/**
* User: heyman
* Date: 5/18/11
* Time: 4:13 PM
*/
public class MyServiceImpl implements MyService{
public String echo(String input) {
return input;
}
public void noReturn(String input) {
}
public String throwException() throws MyException {
throw new MyException("Exception throwed");
}
public String throwSystemException() {
throw new LogConfigurationException("system error");
}
}

View File

@ -1 +1 @@
com.alibaba.dubbo.config.test.MockRegistryFactory
com.alibaba.dubbo.config.support.MockRegistryFactory

View File

@ -1 +1 @@
com.alibaba.dubbo.config.test.MockProtocol
com.alibaba.dubbo.config.support.MockProtocol

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="rpc-callback-demo" />
<dubbo:registry address="127.0.0.1:9234" />
<dubbo:reference id="demoService" interface="com.alibaba.dubbo.callback.explicit.test.IDemoService" version="1.0.0" group="cn" timeout="100000" retries="0" />
</beans>

View File

@ -1,43 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="rpc-callback-demo" />
<dubbo:registry address="127.0.0.1:9234" />
<dubbo:protocol name="dubbo" port="20881" codec="dubbo"/>
<bean id="demoService" class="com.alibaba.dubbo.callback.explicit.test.DemoServiceImpl" />
<dubbo:service interface="com.alibaba.dubbo.callback.explicit.test.IDemoService" ref="demoService" version="1.0.0" group="cn" callbacks="1">
<dubbo:method name="xxx">
<dubbo:argument index="0" callback="true" />
</dubbo:method>
<dubbo:method name="xxx2">
<dubbo:argument type="com.alibaba.dubbo.callback.explicit.test.IDemoCallback" callback="true" />
</dubbo:method>
<dubbo:method name="unxxx">
<dubbo:argument type="com.alibaba.dubbo.callback.explicit.test.IDemoCallback" callback="false" />
</dubbo:method>
</dubbo:service>
</beans>

View File

@ -1,32 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="rpc-callback-demo" />
<dubbo:registry address="127.0.0.1:9234" />
<bean id ="demoCallback" class = "com.alibaba.dubbo.callback.implicit.test.NofifyImpl" />
<dubbo:reference id="demoService" interface="com.alibaba.dubbo.callback.implicit.test.IDemoService" version="1.0.0" group="cn" >
<dubbo:method name="get" async="true" onreturn = "demoCallback.onreturn" onthrow="demoCallback.onthrow" />
</dubbo:reference>
</beans>

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="rpc-callback-demo" />
<dubbo:registry address="127.0.0.1:9234" />
<dubbo:reference id="demoService" interface="com.alibaba.dubbo.callback.implicit.test.IDemoService" version="1.0.0" group="cn" >
</dubbo:reference>
</beans>

View File

@ -1,30 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="rpc-callback-demo" />
<dubbo:registry address="127.0.0.1:9234" />
<dubbo:reference id="demoService" interface="com.alibaba.dubbo.callback.implicit.test.IDemoService" version="1.0.0" group="cn" >
<dubbo:method name="get" async="true" />
</dubbo:reference>
</beans>

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="rpc-callback-demo" />
<dubbo:registry address="127.0.0.1:9234" />
<bean id="demoService" class="com.alibaba.dubbo.callback.implicit.test.NormalDemoService" />
<dubbo:service interface="com.alibaba.dubbo.callback.implicit.test.IDemoService" ref="demoService" version="1.0.0" group="cn"/>
</beans>

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="complex_consumer" />
<dubbo:registry address="10.20.153.28:9090" username="admin" password="hello1234" />
<dubbo:reference id="demoService" interface="com.alibaba.dubbo.demo.api.DemoService" version="1.0.0" local="true" mock="true" check="false" timeout="3000" router="failfast" loadbalance="roundrobin" />
</beans>

View File

@ -1,44 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="complex_provider" />
<dubbo:registry address="10.20.153.28:9090" username="admin" password="hello1234" check="false" />
<dubbo:protocol name="dubbo" port="20882" server="netty" accesslog="D:/dubbo-access.log" />
<dubbo:protocol name="rmi" port="1092" />
<dubbo:protocol name="http" port="8082" server="jetty" />
<dubbo:protocol name="hessian" port="8092" server="jetty" />
<!--
<dubbo:provider protocol="dubbo" port="20883" server="netty" />
<dubbo:provider protocol="rmi" port="1093" />
<dubbo:provider protocol="http" port="8083" server="jetty" />
-->
<dubbo:service interface="com.alibaba.dubbo.demo.api.DemoService" version="1.0.0" ref="demoService" />
<dubbo:service interface="com.alibaba.dubbo.demo.api.DemoService" version="1.0.0" ref="demoService2" path="com.alibaba.demo.api.DemoService2" />
<bean id="demoService" class="com.alibaba.dubbo.demo.provider.impl.DemoServiceImpl" />
<bean id="demoService2" class="com.alibaba.dubbo.demo.provider.impl.DemoServiceImpl2" />
</beans>

View File

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="direct-consumer" />
<dubbo:reference id="demoService" interface="com.alibaba.dubbo.demo.api.DemoService" version="1.0.0" url="dubbo://127.0.0.1:20886/com.alibaba.dubbo.demo.api.DemoService" />
</beans>

View File

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="direct-provider" />
<dubbo:protocol name="dubbo" port="20886" threadpool="fixed" threads="100" server="netty" client="netty" />
<dubbo:service interface="com.alibaba.dubbo.demo.api.DemoService" version="1.0.0" ref="demoService" registry="N/A" />
<bean id="demoService" class="com.alibaba.dubbo.demo.provider.impl.DemoServiceImpl" />
</beans>

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="generic-consumer" />
<dubbo:registry address="10.20.153.28:9090" username="admin" password="hello1234" />
<dubbo:reference id="demoService" interface="com.alibaba.dubbo.demo.api.DemoService" version="1.0.0" generic="true" />
</beans>

View File

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="generic-provider" />
<dubbo:registry address="10.20.153.28:9090" username="admin" password="hello1234" />
<dubbo:protocol name="dubbo" port="20881" />
<dubbo:service interface="com.alibaba.dubbo.demo.api.DemoService" version="1.0.0" generic="true" ref="demoService" />
<bean id="demoService" class="com.alibaba.dubbo.demo.provider.impl.DemoServiceGenericImpl" />
</beans>

View File

@ -1,35 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="simple-consumer" />
<dubbo:registry address="10.20.153.28:9090" username="admin" password="hello1234" />
<dubbo:protocol name="injvm" />
<dubbo:service interface="com.alibaba.dubbo.demo.api.DemoService" ref="demoServiceServer" version="1.0.0" registry="N/A" />
<bean id="demoServiceServer" class="com.alibaba.dubbo.demo.provider.impl.DemoServiceImpl" />
<dubbo:reference id="demoService" interface="com.alibaba.dubbo.demo.api.DemoService" version="1.0.0" />
</beans>

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="performance-consumer" />
<dubbo:registry address="10.20.153.28:9090" username="admin" password="hello1234" />
<dubbo:reference id="demoService" interface="com.alibaba.dubbo.demo.api.DemoService" version="1.0.0" connections="1" retries="0" timeout="5000" actives="10" />
</beans>

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="simple-consumer" />
<dubbo:registry address="zookeeper://10.20.153.10:2181" />
<dubbo:reference id="demoService" interface="com.alibaba.dubbo.demo.api.DemoService" version="1.0.0" stub="true" />
</beans>

View File

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="simple-monitor" />
<dubbo:registry address="127.0.0.1:9090" />
<dubbo:protocol name="dubbo" port="7070" />
<dubbo:service group="simple" interface="com.alibaba.dubbo.monitor.MonitorService" ref="monitorService"/>
<bean id="monitorService" class="com.alibaba.dubbo.monitor.support.SimpleMonitorService" />
</beans>

View File

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="simple-provider" />
<dubbo:registry address="zookeeper://10.20.153.10:2181" />
<dubbo:protocol name="dubbo" port="20881" />
<dubbo:service interface="com.alibaba.dubbo.demo.api.DemoService" ref="demoService" version="1.0.0" />
<bean id="demoService" class="com.alibaba.dubbo.demo.provider.impl.DemoServiceImpl" />
</beans>

View File

@ -1,44 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 1999-2011 Alibaba Group.
-
- 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
<dubbo:application name="simple-registry" />
<dubbo:protocol name="dubbo" port="9090" />
<dubbo:service interface="com.alibaba.dubbo.registry.RegistryService" ref="registryService" protocol="dubbo" registry="N/A" callbacks="1000" ondisconnect="disconnect">
<dubbo:method name="subscribe">
<dubbo:argument index="1" callback="true" />
</dubbo:method>
<dubbo:method name="unsubscribe">
<dubbo:argument index="1" callback="false" />
</dubbo:method>
</dubbo:service>
<bean id="registryService" class="com.alibaba.dubbo.registry.support.SimpleRegistryService" >
<property name="registries">
<list>
<value>127.0.0.1:9091</value>
</list>
</property>
</bean>
</beans>