Search in sources :

Example 1 with Channel

use of org.apache.dubbo.remoting.Channel in project dubbo by alibaba.

the class TelnetCodecTest method testEecode_assertEquals.

protected void testEecode_assertEquals(Object request, byte[] ret, boolean isServerside) throws IOException {
    // init channel
    Channel channel = isServerside ? getServerSideChannel(url) : getCliendSideChannel(url);
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(1024);
    codec.encode(channel, buffer, request);
    byte[] data = new byte[buffer.readableBytes()];
    buffer.readBytes(data);
    Assertions.assertEquals(ret.length, data.length);
    for (int i = 0; i < ret.length; i++) {
        if (ret[i] != data[i]) {
            Assertions.fail();
        }
    }
}
Also used : Channel(org.apache.dubbo.remoting.Channel) ChannelBuffer(org.apache.dubbo.remoting.buffer.ChannelBuffer)

Example 2 with Channel

use of org.apache.dubbo.remoting.Channel in project dubbo by alibaba.

the class TelnetCodecTest method testDecode_PersonWithEnterByte.

private void testDecode_PersonWithEnterByte(byte[] enterbytes, boolean isNeedmore) throws IOException {
    // init channel
    Channel channel = getServerSideChannel(url);
    // init request string
    Person request = new Person();
    byte[] newbuf = join(objectToByte(request), enterbytes);
    ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(newbuf);
    // decode
    Object obj = codec.decode(channel, buffer);
    if (isNeedmore) {
        Assertions.assertEquals(Codec2.DecodeResult.NEED_MORE_INPUT, obj);
    } else {
        Assertions.assertTrue(obj instanceof String, "return must string ");
    }
}
Also used : Channel(org.apache.dubbo.remoting.Channel) ChannelBuffer(org.apache.dubbo.remoting.buffer.ChannelBuffer)

Example 3 with Channel

use of org.apache.dubbo.remoting.Channel in project dubbo by alibaba.

the class TelnetCodecTest method testDecode_assertEquals.

protected void testDecode_assertEquals(byte[] request, Object ret, boolean isServerside) throws IOException {
    // init channel
    Channel channel = isServerside ? getServerSideChannel(url) : getCliendSideChannel(url);
    // init request string
    ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(request);
    // decode
    Object obj = codec.decode(channel, buffer);
    Assertions.assertEquals(ret, obj);
}
Also used : Channel(org.apache.dubbo.remoting.Channel) ChannelBuffer(org.apache.dubbo.remoting.buffer.ChannelBuffer)

Example 4 with Channel

use of org.apache.dubbo.remoting.Channel in project dubbo by alibaba.

the class ExchangeCodecTest method test_Encode_Error_Response.

@Test
public void test_Encode_Error_Response() throws IOException {
    ChannelBuffer encodeBuffer = ChannelBuffers.dynamicBuffer(1024);
    Channel channel = getCliendSideChannel(url);
    Response response = new Response();
    response.setHeartbeat(true);
    response.setId(1001L);
    response.setStatus((byte) 10);
    response.setVersion("11");
    String badString = "bad";
    response.setErrorMessage(badString);
    Person person = new Person();
    response.setResult(person);
    codec.encode(channel, encodeBuffer, response);
    byte[] data = new byte[encodeBuffer.writerIndex()];
    encodeBuffer.readBytes(data);
    // encode resault check need decode
    ChannelBuffer decodeBuffer = ChannelBuffers.wrappedBuffer(data);
    Response obj = (Response) codec.decode(channel, decodeBuffer);
    Assertions.assertEquals(response.getId(), obj.getId());
    Assertions.assertEquals(response.getStatus(), obj.getStatus());
    Assertions.assertEquals(response.isHeartbeat(), obj.isHeartbeat());
    Assertions.assertEquals(badString, obj.getErrorMessage());
    Assertions.assertNull(obj.getResult());
// Assertions.assertEquals(response.getProtocolVersion(), obj.getVersion());
}
Also used : Response(org.apache.dubbo.remoting.exchange.Response) Channel(org.apache.dubbo.remoting.Channel) ChannelBuffer(org.apache.dubbo.remoting.buffer.ChannelBuffer) Test(org.junit.jupiter.api.Test)

Example 5 with Channel

use of org.apache.dubbo.remoting.Channel in project dubbo by alibaba.

the class HeaderExchangeHandlerTest method test_received_request_oneway.

@Test
public void test_received_request_oneway() throws RemotingException {
    final Channel mchannel = new MockedChannel();
    final Person requestdata = new Person("charles");
    Request request = new Request();
    request.setTwoWay(false);
    request.setData(requestdata);
    ExchangeHandler exhandler = new MockedExchangeHandler() {

        @Override
        public void received(Channel channel, Object message) throws RemotingException {
            Assertions.assertEquals(requestdata, message);
        }
    };
    HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(exhandler);
    hexhandler.received(mchannel, request);
}
Also used : ExchangeChannel(org.apache.dubbo.remoting.exchange.ExchangeChannel) Channel(org.apache.dubbo.remoting.Channel) HeaderExchangeHandler(org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler) Request(org.apache.dubbo.remoting.exchange.Request) HeaderExchangeHandler(org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler) ExchangeHandler(org.apache.dubbo.remoting.exchange.ExchangeHandler) Test(org.junit.jupiter.api.Test)

Aggregations

Channel (org.apache.dubbo.remoting.Channel)53 Test (org.junit.jupiter.api.Test)32 Request (org.apache.dubbo.remoting.exchange.Request)18 ChannelBuffer (org.apache.dubbo.remoting.buffer.ChannelBuffer)16 Response (org.apache.dubbo.remoting.exchange.Response)12 ExchangeChannel (org.apache.dubbo.remoting.exchange.ExchangeChannel)9 URL (org.apache.dubbo.common.URL)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 HeaderExchangeHandler (org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler)6 RemotingException (org.apache.dubbo.remoting.RemotingException)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 ExchangeHandler (org.apache.dubbo.remoting.exchange.ExchangeHandler)4 MockedChannel (org.apache.dubbo.remoting.handler.MockedChannel)4 AppResponse (org.apache.dubbo.rpc.AppResponse)4 Demo (org.apache.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 IOException (java.io.IOException)3