use of org.apache.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class HeaderExchangeHandlerTest method test_received_request_event_other_discard.
@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 {
Assertions.fail();
}
};
HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(new MockedExchangeHandler() {
@Override
public CompletableFuture<Object> reply(ExchangeChannel channel, Object request) throws RemotingException {
Assertions.fail();
throw new RemotingException(channel, "");
}
@Override
public void received(Channel channel, Object message) throws RemotingException {
Assertions.fail();
throw new RemotingException(channel, "");
}
});
hexhandler.received(mchannel, request);
}
use of org.apache.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class DeprecatedExchangeCodec method getRequestData.
protected Object getRequestData(long id) {
DefaultFuture future = DefaultFuture.getFuture(id);
if (future == null)
return null;
Request req = future.getRequest();
if (req == null)
return null;
return req.getData();
}
use of org.apache.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class ThriftCodecTest method testEncodeReplyResponse.
@Test
public void testEncodeReplyResponse() throws Exception {
int port = NetUtils.getAvailablePort();
URL url = URL.valueOf(ThriftProtocol.NAME + "://127.0.0.1:" + port + "/" + Demo.Iface.class.getName());
Channel channel = new MockedChannel(url);
Request request = createRequest();
AppResponse appResponse = new AppResponse();
appResponse.setValue("Hello, World!");
Response response = new Response();
response.setResult(appResponse);
response.setId(request.getId());
ChannelBuffer bos = ChannelBuffers.dynamicBuffer(1024);
ThriftCodec.RequestData rd = ThriftCodec.RequestData.create(ThriftCodec.getSeqId(), Demo.Iface.class.getName(), "echoString");
ThriftCodec.CACHED_REQUEST.putIfAbsent(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);
Assertions.assertEquals(ThriftCodec.MAGIC, protocol.readI16());
Assertions.assertEquals(protocol.readI32() + 4, bos.writerIndex());
int headerLength = protocol.readI16();
Assertions.assertEquals(ThriftCodec.VERSION, protocol.readByte());
Assertions.assertEquals(Demo.Iface.class.getName(), protocol.readString());
Assertions.assertEquals(request.getId(), protocol.readI64());
if (bis.markSupported()) {
bis.reset();
bis.skip(headerLength);
}
TMessage message = protocol.readMessageBegin();
Assertions.assertEquals("echoString", message.name);
Assertions.assertEquals(TMessageType.REPLY, message.type);
// Assertions.assertEquals(ThriftCodec.getSeqId(), message.seqid);
Demo.echoString_result result = new Demo.echoString_result();
result.read(protocol);
protocol.readMessageEnd();
Assertions.assertEquals(appResponse.getValue(), result.getSuccess());
}
use of org.apache.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class ThriftCodecTest method testDecodeRequest.
@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(INTERFACE_KEY));
protocol.writeString(((RpcInvocation) request.getData()).getAttachment(PATH_KEY));
protocol.writeI64(request.getId());
protocol.getTransport().flush();
headerLength = bos.size();
Demo.echoString_args args = new Demo.echoString_args();
args.setArg("Hell, World!");
TMessage message = new TMessage("echoString", TMessageType.CALL, ThriftCodec.getSeqId());
protocol.writeMessageBegin(message);
args.write(protocol);
protocol.writeMessageEnd();
protocol.getTransport().flush();
int oldIndex = messageLength = bos.size();
try {
bos.setWriteIndex(ThriftCodec.MESSAGE_HEADER_LENGTH_INDEX);
protocol.writeI16((short) (0xffff & headerLength));
bos.setWriteIndex(ThriftCodec.MESSAGE_LENGTH_INDEX);
protocol.writeI32(messageLength);
} finally {
bos.setWriteIndex(oldIndex);
}
Object obj = codec.decode((Channel) null, ChannelBuffers.wrappedBuffer(encodeFrame(bos.toByteArray())));
Assertions.assertTrue(obj instanceof Request);
obj = ((Request) obj).getData();
Assertions.assertTrue(obj instanceof RpcInvocation);
RpcInvocation invocation = (RpcInvocation) obj;
Assertions.assertEquals("echoString", invocation.getMethodName());
Assertions.assertArrayEquals(new Class[] { String.class }, invocation.getParameterTypes());
Assertions.assertArrayEquals(new Object[] { args.getArg() }, invocation.getArguments());
}
use of org.apache.dubbo.remoting.exchange.Request in project dubbo by alibaba.
the class ThriftCodecTest method createRequest.
private Request createRequest() {
RpcInvocation invocation = new RpcInvocation();
invocation.setMethodName("echoString");
invocation.setArguments(new Object[] { "Hello, World!" });
invocation.setParameterTypes(new Class<?>[] { String.class });
invocation.setAttachment(INTERFACE_KEY, Demo.Iface.class.getName());
invocation.setAttachment(PATH_KEY, Demo.Iface.class.getName());
Request request = new Request(1L);
request.setData(invocation);
return request;
}
Aggregations