本文整理汇总了Java中com.alibaba.dubbo.rpc.RpcInvocation类的典型用法代码示例。如果您正苦于以下问题:Java RpcInvocation类的具体用法?Java RpcInvocation怎么用?Java RpcInvocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RpcInvocation类属于com.alibaba.dubbo.rpc包,在下文中一共展示了RpcInvocation类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testMockInvokerInvoke_forcemock_defaultreturn
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的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());
}
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:19,代码来源:MockClusterInvokerTest.java
示例2: testNofityOverrideUrls_Provider
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的package包/类
/**
* 测试针对某个provider的Override规则
*/
@Test
public void testNofityOverrideUrls_Provider(){
RegistryDirectory registryDirectory = getRegistryDirectory();
invocation = new RpcInvocation();
List<URL> durls = new ArrayList<URL>();
durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1"));//一个一样,一个不一样
durls.add(SERVICEURL2.setHost("10.20.30.141").addParameter("timeout", "2"));
registryDirectory.notify(durls);
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://0.0.0.0?timeout=3"));
durls.add(URL.valueOf("override://10.20.30.141:9092?timeout=4"));
registryDirectory.notify(durls);
List<Invoker<?>> invokers = registryDirectory.list(invocation);
Invoker<?> aInvoker = invokers.get(0);
Invoker<?> bInvoker = invokers.get(1);
Assert.assertEquals("3",aInvoker.getUrl().getParameter("timeout"));
Assert.assertEquals("4",bInvoker.getUrl().getParameter("timeout"));
}
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:25,代码来源:RegistryDirectoryTest.java
示例3: testMockInvokerFromOverride_Invoke_force_throw
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的package包/类
@Test
public void testMockInvokerFromOverride_Invoke_force_throw() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName())
.addParameter("getBoolean2.mock", "force:throw ")
.addParameter("invoke_return_error", "true");
Invoker<IHelloService> cluster = getClusterInvoker(url);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getBoolean2");
try {
cluster.invoke(invocation);
Assert.fail();
} catch (RpcException e) {
Assert.assertFalse("not custem exception", e.isBiz());
}
}
开发者ID:l1325169021,项目名称:github-test,代码行数:17,代码来源:MockClusterInvokerTest.java
示例4: testParmeterRoute
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的package包/类
/**
* When the first arg of a method is String or Enum, Registry server can do parameter-value-based routing.
*/
@Test
public void testParmeterRoute() {
RegistryDirectory registryDirectory = getRegistryDirectory();
List<URL> serviceUrls = new ArrayList<URL>();
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1.napoli"));
serviceUrls.add(SERVICEURL2.addParameter("methods", "getXXX1.MORGAN,getXXX2"));
serviceUrls.add(SERVICEURL3.addParameter("methods", "getXXX1.morgan,getXXX2,getXXX3"));
registryDirectory.notify(serviceUrls);
invocation = new RpcInvocation(
Constants.$INVOKE,
new Class[] { String.class, String[].class, Object[].class },
new Object[] { "getXXX1", new String[] { "Enum" }, new Object[] { Param.MORGAN } });
List invokers = registryDirectory.list(invocation);
Assert.assertEquals(1, invokers.size());
}
开发者ID:flychao88,项目名称:dubbocloud,代码行数:22,代码来源:RegistryDirectoryTest.java
示例5: testNofityOverrideUrls_disabled_specifiedProvider
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的package包/类
/**
* 测试override通过enable=false,禁用指定服务提供者
* 预期:可以禁用指定的服务提供者。
*/
@Test
public void testNofityOverrideUrls_disabled_specifiedProvider() {
RegistryDirectory registryDirectory = getRegistryDirectory();
invocation = new RpcInvocation();
List<URL> durls = new ArrayList<URL>();
durls.add(SERVICEURL.setHost("10.20.30.140"));
durls.add(SERVICEURL.setHost("10.20.30.141"));
registryDirectory.notify(durls);
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://10.20.30.140?" + Constants.DISABLED_KEY + "=true"));
registryDirectory.notify(durls);
List<Invoker<?>> invokers = registryDirectory.list(invocation);
Assert.assertEquals(1, invokers.size());
Assert.assertEquals("10.20.30.141", invokers.get(0).getUrl().getHost());
durls = new ArrayList<URL>();
durls.add(URL.valueOf("empty://0.0.0.0?" + Constants.DISABLED_KEY + "=true&" + Constants.CATEGORY_KEY + "=" + Constants.CONFIGURATORS_CATEGORY));
registryDirectory.notify(durls);
List<Invoker<?>> invokers2 = registryDirectory.list(invocation);
Assert.assertEquals(2, invokers2.size());
}
开发者ID:l1325169021,项目名称:github-test,代码行数:29,代码来源:RegistryDirectoryTest.java
示例6: testNofityOverrideUrls_disabled_allProvider
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的package包/类
/**
* 测试override通过enable=false,禁用所有服务提供者
* 预期:不能通过override禁用所有服务提供者.
*/
@Test
public void testNofityOverrideUrls_disabled_allProvider(){
RegistryDirectory registryDirectory = getRegistryDirectory();
invocation = new RpcInvocation();
List<URL> durls = new ArrayList<URL>();
durls.add(SERVICEURL.setHost("10.20.30.140"));
durls.add(SERVICEURL.setHost("10.20.30.141"));
registryDirectory.notify(durls);
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://0.0.0.0?"+Constants.ENABLED_KEY+"=false"));
registryDirectory.notify(durls);
List<Invoker<?>> invokers = registryDirectory.list(invocation);
//不能通过override禁用所有服务提供者.
Assert.assertEquals(2,invokers.size());
}
开发者ID:flychao88,项目名称:dubbocloud,代码行数:23,代码来源:RegistryDirectoryTest.java
示例7: testMockInvokerFromOverride_Invoke_force_throwCustemExceptionNotFound
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的package包/类
@Test
public void testMockInvokerFromOverride_Invoke_force_throwCustemExceptionNotFound(){
URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName())
.addParameter("getBoolean2.mock","force:throw java.lang.RuntimeException2")
.addParameter("invoke_return_error", "true" );
Invoker<IHelloService> cluster = getClusterInvoker(url);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getBoolean2");
try {
cluster.invoke(invocation);
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(e.getCause() instanceof IllegalStateException);
}
}
开发者ID:flychao88,项目名称:dubbocloud,代码行数:17,代码来源:MockClusterInvokerTest.java
示例8: testNotifyoverrideUrls_withInvoker
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的package包/类
/**
* 测试override规则是否优先
* 场景:与invoker 一起推override规则
*/
@Test
public void testNotifyoverrideUrls_withInvoker(){
RegistryDirectory registryDirectory = getRegistryDirectory();
List<URL> durls = new ArrayList<URL>();
durls.add(SERVICEURL.addParameter("timeout", "1000"));
durls.add(SERVICEURL2.addParameter("timeout", "1000").addParameter("connections", "10"));
durls.add(URL.valueOf("override://0.0.0.0?timeout=1&connections=5"));
registryDirectory.notify(durls);
Assert.assertEquals(true, registryDirectory.isAvailable());
//开始验证参数值
invocation = new RpcInvocation();
List<Invoker<?>> invokers = registryDirectory.list(invocation);
Assert.assertEquals(2, invokers.size());
Assert.assertEquals("override rute must be first priority", "1", invokers.get(0).getUrl().getParameter("timeout"));
Assert.assertEquals("override rute must be first priority", "5", invokers.get(0).getUrl().getParameter("connections"));
}
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:27,代码来源:RegistryDirectoryTest.java
示例9: encodeRequestData
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的package包/类
@Override
protected void encodeRequestData(Channel channel, ObjectOutput out, Object data) throws IOException {
RpcInvocation inv = (RpcInvocation) data;
out.writeUTF(inv.getAttachment(Constants.DUBBO_VERSION_KEY, DUBBO_VERSION));
out.writeUTF(inv.getAttachment(Constants.PATH_KEY));
out.writeUTF(inv.getAttachment(Constants.VERSION_KEY));
out.writeUTF(inv.getMethodName());
out.writeUTF(ReflectUtils.getDesc(inv.getParameterTypes()));
Object[] args = inv.getArguments();
if (args != null)
for (int i = 0; i < args.length; i++){
out.writeObject(encodeInvocationArgument(channel, inv, i));
}
out.writeObject(inv.getAttachments());
}
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:18,代码来源:DubboCodec.java
示例10: invoke
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的package包/类
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName();
Class<?>[] parameterTypes = method.getParameterTypes();
if (method.getDeclaringClass() == Object.class) {
return method.invoke(invoker, args);
}
if ("toString".equals(methodName) && parameterTypes.length == 0) {
return invoker.toString();
}
if ("hashCode".equals(methodName) && parameterTypes.length == 0) {
return invoker.hashCode();
}
if ("equals".equals(methodName) && parameterTypes.length == 1) {
return invoker.equals(args[0]);
}
return invoker.invoke(new RpcInvocation(method, args)).recreate();
}
开发者ID:flychao88,项目名称:dubbocloud,代码行数:18,代码来源:InvokerInvocationHandler.java
示例11: testNofityOverrideUrls_Clean1
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的package包/类
/**
* 测试清除override规则,同时下发清除规则和其他override规则
* 测试是否能够恢复到推送时的providerUrl
*/
@Test
public void testNofityOverrideUrls_Clean1() {
RegistryDirectory registryDirectory = getRegistryDirectory();
invocation = new RpcInvocation();
List<URL> durls = new ArrayList<URL>();
durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1"));
registryDirectory.notify(durls);
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://0.0.0.0?timeout=1000"));
registryDirectory.notify(durls);
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://0.0.0.0?timeout=3"));
durls.add(URL.valueOf("override://0.0.0.0"));
registryDirectory.notify(durls);
List<Invoker<?>> invokers = registryDirectory.list(invocation);
Invoker<?> aInvoker = invokers.get(0);
//需要恢复到最初的providerUrl
Assert.assertEquals("1", aInvoker.getUrl().getParameter("timeout"));
}
开发者ID:l1325169021,项目名称:github-test,代码行数:28,代码来源:RegistryDirectoryTest.java
示例12: invoke
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的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();
}
}
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:17,代码来源:ConsumerContextFilter.java
示例13: testNofityOverrideUrls_Provider
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的package包/类
/**
* 测试针对某个provider的Override规则
*/
@Test
public void testNofityOverrideUrls_Provider() {
RegistryDirectory registryDirectory = getRegistryDirectory();
invocation = new RpcInvocation();
List<URL> durls = new ArrayList<URL>();
durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1"));//一个一样,一个不一样
durls.add(SERVICEURL2.setHost("10.20.30.141").addParameter("timeout", "2"));
registryDirectory.notify(durls);
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://0.0.0.0?timeout=3"));
durls.add(URL.valueOf("override://10.20.30.141:9092?timeout=4"));
registryDirectory.notify(durls);
List<Invoker<?>> invokers = registryDirectory.list(invocation);
Invoker<?> aInvoker = invokers.get(0);
Invoker<?> bInvoker = invokers.get(1);
Assert.assertEquals("3", aInvoker.getUrl().getParameter("timeout"));
Assert.assertEquals("4", bInvoker.getUrl().getParameter("timeout"));
}
开发者ID:l1325169021,项目名称:github-test,代码行数:25,代码来源:RegistryDirectoryTest.java
示例14: test_NotifiedDubbo1
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的package包/类
@Test
public void test_NotifiedDubbo1() {
URL errorPathUrl = URL.valueOf("notsupport:/" + "xxx"+"?refer=" + URL.encode("interface="+service));
RegistryDirectory registryDirectory = getRegistryDirectory(errorPathUrl);
List<URL> serviceUrls = new ArrayList<URL>();
URL Dubbo1URL = URL.valueOf("dubbo://127.0.0.1:9098?lazy=true");
serviceUrls.add(Dubbo1URL.addParameter("methods", "getXXX"));
registryDirectory.notify(serviceUrls);
Assert.assertEquals(true, registryDirectory.isAvailable());
invocation = new RpcInvocation();
List<Invoker<DemoService>> invokers = registryDirectory.list(invocation);
Assert.assertEquals(1, invokers.size());
invocation.setMethodName("getXXX");
invokers = registryDirectory.list(invocation);
Assert.assertEquals(1, invokers.size());
Assert.assertEquals(DemoService.class.getName(), invokers.get(0).getUrl().getPath());
}
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:21,代码来源:RegistryDirectoryTest.java
示例15: testRoute_PickInvokers
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的package包/类
@Test
public void testRoute_PickInvokers() {
String rule = "var result = new java.util.ArrayList(invokers.size());" +
"for (i=0;i<invokers.size(); i++){ " +
"if (invokers.get(i).isAvailable()) {" +
"result.add(invokers.get(i)) ;" +
"}" +
"} ; " +
"return result;";
String script = "function route(invokers,invocation,context){" + rule + "} route(invokers,invocation,context)";
Router router = new ScriptRouterFactory().getRouter(getRouteUrl(script));
List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
Invoker<String> invoker1 = new MockInvoker<String>(false);
Invoker<String> invoker2 = new MockInvoker<String>(true);
Invoker<String> invoker3 = new MockInvoker<String>(true);
invokers.add(invoker1);
invokers.add(invoker2);
invokers.add(invoker3);
List<Invoker<String>> fileredInvokers = router.route(invokers, invokers.get(0).getUrl(), new RpcInvocation());
Assert.assertEquals(2, fileredInvokers.size());
Assert.assertEquals(invoker2, fileredInvokers.get(0));
Assert.assertEquals(invoker3, fileredInvokers.get(1));
}
开发者ID:l1325169021,项目名称:github-test,代码行数:25,代码来源:ScriptRouterTest.java
示例16: test_Notified1invokers
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的package包/类
private void test_Notified1invokers(RegistryDirectory registryDirectory) {
List<URL> serviceUrls = new ArrayList<URL>();
serviceUrls.add(SERVICEURL.addParameter("methods", "getXXX1"));// .addParameter("refer.autodestroy", "true")
registryDirectory.notify(serviceUrls);
Assert.assertEquals(true, registryDirectory.isAvailable());
invocation = new RpcInvocation();
List invokers = registryDirectory.list(invocation);
Assert.assertEquals(1, invokers.size());
invocation.setMethodName("getXXX");
invokers = registryDirectory.list(invocation);
Assert.assertEquals(1, invokers.size());
invocation.setMethodName("getXXX1");
invokers = registryDirectory.list(invocation);
Assert.assertEquals(1, invokers.size());
invocation.setMethodName("getXXX2");
invokers = registryDirectory.list(invocation);
Assert.assertEquals(1, invokers.size());
}
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:25,代码来源:RegistryDirectoryTest.java
示例17: encodeInvocationArgument
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的package包/类
public static Object encodeInvocationArgument(Channel channel, RpcInvocation inv, int paraIndex) throws IOException{
//encode时可直接获取url
URL url = inv.getInvoker() == null ? null : inv.getInvoker().getUrl();
byte callbackstatus = isCallBack(url, inv.getMethodName(), paraIndex);
Object[] args = inv.getArguments();
Class<?>[] pts = inv.getParameterTypes();
switch (callbackstatus) {
case CallbackServiceCodec.CALLBACK_NONE:
return args[paraIndex];
case CallbackServiceCodec.CALLBACK_CREATE:
inv.setAttachment(INV_ATT_CALLBACK_KEY + paraIndex , exportOrunexportCallbackService(channel, url, pts[paraIndex], args[paraIndex], true));
return null;
case CallbackServiceCodec.CALLBACK_DESTROY:
inv.setAttachment(INV_ATT_CALLBACK_KEY + paraIndex, exportOrunexportCallbackService(channel, url, pts[paraIndex], args[paraIndex], false));
return null;
default:
return args[paraIndex];
}
}
开发者ID:flychao88,项目名称:dubbocloud,代码行数:20,代码来源:CallbackServiceCodec.java
示例18: testMockInvokerFromOverride_Invoke_force_throwCustemExceptionNotFound
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的package包/类
@Test
public void testMockInvokerFromOverride_Invoke_force_throwCustemExceptionNotFound() {
URL url = URL.valueOf("remote://1.2.3.4/" + IHelloService.class.getName())
.addParameter("getBoolean2.mock", "force:throw java.lang.RuntimeException2")
.addParameter("invoke_return_error", "true");
Invoker<IHelloService> cluster = getClusterInvoker(url);
//方法配置了mock
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("getBoolean2");
try {
cluster.invoke(invocation);
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(e.getCause() instanceof IllegalStateException);
}
}
开发者ID:l1325169021,项目名称:github-test,代码行数:17,代码来源:MockClusterInvokerTest.java
示例19: testNofityOverrideUrls_Clean1
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的package包/类
/**
* 测试清除override规则,同时下发清除规则和其他override规则
* 测试是否能够恢复到推送时的providerUrl
*/
@Test
public void testNofityOverrideUrls_Clean1(){
RegistryDirectory registryDirectory = getRegistryDirectory();
invocation = new RpcInvocation();
List<URL> durls = new ArrayList<URL>();
durls.add(SERVICEURL.setHost("10.20.30.140").addParameter("timeout", "1"));
registryDirectory.notify(durls);
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://0.0.0.0?timeout=1000"));
registryDirectory.notify(durls);
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://0.0.0.0?timeout=3"));
durls.add(URL.valueOf("override://0.0.0.0"));
registryDirectory.notify(durls);
List<Invoker<?>> invokers = registryDirectory.list(invocation);
Invoker<?> aInvoker = invokers.get(0);
//需要恢复到最初的providerUrl
Assert.assertEquals("1",aInvoker.getUrl().getParameter("timeout"));
}
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:28,代码来源:RegistryDirectoryTest.java
示例20: testNofityOverrideUrls_disabled_allProvider
import com.alibaba.dubbo.rpc.RpcInvocation; //导入依赖的package包/类
/**
* 测试override通过enable=false,禁用所有服务提供者
* 预期:不能通过override禁用所有服务提供者.
*/
@Test
public void testNofityOverrideUrls_disabled_allProvider() {
RegistryDirectory registryDirectory = getRegistryDirectory();
invocation = new RpcInvocation();
List<URL> durls = new ArrayList<URL>();
durls.add(SERVICEURL.setHost("10.20.30.140"));
durls.add(SERVICEURL.setHost("10.20.30.141"));
registryDirectory.notify(durls);
durls = new ArrayList<URL>();
durls.add(URL.valueOf("override://0.0.0.0?" + Constants.ENABLED_KEY + "=false"));
registryDirectory.notify(durls);
List<Invoker<?>> invokers = registryDirectory.list(invocation);
//不能通过override禁用所有服务提供者.
Assert.assertEquals(2, invokers.size());
}
开发者ID:l1325169021,项目名称:github-test,代码行数:23,代码来源:RegistryDirectoryTest.java
注:本文中的com.alibaba.dubbo.rpc.RpcInvocation类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论