Search in sources :

Example 6 with Request

use of org.apache.dubbo.remoting.exchange.Request in project dubbo by alibaba.

the class ExchangeCodecTest method test_Decode_Return_Request_Event_String.

@Test
public void test_Decode_Return_Request_Event_String() throws IOException {
    // |10011111|20-stats=ok|id=0|length=0
    byte[] header = new byte[] { MAGIC_HIGH, MAGIC_LOW, (byte) 0xe2, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    String event = READONLY_EVENT;
    byte[] request = getRequestBytes(event, header);
    Request obj = (Request) decode(request);
    Assertions.assertEquals(event, obj.getData());
    Assertions.assertTrue(obj.isTwoWay());
    Assertions.assertTrue(obj.isEvent());
    Assertions.assertEquals(Version.getProtocolVersion(), obj.getVersion());
    System.out.println(obj);
}
Also used : Request(org.apache.dubbo.remoting.exchange.Request) Test(org.junit.jupiter.api.Test)

Example 7 with Request

use of org.apache.dubbo.remoting.exchange.Request in project dubbo by alibaba.

the class ExchangeCodecTest method testMessageLengthExceedPayloadLimitWhenEncode.

@Test
public void testMessageLengthExceedPayloadLimitWhenEncode() throws Exception {
    Request request = new Request(1L);
    request.setData("hello");
    ChannelBuffer encodeBuffer = ChannelBuffers.dynamicBuffer(512);
    AbstractMockChannel channel = getCliendSideChannel(url.addParameter(Constants.PAYLOAD_KEY, 4));
    try {
        codec.encode(channel, encodeBuffer, request);
        Assertions.fail();
    } catch (IOException e) {
        Assertions.assertTrue(e.getMessage().startsWith("Data length too large: " + 6));
    }
    Response response = new Response(1L);
    response.setResult("hello");
    encodeBuffer = ChannelBuffers.dynamicBuffer(512);
    channel = getServerSideChannel(url.addParameter(Constants.PAYLOAD_KEY, 4));
    codec.encode(channel, encodeBuffer, response);
    Assertions.assertTrue(channel.getReceivedMessage() instanceof Response);
    Response receiveMessage = (Response) channel.getReceivedMessage();
    Assertions.assertEquals(Response.BAD_RESPONSE, receiveMessage.getStatus());
    Assertions.assertTrue(receiveMessage.getErrorMessage().contains("Data length too large: "));
}
Also used : Response(org.apache.dubbo.remoting.exchange.Response) Request(org.apache.dubbo.remoting.exchange.Request) IOException(java.io.IOException) ChannelBuffer(org.apache.dubbo.remoting.buffer.ChannelBuffer) Test(org.junit.jupiter.api.Test)

Example 8 with Request

use of org.apache.dubbo.remoting.exchange.Request in project dubbo by alibaba.

the class HeaderExchangeChannelTest method closeWithTimeoutTest02.

@Test
public void closeWithTimeoutTest02() {
    Assertions.assertFalse(channel.isClosed());
    Request request = new Request();
    DefaultFuture.newFuture(channel, request, 100, null);
    header.close(100);
    // return directly
    header.close(1000);
}
Also used : Request(org.apache.dubbo.remoting.exchange.Request) Test(org.junit.jupiter.api.Test)

Example 9 with Request

use of org.apache.dubbo.remoting.exchange.Request in project dubbo by alibaba.

the class HeaderExchangeChannelTest method sendTest02.

@Test
public void sendTest02() throws RemotingException {
    boolean sent = true;
    int message = 1;
    header.send(message, sent);
    List<Object> objects = channel.getSentObjects();
    Assertions.assertEquals(objects.get(0).getClass(), Request.class);
    Request request = (Request) objects.get(0);
    Assertions.assertEquals(request.getVersion(), "2.0.2");
}
Also used : Request(org.apache.dubbo.remoting.exchange.Request) Test(org.junit.jupiter.api.Test)

Example 10 with Request

use of org.apache.dubbo.remoting.exchange.Request 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

Request (org.apache.dubbo.remoting.exchange.Request)51 Test (org.junit.jupiter.api.Test)30 Response (org.apache.dubbo.remoting.exchange.Response)21 Channel (org.apache.dubbo.remoting.Channel)18 ExchangeChannel (org.apache.dubbo.remoting.exchange.ExchangeChannel)10 ChannelBuffer (org.apache.dubbo.remoting.buffer.ChannelBuffer)9 RemotingException (org.apache.dubbo.remoting.RemotingException)7 TMessage (org.apache.thrift.protocol.TMessage)7 HeaderExchangeHandler (org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler)6 AppResponse (org.apache.dubbo.rpc.AppResponse)6 Demo (org.apache.dubbo.rpc.gen.thrift.Demo)6 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)6 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 DefaultFuture (org.apache.dubbo.remoting.exchange.support.DefaultFuture)5 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 URL (org.apache.dubbo.common.URL)4 MockedChannel (org.apache.dubbo.remoting.handler.MockedChannel)4 IOException (java.io.IOException)3