Search in sources :

Example 11 with MessageHandler

use of com.weibo.api.motan.transport.MessageHandler in project motan by weibocom.

the class NettyEndpointFactoryTest method testNotShareChannel.

private void testNotShareChannel(boolean isServer) {
    NettyEndpointFactory factory = new NettyEndpointFactory();
    MessageHandler handler = new ProviderMessageRouter();
    URL url = new URL("motan", "localhost", 18080, "com.weibo.api.motan.procotol.example.IHello");
    Endpoint endpoint = createEndpoint(url, handler, isServer, factory);
    Assert.assertEquals(endpoint.getUrl().getUri(), url.getUri());
    url = new URL("motan", "localhost", 18081, "com.weibo.api.motan.procotol.example.IHello");
    endpoint = createEndpoint(url, handler, isServer, factory);
    Assert.assertEquals(endpoint.getUrl().getUri(), url.getUri());
    Assert.assertTrue(endpoint != createEndpoint(new URL("motan", "localhost", 18081, "com.weibo.api.motan.procotol.example.IHello"), handler, isServer, factory));
    if (isServer) {
        Assert.assertEquals(factory.getShallServerChannels().size(), 0);
    }
    if (isServer) {
        factory.safeReleaseResource((Server) endpoint, url);
    } else {
        Assert.assertEquals(((HeartbeatClientEndpointManager) factory.getEndpointManager()).getClients().size(), 3);
        factory.safeReleaseResource((Client) endpoint, url);
        Assert.assertEquals(((HeartbeatClientEndpointManager) factory.getEndpointManager()).getClients().size(), 2);
    }
}
Also used : HeartbeatClientEndpointManager(com.weibo.api.motan.transport.support.HeartbeatClientEndpointManager) ProviderMessageRouter(com.weibo.api.motan.transport.ProviderMessageRouter) MessageHandler(com.weibo.api.motan.transport.MessageHandler) Endpoint(com.weibo.api.motan.transport.Endpoint) URL(com.weibo.api.motan.rpc.URL)

Aggregations

MessageHandler (com.weibo.api.motan.transport.MessageHandler)11 Channel (com.weibo.api.motan.transport.Channel)9 Test (org.junit.Test)6 DefaultRequest (com.weibo.api.motan.rpc.DefaultRequest)3 DefaultResponse (com.weibo.api.motan.rpc.DefaultResponse)3 Request (com.weibo.api.motan.rpc.Request)3 URL (com.weibo.api.motan.rpc.URL)2 Endpoint (com.weibo.api.motan.transport.Endpoint)2 ProviderMessageRouter (com.weibo.api.motan.transport.ProviderMessageRouter)2 HeartbeatClientEndpointManager (com.weibo.api.motan.transport.support.HeartbeatClientEndpointManager)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)2 HashMap (java.util.HashMap)2 Expectations (org.jmock.Expectations)2 Invocation (org.jmock.api.Invocation)2 CustomAction (org.jmock.lib.action.CustomAction)2 MotanFrameworkException (com.weibo.api.motan.exception.MotanFrameworkException)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 HashSet (java.util.HashSet)1 ClientBootstrap (org.jboss.netty.bootstrap.ClientBootstrap)1 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)1