Skip to content

Commit

Permalink
Fix compilation errors / Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
trustin committed Oct 8, 2013
1 parent 9097fce commit 136e1eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 97 deletions.
4 changes: 2 additions & 2 deletions transport/src/main/java/io/netty/channel/AbstractChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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]);
}
Expand All @@ -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()) {
Expand All @@ -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);
Expand Down Expand Up @@ -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();
}
}
}
}

0 comments on commit 136e1eb

Please sign in to comment.