DUBBO-69 修复dubbo协议RpcException errorcode丢失

git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@278 1a56cb94-b969-4eaa-88fa-be21384802f2
This commit is contained in:
tony.chenl 2011-11-15 06:24:00 +00:00
parent 2bb7e70564
commit 12a13e7e08
2 changed files with 20 additions and 13 deletions

View File

@ -53,7 +53,7 @@ public class FailoverClusterInvoker<T> extends AbstractClusterInvoker<T>{
len = 1;
// retry loop.
Throwable le = null; // last exception.
RpcException le = null; // last exception.
List<Invoker<T>> invoked = new ArrayList<Invoker<T>>(invokers.size()); // invoked invokers.
Set<URL> providers = new HashSet<URL>(len);
for (int i = 0; i < len; i++) {
@ -81,6 +81,6 @@ public class FailoverClusterInvoker<T> extends AbstractClusterInvoker<T>{
if(invoker != null )
urls.add(invoker.getUrl());
}
throw new RpcException("Tried " + len + " times to invoke providers " + providers + " " + loadbalance.getClass().getAnnotation(Extension.class).value() + " select from all providers " + invokers + " for service " + getInterface().getName() + " method " + invocation.getMethodName() + " on consumer " + NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion() + ", but no luck to perform the invocation. Last error is: " + (le != null ? le.getMessage() : ""), le);
throw new RpcException(le.getCode(),"Tried " + len + " times to invoke providers " + providers + " " + loadbalance.getClass().getAnnotation(Extension.class).value() + " select from all providers " + invokers + " for service " + getInterface().getName() + " method " + invocation.getMethodName() + " on consumer " + NetUtils.getLocalHost() + " use dubbo version " + Version.getVersion() + ", but no luck to perform the invocation. Last error is: " + (le != null ? le.getMessage() : ""), le);
}
}

View File

@ -15,13 +15,14 @@
*/
package com.alibaba.dubbo.rpc.cluster.support;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
import junit.framework.Assert;
import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
@ -71,8 +72,8 @@ public class FailoverClusterInvokerTest {
}
@Test(expected = RpcException.class)
public void testInvokeWithBizException() {
@Test
public void testInvokeWithRuntimeException() {
EasyMock.reset(invoker1);
EasyMock.expect(invoker1.invoke(invocation)).andThrow(new RuntimeException()).anyTimes();
EasyMock.expect(invoker1.isAvailable()).andReturn(true).anyTimes();
@ -88,7 +89,12 @@ public class FailoverClusterInvokerTest {
EasyMock.replay(invoker2);
FailoverClusterInvoker<FailoverClusterInvokerTest> invoker = new FailoverClusterInvoker<FailoverClusterInvokerTest>(dic);
invoker.invoke(invocation);
try {
invoker.invoke(invocation);
fail();
} catch (RpcException expected) {
assertEquals(0,expected.getCode());
}
}
@Test()
@ -111,7 +117,7 @@ public class FailoverClusterInvokerTest {
FailoverClusterInvoker<FailoverClusterInvokerTest> invoker = new FailoverClusterInvoker<FailoverClusterInvokerTest>(dic);
for(int i=0;i<100;i++){
Result ret = invoker.invoke(invocation);
Assert.assertSame(result, ret);
assertSame(result, ret);
}
}
@ -119,7 +125,7 @@ public class FailoverClusterInvokerTest {
public void testInvoke_retryTimes() {
EasyMock.reset(invoker1);
EasyMock.expect(invoker1.invoke(invocation)).andThrow(new RpcException()).anyTimes();
EasyMock.expect(invoker1.invoke(invocation)).andThrow(new RpcException(RpcException.TIMEOUT_EXCEPTION)).anyTimes();
EasyMock.expect(invoker1.isAvailable()).andReturn(false).anyTimes();
EasyMock.expect(invoker1.getUrl()).andReturn(url).anyTimes();
EasyMock.expect(invoker1.getInterface()).andReturn(FailoverClusterInvokerTest.class).anyTimes();
@ -135,10 +141,11 @@ public class FailoverClusterInvokerTest {
FailoverClusterInvoker<FailoverClusterInvokerTest> invoker = new FailoverClusterInvoker<FailoverClusterInvokerTest>(dic);
try{
Result ret = invoker.invoke(invocation);
Assert.assertSame(result, ret);
}catch (RpcException e) {
System.out.println(e.getMessage());
Assert.assertTrue(e.getMessage().indexOf((retries+1)+" times")>0);
assertSame(result, ret);
fail();
}catch (RpcException expected) {
assertTrue(expected.isTimeout());
assertTrue(expected.getMessage().indexOf((retries+1)+" times")>0);
}
}