Search in sources :

Example 26 with LocalChannel

use of io.netty.channel.local.LocalChannel in project netty by netty.

the class DefaultChannelPipelineTest method testAddReplaceHandlerNotRegistered.

@Test
public void testAddReplaceHandlerNotRegistered() throws Throwable {
    final AtomicReference<Throwable> error = new AtomicReference<Throwable>();
    ChannelHandler handler = new ErrorChannelHandler(error);
    ChannelPipeline pipeline = new LocalChannel().pipeline();
    pipeline.addFirst(handler);
    pipeline.replace(handler, null, new ErrorChannelHandler(error));
    Throwable cause = error.get();
    if (cause != null) {
        throw cause;
    }
}
Also used : LocalChannel(io.netty.channel.local.LocalChannel) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 27 with LocalChannel

use of io.netty.channel.local.LocalChannel in project netty by netty.

the class DefaultChannelPipelineTest method testUnexpectedVoidChannelPromiseCloseFuture.

@Test(expected = IllegalArgumentException.class)
public void testUnexpectedVoidChannelPromiseCloseFuture() throws Exception {
    ChannelPipeline pipeline = new LocalChannel().pipeline();
    group.register(pipeline.channel()).sync();
    try {
        ChannelPromise promise = (ChannelPromise) pipeline.channel().closeFuture();
        pipeline.close(promise);
    } finally {
        pipeline.close();
    }
}
Also used : LocalChannel(io.netty.channel.local.LocalChannel) Test(org.junit.Test)

Example 28 with LocalChannel

use of io.netty.channel.local.LocalChannel in project netty by netty.

the class DefaultChannelPipelineTest method testFirstContextEmptyPipeline.

@Test
public void testFirstContextEmptyPipeline() throws Exception {
    ChannelPipeline pipeline = new LocalChannel().pipeline();
    assertNull(pipeline.firstContext());
}
Also used : LocalChannel(io.netty.channel.local.LocalChannel) Test(org.junit.Test)

Example 29 with LocalChannel

use of io.netty.channel.local.LocalChannel in project netty by netty.

the class DefaultChannelPipelineTest method testAddRemoveHandlerCalledOnceRegistered.

@Test(timeout = 2000)
public void testAddRemoveHandlerCalledOnceRegistered() throws Throwable {
    ChannelPipeline pipeline = new LocalChannel().pipeline();
    CallbackCheckHandler handler = new CallbackCheckHandler();
    pipeline.addFirst(handler);
    pipeline.remove(handler);
    assertNull(handler.addedHandler.getNow());
    assertNull(handler.removedHandler.getNow());
    group.register(pipeline.channel()).syncUninterruptibly();
    Throwable cause = handler.error.get();
    if (cause != null) {
        throw cause;
    }
    assertTrue(handler.addedHandler.get());
    assertTrue(handler.removedHandler.get());
}
Also used : LocalChannel(io.netty.channel.local.LocalChannel) Test(org.junit.Test)

Example 30 with LocalChannel

use of io.netty.channel.local.LocalChannel in project netty by netty.

the class DefaultChannelPipelineTest method testCancelWriteAndFlush.

@Test
public void testCancelWriteAndFlush() throws Exception {
    ChannelPipeline pipeline = new LocalChannel().pipeline();
    group.register(pipeline.channel());
    ChannelPromise promise = pipeline.channel().newPromise();
    assertTrue(promise.cancel(false));
    ByteBuf buffer = Unpooled.buffer();
    assertEquals(1, buffer.refCnt());
    ChannelFuture future = pipeline.writeAndFlush(buffer, promise);
    assertTrue(future.isCancelled());
    assertEquals(0, buffer.refCnt());
}
Also used : LocalChannel(io.netty.channel.local.LocalChannel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

LocalChannel (io.netty.channel.local.LocalChannel)53 Test (org.junit.Test)49 LocalServerChannel (io.netty.channel.local.LocalServerChannel)16 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)14 LocalAddress (io.netty.channel.local.LocalAddress)14 Bootstrap (io.netty.bootstrap.Bootstrap)13 Channel (io.netty.channel.Channel)12 EventLoopGroup (io.netty.channel.EventLoopGroup)12 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)11 LocalEventLoopGroup (io.netty.channel.local.LocalEventLoopGroup)11 DefaultEventLoopGroup (io.netty.channel.DefaultEventLoopGroup)8 DefaultEventExecutorGroup (io.netty.util.concurrent.DefaultEventExecutorGroup)7 EventExecutorGroup (io.netty.util.concurrent.EventExecutorGroup)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 TimeoutException (java.util.concurrent.TimeoutException)7 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)4 ExpectedException (org.junit.rules.ExpectedException)4 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)3 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)3 OioSocketChannel (io.netty.channel.socket.oio.OioSocketChannel)3