use of io.netty.channel.Channel in project neo4j by neo4j.
the class FragmentedMessageDeliveryTest method testPermutation.
private void testPermutation(byte[] unfragmented, ByteBuf[] fragments) throws Exception {
// Given
BoltStateMachine machine = mock(BoltStateMachine.class);
Channel ch = mock(Channel.class);
when(ch.alloc()).thenReturn(UnpooledByteBufAllocator.DEFAULT);
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
when(ctx.channel()).thenReturn(ch);
BoltProtocolV1 protocol = new BoltProtocolV1(new SynchronousBoltWorker(machine), ch, NullLogService.getInstance());
// When data arrives split up according to the current permutation
for (ByteBuf fragment : fragments) {
fragment.readerIndex(0).retain();
protocol.handle(ctx, fragment);
}
// Then the session should've received the specified messages, and the protocol should be in a nice clean state
try {
verify(machine).run(eq("Mjölnir"), anyMapOf(String.class, Object.class), any(BoltResponseHandler.class));
} catch (AssertionError e) {
throw new AssertionError("Failed to handle fragmented delivery.\n" + "Messages: " + Arrays.toString(messages) + "\n" + "Chunk size: " + chunkSize + "\n" + "Serialized data delivered in fragments: " + describeFragments(fragments) + "\n" + "Unfragmented data: " + HexPrinter.hex(unfragmented) + "\n", e);
} finally {
// To avoid buffer leak errors
protocol.close();
}
}
use of io.netty.channel.Channel in project neo4j by neo4j.
the class SocketTransportHandlerTest method channelHandlerContextMock.
private static ChannelHandlerContext channelHandlerContextMock() {
Channel channel = mock(Channel.class);
ChannelHandlerContext context = mock(ChannelHandlerContext.class);
when(context.channel()).thenReturn(channel);
when(channel.alloc()).thenReturn(UnpooledByteBufAllocator.DEFAULT);
when(context.alloc()).thenReturn(UnpooledByteBufAllocator.DEFAULT);
return context;
}
use of io.netty.channel.Channel in project jersey by jersey.
the class App method main.
public static void main(String[] args) {
try {
System.out.println("\"Hello World\" Jersey Example App on Netty container.");
ResourceConfig resourceConfig = new ResourceConfig(HelloWorldResource.class);
final Channel server = NettyHttpContainerProvider.createHttp2Server(BASE_URI, resourceConfig, null);
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
server.close();
}
}));
System.out.println(String.format("Application started. (HTTP/2 enabled!)\nTry out %s%s\nStop the application using " + "CTRL+C.", BASE_URI, ROOT_PATH));
Thread.currentThread().join();
} catch (InterruptedException ex) {
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
}
}
use of io.netty.channel.Channel in project netty by netty.
the class SocketSslGreetingTest method testSslGreeting.
public void testSslGreeting(ServerBootstrap sb, Bootstrap cb) throws Throwable {
final ServerHandler sh = new ServerHandler();
final ClientHandler ch = new ClientHandler();
sb.childHandler(new ChannelInitializer<Channel>() {
@Override
public void initChannel(Channel sch) throws Exception {
ChannelPipeline p = sch.pipeline();
p.addLast(serverCtx.newHandler(sch.alloc()));
p.addLast(new LoggingHandler(LOG_LEVEL));
p.addLast(sh);
}
});
cb.handler(new ChannelInitializer<Channel>() {
@Override
public void initChannel(Channel sch) throws Exception {
ChannelPipeline p = sch.pipeline();
p.addLast(clientCtx.newHandler(sch.alloc()));
p.addLast(new LoggingHandler(LOG_LEVEL));
p.addLast(ch);
}
});
Channel sc = sb.bind().sync().channel();
Channel cc = cb.connect().sync().channel();
ch.latch.await();
sh.channel.close().awaitUninterruptibly();
cc.close().awaitUninterruptibly();
sc.close().awaitUninterruptibly();
if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) {
throw sh.exception.get();
}
if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) {
throw ch.exception.get();
}
if (sh.exception.get() != null) {
throw sh.exception.get();
}
if (ch.exception.get() != null) {
throw ch.exception.get();
}
}
use of io.netty.channel.Channel in project neo4j by neo4j.
the class NonBlockingChannel method ensureConnected.
private void ensureConnected() throws IOException {
if (nettyChannel != null && !nettyChannel.isOpen()) {
nettyChannel = null;
}
while (nettyChannel == null && stillRunning) {
ChannelFuture channelFuture = bootstrap.connect(destination);
Channel channel = channelFuture.awaitUninterruptibly().channel();
if (channelFuture.isSuccess()) {
channel.flush();
nettyChannel = channel;
log.info("Connected: " + nettyChannel);
} else {
channel.close();
parkNanos(MILLISECONDS.toNanos(CONNECT_BACKOFF_IN_MS));
}
}
}
Aggregations