當前位置: 首頁>>代碼示例>>Java>>正文


Java RpcException類代碼示例

本文整理匯總了Java中com.alibaba.dubbo.rpc.RpcException的典型用法代碼示例。如果您正苦於以下問題:Java RpcException類的具體用法?Java RpcException怎麽用?Java RpcException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RpcException類屬於com.alibaba.dubbo.rpc包,在下文中一共展示了RpcException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testTimeOut

import com.alibaba.dubbo.rpc.RpcException; //導入依賴的package包/類
@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(6000);
        fail();
    } catch (RpcException expected) {
        Assert.assertEquals(true, expected.isTimeout());
    }finally{
        invoker.destroy();
        exporter.unexport();
    }
    
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:21,代碼來源:HessianProtocolTest.java

示例2: testFail

import com.alibaba.dubbo.rpc.RpcException; //導入依賴的package包/類
@Test(expected = RpcException.class)
public void testFail() throws Exception {
    URL url = URL.valueOf("test://test");
    url = url.addParameter(Constants.INTERFACE_KEY,
                           "com.alibaba.dubbo.rpc.file.TpsService");
    url = url.addParameter(Constants.TPS_LIMIT_RATE_KEY, 5);
    Invoker<TpsLimitFilterTest> invoker = new MyInvoker<TpsLimitFilterTest>(url);
    Invocation invocation = new MockInvocation();
    for (int i = 0; i < 10; i++) {
        try {
            filter.invoke(invoker, invocation);
        } catch (Exception e) {
            assertTrue(i >= 5);
            throw e;
        }
    }
}
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:18,代碼來源:TpsLimitFilterTest.java

示例3: testMockInvokerFromOverride_Invoke_mock_false

import com.alibaba.dubbo.rpc.RpcException; //導入依賴的package包/類
@Test
public void testMockInvokerFromOverride_Invoke_mock_false(){
	URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName())
			.addParameter("mock","false")
			.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.assertTrue(e.isTimeout());
	}
}
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:17,代碼來源:MockClusterInvokerTest.java

示例4: testInvokeWithRuntimeException

import com.alibaba.dubbo.rpc.RpcException; //導入依賴的package包/類
@Test
public void testInvokeWithRuntimeException() {
    EasyMock.reset(invoker1);
    EasyMock.expect(invoker1.invoke(invocation)).andThrow(new RuntimeException()).anyTimes();
    EasyMock.expect(invoker1.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker1.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker1.getInterface()).andReturn(FailoverClusterInvokerTest.class).anyTimes();
    EasyMock.replay(invoker1);
    
    EasyMock.reset(invoker2);
    EasyMock.expect(invoker2.invoke(invocation)).andThrow(new RuntimeException()).anyTimes();
    EasyMock.expect(invoker2.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker2.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker2.getInterface()).andReturn(FailoverClusterInvokerTest.class).anyTimes();
    EasyMock.replay(invoker2);
    
    FailoverClusterInvoker<FailoverClusterInvokerTest> invoker = new FailoverClusterInvoker<FailoverClusterInvokerTest>(dic);
    try {
        invoker.invoke(invocation);
        fail();
    } catch (RpcException expected) {
        assertEquals(0,expected.getCode());
        assertFalse(expected.getCause() instanceof RpcException);
    }
}
 
開發者ID:yunhaibin,項目名稱:dubbox-hystrix,代碼行數:26,代碼來源:FailoverClusterInvokerTest.java

示例5: test_returnSerializationFail

