diff --git a/transport/src/main/java/io/netty/channel/AbstractChannel.java b/transport/src/main/java/io/netty/channel/AbstractChannel.java index 7f3b989c067e..b8a20f928204 100644 --- a/transport/src/main/java/io/netty/channel/AbstractChannel.java +++ b/transport/src/main/java/io/netty/channel/AbstractChannel.java @@ -75,8 +75,8 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha protected AbstractChannel(Channel parent, EventLoop eventLoop) { this.parent = parent; this.eventLoop = validate(eventLoop); - this.unsafe = newUnsafe(); - this.pipeline = new DefaultChannelPipeline(this); + unsafe = newUnsafe(); + pipeline = new DefaultChannelPipeline(this); } @Override diff --git a/transport/src/test/java/io/netty/channel/ChannelOutboundBufferTest.java b/transport/src/test/java/io/netty/channel/ChannelOutboundBufferTest.java index b48d0dfc9e78..51e9ec2161eb 100644 --- a/transport/src/test/java/io/netty/channel/ChannelOutboundBufferTest.java +++ b/transport/src/test/java/io/netty/channel/ChannelOutboundBufferTest.java @@ -17,10 +17,10 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.CompositeByteBuf; +import io.netty.channel.embedded.EmbeddedChannel; import io.netty.util.CharsetUtil; import org.junit.Test; -import java.net.SocketAddress; import java.nio.ByteBuffer; import static io.netty.buffer.Unpooled.*; @@ -30,7 +30,7 @@ public class ChannelOutboundBufferTest { @Test public void testEmptyNioBuffers() { - TestChannel channel = new TestChannel(); + AbstractChannel channel = new EmbeddedChannel(); ChannelOutboundBuffer buffer = ChannelOutboundBuffer.newInstance(channel); assertEquals(0, buffer.nioBufferCount()); ByteBuffer[] buffers = buffer.nioBuffers(); @@ -48,8 +48,7 @@ public void testEmptyNioBuffers() { @Test public void testNioBuffersSingleBacked() { - TestChannel channel = new TestChannel(); - + AbstractChannel channel = new EmbeddedChannel(); ChannelOutboundBuffer buffer = ChannelOutboundBuffer.newInstance(channel); assertEquals(0, buffer.nioBufferCount()); ByteBuffer[] buffers = buffer.nioBuffers(); @@ -73,7 +72,7 @@ public void testNioBuffersSingleBacked() { assertEquals("Should still be 0 as not flushed yet", 1, buffer.nioBufferCount()); for (int i = 0; i < buffers.length; i++) { if (i == 0) { - assertEquals(buffers[i], nioBuf); + assertEquals(buffers[0], nioBuf); } else { assertNull(buffers[i]); } @@ -87,25 +86,24 @@ public void testNioBuffersSingleBacked() { @Test public void testNioBuffersExpand() { - TestChannel channel = new TestChannel(); - + AbstractChannel channel = new EmbeddedChannel(); ChannelOutboundBuffer buffer = ChannelOutboundBuffer.newInstance(channel); ByteBuf buf = directBuffer().writeBytes("buf1".getBytes(CharsetUtil.US_ASCII)); for (int i = 0; i < 64; i++) { buffer.addMessage(buf.copy(), channel.voidPromise()); } - ByteBuffer[] buffers = buffer.nioBuffers(); + ByteBuffer[] nioBuffers = buffer.nioBuffers(); assertEquals("Should still be 0 as not flushed yet", 0, buffer.nioBufferCount()); - for (ByteBuffer b: buffers) { + for (ByteBuffer b: nioBuffers) { assertNull(b); } buffer.addFlush(); - buffers = buffer.nioBuffers(); - assertEquals(64, buffers.length); + nioBuffers = buffer.nioBuffers(); + assertEquals(64, nioBuffers.length); assertEquals(64, buffer.nioBufferCount()); - for (int i = 0; i < buffers.length; i++) { - assertEquals(buffers[i], buf.internalNioBuffer(0, buf.readableBytes())); + for (ByteBuffer nioBuf: nioBuffers) { + assertEquals(nioBuf, buf.internalNioBuffer(0, buf.readableBytes())); } for (;;) { if (!buffer.remove()) { @@ -116,8 +114,7 @@ public void testNioBuffersExpand() { @Test public void testNioBuffersExpand2() { - TestChannel channel = new TestChannel(); - + AbstractChannel channel = new EmbeddedChannel(); ChannelOutboundBuffer buffer = ChannelOutboundBuffer.newInstance(channel); CompositeByteBuf comp = compositeBuffer(256); @@ -149,84 +146,4 @@ public void testNioBuffersExpand2() { } } } - - private static final class TestChannel extends AbstractChannel { - private final ChannelConfig config = new DefaultChannelConfig(this); - - TestChannel() { - super(null); - } - - @Override - protected AbstractUnsafe newUnsafe() { - return new TestUnsafe(); - } - - @Override - protected boolean isCompatible(EventLoop loop) { - return false; - } - - @Override - protected SocketAddress localAddress0() { - throw new UnsupportedOperationException(); - } - - @Override - protected SocketAddress remoteAddress0() { - throw new UnsupportedOperationException(); - } - - @Override - protected void doBind(SocketAddress localAddress) throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected void doDisconnect() throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected void doClose() throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected void doBeginRead() throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected void doWrite(ChannelOutboundBuffer in) throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - public ChannelConfig config() { - return config; - } - - @Override - public boolean isOpen() { - return true; - } - - @Override - public boolean isActive() { - return true; - } - - @Override - public ChannelMetadata metadata() { - throw new UnsupportedOperationException(); - } - - final class TestUnsafe extends AbstractUnsafe { - @Override - public void connect(SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) { - throw new UnsupportedOperationException(); - } - } - } }