Search in sources :

Example 41 with MotanFrameworkException

use of com.weibo.api.motan.exception.MotanFrameworkException 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)41 URL (com.weibo.api.motan.rpc.URL)7 DefaultResponse (com.weibo.api.motan.rpc.DefaultResponse)6 ArrayList (java.util.ArrayList)6 MotanServiceException (com.weibo.api.motan.exception.MotanServiceException)5 IOException (java.io.IOException)5 Method (java.lang.reflect.Method)4 Registry (com.weibo.api.motan.registry.Registry)3 Response (com.weibo.api.motan.rpc.Response)3 HeartbeatFactory (com.weibo.api.motan.transport.HeartbeatFactory)3 ObjectInput (java.io.ObjectInput)3 HashMap (java.util.HashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Serialization (com.weibo.api.motan.codec.Serialization)2 ConfigHandler (com.weibo.api.motan.config.handler.ConfigHandler)2 CommandListener (com.weibo.api.motan.registry.support.command.CommandListener)2 ServiceListener (com.weibo.api.motan.registry.support.command.ServiceListener)2 TransportException (com.weibo.api.motan.transport.TransportException)2 Map (java.util.Map)2 IZkChildListener (org.I0Itec.zkclient.IZkChildListener)2