增加hessian协议的异常ut
git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@206 1a56cb94-b969-4eaa-88fa-be21384802f2
This commit is contained in:
parent
fc09821cc5
commit
b79a7a1354
|
|
@ -15,10 +15,10 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.rpc.protocol.hessian;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.alibaba.dubbo.common.ExtensionLoader;
|
||||
import com.alibaba.dubbo.common.URL;
|
||||
|
|
@ -26,13 +26,15 @@ import com.alibaba.dubbo.rpc.Exporter;
|
|||
import com.alibaba.dubbo.rpc.Invoker;
|
||||
import com.alibaba.dubbo.rpc.Protocol;
|
||||
import com.alibaba.dubbo.rpc.ProxyFactory;
|
||||
import com.alibaba.dubbo.rpc.RpcException;
|
||||
import com.alibaba.dubbo.rpc.protocol.hessian.HessianServiceImpl.MyException;
|
||||
|
||||
/**
|
||||
* HessianProtocolTest
|
||||
*
|
||||
* @author william.liangf
|
||||
*/
|
||||
public class HessianProtocolTest extends TestCase {
|
||||
public class HessianProtocolTest {
|
||||
|
||||
@Test
|
||||
public void testHessianProtocol() {
|
||||
|
|
@ -67,5 +69,43 @@ public class HessianProtocolTest extends TestCase {
|
|||
invoker.destroy();
|
||||
exporter.unexport();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTimeOut() {
|
||||
HessianServiceImpl server = new HessianServiceImpl();
|
||||
ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
|
||||
Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
|
||||
URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.class.getName() + "?version=1.0.0&timeout=10");
|
||||
Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
|
||||
Invoker<HessianService> invoker = protocol.refer(HessianService.class, url);
|
||||
HessianService client = proxyFactory.getProxy(invoker);
|
||||
try {
|
||||
client.timeOut(100000);
|
||||
fail();
|
||||
} catch (RpcException expected) {
|
||||
}finally{
|
||||
invoker.destroy();
|
||||
exporter.unexport();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomException() {
|
||||
HessianServiceImpl server = new HessianServiceImpl();
|
||||
ProxyFactory proxyFactory = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
|
||||
Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
|
||||
URL url = URL.valueOf("hessian://127.0.0.1:5342/" + HessianService.class.getName() + "?version=1.0.0");
|
||||
Exporter<HessianService> exporter = protocol.export(proxyFactory.getInvoker(server, HessianService.class, url));
|
||||
Invoker<HessianService> invoker = protocol.refer(HessianService.class, url);
|
||||
HessianService client = proxyFactory.getProxy(invoker);
|
||||
try {
|
||||
client.customException();
|
||||
fail();
|
||||
} catch (MyException expected) {
|
||||
}
|
||||
invoker.destroy();
|
||||
exporter.unexport();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package com.alibaba.dubbo.rpc.protocol.hessian;
|
||||
|
||||
|
||||
/**
|
||||
* HessianService
|
||||
*
|
||||
|
|
@ -23,5 +24,9 @@ package com.alibaba.dubbo.rpc.protocol.hessian;
|
|||
public interface HessianService {
|
||||
|
||||
String sayHello(String name);
|
||||
|
||||
void timeOut(int millis);
|
||||
|
||||
String customException();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,5 +32,25 @@ public class HessianServiceImpl implements HessianService {
|
|||
public boolean isCalled() {
|
||||
return called;
|
||||
}
|
||||
|
||||
public void timeOut(int millis) {
|
||||
try {
|
||||
Thread.sleep(millis);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String customException() {
|
||||
throw new MyException("custom exception");
|
||||
}
|
||||
|
||||
static class MyException extends RuntimeException{
|
||||
|
||||
private static final long serialVersionUID = -3051041116483629056L;
|
||||
|
||||
public MyException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue