Search in sources :

Example 1 with Hello

use of com.weibo.api.motan.protocol.example.Hello in project motan by weibocom.

the class DefaultRpcProtocolTest method testProtocol.

@Test
public void testProtocol() {
    url = new URL("motan", "localhost", 18080, "com.weibo.api.motan.procotol.example.IHello");
    url.getParameters().put(URLParamType.endpointFactory.getName(), "mockEndpoint");
    try {
        defaultRpcProtocol.export(null, null);
    } catch (Exception e) {
        if (e instanceof MotanFrameworkException) {
            Assert.assertTrue(e.getMessage().contains("url is null"));
        } else {
            Assert.assertTrue(false);
        }
    }
    try {
        defaultRpcProtocol.export(null, url);
    } catch (Exception e) {
        if (e instanceof MotanFrameworkException) {
            Assert.assertTrue(e.getMessage().contains("provider is null"));
        } else {
            Assert.assertTrue(false);
        }
    }
    defaultRpcProtocol.export(new Provider<IHello>() {

        @Override
        public Response call(Request request) {
            IHello hello = new Hello();
            hello.hello();
            return new DefaultResponse("hello");
        }

        @Override
        public void init() {
        }

        @Override
        public void destroy() {
        }

        @Override
        public boolean isAvailable() {
            return false;
        }

        @Override
        public String desc() {
            return null;
        }

        @Override
        public URL getUrl() {
            return new URL("motan", "localhost", 18080, "com.weibo.api.motan.procotol.example.IHello");
        }

        @Override
        public Class<IHello> getInterface() {
            return IHello.class;
        }
    }, url);
    Referer<IHello> referer = defaultRpcProtocol.refer(IHello.class, url);
    DefaultRequest request = new DefaultRequest();
    request.setMethodName("hello");
    request.setInterfaceName(IHello.class.getName());
    Response response = referer.call(request);
    System.out.println("client: " + response.getValue());
    defaultRpcProtocol.destroy();
}
Also used : MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException) MotanFrameworkException(com.weibo.api.motan.exception.MotanFrameworkException) IHello(com.weibo.api.motan.protocol.example.IHello) Hello(com.weibo.api.motan.protocol.example.Hello) IHello(com.weibo.api.motan.protocol.example.IHello) Test(org.junit.Test)

Aggregations

MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)1 Hello (com.weibo.api.motan.protocol.example.Hello)1 IHello (com.weibo.api.motan.protocol.example.IHello)1 Test (org.junit.Test)1