Search in sources :

Example 1 with NioBuffer

use of com.baidu.hugegraph.computer.core.network.buffer.NioBuffer in project hugegraph-computer by hugegraph.

the class NettyEncodeDecodeHandlerTest method testSendMsgWithEncoderExceptionMock.

@Test
public void testSendMsgWithEncoderExceptionMock() throws IOException {
    NettyTransportClient client = (NettyTransportClient) this.oneClient();
    client.startSession();
    int requestId = 1;
    int partition = 1;
    byte[] bytes = StringEncoding.encode("mock msg");
    ByteBuffer buffer = ByteBuffer.wrap(bytes);
    NetworkBuffer body = new NioBuffer(buffer);
    DataMessage dataMessage = new DataMessage(null, requestId, partition, body);
    ChannelFutureListenerOnWrite listener = new ChannelFutureListenerOnWrite(clientHandler);
    ChannelFutureListenerOnWrite spyListener = Mockito.spy(listener);
    client.channel().writeAndFlush(dataMessage).addListener(spyListener);
    Mockito.verify(clientHandler, Mockito.timeout(3000L).times(1)).onChannelActive(Mockito.any());
    Mockito.verify(clientHandler, Mockito.timeout(3000L).times(1)).exceptionCaught(Mockito.any(), Mockito.any());
    Mockito.verify(spyListener, Mockito.timeout(3000L).times(1)).onFailure(Mockito.any(), Mockito.any());
}
Also used : DataMessage(com.baidu.hugegraph.computer.core.network.message.DataMessage) NetworkBuffer(com.baidu.hugegraph.computer.core.network.buffer.NetworkBuffer) ByteBuffer(java.nio.ByteBuffer) NioBuffer(com.baidu.hugegraph.computer.core.network.buffer.NioBuffer) Test(org.junit.Test)

Example 2 with NioBuffer

use of com.baidu.hugegraph.computer.core.network.buffer.NioBuffer in project hugegraph-computer by hugegraph.

the class ClientSession method sendAsync.

public synchronized void sendAsync(MessageType messageType, int partition, ByteBuffer buffer) {
    E.checkArgument(this.state == TransportState.ESTABLISHED, "The state must be ESTABLISHED instead of %s " + "at sendAsync()", this.state);
    int requestId = this.nextRequestId();
    NetworkBuffer networkBuffer = new NioBuffer(buffer);
    DataMessage dataMessage = new DataMessage(messageType, requestId, partition, networkBuffer);
    this.sendFunction.apply(dataMessage);
    this.updateFlowBlocking();
}
Also used : DataMessage(com.baidu.hugegraph.computer.core.network.message.DataMessage) NetworkBuffer(com.baidu.hugegraph.computer.core.network.buffer.NetworkBuffer) NioBuffer(com.baidu.hugegraph.computer.core.network.buffer.NioBuffer)

Aggregations

NetworkBuffer (com.baidu.hugegraph.computer.core.network.buffer.NetworkBuffer)2 NioBuffer (com.baidu.hugegraph.computer.core.network.buffer.NioBuffer)2 DataMessage (com.baidu.hugegraph.computer.core.network.message.DataMessage)2 ByteBuffer (java.nio.ByteBuffer)1 Test (org.junit.Test)1