use of io.netty.buffer.ByteBufAllocator in project neo4j by neo4j.
the class BoltProtocolV1Test method newChannelMock.
private static Channel newChannelMock() {
Channel channel = mock(Channel.class);
ByteBufAllocator allocator = mock(ByteBufAllocator.class, RETURNS_MOCKS);
when(channel.alloc()).thenReturn(allocator);
return channel;
}
use of io.netty.buffer.ByteBufAllocator in project riposte by Nike-Inc.
the class HttpChannelInitializerTest method beforeMethod.
@Before
public void beforeMethod() {
socketChannelMock = mock(SocketChannel.class);
channelPipelineMock = mock(ChannelPipeline.class);
ByteBufAllocator byteBufAllocatorMock = mock(ByteBufAllocator.class);
doReturn(channelPipelineMock).when(socketChannelMock).pipeline();
doReturn(byteBufAllocatorMock).when(socketChannelMock).alloc();
}
use of io.netty.buffer.ByteBufAllocator in project Glowstone by GlowstoneMC.
the class QueryTest method testChannelRead.
private void testChannelRead(QueryHandler handler, byte[] recv, byte[] send) throws Exception {
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
ByteBufAllocator alloc = mock(ByteBufAllocator.class);
when(ctx.alloc()).thenReturn(alloc);
when(alloc.buffer()).thenReturn(Unpooled.buffer());
DatagramPacket packet = new DatagramPacket(Unpooled.wrappedBuffer(recv), null, address);
handler.channelRead(ctx, packet);
verify(ctx).write(argThat(new DatagramPacketMatcher(send)));
}
use of io.netty.buffer.ByteBufAllocator in project spring-framework by spring-projects.
the class RxNettyWebSocketClient method executeInternal.
@SuppressWarnings("cast")
private Observable<Void> executeInternal(URI url, HttpHeaders headers, WebSocketHandler handler) {
String[] protocols = beforeHandshake(url, headers, handler);
return createRequest(url, headers, protocols).flatMap(response -> {
Observable<WebSocketConnection> conn = response.getWebSocketConnection();
return (Observable<Tuple2<WebSocketResponse<ByteBuf>, WebSocketConnection>>) Observable.zip(Observable.just(response), conn, Tuples::of);
}).flatMap(tuple -> {
WebSocketResponse<ByteBuf> response = tuple.getT1();
WebSocketConnection conn = tuple.getT2();
HandshakeInfo info = afterHandshake(url, toHttpHeaders(response));
ByteBufAllocator allocator = response.unsafeNettyChannel().alloc();
NettyDataBufferFactory factory = new NettyDataBufferFactory(allocator);
RxNettyWebSocketSession session = new RxNettyWebSocketSession(conn, info, factory);
session.aggregateFrames(response.unsafeNettyChannel(), WsClientDecoder.getName());
return RxReactiveStreams.toObservable(handler.handle(session));
});
}
use of io.netty.buffer.ByteBufAllocator in project netty by netty.
the class SslHandler method wrap.
// This method will not call setHandshakeFailure(...) !
private void wrap(ChannelHandlerContext ctx, boolean inUnwrap) throws SSLException {
ByteBuf out = null;
ChannelPromise promise = null;
ByteBufAllocator alloc = ctx.alloc();
boolean needUnwrap = false;
try {
// See https://github.com/netty/netty/issues/5860
while (!ctx.isRemoved()) {
Object msg = pendingUnencryptedWrites.current();
if (msg == null) {
break;
}
ByteBuf buf = (ByteBuf) msg;
if (out == null) {
out = allocateOutNetBuf(ctx, buf.readableBytes(), buf.nioBufferCount());
}
SSLEngineResult result = wrap(alloc, engine, buf, out);
if (result.getStatus() == Status.CLOSED) {
// SSLEngine has been closed already.
// Any further write attempts should be denied.
pendingUnencryptedWrites.removeAndFailAll(SSLENGINE_CLOSED);
return;
} else {
if (!buf.isReadable()) {
promise = pendingUnencryptedWrites.remove();
} else {
promise = null;
}
switch(result.getHandshakeStatus()) {
case NEED_TASK:
runDelegatedTasks();
break;
case FINISHED:
setHandshakeSuccess();
// deliberate fall-through
case NOT_HANDSHAKING:
setHandshakeSuccessIfStillHandshaking();
// deliberate fall-through
case NEED_WRAP:
finishWrap(ctx, out, promise, inUnwrap, false);
promise = null;
out = null;
break;
case NEED_UNWRAP:
needUnwrap = true;
return;
default:
throw new IllegalStateException("Unknown handshake status: " + result.getHandshakeStatus());
}
}
}
} finally {
finishWrap(ctx, out, promise, inUnwrap, needUnwrap);
}
}
Aggregations