import com.alibaba.dubbo.rpc.RpcException; //導入依賴的package包/類
@Test
public void test_returnSerializationFail() throws Exception {
    ClassPathXmlApplicationContext providerContext = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider-UnserializableBox.xml");
    providerContext.start();
    try {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/init-reference.xml");
        ctx.start();
        try {
            DemoService demoService = (DemoService)ctx.getBean("demoService");
            try {
                demoService.getBox();
                fail();
            } catch (RpcException expected) {
                assertThat(expected.getMessage(), containsString("must implement java.io.Serializable"));
            }
        } finally {
            ctx.stop();
            ctx.close();
        }
    } finally {
        providerContext.stop();
        providerContext.close();
    }
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:25,代碼來源:ConfigTest.java

示例6: testNoInvoke

import com.alibaba.dubbo.rpc.RpcException; //導入依賴的package包/類
@Test()
public void testNoInvoke() {
    dic = EasyMock.createMock(Directory.class);
    
    EasyMock.expect(dic.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(dic.list(invocation)).andReturn(null).anyTimes();
    EasyMock.expect(dic.getInterface()).andReturn(FailoverClusterInvokerTest.class).anyTimes();
    invocation.setMethodName("method1");
    EasyMock.replay(dic);
    
    invokers.add(invoker1);
    
    
    FailoverClusterInvoker<FailoverClusterInvokerTest> invoker = new FailoverClusterInvoker<FailoverClusterInvokerTest>(dic);
    try {
        invoker.invoke(invocation);
        fail();
    } catch (RpcException expected) {
        assertFalse(expected.getCause() instanceof RpcException);
    }
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:22,代碼來源:FailoverClusterInvokerTest.java

示例7: testNoInvoke

import com.alibaba.dubbo.rpc.RpcException; //導入依賴的package包/類
@Test()
public void testNoInvoke() {
    dic = EasyMock.createMock(Directory.class);
    
    EasyMock.expect(dic.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(dic.list(invocation)).andReturn(null).anyTimes();
    EasyMock.expect(dic.getInterface()).andReturn(FailfastClusterInvokerTest.class).anyTimes();
    
    invocation.setMethodName("method1");
    EasyMock.replay(dic);
    
    invokers.add(invoker1);
    
    resetInvoker1ToNoException();
    
    FailfastClusterInvoker<FailfastClusterInvokerTest> invoker = new FailfastClusterInvoker<FailfastClusterInvokerTest>(dic);
    try {
        invoker.invoke(invocation);
        fail();
    } catch (RpcException expected) {
        assertFalse(expected.getCause() instanceof RpcException);
    }
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:24,代碼來源:FailfastClusterInvokerTest.java

示例8: testRpcException

import com.alibaba.dubbo.rpc.RpcException; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void testRpcException() {
    Logger logger = EasyMock.createMock(Logger.class);
    RpcContext.getContext().setRemoteAddress("127.0.0.1", 1234);
    RpcException exception = new RpcException("TestRpcException");
    logger.error(EasyMock.eq("Got unchecked and undeclared exception which called by 127.0.0.1. service: " + DemoService.class.getName() + ", method: sayHello, exception: " + RpcException.class.getName() + ": TestRpcException"), EasyMock.eq(exception));
    ExceptionFilter exceptionFilter = new ExceptionFilter(logger);
    RpcInvocation invocation = new RpcInvocation("sayHello", new Class<?>[]{String.class}, new Object[]{"world"});
    Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class);
    EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class);
    EasyMock.expect(invoker.invoke(EasyMock.eq(invocation))).andThrow(exception);
    
    EasyMock.replay(logger, invoker);
    
    try {
        exceptionFilter.invoke(invoker, invocation);
    } catch (RpcException e) {
        assertEquals("TestRpcException", e.getMessage());
    }
    EasyMock.verify(logger, invoker);
    RpcContext.removeContext();
}
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:24,代碼來源:ExceptionFilterTest.java

示例9: invoke

import com.alibaba.dubbo.rpc.RpcException; //導入依賴的package包/類
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    if (validation != null && ! invocation.getMethodName().startsWith("$") 
            && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.VALIDATION_KEY))) {
        try {
            Validator validator = validation.getValidator(invoker.getUrl());
            if (validator != null) {
                validator.validate(invocation.getMethodName(), invocation.getParameterTypes(), invocation.getArguments());
            }
        } catch (RpcException e) {
            throw e;
        } catch (Throwable t) {
            throw new RpcException(t.getMessage(), t);
        }
    }
    return invoker.invoke(invocation);
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:17,代碼來源:ValidationFilter.java

示例10: invoke

import com.alibaba.dubbo.rpc.RpcException; //導入依賴的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);
    }
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:20,代碼來源:MonitorFilter.java

示例11: testInvokeWithRPCException

