本文整理汇总了Java中com.alibaba.dubbo.rpc.Result类的典型用法代码示例。如果您正苦于以下问题:Java Result类的具体用法?Java Result怎么用?Java Result使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Result类属于com.alibaba.dubbo.rpc包,在下文中一共展示了Result类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMockInvokerFromOverride_Invoke_check_ListPojo
import com.alibaba.dubbo.rpc.Result; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testMockInvokerFromOverride_Invoke_check_ListPojo(){
URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName())
.addParameter("getUsers.mock","force:return [{id:1, name:\"hi1\"}, {id:2, name:\"hi2\"}]")
.addParameter("invoke_return_error", "true" );
Invoker<IHelloService> cluster = getClusterInvoker(url);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getUsers");
Result ret = cluster.invoke(invocation);
List<User> rl = (List<User>)ret.getValue();
System.out.println(rl);
Assert.assertEquals(2, rl.size());
Assert.assertEquals("hi1", ((User)rl.get(0)).getName());
}
示例2: invoke
import com.alibaba.dubbo.rpc.Result; //导入依赖的package包/类
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
long start = System.currentTimeMillis();
String classDotMethod = (invocation.getInvoker().getInterface().getName().concat(".").concat(invocation
.getMethodName()));
try {
Result r = invoker.invoke(invocation);
long end = System.currentTimeMillis();
LogBean log = new LogBean();
log.ct = (end - start);
log.k = (invocation.getInvoker().getInterface().getName() + "." + invocation.getMethodName());
// provider
log.ext = (invoker.getUrl().getAddress());
log.t = System.currentTimeMillis();
log.p = Arrays.toString(invocation.getArguments());
log.r = (r != null ? r.getValue() : null);
log.tp = LogBean.TYPE_DUBBO_PERF; // DUBBO_PERF
dubboLogger.info(JSON.toJSONString(log));
return r;
} catch (Exception e) {
logger.error("DubboServiceFilter.invoke error args : invoker={},invocation={},e={} ", invoker, invocation, e);
throw e;
}
}
示例3: testResulthasException
import com.alibaba.dubbo.rpc.Result; //导入依赖的package包/类
@Test
public void testResulthasException() {
invocation = EasyMock.createMock(Invocation.class);
EasyMock.expect(invocation.getMethodName()).andReturn("enumlength").anyTimes();
EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Enum.class }).anyTimes();
EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
EasyMock.replay(invocation);
invoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
RpcResult result = new RpcResult();
result.setException(new RuntimeException());
result.setValue("High");
EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
EasyMock.replay(invoker);
Result filterResult = compatibleFilter.invoke(invoker, invocation);
assertEquals(filterResult, result);
}
示例4: invoke
import com.alibaba.dubbo.rpc.Result; //导入依赖的package包/类
public Result invoke(final Invocation invocation) throws RpcException {
checkWheatherDestoried();
LoadBalance loadbalance;
List<Invoker<T>> invokers = list(invocation);
if (invokers != null && invokers.size() > 0) {
loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(invokers.get(0).getUrl()
.getMethodParameter(invocation.getMethodName(),Constants.LOADBALANCE_KEY, Constants.DEFAULT_LOADBALANCE));
} else {
loadbalance = ExtensionLoader.getExtensionLoader(LoadBalance.class).getExtension(Constants.DEFAULT_LOADBALANCE);
}
RpcUtils.attachInvocationIdIfAsync(getUrl(), invocation);
return doInvoke(invocation, invokers, loadbalance);
}
示例5: testMockInvokerInvoke_forcemock_defaultreturn
import com.alibaba.dubbo.rpc.Result; //导入依赖的package包/类
@Test
public void testMockInvokerInvoke_forcemock_defaultreturn(){
URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName());
url = url.addParameter(Constants.MOCK_KEY, "force" );
Invoker<IHelloService> cluster = getClusterInvoker(url);
URL mockUrl = URL.valueOf("mock://localhost/"+IHelloService.class.getName()
+"?getSomething.mock=return aa&getSomething3xx.mock=return xx&sayHello.mock=return ")
.addParameters(url.getParameters());
Protocol protocol = new MockProtocol();
Invoker<IHelloService> mInvoker1 = protocol.refer(IHelloService.class, mockUrl);
invokers.add(mInvoker1);
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("sayHello");
Result ret = cluster.invoke(invocation);
Assert.assertEquals(null, ret.getValue());
}
示例6: testInvokerJsonPojoSerialization
import com.alibaba.dubbo.rpc.Result; //导入依赖的package包/类
@Test
public void testInvokerJsonPojoSerialization() {
invocation = EasyMock.createMock(Invocation.class);
EasyMock.expect(invocation.getMethodName()).andReturn("enumlength").anyTimes();
EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Type[].class }).anyTimes();
EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
EasyMock.replay(invocation);
invoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
RpcResult result = new RpcResult();
result.setValue("High");
EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1&serialization=json");
EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
EasyMock.replay(invoker);
Result filterResult = compatibleFilter.invoke(invoker, invocation);
assertEquals(Type.High, filterResult.getValue());
}
示例7: encodeResponseData
import com.alibaba.dubbo.rpc.Result; //导入依赖的package包/类
@Override
protected void encodeResponseData(Channel channel, ObjectOutput out, Object data) throws IOException {
Result result = (Result) data;
Throwable th = result.getException();
if (th == null) {
Object ret = result.getValue();
if (ret == null) {
out.writeByte(RESPONSE_NULL_VALUE);
} else {
out.writeByte(RESPONSE_VALUE);
out.writeObject(ret);
}
} else {
out.writeByte(RESPONSE_WITH_EXCEPTION);
out.writeObject(th);
}
}
示例8: testInvokerNonJsonEnumSerialization
import com.alibaba.dubbo.rpc.Result; //导入依赖的package包/类
@Test
public void testInvokerNonJsonEnumSerialization() {
invocation = EasyMock.createMock(Invocation.class);
EasyMock.expect(invocation.getMethodName()).andReturn("enumlength").anyTimes();
EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Type[].class }).anyTimes();
EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
EasyMock.replay(invocation);
invoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
RpcResult result = new RpcResult();
result.setValue("High");
EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
EasyMock.replay(invoker);
Result filterResult = compatibleFilter.invoke(invoker, invocation);
assertEquals(Type.High, filterResult.getValue());
}
示例9: testInvokerNonJsonPojoSerialization
import com.alibaba.dubbo.rpc.Result; //导入依赖的package包/类
@Test
public void testInvokerNonJsonPojoSerialization() {
invocation = EasyMock.createMock(Invocation.class);
EasyMock.expect(invocation.getMethodName()).andReturn("echo").anyTimes();
EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { String.class }).anyTimes();
EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
EasyMock.replay(invocation);
invoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
RpcResult result = new RpcResult();
result.setValue("hello");
EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
EasyMock.replay(invoker);
Result filterResult = compatibleFilter.invoke(invoker, invocation);
assertEquals("hello", filterResult.getValue());
}
示例10: invoke
import com.alibaba.dubbo.rpc.Result; //导入依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
RpcContext.getContext()
.setInvoker(invoker)
.setInvocation(invocation)
.setLocalAddress(NetUtils.getLocalHost(), 0)
.setRemoteAddress(invoker.getUrl().getHost(),
invoker.getUrl().getPort());
if (invocation instanceof RpcInvocation) {
((RpcInvocation)invocation).setInvoker(invoker);
}
try {
return invoker.invoke(invocation);
} finally {
RpcContext.getContext().clearAttachments();
}
}
示例11: testInvokerGeneric
import com.alibaba.dubbo.rpc.Result; //导入依赖的package包/类
@Test
public void testInvokerGeneric() {
invocation = EasyMock.createMock(Invocation.class);
EasyMock.expect(invocation.getMethodName()).andReturn("$enumlength").anyTimes();
EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Enum.class }).anyTimes();
EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
EasyMock.replay(invocation);
invoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
RpcResult result = new RpcResult();
result.setValue("High");
EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
EasyMock.replay(invoker);
Result filterResult = compatibleFilter.invoke(invoker, invocation);
assertEquals(filterResult, result);
}
示例12: testNonEcho
import com.alibaba.dubbo.rpc.Result; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testNonEcho() {
Invocation invocation = EasyMock.createMock(Invocation.class);
EasyMock.expect(invocation.getMethodName()).andReturn("echo").anyTimes();
EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Enum.class }).anyTimes();
EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
EasyMock.expect(invocation.getAttachments()).andReturn(null).anyTimes();
EasyMock.replay(invocation);
Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
RpcResult result = new RpcResult();
result.setValue("High");
EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
EasyMock.replay(invoker);
Result filterResult = echoFilter.invoke(invoker, invocation);
assertEquals("High", filterResult.getValue());
}
示例13: testInvokerNonJsonNonPojoSerialization
import com.alibaba.dubbo.rpc.Result; //导入依赖的package包/类
@Test
public void testInvokerNonJsonNonPojoSerialization() {
invocation = EasyMock.createMock(Invocation.class);
EasyMock.expect(invocation.getMethodName()).andReturn("echo").anyTimes();
EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] {String.class }).anyTimes();
EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
EasyMock.replay(invocation);
invoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
RpcResult result = new RpcResult();
result.setValue(new String[]{"High"});
EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
EasyMock.replay(invoker);
Result filterResult = compatibleFilter.invoke(invoker, invocation);
assertArrayEquals(new String[]{"High"}, (String[])filterResult.getValue());
}
示例14: testEcho
import com.alibaba.dubbo.rpc.Result; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testEcho() {
Invocation invocation = EasyMock.createMock(Invocation.class);
EasyMock.expect(invocation.getMethodName()).andReturn("$echo").anyTimes();
EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Enum.class }).anyTimes();
EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
EasyMock.expect(invocation.getAttachments()).andReturn(null).anyTimes();
EasyMock.replay(invocation);
Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
RpcResult result = new RpcResult();
result.setValue("High");
EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
EasyMock.replay(invoker);
Result filterResult = echoFilter.invoke(invoker, invocation);
assertEquals("hello", filterResult.getValue());
}
示例15: invoke
import com.alibaba.dubbo.rpc.Result; //导入依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
if (invoker.getUrl().hasParameter(Constants.MONITOR_KEY)) {
RpcContext context = RpcContext.getContext(); // 提供方必须在invoke()之前获取context信息
long start = System.currentTimeMillis(); // 记录起始时间戮
getConcurrent(invoker, invocation).incrementAndGet(); // 并发计数
try {
Result result = invoker.invoke(invocation); // 让调用链往下执行
collect(invoker, invocation, result, context, start, false);
return result;
} catch (RpcException e) {
collect(invoker, invocation, null, context, start, true);
throw e;
} finally {
getConcurrent(invoker, invocation).decrementAndGet(); // 并发计数
}
} else {
return invoker.invoke(invocation);
}
}