Fix compilation errors / Cleanup

This commit is contained in:
Trustin Lee 2013-10-08 17:20:07 +09:00
parent 9097fce9e3
commit 136e1ebba8
2 changed files with 14 additions and 97 deletions

View File

@ -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

View File

@ -17,10 +17,10 @@ package io.netty.channel;
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 class ChannelOutboundBufferTest {
@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 class ChannelOutboundBufferTest {
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 class ChannelOutboundBufferTest {
@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 class ChannelOutboundBufferTest {
@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 class ChannelOutboundBufferTest {
}
}
}
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();
}
}
}
}