Search in sources :

Example 6 with Channel

use of com.alibaba.dubbo.remoting.Channel in project dubbo by alibaba.

the class HeaderExchangeHandlerTest method test_received_request_twoway_error_reqeustBroken.

@Test
public void test_received_request_twoway_error_reqeustBroken() throws RemotingException {
    final Request request = new Request();
    request.setTwoWay(true);
    request.setData(new BizException());
    request.setBroken(true);
    final AtomicInteger count = new AtomicInteger(0);
    final Channel mchannel = new MockedChannel() {

        @Override
        public void send(Object message) throws RemotingException {
            Response res = (Response) message;
            Assert.assertEquals(request.getId(), res.getId());
            Assert.assertEquals(request.getVersion(), res.getVersion());
            Assert.assertEquals(Response.BAD_REQUEST, res.getStatus());
            Assert.assertNull(res.getResult());
            Assert.assertTrue(res.getErrorMessage().contains(BizException.class.getName()));
            count.incrementAndGet();
        }
    };
    HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(new MockedExchangeHandler());
    hexhandler.received(mchannel, request);
    Assert.assertEquals(1, count.get());
}
Also used : Response(com.alibaba.dubbo.remoting.exchange.Response) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel) Channel(com.alibaba.dubbo.remoting.Channel) HeaderExchangeHandler(com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler) Request(com.alibaba.dubbo.remoting.exchange.Request) Test(org.junit.Test)

Example 7 with Channel

use of com.alibaba.dubbo.remoting.Channel in project dubbo by alibaba.

the class HeaderExchangeHandlerTest method test_received_request_twoway.

@Test
public void test_received_request_twoway() throws RemotingException {
    final Person requestdata = new Person("charles");
    final Request request = new Request();
    request.setTwoWay(true);
    request.setData(requestdata);
    final AtomicInteger count = new AtomicInteger(0);
    final Channel mchannel = new MockedChannel() {

        @Override
        public void send(Object message) throws RemotingException {
            Response res = (Response) message;
            Assert.assertEquals(request.getId(), res.getId());
            Assert.assertEquals(request.getVersion(), res.getVersion());
            Assert.assertEquals(Response.OK, res.getStatus());
            Assert.assertEquals(requestdata, res.getResult());
            Assert.assertEquals(null, res.getErrorMessage());
            count.incrementAndGet();
        }
    };
    ExchangeHandler exhandler = new MockedExchangeHandler() {

        @Override
        public Object reply(ExchangeChannel channel, Object request) throws RemotingException {
            return request;
        }

        public void received(Channel channel, Object message) throws RemotingException {
            Assert.fail();
        }
    };
    HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(exhandler);
    hexhandler.received(mchannel, request);
    Assert.assertEquals(1, count.get());
}
Also used : Response(com.alibaba.dubbo.remoting.exchange.Response) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel) Channel(com.alibaba.dubbo.remoting.Channel) HeaderExchangeHandler(com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler) Request(com.alibaba.dubbo.remoting.exchange.Request) ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel) HeaderExchangeHandler(com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler) ExchangeHandler(com.alibaba.dubbo.remoting.exchange.ExchangeHandler) Test(org.junit.Test)

Example 8 with Channel

use of com.alibaba.dubbo.remoting.Channel in project dubbo by alibaba.

the class AbstractCodecTest method test_checkPayload_default8M.

public void test_checkPayload_default8M() throws Exception {
    Channel channel = createMock(Channel.class);
    expect(channel.getUrl()).andReturn(URL.valueOf("dubbo://1.1.1.1")).anyTimes();
    replay(channel);
    AbstractCodec.checkPayload(channel, 1 * 1024 * 1024);
    try {
        AbstractCodec.checkPayload(channel, 15 * 1024 * 1024);
    } catch (IOException expected) {
        assertThat(expected.getMessage(), allOf(containsString("Data length too large: "), containsString("max payload: " + 8 * 1024 * 1024)));
    }
    verify(channel);
}
Also used : Channel(com.alibaba.dubbo.remoting.Channel) IOException(java.io.IOException)

Example 9 with Channel

use of com.alibaba.dubbo.remoting.Channel in project dubbo by alibaba.

the class MinaServer method getChannels.

public Collection<Channel> getChannels() {
    Set<IoSession> sessions = acceptor.getManagedSessions(getBindAddress());
    Collection<Channel> channels = new HashSet<Channel>();
    for (IoSession session : sessions) {
        if (session.isConnected()) {
            channels.add(MinaChannel.getOrAddChannel(session, getUrl(), this));
        }
    }
    return channels;
}
Also used : Channel(com.alibaba.dubbo.remoting.Channel) IoSession(org.apache.mina.common.IoSession) HashSet(java.util.HashSet)

Example 10 with Channel

use of com.alibaba.dubbo.remoting.Channel in project dubbo by alibaba.

the class AbstractClient method send.

public void send(Object message, boolean sent) throws RemotingException {
    if (send_reconnect && !isConnected()) {
        connect();
    }
    Channel channel = getChannel();
    //TODO getChannel返回的状态是否包含null需要改进
    if (channel == null || !channel.isConnected()) {
        throw new RemotingException(this, "message can not send, because channel is closed . url:" + getUrl());
    }
    channel.send(message, sent);
}
Also used : Channel(com.alibaba.dubbo.remoting.Channel) RemotingException(com.alibaba.dubbo.remoting.RemotingException)

Aggregations

Channel (com.alibaba.dubbo.remoting.Channel)34 Test (org.junit.Test)16 ChannelBuffer (com.alibaba.dubbo.remoting.buffer.ChannelBuffer)15 Request (com.alibaba.dubbo.remoting.exchange.Request)14 Response (com.alibaba.dubbo.remoting.exchange.Response)10 ExchangeChannel (com.alibaba.dubbo.remoting.exchange.ExchangeChannel)8 HeaderExchangeHandler (com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler)6 URL (com.alibaba.dubbo.common.URL)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 RemotingException (com.alibaba.dubbo.remoting.RemotingException)4 RpcResult (com.alibaba.dubbo.rpc.RpcResult)4 Demo (com.alibaba.dubbo.rpc.gen.thrift.Demo)4 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)4 TMessage (org.apache.thrift.protocol.TMessage)4 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)4 ExchangeHandler (com.alibaba.dubbo.remoting.exchange.ExchangeHandler)3 Client (com.alibaba.dubbo.remoting.Client)2 DefaultFuture (com.alibaba.dubbo.remoting.exchange.support.DefaultFuture)2 RandomAccessByteArrayOutputStream (com.alibaba.dubbo.rpc.protocol.thrift.io.RandomAccessByteArrayOutputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2