import com.alibaba.dubbo.rpc.RpcException; //導入依賴的package包/類
@Test()
public void testInvokeWithRPCException() {
    
    EasyMock.reset(invoker1);
    EasyMock.expect(invoker1.invoke(invocation)).andThrow(new RpcException()).anyTimes();
    EasyMock.expect(invoker1.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker1.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker1.getInterface()).andReturn(FailoverClusterInvokerTest.class).anyTimes();
    EasyMock.replay(invoker1);
    
    EasyMock.reset(invoker2);
    EasyMock.expect(invoker2.invoke(invocation)).andReturn(result).anyTimes();
    EasyMock.expect(invoker2.isAvailable()).andReturn(true).anyTimes();
    EasyMock.expect(invoker2.getUrl()).andReturn(url).anyTimes();
    EasyMock.expect(invoker2.getInterface()).andReturn(FailoverClusterInvokerTest.class).anyTimes();
    EasyMock.replay(invoker2);
    
    FailoverClusterInvoker<FailoverClusterInvokerTest> invoker = new FailoverClusterInvoker<FailoverClusterInvokerTest>(dic);
    for(int i=0;i<100;i++){
        Result ret = invoker.invoke(invocation);
        assertSame(result, ret);
    }
}
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:24,代碼來源:FailoverClusterInvokerTest.java

示例12: main

import com.alibaba.dubbo.rpc.RpcException; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    ClassPathXmlApplicationContext context =
            new ClassPathXmlApplicationContext(
                    new String[] {"applicationContext.xml"});
    context.start();
    IValidationService validationService = (IValidationService)context.getBean("validationService");
    // Error
    try {
        ValidationParameter parameter = new ValidationParameter();
        validationService.save(parameter);
        System.out.println("Validation ERROR");
    } catch (RpcException e) { // 拋出的是RpcException
        ConstraintViolationException ve = (ConstraintViolationException) e.getCause();
        // 裏麵嵌了一個ConstraintViolationException

        Set<ConstraintViolation<?>> violations = ve.getConstraintViolations();
        // 可以拿到一個驗證錯誤詳細信息的集合
        System.out.println(violations);
    }
}
 
開發者ID:daishicheng,項目名稱:outcomes,代碼行數:21,代碼來源:ValidationConsumer.java

示例13: invoke

import com.alibaba.dubbo.rpc.RpcException; //導入依賴的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:zhuxiaolei,項目名稱:dubbo2,代碼行數:17,代碼來源:ConsumerContextFilter.java

示例14: doExport

import com.alibaba.dubbo.rpc.RpcException; //導入依賴的package包/類
protected <T> Runnable doExport(final T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    HttpServer server = serverMap.get(addr);
    if (server == null) {
        server = httpBinder.bind(url, new InternalHandler());
        serverMap.put(addr, server);
    }
    final HttpInvokerServiceExporter httpServiceExporter = new HttpInvokerServiceExporter();
    httpServiceExporter.setServiceInterface(type);
    httpServiceExporter.setService(impl);
    try {
        httpServiceExporter.afterPropertiesSet();
    } catch (Exception e) {
        throw new RpcException(e.getMessage(), e);
    }
    final String path = url.getAbsolutePath();
    skeletonMap.put(path, httpServiceExporter);
    return new Runnable() {
        public void run() {
            skeletonMap.remove(path);
        }
    };
}
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:24,代碼來源:HttpProtocol.java

示例15: testRmiProtocolTimeout

import com.alibaba.dubbo.rpc.RpcException; //導入依賴的package包/類
@Test
public void testRmiProtocolTimeout() throws Exception
{
    System.setProperty("sun.rmi.transport.tcp.responseTimeout", "1000");
    DemoService service = new DemoServiceImpl();
    Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("rmi://127.0.0.1:9001/TestService")));
    service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("rmi://127.0.0.1:9001/TestService")));
    try {
        try {
            service.throwTimeout();
        } catch (RpcException e) {
            assertEquals(true, e.isTimeout());
            assertEquals(true, e.getMessage().contains("Read timed out"));
        }
    } finally {
        rpcExporter.unexport();
    }
}
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:19,代碼來源:RmiProtocolTest.java


注:本文中的com.alibaba.dubbo.rpc.RpcException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。