Package com.alibaba.dubbo.remoting.exchange

Examples of com.alibaba.dubbo.remoting.exchange.Request


        URL url = URL.valueOf( ThriftProtocol.NAME + "://127.0.0.1:40880/" + Demo.Iface.class.getName() );

        Channel channel = new MockedChannel( url );

        Request request = createRequest();

        RpcResult rpcResult = new RpcResult();
        String exceptionMessage = "failed";
        rpcResult.setException( new RuntimeException( exceptionMessage ) );

        Response response = new Response();
        response.setResult( rpcResult );
        response.setId( request.getId() );
        ChannelBuffer bos = ChannelBuffers.dynamicBuffer(1024);

        ThriftCodec.RequestData rd = ThriftCodec.RequestData.create(
                ThriftCodec.getSeqId(), Demo.Iface.class.getName(), "echoString" );
        ThriftCodec.cachedRequest.put( request.getId(), rd );
        codec.encode( channel, bos, response );

        byte[] buf = new byte[bos.writerIndex() - 4];
        System.arraycopy( bos.array(), 4, buf, 0, bos.writerIndex() - 4 );
        ByteArrayInputStream bis = new ByteArrayInputStream( buf);

        if ( bis.markSupported() ) {
            bis.mark( 0 );
        }

        TIOStreamTransport transport = new TIOStreamTransport( bis );
        TBinaryProtocol protocol = new TBinaryProtocol( transport );

        Assert.assertEquals( ThriftCodec.MAGIC, protocol.readI16() );
        Assert.assertEquals( protocol.readI32() + 4, bos.writerIndex() );
        int headerLength = protocol.readI16();

        Assert.assertEquals( ThriftCodec.VERSION, protocol.readByte() );
        Assert.assertEquals( Demo.Iface.class.getName(), protocol.readString() );
        Assert.assertEquals( request.getId(), protocol.readI64() );

        if ( bis.markSupported() ) {
            bis.reset();
            bis.skip( headerLength );
        }
View Full Code Here


    }

    @Test
    public void testDecodeRequest() throws Exception {
        Request request = createRequest();
        // encode
        RandomAccessByteArrayOutputStream bos = new RandomAccessByteArrayOutputStream( 1024 );

        TIOStreamTransport transport = new TIOStreamTransport( bos );

        TBinaryProtocol protocol = new TBinaryProtocol( transport );

        int messageLength, headerLength;

        protocol.writeI16( ThriftCodec.MAGIC );
        protocol.writeI32( Integer.MAX_VALUE );
        protocol.writeI16( Short.MAX_VALUE );
        protocol.writeByte( ThriftCodec.VERSION );
        protocol.writeString(
                ( ( RpcInvocation ) request.getData() )
                        .getAttachment( Constants.INTERFACE_KEY) );
        protocol.writeI64( request.getId() );
        protocol.getTransport().flush();
        headerLength = bos.size();

        Demo.echoString_args args = new Demo.echoString_args(  );
        args.setArg( "Hell, World!" );
View Full Code Here

        invocation.setParameterTypes( new Class<?>[]{ String.class } );

        invocation.setAttachment( Constants.INTERFACE_KEY, Demo.Iface.class.getName() );

        Request request = new Request( 1L );

        request.setData( invocation );

        return request;

    }
View Full Code Here

        handler = new ConnectionOrderedChannelHandler(new BizChannelHander(false), url);
        ThreadPoolExecutor executor = (ThreadPoolExecutor)getField(handler, "SHARED_EXECUTOR", 1);
        executor.shutdown();
        executor = (ThreadPoolExecutor)getField(handler, "executor", 1);
        executor.shutdown();
        Request req = new Request();
        req.setHeartbeat(true);
        final AtomicInteger count = new AtomicInteger(0);
        handler.received(new MockedChannel(){
            @Override
            public void send(Object message) throws RemotingException {
                Assert.assertEquals("response.heartbeat", true, ((Response)message).isHeartbeat());
View Full Code Here

    @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(){
            public void received(Channel channel, Object message) throws RemotingException {
                Assert.assertEquals(requestdata, message);
            }
View Full Code Here

    }
   
    @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();
            }
View Full Code Here

        new HeaderExchangeHandler(null);
    }
    @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;
                Assert.assertEquals(request.getId(), res.getId());
                Assert.assertEquals(request.getVersion(), res.getVersion());
                Assert.assertEquals(Response.SERVICE_ERROR, res.getStatus());
                Assert.assertNull(res.getResult());
                Assert.assertTrue(res.getErrorMessage().contains(BizException.class.getName()));
                count.incrementAndGet();
            }
View Full Code Here

        Assert.assertEquals(1, count.get());
    }
   
    @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();
            }
View Full Code Here

        Assert.assertEquals(1, count.get());
    }
   
    @Test
    public void test_received_request_event_readonly() throws RemotingException{
        final Request request = new Request();
        request.setTwoWay(true);
        request.setEvent(Request.READONLY_EVENT);
       
        final Channel mchannel = new MockedChannel();
        HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(new MockedExchangeHandler());
        hexhandler.received(mchannel, request);
        Assert.assertTrue(mchannel.hasAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY));
View Full Code Here

        Assert.assertTrue(mchannel.hasAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY));
    }
   
    @Test
    public void test_received_request_event_other_discard() throws RemotingException{
        final Request request = new Request();
        request.setTwoWay(true);
        request.setEvent("my event");
       
        final Channel mchannel = new MockedChannel(){
            @Override
            public void send(Object message) throws RemotingException {
                Assert.fail();
View Full Code Here

TOP

Related Classes of com.alibaba.dubbo.remoting.exchange.Request

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.