@Test
public void addByteDecoderWhenNoLeft() throws Exception {
channel.pipeline()
.addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
});
ChannelHandler decoder = new LineBasedFrameDecoder(12);
testContext.addHandlerLast("decoder", decoder)
.addHandlerFirst("decoder$extract",
NettyPipeline.inboundHandler(ADD_EXTRACTOR));
assertEquals(channel.pipeline()
.names(),
Arrays.asList("decoder$extract",
"decoder",
NettyPipeline.ReactiveBridge,
"DefaultChannelPipeline$TailContext#0"));
}
java类io.netty.channel.ChannelHandlerAdapter的实例源码
NettyContextTest.java 文件源码
项目:reactor-netty
阅读 28
收藏 0
点赞 0
评论 0
NettyContextTest.java 文件源码
项目:reactor-netty
阅读 28
收藏 0
点赞 0
评论 0
@Test
public void addByteDecoderWhenNoRight() throws Exception {
channel.pipeline()
.addLast(NettyPipeline.HttpCodec, new ChannelHandlerAdapter() {
});
ChannelHandler decoder = new LineBasedFrameDecoder(12);
testContext.addHandlerLast("decoder", decoder)
.addHandlerFirst("decoder$extract",
NettyPipeline.inboundHandler(ADD_EXTRACTOR));
assertEquals(channel.pipeline()
.names(),
Arrays.asList(NettyPipeline.HttpCodec,
"decoder$extract",
"decoder",
"DefaultChannelPipeline$TailContext#0"));
}
NettyContextTest.java 文件源码
项目:reactor-netty
阅读 33
收藏 0
点赞 0
评论 0
@Test
public void addByteDecoderWhenFullReactorPipeline() throws Exception {
channel.pipeline()
.addLast(NettyPipeline.HttpCodec, new HttpServerCodec())
.addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
.addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
});
ChannelHandler decoder = new LineBasedFrameDecoder(12);
testContext.addHandlerLast("decoder", decoder)
.addHandlerFirst("decoder$extract",
NettyPipeline.inboundHandler(ADD_EXTRACTOR));
assertEquals(channel.pipeline()
.names(),
Arrays.asList(NettyPipeline.HttpCodec,
NettyPipeline.HttpServerHandler,
"decoder$extract",
"decoder",
NettyPipeline.ReactiveBridge,
"DefaultChannelPipeline$TailContext#0"));
}
NettyContextTest.java 文件源码
项目:reactor-netty
阅读 27
收藏 0
点赞 0
评论 0
@Test
public void addNonByteDecoderWhenNoLeft() throws Exception {
channel.pipeline()
.addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
});
ChannelHandler decoder = new ChannelHandlerAdapter() {
};
testContext.addHandlerLast("decoder", decoder);
assertEquals(channel.pipeline()
.names(),
Arrays.asList("decoder",
NettyPipeline.ReactiveBridge,
"DefaultChannelPipeline$TailContext#0"));
}
NettyContextTest.java 文件源码
项目:reactor-netty
阅读 31
收藏 0
点赞 0
评论 0
@Test
public void addNonByteDecoderWhenNoRight() throws Exception {
channel.pipeline()
.addLast(NettyPipeline.HttpCodec, new ChannelHandlerAdapter() {
});
ChannelHandler decoder = new ChannelHandlerAdapter() {
};
testContext.addHandlerLast("decoder", decoder);
assertEquals(channel.pipeline()
.names(),
Arrays.asList(NettyPipeline.HttpCodec,
"decoder",
"DefaultChannelPipeline$TailContext#0"));
}
NettyContextTest.java 文件源码
项目:reactor-netty
阅读 27
收藏 0
点赞 0
评论 0
@Test
public void addNonByteDecoderWhenFullReactorPipeline() throws Exception {
channel.pipeline()
.addLast(NettyPipeline.HttpCodec, new HttpServerCodec())
.addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
.addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
});
ChannelHandler decoder = new ChannelHandlerAdapter() {
};
testContext.addHandlerLast("decoder", decoder);
assertEquals(channel.pipeline()
.names(),
Arrays.asList(NettyPipeline.HttpCodec,
NettyPipeline.HttpServerHandler,
"decoder",
NettyPipeline.ReactiveBridge,
"DefaultChannelPipeline$TailContext#0"));
}
NettyContextTest.java 文件源码
项目:reactor-netty
阅读 28
收藏 0
点赞 0
评论 0
@Test
public void addByteEncoderWhenNoLeft() throws Exception {
channel.pipeline()
.addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
});
ChannelHandler encoder = new LineBasedFrameDecoder(12);
testContext.addHandlerFirst("encoder", encoder);
assertEquals(channel.pipeline()
.names(),
Arrays.asList("encoder",
NettyPipeline.ReactiveBridge,
"DefaultChannelPipeline$TailContext#0"));
}
NettyContextTest.java 文件源码
项目:reactor-netty
阅读 26
收藏 0
点赞 0
评论 0
@Test
public void addByteEncoderWhenNoRight() throws Exception {
channel.pipeline()
.addLast(NettyPipeline.HttpCodec, new ChannelHandlerAdapter() {
});
ChannelHandler encoder = new LineBasedFrameDecoder(12);
testContext.addHandlerFirst("encoder", encoder);
assertEquals(channel.pipeline()
.names(),
Arrays.asList(NettyPipeline.HttpCodec,
"encoder",
"DefaultChannelPipeline$TailContext#0"));
}
NettyContextTest.java 文件源码
项目:reactor-netty
阅读 32
收藏 0
点赞 0
评论 0
@Test
public void addByteEncoderWhenFullReactorPipeline() throws Exception {
channel.pipeline()
.addLast(NettyPipeline.HttpCodec, new HttpServerCodec())
.addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
.addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
});
ChannelHandler encoder = new LineBasedFrameDecoder(12);
testContext.addHandlerFirst("encoder", encoder);
assertEquals(channel.pipeline()
.names(),
Arrays.asList(NettyPipeline.HttpCodec,
NettyPipeline.HttpServerHandler,
"encoder",
NettyPipeline.ReactiveBridge,
"DefaultChannelPipeline$TailContext#0"));
}
NettyContextTest.java 文件源码
项目:reactor-netty
阅读 30
收藏 0
点赞 0
评论 0
@Test
public void addNonByteEncoderWhenNoLeft() throws Exception {
channel.pipeline()
.addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
});
ChannelHandler encoder = new ChannelHandlerAdapter() {
};
testContext.addHandlerFirst("encoder", encoder);
assertEquals(channel.pipeline()
.names(),
Arrays.asList("encoder",
NettyPipeline.ReactiveBridge,
"DefaultChannelPipeline$TailContext#0"));
}
NettyContextTest.java 文件源码
项目:reactor-netty
阅读 27
收藏 0
点赞 0
评论 0
@Test
public void addNonByteEncoderWhenNoRight() throws Exception {
channel.pipeline()
.addLast(NettyPipeline.HttpCodec, new ChannelHandlerAdapter() {
});
ChannelHandler encoder = new ChannelHandlerAdapter() {
};
testContext.addHandlerFirst("encoder", encoder);
assertEquals(channel.pipeline()
.names(),
Arrays.asList(NettyPipeline.HttpCodec,
"encoder",
"DefaultChannelPipeline$TailContext#0"));
}
NettyContextTest.java 文件源码
项目:reactor-netty
阅读 32
收藏 0
点赞 0
评论 0
@Test
public void addNonByteEncoderWhenFullReactorPipeline() throws Exception {
channel.pipeline()
.addLast(NettyPipeline.HttpCodec, new HttpServerCodec())
.addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
.addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
});
ChannelHandler encoder = new ChannelHandlerAdapter() {
};
testContext.addHandlerFirst("encoder", encoder);
assertEquals(channel.pipeline()
.names(),
Arrays.asList(NettyPipeline.HttpCodec,
NettyPipeline.HttpServerHandler,
"encoder",
NettyPipeline.ReactiveBridge,
"DefaultChannelPipeline$TailContext#0"));
}
NettyContextTest.java 文件源码
项目:reactor-netty
阅读 37
收藏 0
点赞 0
评论 0
@Test
public void addSeveralByteEncodersWhenCodec() throws Exception {
ChannelHandler encoder1 = new LineBasedFrameDecoder(12);
ChannelHandler encoder2 = new LineBasedFrameDecoder(13);
channel.pipeline()
.addLast(NettyPipeline.HttpCodec, new HttpServerCodec())
.addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
.addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
});
testContext.addHandlerFirst("encoder1", encoder1)
.addHandlerFirst("encoder2", encoder2);
assertEquals(channel.pipeline()
.names(),
Arrays.asList(NettyPipeline.HttpCodec,
NettyPipeline.HttpServerHandler,
"encoder2",
"encoder1",
NettyPipeline.ReactiveBridge,
"DefaultChannelPipeline$TailContext#0"));
}
HttpClientOperationsTest.java 文件源码
项目:reactor-netty
阅读 23
收藏 0
点赞 0
评论 0
@Test
public void testConstructorWithProvidedReplacement() {
EmbeddedChannel channel = new EmbeddedChannel();
channel.pipeline().addFirst(NettyPipeline.SslHandler, new ChannelHandlerAdapter() {
});
HttpClientOperations ops1 = new HttpClientOperations(channel,
(response, request) -> null, handler);
ops1.followRedirect();
ops1.failOnClientError(false);
ops1.failOnServerError(false);
HttpClientOperations ops2 = new HttpClientOperations(channel, ops1);
assertSame(ops1.channel(), ops2.channel());
assertSame(ops1.started, ops2.started);
assertSame(ops1.redirectedFrom, ops2.redirectedFrom);
assertSame(ops1.isSecure, ops2.isSecure);
assertSame(ops1.nettyRequest, ops2.nettyRequest);
assertSame(ops1.responseState, ops2.responseState);
assertSame(ops1.redirectable, ops2.redirectable);
assertSame(ops1.inboundPrefetch, ops2.inboundPrefetch);
assertSame(ops1.requestHeaders, ops2.requestHeaders);
assertSame(ops1.clientError, ops2.clientError);
assertSame(ops1.serverError, ops2.serverError);
}
Client.java 文件源码
项目:javase-study
阅读 34
收藏 0
点赞 0
评论 0
public void run(String host, int port) throws InterruptedException {
NioEventLoopGroup group = new NioEventLoopGroup();
try {
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group)
.channel(NioSocketChannel.class)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new ChannelHandlerAdapter() {
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
System.out.println("connection active");
}
});
}
});
ChannelFuture future = bootstrap.connect(host, port).sync();
future.channel().closeFuture().sync();
} finally {
group.shutdownGracefully();
}
}
SocketConnectionAttemptTest.java 文件源码
项目:netty-netty-5.0.0.Alpha1
阅读 27
收藏 0
点赞 0
评论 0
public void testConnectCancellation(Bootstrap cb) throws Throwable {
cb.handler(new ChannelHandlerAdapter()).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 4000);
ChannelFuture future = cb.connect(BAD_HOST, 8080);
try {
if (future.await(1000)) {
if (future.isSuccess()) {
fail("A connection attempt to " + BAD_HOST + " must not succeed.");
} else {
throw future.cause();
}
}
if (future.cancel(true)) {
assertThat(future.channel().closeFuture().await(500), is(true));
assertThat(future.isCancelled(), is(true));
} else {
// Cancellation not supported by the transport.
}
} finally {
future.channel().close();
}
}
LocalTransportThreadModelTest.java 文件源码
项目:netty-netty-5.0.0.Alpha1
阅读 19
收藏 0
点赞 0
评论 0
@BeforeClass
public static void init() {
// Configure a test server
group = new DefaultEventLoopGroup();
ServerBootstrap sb = new ServerBootstrap();
sb.group(group)
.channel(LocalServerChannel.class)
.childHandler(new ChannelInitializer<LocalChannel>() {
@Override
public void initChannel(LocalChannel ch) throws Exception {
ch.pipeline().addLast(new ChannelHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
// Discard
ReferenceCountUtil.release(msg);
}
});
}
});
localAddr = (LocalAddress) sb.bind(LocalAddress.ANY).syncUninterruptibly().channel().localAddress();
}
LocalTransportThreadModelTest3.java 文件源码
项目:netty-netty-5.0.0.Alpha1
阅读 22
收藏 0
点赞 0
评论 0
@BeforeClass
public static void init() {
// Configure a test server
group = new DefaultEventLoopGroup();
ServerBootstrap sb = new ServerBootstrap();
sb.group(group)
.channel(LocalServerChannel.class)
.childHandler(new ChannelInitializer<LocalChannel>() {
@Override
public void initChannel(LocalChannel ch) throws Exception {
ch.pipeline().addLast(new ChannelHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
// Discard
ReferenceCountUtil.release(msg);
}
});
}
});
localAddr = (LocalAddress) sb.bind(LocalAddress.ANY).syncUninterruptibly().channel().localAddress();
}
OioEventLoopTest.java 文件源码
项目:netty-netty-5.0.0.Alpha1
阅读 18
收藏 0
点赞 0
评论 0
@Test
public void testTooManyAcceptedChannels() throws Exception {
EventLoopGroup g = new OioEventLoopGroup(1);
ServerBootstrap sb = new ServerBootstrap();
sb.channel(OioServerSocketChannel.class);
sb.group(g);
sb.childHandler(new ChannelHandlerAdapter());
ChannelFuture f1 = sb.bind(0);
f1.sync();
Socket s = new Socket(NetUtil.LOCALHOST, ((InetSocketAddress) f1.channel().localAddress()).getPort());
assertThat(s.getInputStream().read(), is(-1));
s.close();
g.shutdownGracefully();
}
ProtocolNegotiators.java 文件源码
项目:grpc-java
阅读 26
收藏 0
点赞 0
评论 0
/**
* Create a server plaintext handler for gRPC.
*/
public static ProtocolNegotiator serverPlaintext() {
return new ProtocolNegotiator() {
@Override
public Handler newHandler(final GrpcHttp2ConnectionHandler handler) {
class PlaintextHandler extends ChannelHandlerAdapter implements Handler {
@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
// Set sttributes before replace to be sure we pass it before accepting any requests.
handler.handleProtocolNegotiationCompleted(Attributes.newBuilder()
.set(Grpc.TRANSPORT_ATTR_REMOTE_ADDR, ctx.channel().remoteAddress())
.build());
// Just replace this handler with the gRPC handler.
ctx.pipeline().replace(this, null, handler);
}
@Override
public AsciiString scheme() {
return Utils.HTTP;
}
}
return new PlaintextHandler();
}
};
}
Http1FrontendHandlerTest.java 文件源码
项目:nitmproxy
阅读 21
收藏 0
点赞 0
评论 0
@Before
public void setUp() throws Exception {
master = mock(NitmProxyMaster.class);
when(master.config()).thenReturn(new NitmProxyConfig());
when(master.handler(any(), any(), any())).thenAnswer(m -> new ChannelHandlerAdapter() {
});
inboundChannel = new EmbeddedChannel();
}
NettyContextTest.java 文件源码
项目:reactor-netty
阅读 27
收藏 0
点赞 0
评论 0
@Test
public void addNonByteDecoderWhenEmptyPipeline() throws Exception {
ChannelHandler decoder = new ChannelHandlerAdapter() {
};
testContext.addHandlerLast("decoder", decoder);
assertEquals(channel.pipeline()
.names(),
Arrays.asList("decoder", "DefaultChannelPipeline$TailContext#0"));
}
NettyContextTest.java 文件源码
项目:reactor-netty
阅读 37
收藏 0
点赞 0
评论 0
@Test
public void addSeveralByteDecodersWhenCodec() throws Exception {
ChannelHandler decoder1 = new LineBasedFrameDecoder(12);
ChannelHandler decoder2 = new LineBasedFrameDecoder(13);
channel.pipeline()
.addLast(NettyPipeline.HttpCodec, new HttpServerCodec())
.addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
.addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
});
testContext.addHandlerLast("decoder1$extract",
NettyPipeline.inboundHandler(ADD_EXTRACTOR))
.addHandlerLast("decoder1", decoder1)
.addHandlerLast("decoder2$extract",
NettyPipeline.inboundHandler(ADD_EXTRACTOR))
.addHandlerLast("decoder2", decoder2);
assertEquals(channel.pipeline()
.names(),
Arrays.asList(NettyPipeline.HttpCodec,
NettyPipeline.HttpServerHandler,
"decoder1$extract",
"decoder1",
"decoder2$extract",
"decoder2",
NettyPipeline.ReactiveBridge,
"DefaultChannelPipeline$TailContext#0"));
}
NettyContextTest.java 文件源码
项目:reactor-netty
阅读 27
收藏 0
点赞 0
评论 0
@Test
public void addNonByteEncoderWhenEmptyPipeline() throws Exception {
ChannelHandler encoder = new ChannelHandlerAdapter() {
};
testContext.addHandlerFirst("encoder", encoder);
assertEquals(channel.pipeline()
.names(),
Arrays.asList("encoder", "DefaultChannelPipeline$TailContext#0"));
}
WebSocketServerProtocolHandler.java 文件源码
项目:netty-netty-5.0.0.Alpha1
阅读 21
收藏 0
点赞 0
评论 0
static ChannelHandler forbiddenHttpRequestResponder() {
return new ChannelHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof FullHttpRequest) {
FullHttpResponse response =
new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.FORBIDDEN);
ctx.channel().writeAndFlush(response);
} else {
ctx.fireChannelRead(msg);
}
}
};
}
SocketConnectionAttemptTest.java 文件源码
项目:netty-netty-5.0.0.Alpha1
阅读 20
收藏 0
点赞 0
评论 0
public void testConnectTimeout(Bootstrap cb) throws Throwable {
cb.handler(new ChannelHandlerAdapter()).option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 2000);
ChannelFuture future = cb.connect(BAD_HOST, 8080);
try {
assertThat(future.await(3000), is(true));
} finally {
future.channel().close();
}
}
DefaultChannnelGroupTest.java 文件源码
项目:netty-netty-5.0.0.Alpha1
阅读 22
收藏 0
点赞 0
评论 0
@Test
public void testNotThrowBlockingOperationException() throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
final ChannelGroup allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup);
b.childHandler(new ChannelHandlerAdapter() {
@Override
public void channelActive(ChannelHandlerContext ctx) {
allChannels.add(ctx.channel());
}
});
b.channel(NioServerSocketChannel.class);
ChannelFuture f = b.bind(0).syncUninterruptibly();
if (f.isSuccess()) {
allChannels.add(f.channel());
allChannels.close().awaitUninterruptibly();
}
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
bossGroup.terminationFuture().sync();
workerGroup.terminationFuture().sync();
}
OioEventLoopTest.java 文件源码
项目:netty-netty-5.0.0.Alpha1
阅读 27
收藏 0
点赞 0
评论 0
@Test
public void testTooManyServerChannels() throws Exception {
EventLoopGroup g = new OioEventLoopGroup(1);
ServerBootstrap b = new ServerBootstrap();
b.channel(OioServerSocketChannel.class);
b.group(g);
b.childHandler(new ChannelHandlerAdapter());
ChannelFuture f1 = b.bind(0);
f1.sync();
ChannelFuture f2 = b.bind(0);
f2.await();
assertThat(f2.cause(), is(instanceOf(ChannelException.class)));
assertThat(f2.cause().getMessage().toLowerCase(), containsString("too many channels"));
final CountDownLatch notified = new CountDownLatch(1);
f2.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
notified.countDown();
}
});
notified.await();
g.shutdownGracefully();
}
OioEventLoopTest.java 文件源码
项目:netty-netty-5.0.0.Alpha1
阅读 22
收藏 0
点赞 0
评论 0
@Test
public void testTooManyClientChannels() throws Exception {
EventLoopGroup g = new OioEventLoopGroup(1);
ServerBootstrap sb = new ServerBootstrap();
sb.channel(OioServerSocketChannel.class);
sb.group(g);
sb.childHandler(new ChannelHandlerAdapter());
ChannelFuture f1 = sb.bind(0);
f1.sync();
Bootstrap cb = new Bootstrap();
cb.channel(OioSocketChannel.class);
cb.group(g);
cb.handler(new ChannelHandlerAdapter());
ChannelFuture f2 = cb.connect(NetUtil.LOCALHOST, ((InetSocketAddress) f1.channel().localAddress()).getPort());
f2.await();
assertThat(f2.cause(), is(instanceOf(ChannelException.class)));
assertThat(f2.cause().getMessage().toLowerCase(), containsString("too many channels"));
final CountDownLatch notified = new CountDownLatch(1);
f2.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
notified.countDown();
}
});
notified.await();
g.shutdownGracefully();
}
NioSocketChannelTest.java 文件源码
项目:netty-netty-5.0.0.Alpha1
阅读 25
收藏 0
点赞 0
评论 0
/**
* Reproduces the issue #1679
*/
@Test
public void testFlushAfterGatheredFlush() throws Exception {
NioEventLoopGroup group = new NioEventLoopGroup(1);
try {
ServerBootstrap sb = new ServerBootstrap();
sb.group(group).channel(NioServerSocketChannel.class);
sb.childHandler(new ChannelHandlerAdapter() {
@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
// Trigger a gathering write by writing two buffers.
ctx.write(Unpooled.wrappedBuffer(new byte[] { 'a' }));
ChannelFuture f = ctx.write(Unpooled.wrappedBuffer(new byte[] { 'b' }));
f.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
// This message must be flushed
ctx.writeAndFlush(Unpooled.wrappedBuffer(new byte[]{'c'}));
}
});
ctx.flush();
}
});
SocketAddress address = sb.bind(0).sync().channel().localAddress();
Socket s = new Socket();
s.connect(address);
DataInput in = new DataInputStream(s.getInputStream());
byte[] buf = new byte[3];
in.readFully(buf);
assertThat(new String(buf, CharsetUtil.US_ASCII), is("abc"));
s.close();
} finally {
group.shutdownGracefully().sync();
}
}