Search in sources :

Example 1 with ExchangeHandler

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

Example 2 with ExchangeHandler

use of org.apache.dubbo.remoting.exchange.ExchangeHandler 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;
            Assertions.assertEquals(request.getId(), res.getId());
            Assertions.assertEquals(request.getVersion(), res.getVersion());
            Assertions.assertEquals(Response.OK, res.getStatus());
            Assertions.assertEquals(requestdata, res.getResult());
            Assertions.assertNull(res.getErrorMessage());
            count.incrementAndGet();
        }
    };
    ExchangeHandler exhandler = new MockedExchangeHandler() {

        @Override
        public CompletableFuture<Object> reply(ExchangeChannel channel, Object request) throws RemotingException {
            return CompletableFuture.completedFuture(request);
        }

        @Override
        public void received(Channel channel, Object message) throws RemotingException {
            Assertions.fail();
        }
    };
    HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(exhandler);
    hexhandler.received(mchannel, request);
    Assertions.assertEquals(1, count.get());
}
Also used : Response(org.apache.dubbo.remoting.exchange.Response) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) ExchangeChannel(org.apache.dubbo.remoting.exchange.ExchangeChannel) HeaderExchangeHandler(org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler) ExchangeHandler(org.apache.dubbo.remoting.exchange.ExchangeHandler) Test(org.junit.jupiter.api.Test)

Example 3 with ExchangeHandler

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

the class HeaderExchangeHandlerTest method test_received_request_twoway_error_reply.

@Test
public void test_received_request_twoway_error_reply() 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;
            Assertions.assertEquals(request.getId(), res.getId());
            Assertions.assertEquals(request.getVersion(), res.getVersion());
            Assertions.assertEquals(Response.SERVICE_ERROR, res.getStatus());
            Assertions.assertNull(res.getResult());
            Assertions.assertTrue(res.getErrorMessage().contains(BizException.class.getName()));
            count.incrementAndGet();
        }
    };
    ExchangeHandler exhandler = new MockedExchangeHandler() {

        @Override
        public CompletableFuture<Object> reply(ExchangeChannel channel, Object request) throws RemotingException {
            throw new BizException();
        }
    };
    HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(exhandler);
    hexhandler.received(mchannel, request);
    Assertions.assertEquals(1, count.get());
}
Also used : Response(org.apache.dubbo.remoting.exchange.Response) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) ExchangeChannel(org.apache.dubbo.remoting.exchange.ExchangeChannel) 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)3 ExchangeChannel (org.apache.dubbo.remoting.exchange.ExchangeChannel)3 ExchangeHandler (org.apache.dubbo.remoting.exchange.ExchangeHandler)3 Request (org.apache.dubbo.remoting.exchange.Request)3 HeaderExchangeHandler (org.apache.dubbo.remoting.exchange.support.header.HeaderExchangeHandler)3 Test (org.junit.jupiter.api.Test)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Response (org.apache.dubbo.remoting.exchange.Response)2