Only use Mockito for mocking.
Motivation: We used various mocking frameworks. We should only use one... Modifications: Make usage of mocking framework consistent by only using Mockito. Result: Less dependencies and more consistent mocking usage.
This commit is contained in:
parent
42c0359820
commit
a7c0ff665c
@ -34,5 +34,9 @@
|
|||||||
<artifactId>netty-common</artifactId>
|
<artifactId>netty-common</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
package io.netty.buffer;
|
package io.netty.buffer;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -25,8 +27,8 @@ import java.nio.channels.GatheringByteChannel;
|
|||||||
import java.nio.channels.ScatteringByteChannel;
|
import java.nio.channels.ScatteringByteChannel;
|
||||||
|
|
||||||
import static io.netty.buffer.Unpooled.*;
|
import static io.netty.buffer.Unpooled.*;
|
||||||
import static org.easymock.EasyMock.*;
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests read-only channel buffers
|
* Tests read-only channel buffers
|
||||||
@ -74,30 +76,28 @@ public class ReadOnlyByteBufTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldForwardReadCallsBlindly() throws Exception {
|
public void shouldForwardReadCallsBlindly() throws Exception {
|
||||||
ByteBuf buf = createStrictMock(ByteBuf.class);
|
ByteBuf buf = mock(ByteBuf.class);
|
||||||
expect(buf.order()).andReturn(BIG_ENDIAN).anyTimes();
|
when(buf.order()).thenReturn(BIG_ENDIAN);
|
||||||
expect(buf.maxCapacity()).andReturn(65536).anyTimes();
|
when(buf.maxCapacity()).thenReturn(65536);
|
||||||
expect(buf.readerIndex()).andReturn(0).anyTimes();
|
when(buf.readerIndex()).thenReturn(0);
|
||||||
expect(buf.writerIndex()).andReturn(0).anyTimes();
|
when(buf.writerIndex()).thenReturn(0);
|
||||||
expect(buf.capacity()).andReturn(0).anyTimes();
|
when(buf.capacity()).thenReturn(0);
|
||||||
|
|
||||||
expect(buf.getBytes(1, (GatheringByteChannel) null, 2)).andReturn(3);
|
when(buf.getBytes(1, (GatheringByteChannel) null, 2)).thenReturn(3);
|
||||||
expect(buf.getBytes(4, (OutputStream) null, 5)).andReturn(buf);
|
when(buf.getBytes(4, (OutputStream) null, 5)).thenReturn(buf);
|
||||||
expect(buf.getBytes(6, (byte[]) null, 7, 8)).andReturn(buf);
|
when(buf.getBytes(6, (byte[]) null, 7, 8)).thenReturn(buf);
|
||||||
expect(buf.getBytes(9, (ByteBuf) null, 10, 11)).andReturn(buf);
|
when(buf.getBytes(9, (ByteBuf) null, 10, 11)).thenReturn(buf);
|
||||||
expect(buf.getBytes(12, (ByteBuffer) null)).andReturn(buf);
|
when(buf.getBytes(12, (ByteBuffer) null)).thenReturn(buf);
|
||||||
expect(buf.getByte(13)).andReturn(Byte.valueOf((byte) 14));
|
when(buf.getByte(13)).thenReturn(Byte.valueOf((byte) 14));
|
||||||
expect(buf.getShort(15)).andReturn(Short.valueOf((short) 16));
|
when(buf.getShort(15)).thenReturn(Short.valueOf((short) 16));
|
||||||
expect(buf.getUnsignedMedium(17)).andReturn(18);
|
when(buf.getUnsignedMedium(17)).thenReturn(18);
|
||||||
expect(buf.getInt(19)).andReturn(20);
|
when(buf.getInt(19)).thenReturn(20);
|
||||||
expect(buf.getLong(21)).andReturn(22L);
|
when(buf.getLong(21)).thenReturn(22L);
|
||||||
|
|
||||||
ByteBuffer bb = ByteBuffer.allocate(100);
|
ByteBuffer bb = ByteBuffer.allocate(100);
|
||||||
|
|
||||||
expect(buf.nioBuffer(23, 24)).andReturn(bb);
|
when(buf.nioBuffer(23, 24)).thenReturn(bb);
|
||||||
expect(buf.capacity()).andReturn(27);
|
when(buf.capacity()).thenReturn(27);
|
||||||
|
|
||||||
replay(buf);
|
|
||||||
|
|
||||||
ByteBuf roBuf = unmodifiableBuffer(buf);
|
ByteBuf roBuf = unmodifiableBuffer(buf);
|
||||||
assertEquals(3, roBuf.getBytes(1, (GatheringByteChannel) null, 2));
|
assertEquals(3, roBuf.getBytes(1, (GatheringByteChannel) null, 2));
|
||||||
@ -116,8 +116,6 @@ public class ReadOnlyByteBufTest {
|
|||||||
assertTrue(roBB.isReadOnly());
|
assertTrue(roBB.isReadOnly());
|
||||||
|
|
||||||
assertEquals(27, roBuf.capacity());
|
assertEquals(27, roBuf.capacity());
|
||||||
|
|
||||||
verify(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = UnsupportedOperationException.class)
|
@Test(expected = UnsupportedOperationException.class)
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.buffer;
|
package io.netty.buffer;
|
||||||
|
|
||||||
import org.easymock.EasyMock;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@ -450,19 +450,23 @@ public class UnpooledTest {
|
|||||||
// Expected
|
// Expected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InputStream inputStream = Mockito.mock(InputStream.class);
|
||||||
try {
|
try {
|
||||||
buf.setBytes(0, EasyMock.createMock(InputStream.class), 0);
|
buf.setBytes(0, inputStream, 0);
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
// Expected
|
// Expected
|
||||||
}
|
}
|
||||||
|
Mockito.verifyZeroInteractions(inputStream);
|
||||||
|
|
||||||
|
ScatteringByteChannel scatteringByteChannel = Mockito.mock(ScatteringByteChannel.class);
|
||||||
try {
|
try {
|
||||||
buf.setBytes(0, EasyMock.createMock(ScatteringByteChannel.class), 0);
|
buf.setBytes(0, scatteringByteChannel, 0);
|
||||||
fail();
|
fail();
|
||||||
} catch (UnsupportedOperationException e) {
|
} catch (UnsupportedOperationException e) {
|
||||||
// Expected
|
// Expected
|
||||||
}
|
}
|
||||||
|
Mockito.verifyZeroInteractions(scatteringByteChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -45,6 +45,10 @@
|
|||||||
<artifactId>jzlib</artifactId>
|
<artifactId>jzlib</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ import io.netty.handler.codec.DecoderResult;
|
|||||||
import io.netty.handler.codec.DecoderResultProvider;
|
import io.netty.handler.codec.DecoderResultProvider;
|
||||||
import io.netty.handler.codec.TooLongFrameException;
|
import io.netty.handler.codec.TooLongFrameException;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import org.easymock.EasyMock;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import java.nio.channels.ClosedChannelException;
|
import java.nio.channels.ClosedChannelException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -221,9 +221,9 @@ public class HttpObjectAggregatorTest {
|
|||||||
@Test(expected = IllegalStateException.class)
|
@Test(expected = IllegalStateException.class)
|
||||||
public void testSetMaxCumulationBufferComponentsAfterInit() throws Exception {
|
public void testSetMaxCumulationBufferComponentsAfterInit() throws Exception {
|
||||||
HttpObjectAggregator aggr = new HttpObjectAggregator(Integer.MAX_VALUE);
|
HttpObjectAggregator aggr = new HttpObjectAggregator(Integer.MAX_VALUE);
|
||||||
ChannelHandlerContext ctx = EasyMock.createMock(ChannelHandlerContext.class);
|
ChannelHandlerContext ctx = Mockito.mock(ChannelHandlerContext.class);
|
||||||
EasyMock.replay(ctx);
|
|
||||||
aggr.handlerAdded(ctx);
|
aggr.handlerAdded(ctx);
|
||||||
|
Mockito.verifyNoMoreInteractions(ctx);
|
||||||
aggr.setMaxCumulationBufferComponents(10);
|
aggr.setMaxCumulationBufferComponents(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,16 +14,16 @@ package io.netty.handler.codec.http.websocketx;
|
|||||||
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
|
||||||
import org.easymock.EasyMock;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
public class WebSocket08FrameDecoderTest {
|
public class WebSocket08FrameDecoderTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void channelInactive() throws Exception {
|
public void channelInactive() throws Exception {
|
||||||
final WebSocket08FrameDecoder decoder = new WebSocket08FrameDecoder(true, true, 65535, false);
|
final WebSocket08FrameDecoder decoder = new WebSocket08FrameDecoder(true, true, 65535, false);
|
||||||
final ChannelHandlerContext ctx = EasyMock.createMock(ChannelHandlerContext.class);
|
final ChannelHandlerContext ctx = Mockito.mock(ChannelHandlerContext.class);
|
||||||
decoder.channelInactive(ctx);
|
decoder.channelInactive(ctx);
|
||||||
|
Mockito.verify(ctx).fireChannelInactive();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,37 +27,35 @@ import java.util.List;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionTestUtil.*;
|
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionTestUtil.*;
|
||||||
import static org.easymock.EasyMock.*;
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.atLeastOnce;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class WebSocketClientExtensionHandlerTest {
|
public class WebSocketClientExtensionHandlerTest {
|
||||||
|
|
||||||
WebSocketClientExtensionHandshaker mainHandshakerMock =
|
WebSocketClientExtensionHandshaker mainHandshakerMock =
|
||||||
createMock("mainHandshaker", WebSocketClientExtensionHandshaker.class);
|
mock(WebSocketClientExtensionHandshaker.class, "mainHandshaker");
|
||||||
WebSocketClientExtensionHandshaker fallbackHandshakerMock =
|
WebSocketClientExtensionHandshaker fallbackHandshakerMock =
|
||||||
createMock("fallbackHandshaker", WebSocketClientExtensionHandshaker.class);
|
mock(WebSocketClientExtensionHandshaker.class, "fallbackHandshaker");
|
||||||
WebSocketClientExtension mainExtensionMock =
|
WebSocketClientExtension mainExtensionMock =
|
||||||
createMock("mainExtension", WebSocketClientExtension.class);
|
mock(WebSocketClientExtension.class, "mainExtension");
|
||||||
WebSocketClientExtension fallbackExtensionMock =
|
WebSocketClientExtension fallbackExtensionMock =
|
||||||
createMock("fallbackExtension", WebSocketClientExtension.class);
|
mock(WebSocketClientExtension.class, "fallbackExtension");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMainSuccess() {
|
public void testMainSuccess() {
|
||||||
// initialize
|
// initialize
|
||||||
expect(mainHandshakerMock.newRequestData()).
|
when(mainHandshakerMock.newRequestData()).
|
||||||
andReturn(new WebSocketExtensionData("main", Collections.<String, String>emptyMap())).once();
|
thenReturn(new WebSocketExtensionData("main", Collections.<String, String>emptyMap()));
|
||||||
expect(mainHandshakerMock.handshakeExtension(
|
when(mainHandshakerMock.handshakeExtension(any(WebSocketExtensionData.class))).thenReturn(mainExtensionMock);
|
||||||
anyObject(WebSocketExtensionData.class))).andReturn(mainExtensionMock).once();
|
when(fallbackHandshakerMock.newRequestData()).
|
||||||
replay(mainHandshakerMock);
|
thenReturn(new WebSocketExtensionData("fallback", Collections.<String, String>emptyMap()));
|
||||||
|
when(mainExtensionMock.rsv()).thenReturn(WebSocketExtension.RSV1);
|
||||||
expect(fallbackHandshakerMock.newRequestData()).
|
when(mainExtensionMock.newExtensionEncoder()).thenReturn(new DummyEncoder());
|
||||||
andReturn(new WebSocketExtensionData("fallback", Collections.<String, String>emptyMap())).once();
|
when(mainExtensionMock.newExtensionDecoder()).thenReturn(new DummyDecoder());
|
||||||
replay(fallbackHandshakerMock);
|
|
||||||
|
|
||||||
expect(mainExtensionMock.rsv()).andReturn(WebSocketExtension.RSV1).anyTimes();
|
|
||||||
expect(mainExtensionMock.newExtensionEncoder()).andReturn(new DummyEncoder()).once();
|
|
||||||
expect(mainExtensionMock.newExtensionDecoder()).andReturn(new DummyDecoder()).once();
|
|
||||||
replay(mainExtensionMock);
|
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
EmbeddedChannel ch = new EmbeddedChannel(new WebSocketClientExtensionHandler(
|
EmbeddedChannel ch = new EmbeddedChannel(new WebSocketClientExtensionHandler(
|
||||||
@ -85,29 +83,30 @@ public class WebSocketClientExtensionHandlerTest {
|
|||||||
assertEquals(1, resExts.size());
|
assertEquals(1, resExts.size());
|
||||||
assertEquals("main", resExts.get(0).name());
|
assertEquals("main", resExts.get(0).name());
|
||||||
assertTrue(resExts.get(0).parameters().isEmpty());
|
assertTrue(resExts.get(0).parameters().isEmpty());
|
||||||
assertTrue(ch.pipeline().get(DummyDecoder.class) != null);
|
assertNotNull(ch.pipeline().get(DummyDecoder.class));
|
||||||
assertTrue(ch.pipeline().get(DummyEncoder.class) != null);
|
assertNotNull(ch.pipeline().get(DummyEncoder.class) != null);
|
||||||
|
|
||||||
|
verify(mainHandshakerMock).newRequestData();
|
||||||
|
verify(mainHandshakerMock).handshakeExtension(any(WebSocketExtensionData.class));
|
||||||
|
verify(fallbackHandshakerMock).newRequestData();
|
||||||
|
verify(mainExtensionMock, atLeastOnce()).rsv();
|
||||||
|
verify(mainExtensionMock).newExtensionEncoder();
|
||||||
|
verify(mainExtensionMock).newExtensionDecoder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFallbackSuccess() {
|
public void testFallbackSuccess() {
|
||||||
// initialize
|
// initialize
|
||||||
expect(mainHandshakerMock.newRequestData()).
|
when(mainHandshakerMock.newRequestData()).
|
||||||
andReturn(new WebSocketExtensionData("main", Collections.<String, String>emptyMap())).once();
|
thenReturn(new WebSocketExtensionData("main", Collections.<String, String>emptyMap()));
|
||||||
expect(mainHandshakerMock.handshakeExtension(
|
when(mainHandshakerMock.handshakeExtension(any(WebSocketExtensionData.class))).thenReturn(null);
|
||||||
anyObject(WebSocketExtensionData.class))).andReturn(null).once();
|
when(fallbackHandshakerMock.newRequestData()).
|
||||||
replay(mainHandshakerMock);
|
thenReturn(new WebSocketExtensionData("fallback", Collections.<String, String>emptyMap()));
|
||||||
|
when(fallbackHandshakerMock.handshakeExtension(
|
||||||
expect(fallbackHandshakerMock.newRequestData()).
|
any(WebSocketExtensionData.class))).thenReturn(fallbackExtensionMock);
|
||||||
andReturn(new WebSocketExtensionData("fallback", Collections.<String, String>emptyMap())).once();
|
when(fallbackExtensionMock.rsv()).thenReturn(WebSocketExtension.RSV1);
|
||||||
expect(fallbackHandshakerMock.handshakeExtension(
|
when(fallbackExtensionMock.newExtensionEncoder()).thenReturn(new DummyEncoder());
|
||||||
anyObject(WebSocketExtensionData.class))).andReturn(fallbackExtensionMock).once();
|
when(fallbackExtensionMock.newExtensionDecoder()).thenReturn(new DummyDecoder());
|
||||||
replay(fallbackHandshakerMock);
|
|
||||||
|
|
||||||
expect(fallbackExtensionMock.rsv()).andReturn(WebSocketExtension.RSV1).anyTimes();
|
|
||||||
expect(fallbackExtensionMock.newExtensionEncoder()).andReturn(new DummyEncoder()).once();
|
|
||||||
expect(fallbackExtensionMock.newExtensionDecoder()).andReturn(new DummyDecoder()).once();
|
|
||||||
replay(fallbackExtensionMock);
|
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
EmbeddedChannel ch = new EmbeddedChannel(new WebSocketClientExtensionHandler(
|
EmbeddedChannel ch = new EmbeddedChannel(new WebSocketClientExtensionHandler(
|
||||||
@ -135,42 +134,45 @@ public class WebSocketClientExtensionHandlerTest {
|
|||||||
assertEquals(1, resExts.size());
|
assertEquals(1, resExts.size());
|
||||||
assertEquals("fallback", resExts.get(0).name());
|
assertEquals("fallback", resExts.get(0).name());
|
||||||
assertTrue(resExts.get(0).parameters().isEmpty());
|
assertTrue(resExts.get(0).parameters().isEmpty());
|
||||||
assertTrue(ch.pipeline().get(DummyDecoder.class) != null);
|
assertNotNull(ch.pipeline().get(DummyDecoder.class));
|
||||||
assertTrue(ch.pipeline().get(DummyEncoder.class) != null);
|
assertNotNull(ch.pipeline().get(DummyEncoder.class));
|
||||||
|
|
||||||
|
verify(mainHandshakerMock).newRequestData();
|
||||||
|
verify(mainHandshakerMock).handshakeExtension(any(WebSocketExtensionData.class));
|
||||||
|
verify(fallbackHandshakerMock).newRequestData();
|
||||||
|
verify(fallbackHandshakerMock).handshakeExtension(any(WebSocketExtensionData.class));
|
||||||
|
verify(fallbackExtensionMock, atLeastOnce()).rsv();
|
||||||
|
verify(fallbackExtensionMock).newExtensionEncoder();
|
||||||
|
verify(fallbackExtensionMock).newExtensionDecoder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAllSuccess() {
|
public void testAllSuccess() {
|
||||||
// initialize
|
// initialize
|
||||||
expect(mainHandshakerMock.newRequestData()).
|
when(mainHandshakerMock.newRequestData()).
|
||||||
andReturn(new WebSocketExtensionData("main", Collections.<String, String>emptyMap())).once();
|
thenReturn(new WebSocketExtensionData("main", Collections.<String, String>emptyMap()));
|
||||||
expect(mainHandshakerMock.handshakeExtension(
|
when(mainHandshakerMock.handshakeExtension(
|
||||||
webSocketExtensionDataEqual("main"))).andReturn(mainExtensionMock).anyTimes();
|
webSocketExtensionDataMatcher("main"))).thenReturn(mainExtensionMock);
|
||||||
expect(mainHandshakerMock.handshakeExtension(
|
when(mainHandshakerMock.handshakeExtension(
|
||||||
webSocketExtensionDataEqual("fallback"))).andReturn(null).anyTimes();
|
webSocketExtensionDataMatcher("fallback"))).thenReturn(null);
|
||||||
replay(mainHandshakerMock);
|
when(fallbackHandshakerMock.newRequestData()).
|
||||||
|
thenReturn(new WebSocketExtensionData("fallback", Collections.<String, String>emptyMap()));
|
||||||
expect(fallbackHandshakerMock.newRequestData()).
|
when(fallbackHandshakerMock.handshakeExtension(
|
||||||
andReturn(new WebSocketExtensionData("fallback", Collections.<String, String>emptyMap())).once();
|
webSocketExtensionDataMatcher("main"))).thenReturn(null);
|
||||||
expect(fallbackHandshakerMock.handshakeExtension(
|
when(fallbackHandshakerMock.handshakeExtension(
|
||||||
webSocketExtensionDataEqual("main"))).andReturn(null).anyTimes();
|
webSocketExtensionDataMatcher("fallback"))).thenReturn(fallbackExtensionMock);
|
||||||
expect(fallbackHandshakerMock.handshakeExtension(
|
|
||||||
webSocketExtensionDataEqual("fallback"))).andReturn(fallbackExtensionMock).anyTimes();
|
|
||||||
replay(fallbackHandshakerMock);
|
|
||||||
|
|
||||||
DummyEncoder mainEncoder = new DummyEncoder();
|
DummyEncoder mainEncoder = new DummyEncoder();
|
||||||
DummyDecoder mainDecoder = new DummyDecoder();
|
DummyDecoder mainDecoder = new DummyDecoder();
|
||||||
expect(mainExtensionMock.rsv()).andReturn(WebSocketExtension.RSV1).anyTimes();
|
when(mainExtensionMock.rsv()).thenReturn(WebSocketExtension.RSV1);
|
||||||
expect(mainExtensionMock.newExtensionEncoder()).andReturn(mainEncoder).once();
|
when(mainExtensionMock.newExtensionEncoder()).thenReturn(mainEncoder);
|
||||||
expect(mainExtensionMock.newExtensionDecoder()).andReturn(mainDecoder).once();
|
when(mainExtensionMock.newExtensionDecoder()).thenReturn(mainDecoder);
|
||||||
replay(mainExtensionMock);
|
|
||||||
|
|
||||||
Dummy2Encoder fallbackEncoder = new Dummy2Encoder();
|
Dummy2Encoder fallbackEncoder = new Dummy2Encoder();
|
||||||
Dummy2Decoder fallbackDecoder = new Dummy2Decoder();
|
Dummy2Decoder fallbackDecoder = new Dummy2Decoder();
|
||||||
expect(fallbackExtensionMock.rsv()).andReturn(WebSocketExtension.RSV2).anyTimes();
|
when(fallbackExtensionMock.rsv()).thenReturn(WebSocketExtension.RSV2);
|
||||||
expect(fallbackExtensionMock.newExtensionEncoder()).andReturn(fallbackEncoder).once();
|
when(fallbackExtensionMock.newExtensionEncoder()).thenReturn(fallbackEncoder);
|
||||||
expect(fallbackExtensionMock.newExtensionDecoder()).andReturn(fallbackDecoder).once();
|
when(fallbackExtensionMock.newExtensionDecoder()).thenReturn(fallbackDecoder);
|
||||||
replay(fallbackExtensionMock);
|
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
EmbeddedChannel ch = new EmbeddedChannel(new WebSocketClientExtensionHandler(
|
EmbeddedChannel ch = new EmbeddedChannel(new WebSocketClientExtensionHandler(
|
||||||
@ -198,36 +200,41 @@ public class WebSocketClientExtensionHandlerTest {
|
|||||||
assertEquals(2, resExts.size());
|
assertEquals(2, resExts.size());
|
||||||
assertEquals("main", resExts.get(0).name());
|
assertEquals("main", resExts.get(0).name());
|
||||||
assertEquals("fallback", resExts.get(1).name());
|
assertEquals("fallback", resExts.get(1).name());
|
||||||
assertTrue(ch.pipeline().context(mainEncoder) != null);
|
assertNotNull(ch.pipeline().context(mainEncoder));
|
||||||
assertTrue(ch.pipeline().context(mainDecoder) != null);
|
assertNotNull(ch.pipeline().context(mainDecoder));
|
||||||
assertTrue(ch.pipeline().context(fallbackEncoder) != null);
|
assertNotNull(ch.pipeline().context(fallbackEncoder));
|
||||||
assertTrue(ch.pipeline().context(fallbackDecoder) != null);
|
assertNotNull(ch.pipeline().context(fallbackDecoder));
|
||||||
|
|
||||||
|
verify(mainHandshakerMock).newRequestData();
|
||||||
|
verify(mainHandshakerMock).handshakeExtension(webSocketExtensionDataMatcher("main"));
|
||||||
|
verify(mainHandshakerMock).handshakeExtension(webSocketExtensionDataMatcher("fallback"));
|
||||||
|
verify(fallbackHandshakerMock).newRequestData();
|
||||||
|
verify(fallbackHandshakerMock).handshakeExtension(webSocketExtensionDataMatcher("fallback"));
|
||||||
|
verify(mainExtensionMock, atLeastOnce()).rsv();
|
||||||
|
verify(mainExtensionMock).newExtensionEncoder();
|
||||||
|
verify(mainExtensionMock).newExtensionDecoder();
|
||||||
|
verify(fallbackExtensionMock, atLeastOnce()).rsv();
|
||||||
|
verify(fallbackExtensionMock).newExtensionEncoder();
|
||||||
|
verify(fallbackExtensionMock).newExtensionDecoder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = CodecException.class)
|
@Test(expected = CodecException.class)
|
||||||
public void testIfMainAndFallbackUseRSV1WillFail() {
|
public void testIfMainAndFallbackUseRSV1WillFail() {
|
||||||
// initialize
|
// initialize
|
||||||
expect(mainHandshakerMock.newRequestData()).
|
when(mainHandshakerMock.newRequestData()).
|
||||||
andReturn(new WebSocketExtensionData("main", Collections.<String, String>emptyMap())).once();
|
thenReturn(new WebSocketExtensionData("main", Collections.<String, String>emptyMap()));
|
||||||
expect(mainHandshakerMock.handshakeExtension(
|
when(mainHandshakerMock.handshakeExtension(
|
||||||
webSocketExtensionDataEqual("main"))).andReturn(mainExtensionMock).anyTimes();
|
webSocketExtensionDataMatcher("main"))).thenReturn(mainExtensionMock);
|
||||||
expect(mainHandshakerMock.handshakeExtension(
|
when(mainHandshakerMock.handshakeExtension(
|
||||||
webSocketExtensionDataEqual("fallback"))).andReturn(null).anyTimes();
|
webSocketExtensionDataMatcher("fallback"))).thenReturn(null);
|
||||||
replay(mainHandshakerMock);
|
when(fallbackHandshakerMock.newRequestData()).
|
||||||
|
thenReturn(new WebSocketExtensionData("fallback", Collections.<String, String>emptyMap()));
|
||||||
expect(fallbackHandshakerMock.newRequestData()).
|
when(fallbackHandshakerMock.handshakeExtension(
|
||||||
andReturn(new WebSocketExtensionData("fallback", Collections.<String, String>emptyMap())).once();
|
webSocketExtensionDataMatcher("main"))).thenReturn(null);
|
||||||
expect(fallbackHandshakerMock.handshakeExtension(
|
when(fallbackHandshakerMock.handshakeExtension(
|
||||||
webSocketExtensionDataEqual("main"))).andReturn(null).anyTimes();
|
webSocketExtensionDataMatcher("fallback"))).thenReturn(fallbackExtensionMock);
|
||||||
expect(fallbackHandshakerMock.handshakeExtension(
|
when(mainExtensionMock.rsv()).thenReturn(WebSocketExtension.RSV1);
|
||||||
webSocketExtensionDataEqual("fallback"))).andReturn(fallbackExtensionMock).anyTimes();
|
when(fallbackExtensionMock.rsv()).thenReturn(WebSocketExtension.RSV1);
|
||||||
replay(fallbackHandshakerMock);
|
|
||||||
|
|
||||||
expect(mainExtensionMock.rsv()).andReturn(WebSocketExtension.RSV1).anyTimes();
|
|
||||||
replay(mainExtensionMock);
|
|
||||||
|
|
||||||
expect(fallbackExtensionMock.rsv()).andReturn(WebSocketExtension.RSV1).anyTimes();
|
|
||||||
replay(fallbackExtensionMock);
|
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
EmbeddedChannel ch = new EmbeddedChannel(new WebSocketClientExtensionHandler(
|
EmbeddedChannel ch = new EmbeddedChannel(new WebSocketClientExtensionHandler(
|
||||||
@ -247,6 +254,16 @@ public class WebSocketClientExtensionHandlerTest {
|
|||||||
assertEquals(2, reqExts.size());
|
assertEquals(2, reqExts.size());
|
||||||
assertEquals("main", reqExts.get(0).name());
|
assertEquals("main", reqExts.get(0).name());
|
||||||
assertEquals("fallback", reqExts.get(1).name());
|
assertEquals("fallback", reqExts.get(1).name());
|
||||||
}
|
|
||||||
|
|
||||||
|
verify(mainHandshakerMock).newRequestData();
|
||||||
|
verify(mainHandshakerMock, atLeastOnce()).handshakeExtension(webSocketExtensionDataMatcher("main"));
|
||||||
|
verify(mainHandshakerMock, atLeastOnce()).handshakeExtension(webSocketExtensionDataMatcher("fallback"));
|
||||||
|
|
||||||
|
verify(fallbackHandshakerMock).newRequestData();
|
||||||
|
verify(fallbackHandshakerMock, atLeastOnce()).handshakeExtension(webSocketExtensionDataMatcher("main"));
|
||||||
|
verify(fallbackHandshakerMock, atLeastOnce()).handshakeExtension(webSocketExtensionDataMatcher("fallback"));
|
||||||
|
|
||||||
|
verify(mainExtensionMock, atLeastOnce()).rsv();
|
||||||
|
verify(fallbackExtensionMock, atLeastOnce()).rsv();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,6 @@ import java.util.List;
|
|||||||
|
|
||||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||||
import io.netty.handler.codec.http.HttpHeaderValues;
|
import io.netty.handler.codec.http.HttpHeaderValues;
|
||||||
import org.easymock.EasyMock;
|
|
||||||
import org.easymock.IArgumentMatcher;
|
|
||||||
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.http.DefaultHttpRequest;
|
import io.netty.handler.codec.http.DefaultHttpRequest;
|
||||||
@ -31,6 +29,9 @@ import io.netty.handler.codec.http.HttpRequest;
|
|||||||
import io.netty.handler.codec.http.HttpResponse;
|
import io.netty.handler.codec.http.HttpResponse;
|
||||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
import io.netty.handler.codec.http.HttpVersion;
|
import io.netty.handler.codec.http.HttpVersion;
|
||||||
|
import org.mockito.ArgumentMatcher;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.argThat;
|
||||||
|
|
||||||
public final class WebSocketExtensionTestUtil {
|
public final class WebSocketExtensionTestUtil {
|
||||||
|
|
||||||
@ -64,12 +65,7 @@ public final class WebSocketExtensionTestUtil {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WebSocketExtensionData webSocketExtensionDataEqual(String name) {
|
static final class WebSocketExtensionDataMatcher implements ArgumentMatcher<WebSocketExtensionData> {
|
||||||
EasyMock.reportMatcher(new WebSocketExtensionDataMatcher(name));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class WebSocketExtensionDataMatcher implements IArgumentMatcher {
|
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
@ -78,15 +74,13 @@ public final class WebSocketExtensionTestUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendTo(StringBuffer buf) {
|
public boolean matches(WebSocketExtensionData data) {
|
||||||
buf.append("WebSocketExtensionData with name=" + name);
|
return data != null && name.equals(data.name());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
static WebSocketExtensionData webSocketExtensionDataMatcher(String text) {
|
||||||
public boolean matches(Object o) {
|
return argThat(new WebSocketExtensionDataMatcher(text));
|
||||||
return o instanceof WebSocketExtensionData &&
|
|
||||||
name.equals(((WebSocketExtensionData) o).name());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private WebSocketExtensionTestUtil() {
|
private WebSocketExtensionTestUtil() {
|
||||||
@ -124,5 +118,4 @@ public final class WebSocketExtensionTestUtil {
|
|||||||
// unused
|
// unused
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -26,44 +26,40 @@ import java.util.List;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionTestUtil.*;
|
import static io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionTestUtil.*;
|
||||||
import static org.easymock.EasyMock.*;
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
public class WebSocketServerExtensionHandlerTest {
|
public class WebSocketServerExtensionHandlerTest {
|
||||||
|
|
||||||
WebSocketServerExtensionHandshaker mainHandshakerMock =
|
WebSocketServerExtensionHandshaker mainHandshakerMock =
|
||||||
createMock("mainHandshaker", WebSocketServerExtensionHandshaker.class);
|
mock(WebSocketServerExtensionHandshaker.class, "mainHandshaker");
|
||||||
WebSocketServerExtensionHandshaker fallbackHandshakerMock =
|
WebSocketServerExtensionHandshaker fallbackHandshakerMock =
|
||||||
createMock("fallbackHandshaker", WebSocketServerExtensionHandshaker.class);
|
mock(WebSocketServerExtensionHandshaker.class, "fallbackHandshaker");
|
||||||
WebSocketServerExtension mainExtensionMock =
|
WebSocketServerExtension mainExtensionMock =
|
||||||
createMock("mainExtension", WebSocketServerExtension.class);
|
mock(WebSocketServerExtension.class, "mainExtension");
|
||||||
WebSocketServerExtension fallbackExtensionMock =
|
WebSocketServerExtension fallbackExtensionMock =
|
||||||
createMock("fallbackExtension", WebSocketServerExtension.class);
|
mock(WebSocketServerExtension.class, "fallbackExtension");
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMainSuccess() {
|
public void testMainSuccess() {
|
||||||
// initialize
|
// initialize
|
||||||
expect(mainHandshakerMock.handshakeExtension(webSocketExtensionDataEqual("main"))).
|
when(mainHandshakerMock.handshakeExtension(webSocketExtensionDataMatcher("main"))).
|
||||||
andReturn(mainExtensionMock).anyTimes();
|
thenReturn(mainExtensionMock);
|
||||||
expect(mainHandshakerMock.handshakeExtension(webSocketExtensionDataEqual("fallback"))).
|
when(mainHandshakerMock.handshakeExtension(webSocketExtensionDataMatcher("fallback"))).
|
||||||
andReturn(null).anyTimes();
|
thenReturn(null);
|
||||||
replay(mainHandshakerMock);
|
|
||||||
|
|
||||||
expect(fallbackHandshakerMock.handshakeExtension(webSocketExtensionDataEqual("fallback"))).
|
when(fallbackHandshakerMock.handshakeExtension(webSocketExtensionDataMatcher("fallback"))).
|
||||||
andReturn(fallbackExtensionMock).anyTimes();
|
thenReturn(fallbackExtensionMock);
|
||||||
expect(fallbackHandshakerMock.handshakeExtension(webSocketExtensionDataEqual("main"))).
|
when(fallbackHandshakerMock.handshakeExtension(webSocketExtensionDataMatcher("main"))).
|
||||||
andReturn(null).anyTimes();
|
thenReturn(null);
|
||||||
replay(fallbackHandshakerMock);
|
|
||||||
|
|
||||||
expect(mainExtensionMock.rsv()).andReturn(WebSocketExtension.RSV1).anyTimes();
|
when(mainExtensionMock.rsv()).thenReturn(WebSocketExtension.RSV1);
|
||||||
expect(mainExtensionMock.newReponseData()).andReturn(
|
when(mainExtensionMock.newReponseData()).thenReturn(
|
||||||
new WebSocketExtensionData("main", Collections.<String, String>emptyMap())).once();
|
new WebSocketExtensionData("main", Collections.<String, String>emptyMap()));
|
||||||
expect(mainExtensionMock.newExtensionEncoder()).andReturn(new DummyEncoder()).once();
|
when(mainExtensionMock.newExtensionEncoder()).thenReturn(new DummyEncoder());
|
||||||
expect(mainExtensionMock.newExtensionDecoder()).andReturn(new DummyDecoder()).once();
|
when(mainExtensionMock.newExtensionDecoder()).thenReturn(new DummyDecoder());
|
||||||
replay(mainExtensionMock);
|
|
||||||
|
|
||||||
expect(fallbackExtensionMock.rsv()).andReturn(WebSocketExtension.RSV1).anyTimes();
|
when(fallbackExtensionMock.rsv()).thenReturn(WebSocketExtension.RSV1);
|
||||||
replay(fallbackExtensionMock);
|
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
EmbeddedChannel ch = new EmbeddedChannel(new WebSocketServerExtensionHandler(
|
EmbeddedChannel ch = new EmbeddedChannel(new WebSocketServerExtensionHandler(
|
||||||
@ -83,38 +79,44 @@ public class WebSocketServerExtensionHandlerTest {
|
|||||||
assertEquals(1, resExts.size());
|
assertEquals(1, resExts.size());
|
||||||
assertEquals("main", resExts.get(0).name());
|
assertEquals("main", resExts.get(0).name());
|
||||||
assertTrue(resExts.get(0).parameters().isEmpty());
|
assertTrue(resExts.get(0).parameters().isEmpty());
|
||||||
assertTrue(ch.pipeline().get(DummyDecoder.class) != null);
|
assertNotNull(ch.pipeline().get(DummyDecoder.class));
|
||||||
assertTrue(ch.pipeline().get(DummyEncoder.class) != null);
|
assertNotNull(ch.pipeline().get(DummyEncoder.class));
|
||||||
|
|
||||||
|
verify(mainHandshakerMock, atLeastOnce()).handshakeExtension(webSocketExtensionDataMatcher("main"));
|
||||||
|
verify(mainHandshakerMock, atLeastOnce()).handshakeExtension(webSocketExtensionDataMatcher("fallback"));
|
||||||
|
verify(fallbackHandshakerMock, atLeastOnce()).handshakeExtension(webSocketExtensionDataMatcher("fallback"));
|
||||||
|
|
||||||
|
verify(mainExtensionMock, atLeastOnce()).rsv();
|
||||||
|
verify(mainExtensionMock).newReponseData();
|
||||||
|
verify(mainExtensionMock).newExtensionEncoder();
|
||||||
|
verify(mainExtensionMock).newExtensionDecoder();
|
||||||
|
verify(fallbackExtensionMock, atLeastOnce()).rsv();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCompatibleExtensionTogetherSuccess() {
|
public void testCompatibleExtensionTogetherSuccess() {
|
||||||
// initialize
|
// initialize
|
||||||
expect(mainHandshakerMock.handshakeExtension(webSocketExtensionDataEqual("main"))).
|
when(mainHandshakerMock.handshakeExtension(webSocketExtensionDataMatcher("main"))).
|
||||||
andReturn(mainExtensionMock).anyTimes();
|
thenReturn(mainExtensionMock);
|
||||||
expect(mainHandshakerMock.handshakeExtension(webSocketExtensionDataEqual("fallback"))).
|
when(mainHandshakerMock.handshakeExtension(webSocketExtensionDataMatcher("fallback"))).
|
||||||
andReturn(null).anyTimes();
|
thenReturn(null);
|
||||||
replay(mainHandshakerMock);
|
|
||||||
|
|
||||||
expect(fallbackHandshakerMock.handshakeExtension(webSocketExtensionDataEqual("fallback"))).
|
when(fallbackHandshakerMock.handshakeExtension(webSocketExtensionDataMatcher("fallback"))).
|
||||||
andReturn(fallbackExtensionMock).anyTimes();
|
thenReturn(fallbackExtensionMock);
|
||||||
expect(fallbackHandshakerMock.handshakeExtension(webSocketExtensionDataEqual("main"))).
|
when(fallbackHandshakerMock.handshakeExtension(webSocketExtensionDataMatcher("main"))).
|
||||||
andReturn(null).anyTimes();
|
thenReturn(null);
|
||||||
replay(fallbackHandshakerMock);
|
|
||||||
|
|
||||||
expect(mainExtensionMock.rsv()).andReturn(WebSocketExtension.RSV1).anyTimes();
|
when(mainExtensionMock.rsv()).thenReturn(WebSocketExtension.RSV1);
|
||||||
expect(mainExtensionMock.newReponseData()).andReturn(
|
when(mainExtensionMock.newReponseData()).thenReturn(
|
||||||
new WebSocketExtensionData("main", Collections.<String, String>emptyMap())).once();
|
new WebSocketExtensionData("main", Collections.<String, String>emptyMap()));
|
||||||
expect(mainExtensionMock.newExtensionEncoder()).andReturn(new DummyEncoder()).once();
|
when(mainExtensionMock.newExtensionEncoder()).thenReturn(new DummyEncoder());
|
||||||
expect(mainExtensionMock.newExtensionDecoder()).andReturn(new DummyDecoder()).once();
|
when(mainExtensionMock.newExtensionDecoder()).thenReturn(new DummyDecoder());
|
||||||
replay(mainExtensionMock);
|
|
||||||
|
|
||||||
expect(fallbackExtensionMock.rsv()).andReturn(WebSocketExtension.RSV2).anyTimes();
|
when(fallbackExtensionMock.rsv()).thenReturn(WebSocketExtension.RSV2);
|
||||||
expect(fallbackExtensionMock.newReponseData()).andReturn(
|
when(fallbackExtensionMock.newReponseData()).thenReturn(
|
||||||
new WebSocketExtensionData("fallback", Collections.<String, String>emptyMap())).once();
|
new WebSocketExtensionData("fallback", Collections.<String, String>emptyMap()));
|
||||||
expect(fallbackExtensionMock.newExtensionEncoder()).andReturn(new Dummy2Encoder()).once();
|
when(fallbackExtensionMock.newExtensionEncoder()).thenReturn(new Dummy2Encoder());
|
||||||
expect(fallbackExtensionMock.newExtensionDecoder()).andReturn(new Dummy2Decoder()).once();
|
when(fallbackExtensionMock.newExtensionDecoder()).thenReturn(new Dummy2Decoder());
|
||||||
replay(fallbackExtensionMock);
|
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
EmbeddedChannel ch = new EmbeddedChannel(new WebSocketServerExtensionHandler(
|
EmbeddedChannel ch = new EmbeddedChannel(new WebSocketServerExtensionHandler(
|
||||||
@ -134,26 +136,38 @@ public class WebSocketServerExtensionHandlerTest {
|
|||||||
assertEquals(2, resExts.size());
|
assertEquals(2, resExts.size());
|
||||||
assertEquals("main", resExts.get(0).name());
|
assertEquals("main", resExts.get(0).name());
|
||||||
assertEquals("fallback", resExts.get(1).name());
|
assertEquals("fallback", resExts.get(1).name());
|
||||||
assertTrue(ch.pipeline().get(DummyDecoder.class) != null);
|
assertNotNull(ch.pipeline().get(DummyDecoder.class));
|
||||||
assertTrue(ch.pipeline().get(DummyEncoder.class) != null);
|
assertNotNull(ch.pipeline().get(DummyEncoder.class));
|
||||||
assertTrue(ch.pipeline().get(Dummy2Decoder.class) != null);
|
assertNotNull(ch.pipeline().get(Dummy2Decoder.class));
|
||||||
assertTrue(ch.pipeline().get(Dummy2Encoder.class) != null);
|
assertNotNull(ch.pipeline().get(Dummy2Encoder.class));
|
||||||
|
|
||||||
|
verify(mainHandshakerMock).handshakeExtension(webSocketExtensionDataMatcher("main"));
|
||||||
|
verify(mainHandshakerMock).handshakeExtension(webSocketExtensionDataMatcher("fallback"));
|
||||||
|
verify(fallbackHandshakerMock).handshakeExtension(webSocketExtensionDataMatcher("fallback"));
|
||||||
|
verify(mainExtensionMock, times(2)).rsv();
|
||||||
|
verify(mainExtensionMock).newReponseData();
|
||||||
|
verify(mainExtensionMock).newExtensionEncoder();
|
||||||
|
verify(mainExtensionMock).newExtensionDecoder();
|
||||||
|
|
||||||
|
verify(fallbackExtensionMock, times(2)).rsv();
|
||||||
|
|
||||||
|
verify(fallbackExtensionMock).newReponseData();
|
||||||
|
verify(fallbackExtensionMock).newExtensionEncoder();
|
||||||
|
verify(fallbackExtensionMock).newExtensionDecoder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoneExtensionMatchingSuccess() {
|
public void testNoneExtensionMatchingSuccess() {
|
||||||
// initialize
|
// initialize
|
||||||
expect(mainHandshakerMock.handshakeExtension(webSocketExtensionDataEqual("unknown"))).
|
when(mainHandshakerMock.handshakeExtension(webSocketExtensionDataMatcher("unknown"))).
|
||||||
andReturn(null).anyTimes();
|
thenReturn(null);
|
||||||
expect(mainHandshakerMock.handshakeExtension(webSocketExtensionDataEqual("unknown2"))).
|
when(mainHandshakerMock.handshakeExtension(webSocketExtensionDataMatcher("unknown2"))).
|
||||||
andReturn(null).anyTimes();
|
thenReturn(null);
|
||||||
replay(mainHandshakerMock);
|
|
||||||
|
|
||||||
expect(fallbackHandshakerMock.handshakeExtension(webSocketExtensionDataEqual("unknown"))).
|
when(fallbackHandshakerMock.handshakeExtension(webSocketExtensionDataMatcher("unknown"))).
|
||||||
andReturn(null).anyTimes();
|
thenReturn(null);
|
||||||
expect(fallbackHandshakerMock.handshakeExtension(webSocketExtensionDataEqual("unknown2"))).
|
when(fallbackHandshakerMock.handshakeExtension(webSocketExtensionDataMatcher("unknown2"))).
|
||||||
andReturn(null).anyTimes();
|
thenReturn(null);
|
||||||
replay(fallbackHandshakerMock);
|
|
||||||
|
|
||||||
// execute
|
// execute
|
||||||
EmbeddedChannel ch = new EmbeddedChannel(new WebSocketServerExtensionHandler(
|
EmbeddedChannel ch = new EmbeddedChannel(new WebSocketServerExtensionHandler(
|
||||||
@ -169,6 +183,11 @@ public class WebSocketServerExtensionHandlerTest {
|
|||||||
|
|
||||||
// test
|
// test
|
||||||
assertFalse(res2.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
assertFalse(res2.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_EXTENSIONS));
|
||||||
}
|
|
||||||
|
|
||||||
|
verify(mainHandshakerMock).handshakeExtension(webSocketExtensionDataMatcher("unknown"));
|
||||||
|
verify(mainHandshakerMock).handshakeExtension(webSocketExtensionDataMatcher("unknown2"));
|
||||||
|
|
||||||
|
verify(fallbackHandshakerMock).handshakeExtension(webSocketExtensionDataMatcher("unknown"));
|
||||||
|
verify(fallbackHandshakerMock).handshakeExtension(webSocketExtensionDataMatcher("unknown2"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,110 +17,123 @@ package io.netty.handler.codec.spdy;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayDeque;
|
||||||
|
import java.util.Queue;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import static io.netty.handler.codec.spdy.SpdyCodecUtil.SPDY_HEADER_SIZE;
|
import static io.netty.handler.codec.spdy.SpdyCodecUtil.SPDY_HEADER_SIZE;
|
||||||
import static org.easymock.EasyMock.anyObject;
|
|
||||||
import static org.easymock.EasyMock.createStrictMock;
|
|
||||||
import static org.easymock.EasyMock.expectLastCall;
|
|
||||||
import static org.easymock.EasyMock.replay;
|
|
||||||
import static org.easymock.EasyMock.verify;
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
public class SpdyFrameDecoderTest {
|
public class SpdyFrameDecoderTest {
|
||||||
|
|
||||||
private static final Random RANDOM = new Random();
|
private static final Random RANDOM = new Random();
|
||||||
|
|
||||||
private final SpdyFrameDecoderDelegate delegate = createStrictMock(SpdyFrameDecoderDelegate.class);
|
private final SpdyFrameDecoderDelegate delegate = mock(SpdyFrameDecoderDelegate.class);
|
||||||
|
private final TestSpdyFrameDecoderDelegate testDelegate = new TestSpdyFrameDecoderDelegate();
|
||||||
private SpdyFrameDecoder decoder;
|
private SpdyFrameDecoder decoder;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void createDecoder() {
|
public void createDecoder() {
|
||||||
decoder = new SpdyFrameDecoder(SpdyVersion.SPDY_3_1, new SpdyFrameDecoderDelegate() {
|
decoder = new SpdyFrameDecoder(SpdyVersion.SPDY_3_1, testDelegate);
|
||||||
@Override
|
}
|
||||||
public void readDataFrame(int streamId, boolean last, ByteBuf data) {
|
|
||||||
try {
|
@After
|
||||||
delegate.readDataFrame(streamId, last, data);
|
public void releaseBuffers() {
|
||||||
} finally {
|
testDelegate.releaseAll();
|
||||||
// release the data after we delegate it and so checked it.
|
}
|
||||||
data.release();
|
|
||||||
|
private final class TestSpdyFrameDecoderDelegate implements SpdyFrameDecoderDelegate {
|
||||||
|
private final Queue<ByteBuf> buffers = new ArrayDeque<ByteBuf>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readDataFrame(int streamId, boolean last, ByteBuf data) {
|
||||||
|
delegate.readDataFrame(streamId, last, data);
|
||||||
|
buffers.add(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readSynStreamFrame(int streamId, int associatedToStreamId,
|
||||||
|
byte priority, boolean last, boolean unidirectional) {
|
||||||
|
delegate.readSynStreamFrame(streamId, associatedToStreamId, priority, last, unidirectional);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readSynReplyFrame(int streamId, boolean last) {
|
||||||
|
delegate.readSynReplyFrame(streamId, last);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readRstStreamFrame(int streamId, int statusCode) {
|
||||||
|
delegate.readRstStreamFrame(streamId, statusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readSettingsFrame(boolean clearPersisted) {
|
||||||
|
delegate.readSettingsFrame(clearPersisted);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readSetting(int id, int value, boolean persistValue, boolean persisted) {
|
||||||
|
delegate.readSetting(id, value, persistValue, persisted);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readSettingsEnd() {
|
||||||
|
delegate.readSettingsEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readPingFrame(int id) {
|
||||||
|
delegate.readPingFrame(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readGoAwayFrame(int lastGoodStreamId, int statusCode) {
|
||||||
|
delegate.readGoAwayFrame(lastGoodStreamId, statusCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readHeadersFrame(int streamId, boolean last) {
|
||||||
|
delegate.readHeadersFrame(streamId, last);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readWindowUpdateFrame(int streamId, int deltaWindowSize) {
|
||||||
|
delegate.readWindowUpdateFrame(streamId, deltaWindowSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readHeaderBlock(ByteBuf headerBlock) {
|
||||||
|
delegate.readHeaderBlock(headerBlock);
|
||||||
|
buffers.add(headerBlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readHeaderBlockEnd() {
|
||||||
|
delegate.readHeaderBlockEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readFrameError(String message) {
|
||||||
|
delegate.readFrameError(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void releaseAll() {
|
||||||
|
for (;;) {
|
||||||
|
ByteBuf buf = buffers.poll();
|
||||||
|
if (buf == null) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
buf.release();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void readSynStreamFrame(int streamId, int associatedToStreamId,
|
|
||||||
byte priority, boolean last, boolean unidirectional) {
|
|
||||||
delegate.readSynStreamFrame(streamId, associatedToStreamId, priority, last, unidirectional);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readSynReplyFrame(int streamId, boolean last) {
|
|
||||||
delegate.readSynReplyFrame(streamId, last);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readRstStreamFrame(int streamId, int statusCode) {
|
|
||||||
delegate.readRstStreamFrame(streamId, statusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readSettingsFrame(boolean clearPersisted) {
|
|
||||||
delegate.readSettingsFrame(clearPersisted);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readSetting(int id, int value, boolean persistValue, boolean persisted) {
|
|
||||||
delegate.readSetting(id, value, persistValue, persisted);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readSettingsEnd() {
|
|
||||||
delegate.readSettingsEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readPingFrame(int id) {
|
|
||||||
delegate.readPingFrame(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readGoAwayFrame(int lastGoodStreamId, int statusCode) {
|
|
||||||
delegate.readGoAwayFrame(lastGoodStreamId, statusCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readHeadersFrame(int streamId, boolean last) {
|
|
||||||
delegate.readHeadersFrame(streamId, last);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readWindowUpdateFrame(int streamId, int deltaWindowSize) {
|
|
||||||
delegate.readWindowUpdateFrame(streamId, deltaWindowSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readHeaderBlock(ByteBuf headerBlock) {
|
|
||||||
try {
|
|
||||||
delegate.readHeaderBlock(headerBlock);
|
|
||||||
} finally {
|
|
||||||
// release the data after we delegate it and so checked it.
|
|
||||||
headerBlock.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readHeaderBlockEnd() {
|
|
||||||
delegate.readHeaderBlockEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void readFrameError(String message) {
|
|
||||||
delegate.readFrameError(message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void encodeDataFrameHeader(ByteBuf buffer, int streamId, byte flags, int length) {
|
private static void encodeDataFrameHeader(ByteBuf buffer, int streamId, byte flags, int length) {
|
||||||
@ -147,10 +160,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
for (int i = 0; i < 256; i ++) {
|
for (int i = 0; i < 256; i ++) {
|
||||||
buf.writeInt(RANDOM.nextInt());
|
buf.writeInt(RANDOM.nextInt());
|
||||||
}
|
}
|
||||||
delegate.readDataFrame(streamId, false, buf.slice(SPDY_HEADER_SIZE, length));
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readDataFrame(streamId, false, buf.slice(SPDY_HEADER_SIZE, length));
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -164,10 +175,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||||
encodeDataFrameHeader(buf, streamId, flags, length);
|
encodeDataFrameHeader(buf, streamId, flags, length);
|
||||||
|
|
||||||
delegate.readDataFrame(streamId, false, Unpooled.EMPTY_BUFFER);
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readDataFrame(streamId, false, Unpooled.EMPTY_BUFFER);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -181,10 +190,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||||
encodeDataFrameHeader(buf, streamId, flags, length);
|
encodeDataFrameHeader(buf, streamId, flags, length);
|
||||||
|
|
||||||
delegate.readDataFrame(streamId, true, Unpooled.EMPTY_BUFFER);
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readDataFrame(streamId, true, Unpooled.EMPTY_BUFFER);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -198,10 +205,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||||
encodeDataFrameHeader(buf, streamId, flags, length);
|
encodeDataFrameHeader(buf, streamId, flags, length);
|
||||||
|
|
||||||
delegate.readDataFrame(streamId, false, Unpooled.EMPTY_BUFFER);
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readDataFrame(streamId, false, Unpooled.EMPTY_BUFFER);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -215,10 +220,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||||
encodeDataFrameHeader(buf, streamId, flags, length);
|
encodeDataFrameHeader(buf, streamId, flags, length);
|
||||||
|
|
||||||
delegate.readFrameError((String) anyObject());
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readFrameError((String) any());
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -234,11 +237,9 @@ public class SpdyFrameDecoderTest {
|
|||||||
encodeDataFrameHeader(buf, streamId1, flags, length);
|
encodeDataFrameHeader(buf, streamId1, flags, length);
|
||||||
encodeDataFrameHeader(buf, streamId2, flags, length);
|
encodeDataFrameHeader(buf, streamId2, flags, length);
|
||||||
|
|
||||||
delegate.readDataFrame(streamId1, false, Unpooled.EMPTY_BUFFER);
|
|
||||||
delegate.readDataFrame(streamId2, false, Unpooled.EMPTY_BUFFER);
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readDataFrame(streamId1, false, Unpooled.EMPTY_BUFFER);
|
||||||
|
verify(delegate).readDataFrame(streamId2, false, Unpooled.EMPTY_BUFFER);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -259,11 +260,9 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeByte(priority << 5);
|
buf.writeByte(priority << 5);
|
||||||
buf.writeByte(0);
|
buf.writeByte(0);
|
||||||
|
|
||||||
delegate.readSynStreamFrame(streamId, associatedToStreamId, priority, false, false);
|
|
||||||
delegate.readHeaderBlockEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readSynStreamFrame(streamId, associatedToStreamId, priority, false, false);
|
||||||
|
verify(delegate).readHeaderBlockEnd();
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -284,11 +283,9 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeByte(priority << 5);
|
buf.writeByte(priority << 5);
|
||||||
buf.writeByte(0);
|
buf.writeByte(0);
|
||||||
|
|
||||||
delegate.readSynStreamFrame(streamId, associatedToStreamId, priority, true, false);
|
|
||||||
delegate.readHeaderBlockEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readSynStreamFrame(streamId, associatedToStreamId, priority, true, false);
|
||||||
|
verify(delegate).readHeaderBlockEnd();
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -309,11 +306,9 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeByte(priority << 5);
|
buf.writeByte(priority << 5);
|
||||||
buf.writeByte(0);
|
buf.writeByte(0);
|
||||||
|
|
||||||
delegate.readSynStreamFrame(streamId, associatedToStreamId, priority, false, true);
|
|
||||||
delegate.readHeaderBlockEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readSynStreamFrame(streamId, associatedToStreamId, priority, false, true);
|
||||||
|
verify(delegate).readHeaderBlockEnd();
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -334,11 +329,9 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeByte(priority << 5);
|
buf.writeByte(priority << 5);
|
||||||
buf.writeByte(0);
|
buf.writeByte(0);
|
||||||
|
|
||||||
delegate.readSynStreamFrame(streamId, associatedToStreamId, priority, false, false);
|
|
||||||
delegate.readHeaderBlockEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readSynStreamFrame(streamId, associatedToStreamId, priority, false, false);
|
||||||
|
verify(delegate).readHeaderBlockEnd();
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -359,11 +352,9 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeByte(priority << 5);
|
buf.writeByte(priority << 5);
|
||||||
buf.writeByte(0);
|
buf.writeByte(0);
|
||||||
|
|
||||||
delegate.readSynStreamFrame(streamId, associatedToStreamId, priority, false, false);
|
|
||||||
delegate.readHeaderBlockEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readSynStreamFrame(streamId, associatedToStreamId, priority, false, false);
|
||||||
|
verify(delegate).readHeaderBlockEnd();
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -384,11 +375,9 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeByte(priority << 5 | 0x1F); // should ignore reserved bits
|
buf.writeByte(priority << 5 | 0x1F); // should ignore reserved bits
|
||||||
buf.writeByte(0xFF); // should ignore reserved bits
|
buf.writeByte(0xFF); // should ignore reserved bits
|
||||||
|
|
||||||
delegate.readSynStreamFrame(streamId, associatedToStreamId, priority, false, false);
|
|
||||||
delegate.readHeaderBlockEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readSynStreamFrame(streamId, associatedToStreamId, priority, false, false);
|
||||||
|
verify(delegate).readHeaderBlockEnd();
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -406,10 +395,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(streamId);
|
buf.writeInt(streamId);
|
||||||
buf.writeInt(associatedToStreamId);
|
buf.writeInt(associatedToStreamId);
|
||||||
|
|
||||||
delegate.readFrameError((String) anyObject());
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readFrameError(anyString());
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -430,10 +417,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeByte(priority << 5);
|
buf.writeByte(priority << 5);
|
||||||
buf.writeByte(0);
|
buf.writeByte(0);
|
||||||
|
|
||||||
delegate.readFrameError((String) anyObject());
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readFrameError(anyString());
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -460,13 +445,11 @@ public class SpdyFrameDecoderTest {
|
|||||||
headerBlock.writeInt(RANDOM.nextInt());
|
headerBlock.writeInt(RANDOM.nextInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate.readSynStreamFrame(streamId, associatedToStreamId, priority, false, false);
|
|
||||||
delegate.readHeaderBlock(headerBlock.duplicate());
|
|
||||||
delegate.readHeaderBlockEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
decoder.decode(headerBlock);
|
decoder.decode(headerBlock);
|
||||||
verify(delegate);
|
verify(delegate).readSynStreamFrame(streamId, associatedToStreamId, priority, false, false);
|
||||||
|
verify(delegate).readHeaderBlock(headerBlock.slice(0, headerBlock.writerIndex()));
|
||||||
|
verify(delegate).readHeaderBlockEnd();
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
assertFalse(headerBlock.isReadable());
|
assertFalse(headerBlock.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
@ -484,11 +467,9 @@ public class SpdyFrameDecoderTest {
|
|||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
buf.writeInt(streamId);
|
buf.writeInt(streamId);
|
||||||
|
|
||||||
delegate.readSynReplyFrame(streamId, false);
|
|
||||||
delegate.readHeaderBlockEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readSynReplyFrame(streamId, false);
|
||||||
|
verify(delegate).readHeaderBlockEnd();
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -504,11 +485,9 @@ public class SpdyFrameDecoderTest {
|
|||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
buf.writeInt(streamId);
|
buf.writeInt(streamId);
|
||||||
|
|
||||||
delegate.readSynReplyFrame(streamId, true);
|
|
||||||
delegate.readHeaderBlockEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readSynReplyFrame(streamId, true);
|
||||||
|
verify(delegate).readHeaderBlockEnd();
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -524,11 +503,9 @@ public class SpdyFrameDecoderTest {
|
|||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
buf.writeInt(streamId);
|
buf.writeInt(streamId);
|
||||||
|
|
||||||
delegate.readSynReplyFrame(streamId, false);
|
|
||||||
delegate.readHeaderBlockEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readSynReplyFrame(streamId, false);
|
||||||
|
verify(delegate).readHeaderBlockEnd();
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -544,11 +521,10 @@ public class SpdyFrameDecoderTest {
|
|||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
buf.writeInt(streamId | 0x80000000); // should ignore reserved bit
|
buf.writeInt(streamId | 0x80000000); // should ignore reserved bit
|
||||||
|
|
||||||
delegate.readSynReplyFrame(streamId, false);
|
|
||||||
delegate.readHeaderBlockEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readSynReplyFrame(streamId, false);
|
||||||
|
verify(delegate).readHeaderBlockEnd();
|
||||||
|
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -562,10 +538,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
|
|
||||||
delegate.readFrameError((String) anyObject());
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readFrameError(anyString());
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -581,10 +555,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
buf.writeInt(streamId);
|
buf.writeInt(streamId);
|
||||||
|
|
||||||
delegate.readFrameError((String) anyObject());
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readFrameError(anyString());
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -606,13 +578,11 @@ public class SpdyFrameDecoderTest {
|
|||||||
headerBlock.writeInt(RANDOM.nextInt());
|
headerBlock.writeInt(RANDOM.nextInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate.readSynReplyFrame(streamId, false);
|
|
||||||
delegate.readHeaderBlock(headerBlock.duplicate());
|
|
||||||
delegate.readHeaderBlockEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
decoder.decode(headerBlock);
|
decoder.decode(headerBlock);
|
||||||
verify(delegate);
|
verify(delegate).readSynReplyFrame(streamId, false);
|
||||||
|
verify(delegate).readHeaderBlock(headerBlock.slice(0, headerBlock.writerIndex()));
|
||||||
|
verify(delegate).readHeaderBlockEnd();
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
assertFalse(headerBlock.isReadable());
|
assertFalse(headerBlock.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
@ -632,10 +602,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(streamId);
|
buf.writeInt(streamId);
|
||||||
buf.writeInt(statusCode);
|
buf.writeInt(statusCode);
|
||||||
|
|
||||||
delegate.readRstStreamFrame(streamId, statusCode);
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readRstStreamFrame(streamId, statusCode);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -653,10 +621,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(streamId | 0x80000000); // should ignore reserved bit
|
buf.writeInt(streamId | 0x80000000); // should ignore reserved bit
|
||||||
buf.writeInt(statusCode);
|
buf.writeInt(statusCode);
|
||||||
|
|
||||||
delegate.readRstStreamFrame(streamId, statusCode);
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readRstStreamFrame(streamId, statusCode);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -674,10 +640,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(streamId);
|
buf.writeInt(streamId);
|
||||||
buf.writeInt(statusCode);
|
buf.writeInt(statusCode);
|
||||||
|
|
||||||
delegate.readFrameError((String) anyObject());
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readFrameError(anyString());
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -695,10 +659,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(streamId);
|
buf.writeInt(streamId);
|
||||||
buf.writeInt(statusCode);
|
buf.writeInt(statusCode);
|
||||||
|
|
||||||
delegate.readFrameError((String) anyObject());
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readFrameError(anyString());
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -716,10 +678,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(streamId);
|
buf.writeInt(streamId);
|
||||||
buf.writeInt(statusCode);
|
buf.writeInt(statusCode);
|
||||||
|
|
||||||
delegate.readFrameError((String) anyObject());
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readFrameError(anyString());
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -737,10 +697,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(streamId);
|
buf.writeInt(streamId);
|
||||||
buf.writeInt(statusCode);
|
buf.writeInt(statusCode);
|
||||||
|
|
||||||
delegate.readFrameError((String) anyObject());
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readFrameError(anyString());
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -764,13 +722,10 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(value);
|
buf.writeInt(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate.readSettingsFrame(false);
|
|
||||||
delegate.readSetting(id, value, false, false);
|
|
||||||
expectLastCall().times(numSettings);
|
|
||||||
delegate.readSettingsEnd();
|
delegate.readSettingsEnd();
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readSettingsFrame(false);
|
||||||
|
verify(delegate, times(numSettings)).readSetting(id, value, false, false);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -786,11 +741,9 @@ public class SpdyFrameDecoderTest {
|
|||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
buf.writeInt(numSettings);
|
buf.writeInt(numSettings);
|
||||||
|
|
||||||
delegate.readSettingsFrame(false);
|
|
||||||
delegate.readSettingsEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readSettingsFrame(false);
|
||||||
|
verify(delegate).readSettingsEnd();
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -806,11 +759,9 @@ public class SpdyFrameDecoderTest {
|
|||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
buf.writeInt(numSettings);
|
buf.writeInt(numSettings);
|
||||||
|
|
||||||
delegate.readSettingsFrame(true);
|
|
||||||
delegate.readSettingsEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readSettingsFrame(true);
|
||||||
|
verify(delegate).readSettingsEnd();
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -834,13 +785,10 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(value);
|
buf.writeInt(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate.readSettingsFrame(false);
|
|
||||||
delegate.readSetting(id, value, true, false);
|
|
||||||
expectLastCall().times(numSettings);
|
|
||||||
delegate.readSettingsEnd();
|
delegate.readSettingsEnd();
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readSettingsFrame(false);
|
||||||
|
verify(delegate, times(numSettings)).readSetting(id, value, true, false);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -864,13 +812,10 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(value);
|
buf.writeInt(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate.readSettingsFrame(false);
|
|
||||||
delegate.readSetting(id, value, false, true);
|
|
||||||
expectLastCall().times(numSettings);
|
|
||||||
delegate.readSettingsEnd();
|
delegate.readSettingsEnd();
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readSettingsFrame(false);
|
||||||
|
verify(delegate, times(numSettings)).readSetting(id, value, false, true);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -886,11 +831,9 @@ public class SpdyFrameDecoderTest {
|
|||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
buf.writeInt(numSettings);
|
buf.writeInt(numSettings);
|
||||||
|
|
||||||
delegate.readSettingsFrame(false);
|
|
||||||
delegate.readSettingsEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readSettingsFrame(false);
|
||||||
|
verify(delegate).readSettingsEnd();
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -914,13 +857,10 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(value);
|
buf.writeInt(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate.readSettingsFrame(false);
|
|
||||||
delegate.readSetting(id, value, false, false);
|
|
||||||
expectLastCall().times(numSettings);
|
|
||||||
delegate.readSettingsEnd();
|
delegate.readSettingsEnd();
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readSettingsFrame(false);
|
||||||
|
verify(delegate, times(numSettings)).readSetting(id, value, false, false);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -944,10 +884,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(value);
|
buf.writeInt(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate.readFrameError((String) anyObject());
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readFrameError(anyString());
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -971,10 +909,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(value);
|
buf.writeInt(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate.readFrameError((String) anyObject());
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readFrameError(anyString());
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -989,9 +925,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
buf.writeLong(RANDOM.nextLong());
|
buf.writeLong(RANDOM.nextLong());
|
||||||
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verifyZeroInteractions(delegate);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -1005,9 +940,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verifyZeroInteractions(delegate);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -1026,11 +960,10 @@ public class SpdyFrameDecoderTest {
|
|||||||
segment1.writeInt(RANDOM.nextInt());
|
segment1.writeInt(RANDOM.nextInt());
|
||||||
segment2.writeInt(RANDOM.nextInt());
|
segment2.writeInt(RANDOM.nextInt());
|
||||||
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(header);
|
decoder.decode(header);
|
||||||
decoder.decode(segment1);
|
decoder.decode(segment1);
|
||||||
decoder.decode(segment2);
|
decoder.decode(segment2);
|
||||||
verify(delegate);
|
verifyZeroInteractions(delegate);
|
||||||
assertFalse(header.isReadable());
|
assertFalse(header.isReadable());
|
||||||
assertFalse(segment1.isReadable());
|
assertFalse(segment1.isReadable());
|
||||||
assertFalse(segment2.isReadable());
|
assertFalse(segment2.isReadable());
|
||||||
@ -1050,10 +983,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
buf.writeInt(id);
|
buf.writeInt(id);
|
||||||
|
|
||||||
delegate.readPingFrame(id);
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readPingFrame(id);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -1069,10 +1000,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
buf.writeInt(id);
|
buf.writeInt(id);
|
||||||
|
|
||||||
delegate.readPingFrame(id);
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readPingFrame(id);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -1088,10 +1017,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
buf.writeInt(id);
|
buf.writeInt(id);
|
||||||
|
|
||||||
delegate.readFrameError((String) anyObject());
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readFrameError(anyString());
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -1109,10 +1036,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(lastGoodStreamId);
|
buf.writeInt(lastGoodStreamId);
|
||||||
buf.writeInt(statusCode);
|
buf.writeInt(statusCode);
|
||||||
|
|
||||||
delegate.readGoAwayFrame(lastGoodStreamId, statusCode);
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readGoAwayFrame(lastGoodStreamId, statusCode);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -1130,10 +1055,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(lastGoodStreamId);
|
buf.writeInt(lastGoodStreamId);
|
||||||
buf.writeInt(statusCode);
|
buf.writeInt(statusCode);
|
||||||
|
|
||||||
delegate.readGoAwayFrame(lastGoodStreamId, statusCode);
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readGoAwayFrame(lastGoodStreamId, statusCode);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -1151,10 +1074,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(lastGoodStreamId | 0x80000000); // should ignore reserved bit
|
buf.writeInt(lastGoodStreamId | 0x80000000); // should ignore reserved bit
|
||||||
buf.writeInt(statusCode);
|
buf.writeInt(statusCode);
|
||||||
|
|
||||||
delegate.readGoAwayFrame(lastGoodStreamId, statusCode);
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readGoAwayFrame(lastGoodStreamId, statusCode);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -1172,10 +1093,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(lastGoodStreamId);
|
buf.writeInt(lastGoodStreamId);
|
||||||
buf.writeInt(statusCode);
|
buf.writeInt(statusCode);
|
||||||
|
|
||||||
delegate.readFrameError((String) anyObject());
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readFrameError(anyString());
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -1191,11 +1110,9 @@ public class SpdyFrameDecoderTest {
|
|||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
buf.writeInt(streamId);
|
buf.writeInt(streamId);
|
||||||
|
|
||||||
delegate.readHeadersFrame(streamId, false);
|
|
||||||
delegate.readHeaderBlockEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readHeadersFrame(streamId, false);
|
||||||
|
verify(delegate).readHeaderBlockEnd();
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -1211,11 +1128,9 @@ public class SpdyFrameDecoderTest {
|
|||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
buf.writeInt(streamId);
|
buf.writeInt(streamId);
|
||||||
|
|
||||||
delegate.readHeadersFrame(streamId, true);
|
|
||||||
delegate.readHeaderBlockEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readHeadersFrame(streamId, true);
|
||||||
|
verify(delegate).readHeaderBlockEnd();
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -1231,11 +1146,9 @@ public class SpdyFrameDecoderTest {
|
|||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
buf.writeInt(streamId);
|
buf.writeInt(streamId);
|
||||||
|
|
||||||
delegate.readHeadersFrame(streamId, false);
|
|
||||||
delegate.readHeaderBlockEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readHeadersFrame(streamId, false);
|
||||||
|
verify(delegate).readHeaderBlockEnd();
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -1251,11 +1164,9 @@ public class SpdyFrameDecoderTest {
|
|||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
buf.writeInt(streamId | 0x80000000); // should ignore reserved bit
|
buf.writeInt(streamId | 0x80000000); // should ignore reserved bit
|
||||||
|
|
||||||
delegate.readHeadersFrame(streamId, false);
|
|
||||||
delegate.readHeaderBlockEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readHeadersFrame(streamId, false);
|
||||||
|
verify(delegate).readHeaderBlockEnd();
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -1269,10 +1180,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
ByteBuf buf = Unpooled.buffer(SPDY_HEADER_SIZE + length);
|
||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
|
|
||||||
delegate.readFrameError((String) anyObject());
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readFrameError(anyString());
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -1288,10 +1197,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
encodeControlFrameHeader(buf, type, flags, length);
|
encodeControlFrameHeader(buf, type, flags, length);
|
||||||
buf.writeInt(streamId);
|
buf.writeInt(streamId);
|
||||||
|
|
||||||
delegate.readFrameError((String) anyObject());
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readFrameError(anyString());
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -1312,14 +1219,11 @@ public class SpdyFrameDecoderTest {
|
|||||||
for (int i = 0; i < 256; i ++) {
|
for (int i = 0; i < 256; i ++) {
|
||||||
headerBlock.writeInt(RANDOM.nextInt());
|
headerBlock.writeInt(RANDOM.nextInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate.readHeadersFrame(streamId, false);
|
|
||||||
delegate.readHeaderBlock(headerBlock.duplicate());
|
|
||||||
delegate.readHeaderBlockEnd();
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
decoder.decode(headerBlock);
|
decoder.decode(headerBlock);
|
||||||
verify(delegate);
|
verify(delegate).readHeadersFrame(streamId, false);
|
||||||
|
verify(delegate).readHeaderBlock(headerBlock.slice(0, headerBlock.writerIndex()));
|
||||||
|
verify(delegate).readHeaderBlockEnd();
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
assertFalse(headerBlock.isReadable());
|
assertFalse(headerBlock.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
@ -1339,10 +1243,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(streamId);
|
buf.writeInt(streamId);
|
||||||
buf.writeInt(deltaWindowSize);
|
buf.writeInt(deltaWindowSize);
|
||||||
|
|
||||||
delegate.readWindowUpdateFrame(streamId, deltaWindowSize);
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readWindowUpdateFrame(streamId, deltaWindowSize);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1359,10 +1261,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(streamId);
|
buf.writeInt(streamId);
|
||||||
buf.writeInt(deltaWindowSize);
|
buf.writeInt(deltaWindowSize);
|
||||||
|
|
||||||
delegate.readWindowUpdateFrame(streamId, deltaWindowSize);
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readWindowUpdateFrame(streamId, deltaWindowSize);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -1380,10 +1280,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(streamId | 0x80000000); // should ignore reserved bit
|
buf.writeInt(streamId | 0x80000000); // should ignore reserved bit
|
||||||
buf.writeInt(deltaWindowSize | 0x80000000); // should ignore reserved bit
|
buf.writeInt(deltaWindowSize | 0x80000000); // should ignore reserved bit
|
||||||
|
|
||||||
delegate.readWindowUpdateFrame(streamId, deltaWindowSize);
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readWindowUpdateFrame(streamId, deltaWindowSize);
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -1401,10 +1299,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(streamId);
|
buf.writeInt(streamId);
|
||||||
buf.writeInt(deltaWindowSize);
|
buf.writeInt(deltaWindowSize);
|
||||||
|
|
||||||
delegate.readFrameError((String) anyObject());
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readFrameError(anyString());
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
@ -1422,10 +1318,8 @@ public class SpdyFrameDecoderTest {
|
|||||||
buf.writeInt(streamId);
|
buf.writeInt(streamId);
|
||||||
buf.writeInt(deltaWindowSize);
|
buf.writeInt(deltaWindowSize);
|
||||||
|
|
||||||
delegate.readFrameError((String) anyObject());
|
|
||||||
replay(delegate);
|
|
||||||
decoder.decode(buf);
|
decoder.decode(buf);
|
||||||
verify(delegate);
|
verify(delegate).readFrameError(anyString());
|
||||||
assertFalse(buf.isReadable());
|
assertFalse(buf.isReadable());
|
||||||
buf.release();
|
buf.release();
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,10 @@
|
|||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
<artifactId>gson</artifactId>
|
<artifactId>gson</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
@ -33,8 +33,8 @@ abstract class AbstractWeightedFairQueueByteDistributorDependencyTest {
|
|||||||
return new Answer<Void>() {
|
return new Answer<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void answer(InvocationOnMock in) throws Throwable {
|
public Void answer(InvocationOnMock in) throws Throwable {
|
||||||
Http2Stream stream = in.getArgumentAt(0, Http2Stream.class);
|
Http2Stream stream = in.getArgument(0);
|
||||||
int numBytes = in.getArgumentAt(1, Integer.class);
|
int numBytes = in.getArgument(1);
|
||||||
int streamableBytes = distributor.streamableBytes0(stream) - numBytes;
|
int streamableBytes = distributor.streamableBytes0(stream) - numBytes;
|
||||||
boolean hasFrame = streamableBytes > 0;
|
boolean hasFrame = streamableBytes > 0;
|
||||||
updateStream(stream.id(), streamableBytes, hasFrame, hasFrame, closeIfNoFrame);
|
updateStream(stream.id(), streamableBytes, hasFrame, hasFrame, closeIfNoFrame);
|
||||||
|
@ -93,8 +93,8 @@ public class DataCompressionHttp2Test {
|
|||||||
doAnswer(new Answer<Void>() {
|
doAnswer(new Answer<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||||
if (invocation.getArgumentAt(4, Boolean.class)) {
|
if (invocation.getArgument(4)) {
|
||||||
serverConnection.stream(invocation.getArgumentAt(1, Integer.class)).close();
|
serverConnection.stream((Integer) invocation.getArgument(1)).close();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -103,8 +103,8 @@ public class DataCompressionHttp2Test {
|
|||||||
doAnswer(new Answer<Void>() {
|
doAnswer(new Answer<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||||
if (invocation.getArgumentAt(7, Boolean.class)) {
|
if (invocation.getArgument(7)) {
|
||||||
serverConnection.stream(invocation.getArgumentAt(1, Integer.class)).close();
|
serverConnection.stream((Integer) invocation.getArgument(1)).close();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -283,8 +283,8 @@ public class DataCompressionHttp2Test {
|
|||||||
|
|
||||||
buf.readBytes(serverOut, buf.readableBytes());
|
buf.readBytes(serverOut, buf.readableBytes());
|
||||||
|
|
||||||
if (in.getArgumentAt(4, Boolean.class)) {
|
if (in.getArgument(4)) {
|
||||||
serverConnection.stream(in.getArgumentAt(1, Integer.class)).close();
|
serverConnection.stream((Integer) in.getArgument(1)).close();
|
||||||
}
|
}
|
||||||
return processedBytes;
|
return processedBytes;
|
||||||
}
|
}
|
||||||
|
@ -107,6 +107,9 @@ public class DefaultHttp2ConnectionDecoderTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private Http2FrameReader reader;
|
private Http2FrameReader reader;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private Http2FrameWriter writer;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Http2ConnectionEncoder encoder;
|
private Http2ConnectionEncoder encoder;
|
||||||
|
|
||||||
@ -127,7 +130,7 @@ public class DefaultHttp2ConnectionDecoderTest {
|
|||||||
doAnswer(new Answer<Http2Stream>() {
|
doAnswer(new Answer<Http2Stream>() {
|
||||||
@Override
|
@Override
|
||||||
public Http2Stream answer(InvocationOnMock in) throws Throwable {
|
public Http2Stream answer(InvocationOnMock in) throws Throwable {
|
||||||
Http2StreamVisitor visitor = in.getArgumentAt(0, Http2StreamVisitor.class);
|
Http2StreamVisitor visitor = in.getArgument(0);
|
||||||
if (!visitor.visit(stream)) {
|
if (!visitor.visit(stream)) {
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
@ -139,6 +142,7 @@ public class DefaultHttp2ConnectionDecoderTest {
|
|||||||
when(connection.local()).thenReturn(local);
|
when(connection.local()).thenReturn(local);
|
||||||
when(local.flowController()).thenReturn(localFlow);
|
when(local.flowController()).thenReturn(localFlow);
|
||||||
when(encoder.flowController()).thenReturn(remoteFlow);
|
when(encoder.flowController()).thenReturn(remoteFlow);
|
||||||
|
when(encoder.frameWriter()).thenReturn(writer);
|
||||||
when(connection.remote()).thenReturn(remote);
|
when(connection.remote()).thenReturn(remote);
|
||||||
when(local.reservePushStream(eq(PUSH_STREAM_ID), eq(stream))).thenReturn(pushStream);
|
when(local.reservePushStream(eq(PUSH_STREAM_ID), eq(stream))).thenReturn(pushStream);
|
||||||
when(remote.reservePushStream(eq(PUSH_STREAM_ID), eq(stream))).thenReturn(pushStream);
|
when(remote.reservePushStream(eq(PUSH_STREAM_ID), eq(stream))).thenReturn(pushStream);
|
||||||
|
@ -288,7 +288,7 @@ public class DefaultHttp2ConnectionEncoderTest {
|
|||||||
.then(new Answer<ChannelFuture>() {
|
.then(new Answer<ChannelFuture>() {
|
||||||
@Override
|
@Override
|
||||||
public ChannelFuture answer(InvocationOnMock invocationOnMock) throws Throwable {
|
public ChannelFuture answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||||
ChannelPromise promise = invocationOnMock.getArgumentAt(8, ChannelPromise.class);
|
ChannelPromise promise = invocationOnMock.getArgument(8);
|
||||||
assertFalse(promise.isVoid());
|
assertFalse(promise.isVoid());
|
||||||
return promise.setFailure(cause);
|
return promise.setFailure(cause);
|
||||||
}
|
}
|
||||||
@ -422,7 +422,7 @@ public class DefaultHttp2ConnectionEncoderTest {
|
|||||||
stream(STREAM_ID);
|
stream(STREAM_ID);
|
||||||
ChannelPromise promise = newPromise();
|
ChannelPromise promise = newPromise();
|
||||||
encoder.writeRstStream(ctx, STREAM_ID, PROTOCOL_ERROR.code(), promise);
|
encoder.writeRstStream(ctx, STREAM_ID, PROTOCOL_ERROR.code(), promise);
|
||||||
verify(lifecycleManager).resetStream(eq(ctx), eq(STREAM_ID), anyInt(), eq(promise));
|
verify(lifecycleManager).resetStream(eq(ctx), eq(STREAM_ID), anyLong(), eq(promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -89,14 +89,14 @@ public class DefaultHttp2ConnectionTest {
|
|||||||
doAnswer(new Answer<Void>() {
|
doAnswer(new Answer<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||||
assertNotNull(client.stream(invocation.getArgumentAt(0, Http2Stream.class).id()));
|
assertNotNull(client.stream(((Http2Stream) invocation.getArgument(0)).id()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}).when(clientListener).onStreamClosed(any(Http2Stream.class));
|
}).when(clientListener).onStreamClosed(any(Http2Stream.class));
|
||||||
doAnswer(new Answer<Void>() {
|
doAnswer(new Answer<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||||
assertNull(client.stream(invocation.getArgumentAt(0, Http2Stream.class).id()));
|
assertNull(client.stream(((Http2Stream) invocation.getArgument(0)).id()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}).when(clientListener).onStreamRemoved(any(Http2Stream.class));
|
}).when(clientListener).onStreamRemoved(any(Http2Stream.class));
|
||||||
|
@ -27,7 +27,6 @@ import io.netty.channel.ChannelPromise;
|
|||||||
import io.netty.channel.DefaultChannelPromise;
|
import io.netty.channel.DefaultChannelPromise;
|
||||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||||
import io.netty.handler.codec.http2.Http2CodecUtil.SimpleChannelPromiseAggregator;
|
import io.netty.handler.codec.http2.Http2CodecUtil.SimpleChannelPromiseAggregator;
|
||||||
import io.netty.util.CharsetUtil;
|
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
import io.netty.util.concurrent.EventExecutor;
|
import io.netty.util.concurrent.EventExecutor;
|
||||||
import io.netty.util.concurrent.GenericFutureListener;
|
import io.netty.util.concurrent.GenericFutureListener;
|
||||||
@ -49,7 +48,6 @@ import static io.netty.buffer.Unpooled.copiedBuffer;
|
|||||||
import static io.netty.handler.codec.http2.Http2CodecUtil.connectionPrefaceBuf;
|
import static io.netty.handler.codec.http2.Http2CodecUtil.connectionPrefaceBuf;
|
||||||
import static io.netty.handler.codec.http2.Http2Error.PROTOCOL_ERROR;
|
import static io.netty.handler.codec.http2.Http2Error.PROTOCOL_ERROR;
|
||||||
import static io.netty.handler.codec.http2.Http2Error.STREAM_CLOSED;
|
import static io.netty.handler.codec.http2.Http2Error.STREAM_CLOSED;
|
||||||
import static io.netty.handler.codec.http2.Http2Exception.connectionError;
|
|
||||||
import static io.netty.handler.codec.http2.Http2Stream.State.CLOSED;
|
import static io.netty.handler.codec.http2.Http2Stream.State.CLOSED;
|
||||||
import static io.netty.handler.codec.http2.Http2Stream.State.IDLE;
|
import static io.netty.handler.codec.http2.Http2Stream.State.IDLE;
|
||||||
import static io.netty.handler.codec.http2.Http2TestUtil.newVoidPromise;
|
import static io.netty.handler.codec.http2.Http2TestUtil.newVoidPromise;
|
||||||
@ -80,6 +78,7 @@ public class Http2ConnectionHandlerTest {
|
|||||||
|
|
||||||
private Http2ConnectionHandler handler;
|
private Http2ConnectionHandler handler;
|
||||||
private ChannelPromise promise;
|
private ChannelPromise promise;
|
||||||
|
private ChannelPromise voidPromise;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Http2Connection connection;
|
private Http2Connection connection;
|
||||||
@ -137,7 +136,7 @@ public class Http2ConnectionHandlerTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
promise = new DefaultChannelPromise(channel, ImmediateEventExecutor.INSTANCE);
|
promise = new DefaultChannelPromise(channel, ImmediateEventExecutor.INSTANCE);
|
||||||
|
voidPromise = new DefaultChannelPromise(channel, ImmediateEventExecutor.INSTANCE);
|
||||||
Throwable fakeException = new RuntimeException("Fake exception");
|
Throwable fakeException = new RuntimeException("Fake exception");
|
||||||
when(encoder.connection()).thenReturn(connection);
|
when(encoder.connection()).thenReturn(connection);
|
||||||
when(decoder.connection()).thenReturn(connection);
|
when(decoder.connection()).thenReturn(connection);
|
||||||
@ -147,13 +146,13 @@ public class Http2ConnectionHandlerTest {
|
|||||||
doAnswer(new Answer<ChannelFuture>() {
|
doAnswer(new Answer<ChannelFuture>() {
|
||||||
@Override
|
@Override
|
||||||
public ChannelFuture answer(InvocationOnMock invocation) throws Throwable {
|
public ChannelFuture answer(InvocationOnMock invocation) throws Throwable {
|
||||||
ByteBuf buf = invocation.getArgumentAt(3, ByteBuf.class);
|
ByteBuf buf = invocation.getArgument(3);
|
||||||
goAwayDebugCap = buf.toString(UTF_8);
|
goAwayDebugCap = buf.toString(UTF_8);
|
||||||
buf.release();
|
buf.release();
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
}).when(frameWriter).writeGoAway(
|
}).when(frameWriter).writeGoAway(
|
||||||
any(ChannelHandlerContext.class), anyInt(), anyInt(), any(ByteBuf.class), any(ChannelPromise.class));
|
any(ChannelHandlerContext.class), anyInt(), anyLong(), any(ByteBuf.class), any(ChannelPromise.class));
|
||||||
doAnswer(new Answer<ChannelFuture>() {
|
doAnswer(new Answer<ChannelFuture>() {
|
||||||
@Override
|
@Override
|
||||||
public ChannelFuture answer(InvocationOnMock invocation) throws Throwable {
|
public ChannelFuture answer(InvocationOnMock invocation) throws Throwable {
|
||||||
@ -175,7 +174,7 @@ public class Http2ConnectionHandlerTest {
|
|||||||
doAnswer(new Answer<Http2Stream>() {
|
doAnswer(new Answer<Http2Stream>() {
|
||||||
@Override
|
@Override
|
||||||
public Http2Stream answer(InvocationOnMock in) throws Throwable {
|
public Http2Stream answer(InvocationOnMock in) throws Throwable {
|
||||||
Http2StreamVisitor visitor = in.getArgumentAt(0, Http2StreamVisitor.class);
|
Http2StreamVisitor visitor = in.getArgument(0);
|
||||||
if (!visitor.visit(stream)) {
|
if (!visitor.visit(stream)) {
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
@ -191,12 +190,13 @@ public class Http2ConnectionHandlerTest {
|
|||||||
when(ctx.channel()).thenReturn(channel);
|
when(ctx.channel()).thenReturn(channel);
|
||||||
when(ctx.newSucceededFuture()).thenReturn(future);
|
when(ctx.newSucceededFuture()).thenReturn(future);
|
||||||
when(ctx.newPromise()).thenReturn(promise);
|
when(ctx.newPromise()).thenReturn(promise);
|
||||||
|
when(ctx.voidPromise()).thenReturn(voidPromise);
|
||||||
when(ctx.write(any())).thenReturn(future);
|
when(ctx.write(any())).thenReturn(future);
|
||||||
when(ctx.executor()).thenReturn(executor);
|
when(ctx.executor()).thenReturn(executor);
|
||||||
doAnswer(new Answer() {
|
doAnswer(new Answer() {
|
||||||
@Override
|
@Override
|
||||||
public Object answer(InvocationOnMock in) throws Throwable {
|
public Object answer(InvocationOnMock in) throws Throwable {
|
||||||
Object msg = in.getArgumentAt(0, Object.class);
|
Object msg = in.getArgument(0);
|
||||||
ReferenceCountUtil.release(msg);
|
ReferenceCountUtil.release(msg);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -523,7 +523,7 @@ public class Http2ConnectionHandlerTest {
|
|||||||
doAnswer(new Answer<Void>() {
|
doAnswer(new Answer<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||||
invocation.getArgumentAt(0, GenericFutureListener.class).operationComplete(future);
|
((GenericFutureListener) invocation.getArgument(0)).operationComplete(future);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}).when(future).addListener(any(GenericFutureListener.class));
|
}).when(future).addListener(any(GenericFutureListener.class));
|
||||||
@ -585,7 +585,7 @@ public class Http2ConnectionHandlerTest {
|
|||||||
doAnswer(new Answer<ChannelFuture>() {
|
doAnswer(new Answer<ChannelFuture>() {
|
||||||
@Override
|
@Override
|
||||||
public ChannelFuture answer(InvocationOnMock invocation) throws Throwable {
|
public ChannelFuture answer(InvocationOnMock invocation) throws Throwable {
|
||||||
ChannelPromise promise = invocation.getArgumentAt(4, ChannelPromise.class);
|
ChannelPromise promise = invocation.getArgument(4);
|
||||||
assertFalse(promise.isVoid());
|
assertFalse(promise.isVoid());
|
||||||
// This is what DefaultHttp2FrameWriter does... I hate mocking :-(.
|
// This is what DefaultHttp2FrameWriter does... I hate mocking :-(.
|
||||||
SimpleChannelPromiseAggregator aggregatedPromise =
|
SimpleChannelPromiseAggregator aggregatedPromise =
|
||||||
@ -595,7 +595,7 @@ public class Http2ConnectionHandlerTest {
|
|||||||
return aggregatedPromise.setFailure(cause);
|
return aggregatedPromise.setFailure(cause);
|
||||||
}
|
}
|
||||||
}).when(frameWriter).writeGoAway(
|
}).when(frameWriter).writeGoAway(
|
||||||
any(ChannelHandlerContext.class), anyInt(), anyInt(), any(ByteBuf.class), any(ChannelPromise.class));
|
any(ChannelHandlerContext.class), anyInt(), anyLong(), any(ByteBuf.class), any(ChannelPromise.class));
|
||||||
handler.goAway(ctx, STREAM_ID, errorCode, data, newVoidPromise(channel));
|
handler.goAway(ctx, STREAM_ID, errorCode, data, newVoidPromise(channel));
|
||||||
verify(pipeline).fireExceptionCaught(cause);
|
verify(pipeline).fireExceptionCaught(cause);
|
||||||
}
|
}
|
||||||
@ -637,7 +637,7 @@ public class Http2ConnectionHandlerTest {
|
|||||||
.then(new Answer<ChannelFuture>() {
|
.then(new Answer<ChannelFuture>() {
|
||||||
@Override
|
@Override
|
||||||
public ChannelFuture answer(InvocationOnMock invocationOnMock) throws Throwable {
|
public ChannelFuture answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||||
ChannelPromise promise = invocationOnMock.getArgumentAt(3, ChannelPromise.class);
|
ChannelPromise promise = invocationOnMock.getArgument(3);
|
||||||
assertFalse(promise.isVoid());
|
assertFalse(promise.isVoid());
|
||||||
return promise.setFailure(cause);
|
return promise.setFailure(cause);
|
||||||
}
|
}
|
||||||
|
@ -137,10 +137,10 @@ public class Http2ConnectionRoundtripTest {
|
|||||||
doAnswer(new Answer<Void>() {
|
doAnswer(new Answer<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
|
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||||
ChannelHandlerContext ctx = invocationOnMock.getArgumentAt(0, ChannelHandlerContext.class);
|
ChannelHandlerContext ctx = invocationOnMock.getArgument(0);
|
||||||
http2Server.encoder().writeHeaders(ctx,
|
http2Server.encoder().writeHeaders(ctx,
|
||||||
invocationOnMock.getArgumentAt(1, Integer.class),
|
(Integer) invocationOnMock.getArgument(1),
|
||||||
invocationOnMock.getArgumentAt(2, Http2Headers.class),
|
(Http2Headers) invocationOnMock.getArgument(2),
|
||||||
0,
|
0,
|
||||||
false,
|
false,
|
||||||
ctx.newPromise());
|
ctx.newPromise());
|
||||||
|
@ -81,8 +81,8 @@ public class UniformStreamByteDistributorTest {
|
|||||||
return new Answer<Void>() {
|
return new Answer<Void>() {
|
||||||
@Override
|
@Override
|
||||||
public Void answer(InvocationOnMock in) throws Throwable {
|
public Void answer(InvocationOnMock in) throws Throwable {
|
||||||
Http2Stream stream = in.getArgumentAt(0, Http2Stream.class);
|
Http2Stream stream = in.getArgument(0);
|
||||||
int numBytes = in.getArgumentAt(1, Integer.class);
|
int numBytes = in.getArgument(1);
|
||||||
int streamableBytes = distributor.streamableBytes0(stream) - numBytes;
|
int streamableBytes = distributor.streamableBytes0(stream) - numBytes;
|
||||||
updateStream(stream.id(), streamableBytes, streamableBytes > 0);
|
updateStream(stream.id(), streamableBytes, streamableBytes > 0);
|
||||||
return null;
|
return null;
|
||||||
|
@ -18,6 +18,8 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
import org.mockito.verification.VerificationMode;
|
import org.mockito.verification.VerificationMode;
|
||||||
|
|
||||||
import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_PRIORITY_WEIGHT;
|
import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_PRIORITY_WEIGHT;
|
||||||
|
@ -34,5 +34,9 @@
|
|||||||
<artifactId>netty-codec</artifactId>
|
<artifactId>netty-codec</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -23,9 +23,9 @@ import io.netty.channel.Channel;
|
|||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.DecoderException;
|
import io.netty.handler.codec.DecoderException;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import org.easymock.Mock;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
@ -70,6 +70,11 @@
|
|||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Test dependencies for jboss marshalling encoder/decoder -->
|
<!-- Test dependencies for jboss marshalling encoder/decoder -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jboss.marshalling</groupId>
|
<groupId>org.jboss.marshalling</groupId>
|
||||||
|
@ -77,6 +77,10 @@
|
|||||||
<artifactId>log4j-core</artifactId>
|
<artifactId>log4j-core</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -16,9 +16,10 @@
|
|||||||
|
|
||||||
package io.netty.util.concurrent;
|
package io.netty.util.concurrent;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.*;
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -38,7 +39,7 @@ public class PromiseAggregatorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testAddNullFuture() {
|
public void testAddNullFuture() {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Promise<Void> p = createStrictMock(Promise.class);
|
Promise<Void> p = mock(Promise.class);
|
||||||
PromiseAggregator<Void, Future<Void>> a =
|
PromiseAggregator<Void, Future<Void>> a =
|
||||||
new PromiseAggregator<Void, Future<Void>>(p);
|
new PromiseAggregator<Void, Future<Void>>(p);
|
||||||
expectedException.expect(NullPointerException.class);
|
expectedException.expect(NullPointerException.class);
|
||||||
@ -48,85 +49,95 @@ public class PromiseAggregatorTest {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testSucessfulNoPending() throws Exception {
|
public void testSucessfulNoPending() throws Exception {
|
||||||
Promise<Void> p = createStrictMock(Promise.class);
|
Promise<Void> p = mock(Promise.class);
|
||||||
PromiseAggregator<Void, Future<Void>> a =
|
PromiseAggregator<Void, Future<Void>> a =
|
||||||
new PromiseAggregator<Void, Future<Void>>(p);
|
new PromiseAggregator<Void, Future<Void>>(p);
|
||||||
|
|
||||||
Future<Void> future = createStrictMock(Future.class);
|
Future<Void> future = mock(Future.class);
|
||||||
expect(p.setSuccess(null)).andReturn(p);
|
when(p.setSuccess(null)).thenReturn(p);
|
||||||
replay(future, p);
|
|
||||||
|
|
||||||
a.add();
|
a.add();
|
||||||
a.operationComplete(future);
|
a.operationComplete(future);
|
||||||
verify(future, p);
|
verifyNoMoreInteractions(future);
|
||||||
|
verify(p).setSuccess(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testSuccessfulPending() throws Exception {
|
public void testSuccessfulPending() throws Exception {
|
||||||
Promise<Void> p = createStrictMock(Promise.class);
|
Promise<Void> p = mock(Promise.class);
|
||||||
PromiseAggregator<Void, Future<Void>> a =
|
PromiseAggregator<Void, Future<Void>> a =
|
||||||
new PromiseAggregator<Void, Future<Void>>(p);
|
new PromiseAggregator<Void, Future<Void>>(p);
|
||||||
Promise<Void> p1 = createStrictMock(Promise.class);
|
Promise<Void> p1 = mock(Promise.class);
|
||||||
Promise<Void> p2 = createStrictMock(Promise.class);
|
Promise<Void> p2 = mock(Promise.class);
|
||||||
|
|
||||||
expect(p1.addListener(a)).andReturn(p1);
|
when(p1.addListener(a)).thenReturn(p1);
|
||||||
expect(p2.addListener(a)).andReturn(p2);
|
when(p2.addListener(a)).thenReturn(p2);
|
||||||
expect(p1.isSuccess()).andReturn(true);
|
when(p1.isSuccess()).thenReturn(true);
|
||||||
expect(p2.isSuccess()).andReturn(true);
|
when(p2.isSuccess()).thenReturn(true);
|
||||||
expect(p.setSuccess(null)).andReturn(p);
|
when(p.setSuccess(null)).thenReturn(p);
|
||||||
replay(p1, p2, p);
|
|
||||||
|
|
||||||
assertThat(a.add(p1, null, p2), is(a));
|
assertThat(a.add(p1, null, p2), is(a));
|
||||||
a.operationComplete(p1);
|
a.operationComplete(p1);
|
||||||
a.operationComplete(p2);
|
a.operationComplete(p2);
|
||||||
|
|
||||||
verify(p1, p2, p);
|
verify(p1).addListener(a);
|
||||||
|
verify(p2).addListener(a);
|
||||||
|
verify(p1).isSuccess();
|
||||||
|
verify(p2).isSuccess();
|
||||||
|
verify(p).setSuccess(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testFailedFutureFailPending() throws Exception {
|
public void testFailedFutureFailPending() throws Exception {
|
||||||
Promise<Void> p = createStrictMock(Promise.class);
|
Promise<Void> p = mock(Promise.class);
|
||||||
PromiseAggregator<Void, Future<Void>> a =
|
PromiseAggregator<Void, Future<Void>> a =
|
||||||
new PromiseAggregator<Void, Future<Void>>(p);
|
new PromiseAggregator<Void, Future<Void>>(p);
|
||||||
Promise<Void> p1 = createStrictMock(Promise.class);
|
Promise<Void> p1 = mock(Promise.class);
|
||||||
Promise<Void> p2 = createStrictMock(Promise.class);
|
Promise<Void> p2 = mock(Promise.class);
|
||||||
Throwable t = createStrictMock(Throwable.class);
|
Throwable t = mock(Throwable.class);
|
||||||
|
|
||||||
expect(p1.addListener(a)).andReturn(p1);
|
when(p1.addListener(a)).thenReturn(p1);
|
||||||
expect(p2.addListener(a)).andReturn(p2);
|
when(p2.addListener(a)).thenReturn(p2);
|
||||||
expect(p1.isSuccess()).andReturn(false);
|
when(p1.isSuccess()).thenReturn(false);
|
||||||
expect(p1.cause()).andReturn(t);
|
when(p1.cause()).thenReturn(t);
|
||||||
expect(p.setFailure(t)).andReturn(p);
|
when(p.setFailure(t)).thenReturn(p);
|
||||||
expect(p2.setFailure(t)).andReturn(p2);
|
when(p2.setFailure(t)).thenReturn(p2);
|
||||||
replay(p1, p2, p);
|
|
||||||
|
|
||||||
a.add(p1, p2);
|
a.add(p1, p2);
|
||||||
a.operationComplete(p1);
|
a.operationComplete(p1);
|
||||||
verify(p1, p2, p);
|
|
||||||
|
verify(p1).addListener(a);
|
||||||
|
verify(p2).addListener(a);
|
||||||
|
verify(p1).cause();
|
||||||
|
verify(p).setFailure(t);
|
||||||
|
verify(p2).setFailure(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testFailedFutureNoFailPending() throws Exception {
|
public void testFailedFutureNoFailPending() throws Exception {
|
||||||
Promise<Void> p = createStrictMock(Promise.class);
|
Promise<Void> p = mock(Promise.class);
|
||||||
PromiseAggregator<Void, Future<Void>> a =
|
PromiseAggregator<Void, Future<Void>> a =
|
||||||
new PromiseAggregator<Void, Future<Void>>(p, false);
|
new PromiseAggregator<Void, Future<Void>>(p, false);
|
||||||
Promise<Void> p1 = createStrictMock(Promise.class);
|
Promise<Void> p1 = mock(Promise.class);
|
||||||
Promise<Void> p2 = createStrictMock(Promise.class);
|
Promise<Void> p2 = mock(Promise.class);
|
||||||
Throwable t = createStrictMock(Throwable.class);
|
Throwable t = mock(Throwable.class);
|
||||||
|
|
||||||
expect(p1.addListener(a)).andReturn(p1);
|
when(p1.addListener(a)).thenReturn(p1);
|
||||||
expect(p2.addListener(a)).andReturn(p2);
|
when(p2.addListener(a)).thenReturn(p2);
|
||||||
expect(p1.isSuccess()).andReturn(false);
|
when(p1.isSuccess()).thenReturn(false);
|
||||||
expect(p1.cause()).andReturn(t);
|
when(p1.cause()).thenReturn(t);
|
||||||
expect(p.setFailure(t)).andReturn(p);
|
when(p.setFailure(t)).thenReturn(p);
|
||||||
replay(p1, p2, p);
|
|
||||||
|
|
||||||
a.add(p1, p2);
|
a.add(p1, p2);
|
||||||
a.operationComplete(p1);
|
a.operationComplete(p1);
|
||||||
verify(p1, p2, p);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
verify(p1).addListener(a);
|
||||||
|
verify(p2).addListener(a);
|
||||||
|
verify(p1).isSuccess();
|
||||||
|
verify(p1).cause();
|
||||||
|
verify(p).setFailure(t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ public class PromiseCombinerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testNullAggregatePromise() {
|
public void testNullAggregatePromise() {
|
||||||
combiner.finish(p1);
|
combiner.finish(p1);
|
||||||
verify(p1).trySuccess(any(Void.class));
|
verify(p1).trySuccess(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
@ -153,7 +153,7 @@ public class PromiseCombinerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void verifySuccess(Promise<Void> p) {
|
private void verifySuccess(Promise<Void> p) {
|
||||||
verify(p).trySuccess(any(Void.class));
|
verify(p).trySuccess(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyNotCompleted(Promise<Void> p) {
|
private void verifyNotCompleted(Promise<Void> p) {
|
||||||
@ -179,10 +179,10 @@ public class PromiseCombinerTest {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void mockListener(final Promise<Void> p, final GenericFutureListenerConsumer consumer) {
|
private void mockListener(final Promise<Void> p, final GenericFutureListenerConsumer consumer) {
|
||||||
doAnswer(new Answer<Promise<Void>>() {
|
doAnswer(new Answer<Promise<Void>>() {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({ "unchecked", "raw-types" })
|
||||||
@Override
|
@Override
|
||||||
public Promise<Void> answer(InvocationOnMock invocation) throws Throwable {
|
public Promise<Void> answer(InvocationOnMock invocation) throws Throwable {
|
||||||
consumer.accept(invocation.getArgumentAt(0, GenericFutureListener.class));
|
consumer.accept((GenericFutureListener) invocation.getArgument(0));
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
}).when(p).addListener(any(GenericFutureListener.class));
|
}).when(p).addListener(any(GenericFutureListener.class));
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package io.netty.util.concurrent;
|
package io.netty.util.concurrent;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -43,49 +43,49 @@ public class PromiseNotifierTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testListenerSuccess() throws Exception {
|
public void testListenerSuccess() throws Exception {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Promise<Void> p1 = createStrictMock(Promise.class);
|
Promise<Void> p1 = mock(Promise.class);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Promise<Void> p2 = createStrictMock(Promise.class);
|
Promise<Void> p2 = mock(Promise.class);
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
PromiseNotifier<Void, Future<Void>> notifier =
|
PromiseNotifier<Void, Future<Void>> notifier =
|
||||||
new PromiseNotifier<Void, Future<Void>>(p1, p2);
|
new PromiseNotifier<Void, Future<Void>>(p1, p2);
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Future<Void> future = createStrictMock(Future.class);
|
Future<Void> future = mock(Future.class);
|
||||||
expect(future.isSuccess()).andReturn(true);
|
when(future.isSuccess()).thenReturn(true);
|
||||||
expect(future.get()).andReturn(null);
|
when(future.get()).thenReturn(null);
|
||||||
expect(p1.trySuccess(null)).andReturn(true);
|
when(p1.trySuccess(null)).thenReturn(true);
|
||||||
expect(p2.trySuccess(null)).andReturn(true);
|
when(p2.trySuccess(null)).thenReturn(true);
|
||||||
replay(p1, p2, future);
|
|
||||||
|
|
||||||
notifier.operationComplete(future);
|
notifier.operationComplete(future);
|
||||||
verify(p1, p2);
|
verify(p1).trySuccess(null);
|
||||||
|
verify(p2).trySuccess(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListenerFailure() throws Exception {
|
public void testListenerFailure() throws Exception {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Promise<Void> p1 = createStrictMock(Promise.class);
|
Promise<Void> p1 = mock(Promise.class);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Promise<Void> p2 = createStrictMock(Promise.class);
|
Promise<Void> p2 = mock(Promise.class);
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
PromiseNotifier<Void, Future<Void>> notifier =
|
PromiseNotifier<Void, Future<Void>> notifier =
|
||||||
new PromiseNotifier<Void, Future<Void>>(p1, p2);
|
new PromiseNotifier<Void, Future<Void>>(p1, p2);
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Future<Void> future = createStrictMock(Future.class);
|
Future<Void> future = mock(Future.class);
|
||||||
Throwable t = createStrictMock(Throwable.class);
|
Throwable t = mock(Throwable.class);
|
||||||
expect(future.isSuccess()).andReturn(false);
|
when(future.isSuccess()).thenReturn(false);
|
||||||
expect(future.isCancelled()).andReturn(false);
|
when(future.isCancelled()).thenReturn(false);
|
||||||
expect(future.cause()).andReturn(t);
|
when(future.cause()).thenReturn(t);
|
||||||
expect(p1.tryFailure(t)).andReturn(true);
|
when(p1.tryFailure(t)).thenReturn(true);
|
||||||
expect(p2.tryFailure(t)).andReturn(true);
|
when(p2.tryFailure(t)).thenReturn(true);
|
||||||
replay(p1, p2, future);
|
|
||||||
|
|
||||||
notifier.operationComplete(future);
|
notifier.operationComplete(future);
|
||||||
verify(p1, p2);
|
verify(p1).tryFailure(t);
|
||||||
|
verify(p2).tryFailure(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,204 +18,169 @@ package io.netty.util.internal.logging;
|
|||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.*;
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
public class CommonsLoggerTest {
|
public class CommonsLoggerTest {
|
||||||
private static final Exception e = new Exception();
|
private static final Exception e = new Exception();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsTraceEnabled() {
|
public void testIsTraceEnabled() {
|
||||||
Log mock =
|
Log mockLog = mock(Log.class);
|
||||||
createStrictMock(Log.class);
|
|
||||||
|
|
||||||
expect(mock.isTraceEnabled()).andReturn(true);
|
when(mockLog.isTraceEnabled()).thenReturn(true);
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new CommonsLogger(mock, "foo");
|
InternalLogger logger = new CommonsLogger(mockLog, "foo");
|
||||||
assertTrue(logger.isTraceEnabled());
|
assertTrue(logger.isTraceEnabled());
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLog).isTraceEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsDebugEnabled() {
|
public void testIsDebugEnabled() {
|
||||||
Log mock =
|
Log mockLog = mock(Log.class);
|
||||||
createStrictMock(Log.class);
|
|
||||||
|
|
||||||
expect(mock.isDebugEnabled()).andReturn(true);
|
when(mockLog.isDebugEnabled()).thenReturn(true);
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new CommonsLogger(mock, "foo");
|
InternalLogger logger = new CommonsLogger(mockLog, "foo");
|
||||||
assertTrue(logger.isDebugEnabled());
|
assertTrue(logger.isDebugEnabled());
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLog).isDebugEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsInfoEnabled() {
|
public void testIsInfoEnabled() {
|
||||||
Log mock =
|
Log mockLog = mock(Log.class);
|
||||||
createStrictMock(Log.class);
|
|
||||||
|
|
||||||
expect(mock.isInfoEnabled()).andReturn(true);
|
when(mockLog.isInfoEnabled()).thenReturn(true);
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new CommonsLogger(mock, "foo");
|
InternalLogger logger = new CommonsLogger(mockLog, "foo");
|
||||||
assertTrue(logger.isInfoEnabled());
|
assertTrue(logger.isInfoEnabled());
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLog).isInfoEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsWarnEnabled() {
|
public void testIsWarnEnabled() {
|
||||||
Log mock =
|
Log mockLog = mock(Log.class);
|
||||||
createStrictMock(Log.class);
|
|
||||||
|
|
||||||
expect(mock.isWarnEnabled()).andReturn(true);
|
when(mockLog.isWarnEnabled()).thenReturn(true);
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new CommonsLogger(mock, "foo");
|
InternalLogger logger = new CommonsLogger(mockLog, "foo");
|
||||||
assertTrue(logger.isWarnEnabled());
|
assertTrue(logger.isWarnEnabled());
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLog).isWarnEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsErrorEnabled() {
|
public void testIsErrorEnabled() {
|
||||||
Log mock =
|
Log mockLog = mock(Log.class);
|
||||||
createStrictMock(Log.class);
|
|
||||||
|
|
||||||
expect(mock.isErrorEnabled()).andReturn(true);
|
when(mockLog.isErrorEnabled()).thenReturn(true);
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new CommonsLogger(mock, "foo");
|
InternalLogger logger = new CommonsLogger(mockLog, "foo");
|
||||||
assertTrue(logger.isErrorEnabled());
|
assertTrue(logger.isErrorEnabled());
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLog).isErrorEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTrace() {
|
public void testTrace() {
|
||||||
Log mock =
|
Log mockLog = mock(Log.class);
|
||||||
createStrictMock(Log.class);
|
|
||||||
|
|
||||||
mock.trace("a");
|
InternalLogger logger = new CommonsLogger(mockLog, "foo");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new CommonsLogger(mock, "foo");
|
|
||||||
logger.trace("a");
|
logger.trace("a");
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLog).trace("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTraceWithException() {
|
public void testTraceWithException() {
|
||||||
Log mock =
|
Log mockLog = mock(Log.class);
|
||||||
createStrictMock(Log.class);
|
|
||||||
|
|
||||||
mock.trace("a", e);
|
InternalLogger logger = new CommonsLogger(mockLog, "foo");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new CommonsLogger(mock, "foo");
|
|
||||||
logger.trace("a", e);
|
logger.trace("a", e);
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLog).trace("a", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDebug() {
|
public void testDebug() {
|
||||||
Log mock =
|
Log mockLog = mock(Log.class);
|
||||||
createStrictMock(Log.class);
|
|
||||||
|
|
||||||
mock.debug("a");
|
InternalLogger logger = new CommonsLogger(mockLog, "foo");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new CommonsLogger(mock, "foo");
|
|
||||||
logger.debug("a");
|
logger.debug("a");
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLog).debug("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDebugWithException() {
|
public void testDebugWithException() {
|
||||||
Log mock =
|
Log mockLog = mock(Log.class);
|
||||||
createStrictMock(Log.class);
|
|
||||||
|
|
||||||
mock.debug("a", e);
|
InternalLogger logger = new CommonsLogger(mockLog, "foo");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new CommonsLogger(mock, "foo");
|
|
||||||
logger.debug("a", e);
|
logger.debug("a", e);
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLog).debug("a", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInfo() {
|
public void testInfo() {
|
||||||
Log mock =
|
Log mockLog = mock(Log.class);
|
||||||
createStrictMock(Log.class);
|
|
||||||
|
|
||||||
mock.info("a");
|
InternalLogger logger = new CommonsLogger(mockLog, "foo");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new CommonsLogger(mock, "foo");
|
|
||||||
logger.info("a");
|
logger.info("a");
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLog).info("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInfoWithException() {
|
public void testInfoWithException() {
|
||||||
Log mock =
|
Log mockLog = mock(Log.class);
|
||||||
createStrictMock(Log.class);
|
|
||||||
|
|
||||||
mock.info("a", e);
|
InternalLogger logger = new CommonsLogger(mockLog, "foo");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new CommonsLogger(mock, "foo");
|
|
||||||
logger.info("a", e);
|
logger.info("a", e);
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLog).info("a", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWarn() {
|
public void testWarn() {
|
||||||
Log mock =
|
Log mockLog = mock(Log.class);
|
||||||
createStrictMock(Log.class);
|
|
||||||
|
|
||||||
mock.warn("a");
|
InternalLogger logger = new CommonsLogger(mockLog, "foo");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new CommonsLogger(mock, "foo");
|
|
||||||
logger.warn("a");
|
logger.warn("a");
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLog).warn("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWarnWithException() {
|
public void testWarnWithException() {
|
||||||
Log mock =
|
Log mockLog = mock(Log.class);
|
||||||
createStrictMock(Log.class);
|
|
||||||
|
|
||||||
mock.warn("a", e);
|
InternalLogger logger = new CommonsLogger(mockLog, "foo");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new CommonsLogger(mock, "foo");
|
|
||||||
logger.warn("a", e);
|
logger.warn("a", e);
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLog).warn("a", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testError() {
|
public void testError() {
|
||||||
Log mock =
|
Log mockLog = mock(Log.class);
|
||||||
createStrictMock(Log.class);
|
|
||||||
|
|
||||||
mock.error("a");
|
InternalLogger logger = new CommonsLogger(mockLog, "foo");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new CommonsLogger(mock, "foo");
|
|
||||||
logger.error("a");
|
logger.error("a");
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLog).error("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testErrorWithException() {
|
public void testErrorWithException() {
|
||||||
Log mock =
|
Log mockLog = mock(Log.class);
|
||||||
createStrictMock(Log.class);
|
|
||||||
|
|
||||||
mock.error("a", e);
|
InternalLogger logger = new CommonsLogger(mockLog, "foo");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new CommonsLogger(mock, "foo");
|
|
||||||
logger.error("a", e);
|
logger.error("a", e);
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLog).error("a", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,27 +19,29 @@ import org.junit.After;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.*;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertNotSame;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
public class InternalLoggerFactoryTest {
|
public class InternalLoggerFactoryTest {
|
||||||
private static final Exception e = new Exception();
|
private static final Exception e = new Exception();
|
||||||
private InternalLoggerFactory oldLoggerFactory;
|
private InternalLoggerFactory oldLoggerFactory;
|
||||||
private InternalLogger mock;
|
private InternalLogger mockLogger;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() {
|
public void init() {
|
||||||
oldLoggerFactory = InternalLoggerFactory.getDefaultFactory();
|
oldLoggerFactory = InternalLoggerFactory.getDefaultFactory();
|
||||||
InternalLoggerFactory mockFactory = createMock(InternalLoggerFactory.class);
|
|
||||||
mock = createStrictMock(InternalLogger.class);
|
final InternalLoggerFactory mockFactory = mock(InternalLoggerFactory.class);
|
||||||
expect(mockFactory.newInstance("mock")).andReturn(mock).anyTimes();
|
mockLogger = mock(InternalLogger.class);
|
||||||
replay(mockFactory);
|
when(mockFactory.newInstance("mock")).thenReturn(mockLogger);
|
||||||
InternalLoggerFactory.setDefaultFactory(mockFactory);
|
InternalLoggerFactory.setDefaultFactory(mockFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
reset(mock);
|
reset(mockLogger);
|
||||||
InternalLoggerFactory.setDefaultFactory(oldLoggerFactory);
|
InternalLoggerFactory.setDefaultFactory(oldLoggerFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,151 +66,116 @@ public class InternalLoggerFactoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsTraceEnabled() {
|
public void testIsTraceEnabled() {
|
||||||
expect(mock.isTraceEnabled()).andReturn(true);
|
when(mockLogger.isTraceEnabled()).thenReturn(true);
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
||||||
assertTrue(logger.isTraceEnabled());
|
assertTrue(logger.isTraceEnabled());
|
||||||
verify(mock);
|
verify(mockLogger).isTraceEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsDebugEnabled() {
|
public void testIsDebugEnabled() {
|
||||||
expect(mock.isDebugEnabled()).andReturn(true);
|
when(mockLogger.isDebugEnabled()).thenReturn(true);
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
||||||
assertTrue(logger.isDebugEnabled());
|
assertTrue(logger.isDebugEnabled());
|
||||||
verify(mock);
|
verify(mockLogger).isDebugEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsInfoEnabled() {
|
public void testIsInfoEnabled() {
|
||||||
expect(mock.isInfoEnabled()).andReturn(true);
|
when(mockLogger.isInfoEnabled()).thenReturn(true);
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
||||||
assertTrue(logger.isInfoEnabled());
|
assertTrue(logger.isInfoEnabled());
|
||||||
verify(mock);
|
verify(mockLogger).isInfoEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsWarnEnabled() {
|
public void testIsWarnEnabled() {
|
||||||
expect(mock.isWarnEnabled()).andReturn(true);
|
when(mockLogger.isWarnEnabled()).thenReturn(true);
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
||||||
assertTrue(logger.isWarnEnabled());
|
assertTrue(logger.isWarnEnabled());
|
||||||
verify(mock);
|
verify(mockLogger).isWarnEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsErrorEnabled() {
|
public void testIsErrorEnabled() {
|
||||||
expect(mock.isErrorEnabled()).andReturn(true);
|
when(mockLogger.isErrorEnabled()).thenReturn(true);
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
||||||
assertTrue(logger.isErrorEnabled());
|
assertTrue(logger.isErrorEnabled());
|
||||||
verify(mock);
|
verify(mockLogger).isErrorEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTrace() {
|
public void testTrace() {
|
||||||
mock.trace("a");
|
final InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
|
||||||
logger.trace("a");
|
logger.trace("a");
|
||||||
verify(mock);
|
verify(mockLogger).trace("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTraceWithException() {
|
public void testTraceWithException() {
|
||||||
mock.trace("a", e);
|
final InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
|
||||||
logger.trace("a", e);
|
logger.trace("a", e);
|
||||||
verify(mock);
|
verify(mockLogger).trace("a", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDebug() {
|
public void testDebug() {
|
||||||
mock.debug("a");
|
final InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
|
||||||
logger.debug("a");
|
logger.debug("a");
|
||||||
verify(mock);
|
verify(mockLogger).debug("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDebugWithException() {
|
public void testDebugWithException() {
|
||||||
mock.debug("a", e);
|
final InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
|
||||||
logger.debug("a", e);
|
logger.debug("a", e);
|
||||||
verify(mock);
|
verify(mockLogger).debug("a", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInfo() {
|
public void testInfo() {
|
||||||
mock.info("a");
|
final InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
|
||||||
logger.info("a");
|
logger.info("a");
|
||||||
verify(mock);
|
verify(mockLogger).info("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInfoWithException() {
|
public void testInfoWithException() {
|
||||||
mock.info("a", e);
|
final InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
|
||||||
logger.info("a", e);
|
logger.info("a", e);
|
||||||
verify(mock);
|
verify(mockLogger).info("a", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWarn() {
|
public void testWarn() {
|
||||||
mock.warn("a");
|
final InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
|
||||||
logger.warn("a");
|
logger.warn("a");
|
||||||
verify(mock);
|
verify(mockLogger).warn("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWarnWithException() {
|
public void testWarnWithException() {
|
||||||
mock.warn("a", e);
|
final InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
|
||||||
logger.warn("a", e);
|
logger.warn("a", e);
|
||||||
verify(mock);
|
verify(mockLogger).warn("a", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testError() {
|
public void testError() {
|
||||||
mock.error("a");
|
final InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
|
||||||
logger.error("a");
|
logger.error("a");
|
||||||
verify(mock);
|
verify(mockLogger).error("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testErrorWithException() {
|
public void testErrorWithException() {
|
||||||
mock.error("a", e);
|
final InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = InternalLoggerFactory.getInstance("mock");
|
|
||||||
logger.error("a", e);
|
logger.error("a", e);
|
||||||
verify(mock);
|
verify(mockLogger).error("a", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,207 +18,208 @@ package io.netty.util.internal.logging;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.createStrictMock;
|
|
||||||
import static org.easymock.EasyMock.expect;
|
|
||||||
import static org.easymock.EasyMock.replay;
|
|
||||||
import static org.easymock.EasyMock.verify;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
public class Log4J2LoggerTest {
|
public class Log4J2LoggerTest {
|
||||||
private static final Exception e = new Exception();
|
private static final Exception e = new Exception();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsTraceEnabled() {
|
public void testIsTraceEnabled() {
|
||||||
Logger mock = createStrictMock(Logger.class);
|
Logger mock = mock(Logger.class);
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
|
||||||
expect(mock.isTraceEnabled()).andReturn(true);
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
|
when(mock.getName()).thenReturn("foo");
|
||||||
|
when(mock.isTraceEnabled()).thenReturn(true);
|
||||||
InternalLogger logger = new Log4J2Logger(mock);
|
InternalLogger logger = new Log4J2Logger(mock);
|
||||||
assertTrue(logger.isTraceEnabled());
|
assertTrue(logger.isTraceEnabled());
|
||||||
verify(mock);
|
|
||||||
|
verify(mock).getName();
|
||||||
|
verify(mock).isTraceEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsDebugEnabled() {
|
public void testIsDebugEnabled() {
|
||||||
Logger mock = createStrictMock(Logger.class);
|
Logger mock = mock(Logger.class);
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mock.getName()).thenReturn("foo");
|
||||||
expect(mock.isDebugEnabled()).andReturn(true);
|
when(mock.isDebugEnabled()).thenReturn(true);
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Log4J2Logger(mock);
|
InternalLogger logger = new Log4J2Logger(mock);
|
||||||
assertTrue(logger.isDebugEnabled());
|
assertTrue(logger.isDebugEnabled());
|
||||||
verify(mock);
|
|
||||||
|
verify(mock).getName();
|
||||||
|
verify(mock).isDebugEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsInfoEnabled() {
|
public void testIsInfoEnabled() {
|
||||||
Logger mock = createStrictMock(Logger.class);
|
Logger mock = mock(Logger.class);
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mock.getName()).thenReturn("foo");
|
||||||
expect(mock.isInfoEnabled()).andReturn(true);
|
when(mock.isInfoEnabled()).thenReturn(true);
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Log4J2Logger(mock);
|
InternalLogger logger = new Log4J2Logger(mock);
|
||||||
assertTrue(logger.isInfoEnabled());
|
assertTrue(logger.isInfoEnabled());
|
||||||
verify(mock);
|
|
||||||
|
verify(mock).getName();
|
||||||
|
verify(mock).isInfoEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsWarnEnabled() {
|
public void testIsWarnEnabled() {
|
||||||
Logger mock = createStrictMock(Logger.class);
|
Logger mock = mock(Logger.class);
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mock.getName()).thenReturn("foo");
|
||||||
expect(mock.isWarnEnabled()).andReturn(true);
|
when(mock.isWarnEnabled()).thenReturn(true);
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Log4J2Logger(mock);
|
InternalLogger logger = new Log4J2Logger(mock);
|
||||||
assertTrue(logger.isWarnEnabled());
|
assertTrue(logger.isWarnEnabled());
|
||||||
verify(mock);
|
|
||||||
|
verify(mock).getName();
|
||||||
|
verify(mock).isWarnEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsErrorEnabled() {
|
public void testIsErrorEnabled() {
|
||||||
Logger mock = createStrictMock(Logger.class);
|
Logger mock = mock(Logger.class);
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mock.getName()).thenReturn("foo");
|
||||||
expect(mock.isErrorEnabled()).andReturn(true);
|
when(mock.isErrorEnabled()).thenReturn(true);
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Log4J2Logger(mock);
|
InternalLogger logger = new Log4J2Logger(mock);
|
||||||
assertTrue(logger.isErrorEnabled());
|
assertTrue(logger.isErrorEnabled());
|
||||||
verify(mock);
|
|
||||||
|
verify(mock).getName();
|
||||||
|
verify(mock).isErrorEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTrace() {
|
public void testTrace() {
|
||||||
Logger mock = createStrictMock(Logger.class);
|
Logger mock = mock(Logger.class);
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mock.getName()).thenReturn("foo");
|
||||||
mock.trace("a");
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Log4J2Logger(mock);
|
InternalLogger logger = new Log4J2Logger(mock);
|
||||||
logger.trace("a");
|
logger.trace("a");
|
||||||
verify(mock);
|
|
||||||
|
verify(mock).getName();
|
||||||
|
verify(mock).trace("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTraceWithException() {
|
public void testTraceWithException() {
|
||||||
Logger mock = createStrictMock(Logger.class);
|
Logger mock = mock(Logger.class);
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mock.getName()).thenReturn("foo");
|
||||||
mock.trace("a", e);
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Log4J2Logger(mock);
|
InternalLogger logger = new Log4J2Logger(mock);
|
||||||
logger.trace("a", e);
|
logger.trace("a", e);
|
||||||
verify(mock);
|
|
||||||
|
verify(mock).getName();
|
||||||
|
verify(mock).trace("a", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDebug() {
|
public void testDebug() {
|
||||||
Logger mock = createStrictMock(Logger.class);
|
Logger mock = mock(Logger.class);
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mock.getName()).thenReturn("foo");
|
||||||
mock.debug("a");
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Log4J2Logger(mock);
|
InternalLogger logger = new Log4J2Logger(mock);
|
||||||
logger.debug("a");
|
logger.debug("a");
|
||||||
verify(mock);
|
|
||||||
|
verify(mock).getName();
|
||||||
|
verify(mock).debug("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDebugWithException() {
|
public void testDebugWithException() {
|
||||||
Logger mock = createStrictMock(Logger.class);
|
Logger mock = mock(Logger.class);
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mock.getName()).thenReturn("foo");
|
||||||
mock.debug("a", e);
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Log4J2Logger(mock);
|
InternalLogger logger = new Log4J2Logger(mock);
|
||||||
logger.debug("a", e);
|
logger.debug("a", e);
|
||||||
verify(mock);
|
|
||||||
|
verify(mock).getName();
|
||||||
|
verify(mock).debug("a", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInfo() {
|
public void testInfo() {
|
||||||
Logger mock = createStrictMock(Logger.class);
|
Logger mock = mock(Logger.class);
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mock.getName()).thenReturn("foo");
|
||||||
mock.info("a");
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Log4J2Logger(mock);
|
InternalLogger logger = new Log4J2Logger(mock);
|
||||||
logger.info("a");
|
logger.info("a");
|
||||||
verify(mock);
|
|
||||||
|
verify(mock).getName();
|
||||||
|
verify(mock).info("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInfoWithException() {
|
public void testInfoWithException() {
|
||||||
Logger mock = createStrictMock(Logger.class);
|
Logger mock = mock(Logger.class);
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mock.getName()).thenReturn("foo");
|
||||||
mock.info("a", e);
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Log4J2Logger(mock);
|
InternalLogger logger = new Log4J2Logger(mock);
|
||||||
logger.info("a", e);
|
logger.info("a", e);
|
||||||
verify(mock);
|
|
||||||
|
verify(mock).getName();
|
||||||
|
verify(mock).info("a", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWarn() {
|
public void testWarn() {
|
||||||
Logger mock = createStrictMock(Logger.class);
|
Logger mock = mock(Logger.class);
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mock.getName()).thenReturn("foo");
|
||||||
mock.warn("a");
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Log4J2Logger(mock);
|
InternalLogger logger = new Log4J2Logger(mock);
|
||||||
logger.warn("a");
|
logger.warn("a");
|
||||||
verify(mock);
|
|
||||||
|
verify(mock).getName();
|
||||||
|
verify(mock).warn("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWarnWithException() {
|
public void testWarnWithException() {
|
||||||
Logger mock = createStrictMock(Logger.class);
|
Logger mock = mock(Logger.class);
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mock.getName()).thenReturn("foo");
|
||||||
mock.warn("a", e);
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Log4J2Logger(mock);
|
InternalLogger logger = new Log4J2Logger(mock);
|
||||||
logger.warn("a", e);
|
logger.warn("a", e);
|
||||||
verify(mock);
|
|
||||||
|
verify(mock).getName();
|
||||||
|
verify(mock).warn("a", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testError() {
|
public void testError() {
|
||||||
Logger mock = createStrictMock(Logger.class);
|
Logger mock = mock(Logger.class);
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mock.getName()).thenReturn("foo");
|
||||||
mock.error("a");
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Log4J2Logger(mock);
|
InternalLogger logger = new Log4J2Logger(mock);
|
||||||
logger.error("a");
|
logger.error("a");
|
||||||
verify(mock);
|
|
||||||
|
verify(mock).getName();
|
||||||
|
verify(mock).error("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testErrorWithException() {
|
public void testErrorWithException() {
|
||||||
Logger mock = createStrictMock(Logger.class);
|
Logger mock = mock(Logger.class);
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mock.getName()).thenReturn("foo");
|
||||||
mock.error("a", e);
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Log4J2Logger(mock);
|
InternalLogger logger = new Log4J2Logger(mock);
|
||||||
logger.error("a", e);
|
logger.error("a", e);
|
||||||
verify(mock);
|
|
||||||
|
verify(mock).getName();
|
||||||
|
verify(mock).error("a", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,219 +18,209 @@ package io.netty.util.internal.logging;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.*;
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
public class Slf4JLoggerTest {
|
public class Slf4JLoggerTest {
|
||||||
private static final Exception e = new Exception();
|
private static final Exception e = new Exception();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsTraceEnabled() {
|
public void testIsTraceEnabled() {
|
||||||
Logger mock =
|
Logger mockLogger = mock(Logger.class);
|
||||||
createStrictMock(Logger.class);
|
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mockLogger.getName()).thenReturn("foo");
|
||||||
expect(mock.isTraceEnabled()).andReturn(true);
|
when(mockLogger.isTraceEnabled()).thenReturn(true);
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Slf4JLogger(mock);
|
InternalLogger logger = new Slf4JLogger(mockLogger);
|
||||||
assertTrue(logger.isTraceEnabled());
|
assertTrue(logger.isTraceEnabled());
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLogger).getName();
|
||||||
|
verify(mockLogger).isTraceEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsDebugEnabled() {
|
public void testIsDebugEnabled() {
|
||||||
Logger mock =
|
Logger mockLogger = mock(Logger.class);
|
||||||
createStrictMock(Logger.class);
|
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mockLogger.getName()).thenReturn("foo");
|
||||||
expect(mock.isDebugEnabled()).andReturn(true);
|
when(mockLogger.isDebugEnabled()).thenReturn(true);
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Slf4JLogger(mock);
|
InternalLogger logger = new Slf4JLogger(mockLogger);
|
||||||
assertTrue(logger.isDebugEnabled());
|
assertTrue(logger.isDebugEnabled());
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLogger).getName();
|
||||||
|
verify(mockLogger).isDebugEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsInfoEnabled() {
|
public void testIsInfoEnabled() {
|
||||||
Logger mock =
|
Logger mockLogger = mock(Logger.class);
|
||||||
createStrictMock(Logger.class);
|
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mockLogger.getName()).thenReturn("foo");
|
||||||
expect(mock.isInfoEnabled()).andReturn(true);
|
when(mockLogger.isInfoEnabled()).thenReturn(true);
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Slf4JLogger(mock);
|
InternalLogger logger = new Slf4JLogger(mockLogger);
|
||||||
assertTrue(logger.isInfoEnabled());
|
assertTrue(logger.isInfoEnabled());
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLogger).getName();
|
||||||
|
verify(mockLogger).isInfoEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsWarnEnabled() {
|
public void testIsWarnEnabled() {
|
||||||
Logger mock =
|
Logger mockLogger = mock(Logger.class);
|
||||||
createStrictMock(Logger.class);
|
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mockLogger.getName()).thenReturn("foo");
|
||||||
expect(mock.isWarnEnabled()).andReturn(true);
|
when(mockLogger.isWarnEnabled()).thenReturn(true);
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Slf4JLogger(mock);
|
InternalLogger logger = new Slf4JLogger(mockLogger);
|
||||||
assertTrue(logger.isWarnEnabled());
|
assertTrue(logger.isWarnEnabled());
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLogger).getName();
|
||||||
|
verify(mockLogger).isWarnEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testIsErrorEnabled() {
|
public void testIsErrorEnabled() {
|
||||||
Logger mock =
|
Logger mockLogger = mock(Logger.class);
|
||||||
createStrictMock(Logger.class);
|
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mockLogger.getName()).thenReturn("foo");
|
||||||
expect(mock.isErrorEnabled()).andReturn(true);
|
when(mockLogger.isErrorEnabled()).thenReturn(true);
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Slf4JLogger(mock);
|
InternalLogger logger = new Slf4JLogger(mockLogger);
|
||||||
assertTrue(logger.isErrorEnabled());
|
assertTrue(logger.isErrorEnabled());
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLogger).getName();
|
||||||
|
verify(mockLogger).isErrorEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTrace() {
|
public void testTrace() {
|
||||||
Logger mock =
|
Logger mockLogger = mock(Logger.class);
|
||||||
createStrictMock(Logger.class);
|
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mockLogger.getName()).thenReturn("foo");
|
||||||
mock.trace("a");
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Slf4JLogger(mock);
|
InternalLogger logger = new Slf4JLogger(mockLogger);
|
||||||
logger.trace("a");
|
logger.trace("a");
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLogger).getName();
|
||||||
|
verify(mockLogger).trace("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTraceWithException() {
|
public void testTraceWithException() {
|
||||||
Logger mock =
|
Logger mockLogger = mock(Logger.class);
|
||||||
createStrictMock(Logger.class);
|
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mockLogger.getName()).thenReturn("foo");
|
||||||
mock.trace("a", e);
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Slf4JLogger(mock);
|
InternalLogger logger = new Slf4JLogger(mockLogger);
|
||||||
logger.trace("a", e);
|
logger.trace("a", e);
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLogger).getName();
|
||||||
|
verify(mockLogger).trace("a", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDebug() {
|
public void testDebug() {
|
||||||
Logger mock =
|
Logger mockLogger = mock(Logger.class);
|
||||||
createStrictMock(Logger.class);
|
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mockLogger.getName()).thenReturn("foo");
|
||||||
mock.debug("a");
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Slf4JLogger(mock);
|
InternalLogger logger = new Slf4JLogger(mockLogger);
|
||||||
logger.debug("a");
|
logger.debug("a");
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLogger).getName();
|
||||||
|
verify(mockLogger).debug("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDebugWithException() {
|
public void testDebugWithException() {
|
||||||
Logger mock =
|
Logger mockLogger = mock(Logger.class);
|
||||||
createStrictMock(Logger.class);
|
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mockLogger.getName()).thenReturn("foo");
|
||||||
mock.debug("a", e);
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Slf4JLogger(mock);
|
InternalLogger logger = new Slf4JLogger(mockLogger);
|
||||||
logger.debug("a", e);
|
logger.debug("a", e);
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLogger).getName();
|
||||||
|
verify(mockLogger).debug("a", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInfo() {
|
public void testInfo() {
|
||||||
Logger mock =
|
Logger mockLogger = mock(Logger.class);
|
||||||
createStrictMock(Logger.class);
|
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mockLogger.getName()).thenReturn("foo");
|
||||||
mock.info("a");
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Slf4JLogger(mock);
|
InternalLogger logger = new Slf4JLogger(mockLogger);
|
||||||
logger.info("a");
|
logger.info("a");
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLogger).getName();
|
||||||
|
verify(mockLogger).info("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInfoWithException() {
|
public void testInfoWithException() {
|
||||||
Logger mock =
|
Logger mockLogger = mock(Logger.class);
|
||||||
createStrictMock(Logger.class);
|
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mockLogger.getName()).thenReturn("foo");
|
||||||
mock.info("a", e);
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Slf4JLogger(mock);
|
InternalLogger logger = new Slf4JLogger(mockLogger);
|
||||||
logger.info("a", e);
|
logger.info("a", e);
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLogger).getName();
|
||||||
|
verify(mockLogger).info("a", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWarn() {
|
public void testWarn() {
|
||||||
Logger mock =
|
Logger mockLogger = mock(Logger.class);
|
||||||
createStrictMock(Logger.class);
|
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mockLogger.getName()).thenReturn("foo");
|
||||||
mock.warn("a");
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Slf4JLogger(mock);
|
InternalLogger logger = new Slf4JLogger(mockLogger);
|
||||||
logger.warn("a");
|
logger.warn("a");
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLogger).getName();
|
||||||
|
verify(mockLogger).warn("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWarnWithException() {
|
public void testWarnWithException() {
|
||||||
Logger mock =
|
Logger mockLogger = mock(Logger.class);
|
||||||
createStrictMock(Logger.class);
|
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mockLogger.getName()).thenReturn("foo");
|
||||||
mock.warn("a", e);
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Slf4JLogger(mock);
|
InternalLogger logger = new Slf4JLogger(mockLogger);
|
||||||
logger.warn("a", e);
|
logger.warn("a", e);
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLogger).getName();
|
||||||
|
verify(mockLogger).warn("a", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testError() {
|
public void testError() {
|
||||||
Logger mock =
|
Logger mockLogger = mock(Logger.class);
|
||||||
createStrictMock(Logger.class);
|
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mockLogger.getName()).thenReturn("foo");
|
||||||
mock.error("a");
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Slf4JLogger(mock);
|
InternalLogger logger = new Slf4JLogger(mockLogger);
|
||||||
logger.error("a");
|
logger.error("a");
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLogger).getName();
|
||||||
|
verify(mockLogger).error("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testErrorWithException() {
|
public void testErrorWithException() {
|
||||||
Logger mock =
|
Logger mockLogger = mock(Logger.class);
|
||||||
createStrictMock(Logger.class);
|
|
||||||
|
|
||||||
expect(mock.getName()).andReturn("foo");
|
when(mockLogger.getName()).thenReturn("foo");
|
||||||
mock.error("a", e);
|
|
||||||
replay(mock);
|
|
||||||
|
|
||||||
InternalLogger logger = new Slf4JLogger(mock);
|
InternalLogger logger = new Slf4JLogger(mockLogger);
|
||||||
logger.error("a", e);
|
logger.error("a", e);
|
||||||
verify(mock);
|
|
||||||
|
verify(mockLogger).getName();
|
||||||
|
verify(mockLogger).error("a", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,10 @@
|
|||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
@ -65,6 +65,10 @@
|
|||||||
<artifactId>alpn-api</artifactId>
|
<artifactId>alpn-api</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
@ -26,12 +26,12 @@ import io.netty.channel.ChannelHandler;
|
|||||||
import io.netty.channel.ChannelMetadata;
|
import io.netty.channel.ChannelMetadata;
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
import io.netty.channel.embedded.EmbeddedChannel;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import org.easymock.IArgumentMatcher;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.ArgumentMatcher;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
@ -39,15 +39,12 @@ import java.util.ArrayList;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.createNiceMock;
|
|
||||||
import static org.easymock.EasyMock.replay;
|
|
||||||
import static org.easymock.EasyMock.reportMatcher;
|
|
||||||
import static org.easymock.EasyMock.verify;
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.CoreMatchers.nullValue;
|
import static org.hamcrest.CoreMatchers.nullValue;
|
||||||
import static org.hamcrest.CoreMatchers.sameInstance;
|
import static org.hamcrest.CoreMatchers.sameInstance;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
import static org.slf4j.Logger.ROOT_LOGGER_NAME;
|
import static org.slf4j.Logger.ROOT_LOGGER_NAME;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,7 +84,7 @@ public class LoggingHandlerTest {
|
|||||||
@Before
|
@Before
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void setup() {
|
public void setup() {
|
||||||
appender = createNiceMock(Appender.class);
|
appender = mock(Appender.class);
|
||||||
logger.addAppender(appender);
|
logger.addAppender(appender);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,116 +107,94 @@ public class LoggingHandlerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldLogChannelActive() {
|
public void shouldLogChannelActive() {
|
||||||
appender.doAppend(matchesLog(".+ACTIVE$"));
|
|
||||||
replay(appender);
|
|
||||||
new EmbeddedChannel(new LoggingHandler());
|
new EmbeddedChannel(new LoggingHandler());
|
||||||
verify(appender);
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+ACTIVE$")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldLogChannelRegistered() {
|
public void shouldLogChannelRegistered() {
|
||||||
appender.doAppend(matchesLog(".+REGISTERED$"));
|
|
||||||
replay(appender);
|
|
||||||
new EmbeddedChannel(new LoggingHandler());
|
new EmbeddedChannel(new LoggingHandler());
|
||||||
verify(appender);
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+REGISTERED$")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldLogChannelClose() throws Exception {
|
public void shouldLogChannelClose() throws Exception {
|
||||||
appender.doAppend(matchesLog(".+CLOSE$"));
|
|
||||||
replay(appender);
|
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
||||||
channel.close().await();
|
channel.close().await();
|
||||||
verify(appender);
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+CLOSE$")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldLogChannelConnect() throws Exception {
|
public void shouldLogChannelConnect() throws Exception {
|
||||||
appender.doAppend(matchesLog(".+CONNECT: 0.0.0.0/0.0.0.0:80$"));
|
|
||||||
replay(appender);
|
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
||||||
channel.connect(new InetSocketAddress(80)).await();
|
channel.connect(new InetSocketAddress(80)).await();
|
||||||
verify(appender);
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+CONNECT: 0.0.0.0/0.0.0.0:80$")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldLogChannelConnectWithLocalAddress() throws Exception {
|
public void shouldLogChannelConnectWithLocalAddress() throws Exception {
|
||||||
appender.doAppend(matchesLog(".+CONNECT: 0.0.0.0/0.0.0.0:80, 0.0.0.0/0.0.0.0:81$"));
|
|
||||||
replay(appender);
|
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
||||||
channel.connect(new InetSocketAddress(80), new InetSocketAddress(81)).await();
|
channel.connect(new InetSocketAddress(80), new InetSocketAddress(81)).await();
|
||||||
verify(appender);
|
verify(appender).doAppend(argThat(
|
||||||
|
new RegexLogMatcher(".+CONNECT: 0.0.0.0/0.0.0.0:80, 0.0.0.0/0.0.0.0:81$")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldLogChannelDisconnect() throws Exception {
|
public void shouldLogChannelDisconnect() throws Exception {
|
||||||
appender.doAppend(matchesLog(".+DISCONNECT$"));
|
|
||||||
replay(appender);
|
|
||||||
EmbeddedChannel channel = new DisconnectingEmbeddedChannel(new LoggingHandler());
|
EmbeddedChannel channel = new DisconnectingEmbeddedChannel(new LoggingHandler());
|
||||||
channel.connect(new InetSocketAddress(80)).await();
|
channel.connect(new InetSocketAddress(80)).await();
|
||||||
channel.disconnect().await();
|
channel.disconnect().await();
|
||||||
verify(appender);
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+DISCONNECT$")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldLogChannelInactive() throws Exception {
|
public void shouldLogChannelInactive() throws Exception {
|
||||||
appender.doAppend(matchesLog(".+INACTIVE$"));
|
|
||||||
replay(appender);
|
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
||||||
channel.pipeline().fireChannelInactive();
|
channel.pipeline().fireChannelInactive();
|
||||||
verify(appender);
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+INACTIVE$")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldLogChannelBind() throws Exception {
|
public void shouldLogChannelBind() throws Exception {
|
||||||
appender.doAppend(matchesLog(".+BIND: 0.0.0.0/0.0.0.0:80$"));
|
|
||||||
replay(appender);
|
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
||||||
channel.bind(new InetSocketAddress(80));
|
channel.bind(new InetSocketAddress(80));
|
||||||
verify(appender);
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+BIND: 0.0.0.0/0.0.0.0:80$")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("RedundantStringConstructorCall")
|
@SuppressWarnings("RedundantStringConstructorCall")
|
||||||
public void shouldLogChannelUserEvent() throws Exception {
|
public void shouldLogChannelUserEvent() throws Exception {
|
||||||
String userTriggered = "iAmCustom!";
|
String userTriggered = "iAmCustom!";
|
||||||
appender.doAppend(matchesLog(".+USER_EVENT: " + userTriggered + '$'));
|
|
||||||
replay(appender);
|
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
||||||
channel.pipeline().fireUserEventTriggered(new String(userTriggered));
|
channel.pipeline().fireUserEventTriggered(new String(userTriggered));
|
||||||
verify(appender);
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+USER_EVENT: " + userTriggered + '$')));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldLogChannelException() throws Exception {
|
public void shouldLogChannelException() throws Exception {
|
||||||
String msg = "illegalState";
|
String msg = "illegalState";
|
||||||
Throwable cause = new IllegalStateException(msg);
|
Throwable cause = new IllegalStateException(msg);
|
||||||
appender.doAppend(matchesLog(".+EXCEPTION: " + cause.getClass().getCanonicalName() + ": " + msg + '$'));
|
|
||||||
replay(appender);
|
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
||||||
channel.pipeline().fireExceptionCaught(cause);
|
channel.pipeline().fireExceptionCaught(cause);
|
||||||
verify(appender);
|
verify(appender).doAppend(argThat(new RegexLogMatcher(
|
||||||
|
".+EXCEPTION: " + cause.getClass().getCanonicalName() + ": " + msg + '$')));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldLogDataWritten() throws Exception {
|
public void shouldLogDataWritten() throws Exception {
|
||||||
String msg = "hello";
|
String msg = "hello";
|
||||||
appender.doAppend(matchesLog(".+WRITE: " + msg + '$'));
|
|
||||||
appender.doAppend(matchesLog(".+FLUSH$"));
|
|
||||||
replay(appender);
|
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
||||||
channel.writeOutbound(msg);
|
channel.writeOutbound(msg);
|
||||||
verify(appender);
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+WRITE: " + msg + '$')));
|
||||||
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+FLUSH$")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldLogNonByteBufDataRead() throws Exception {
|
public void shouldLogNonByteBufDataRead() throws Exception {
|
||||||
String msg = "hello";
|
String msg = "hello";
|
||||||
appender.doAppend(matchesLog(".+RECEIVED: " + msg + '$'));
|
|
||||||
replay(appender);
|
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
||||||
channel.writeInbound(msg);
|
channel.writeInbound(msg);
|
||||||
verify(appender);
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+RECEIVED: " + msg + '$')));
|
||||||
|
|
||||||
String handledMsg = channel.readInbound();
|
String handledMsg = channel.readInbound();
|
||||||
assertThat(msg, is(sameInstance(handledMsg)));
|
assertThat(msg, is(sameInstance(handledMsg)));
|
||||||
@ -229,11 +204,9 @@ public class LoggingHandlerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldLogByteBufDataRead() throws Exception {
|
public void shouldLogByteBufDataRead() throws Exception {
|
||||||
ByteBuf msg = Unpooled.copiedBuffer("hello", CharsetUtil.UTF_8);
|
ByteBuf msg = Unpooled.copiedBuffer("hello", CharsetUtil.UTF_8);
|
||||||
appender.doAppend(matchesLog(".+RECEIVED: " + msg.readableBytes() + "B$"));
|
|
||||||
replay(appender);
|
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
||||||
channel.writeInbound(msg);
|
channel.writeInbound(msg);
|
||||||
verify(appender);
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+RECEIVED: " + msg.readableBytes() + "B$")));
|
||||||
|
|
||||||
ByteBuf handledMsg = channel.readInbound();
|
ByteBuf handledMsg = channel.readInbound();
|
||||||
assertThat(msg, is(sameInstance(handledMsg)));
|
assertThat(msg, is(sameInstance(handledMsg)));
|
||||||
@ -244,11 +217,9 @@ public class LoggingHandlerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldLogEmptyByteBufDataRead() throws Exception {
|
public void shouldLogEmptyByteBufDataRead() throws Exception {
|
||||||
ByteBuf msg = Unpooled.EMPTY_BUFFER;
|
ByteBuf msg = Unpooled.EMPTY_BUFFER;
|
||||||
appender.doAppend(matchesLog(".+RECEIVED: 0B$"));
|
|
||||||
replay(appender);
|
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
||||||
channel.writeInbound(msg);
|
channel.writeInbound(msg);
|
||||||
verify(appender);
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+RECEIVED: 0B$")));
|
||||||
|
|
||||||
ByteBuf handledMsg = channel.readInbound();
|
ByteBuf handledMsg = channel.readInbound();
|
||||||
assertThat(msg, is(sameInstance(handledMsg)));
|
assertThat(msg, is(sameInstance(handledMsg)));
|
||||||
@ -264,11 +235,9 @@ public class LoggingHandlerTest {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
appender.doAppend(matchesLog(".+RECEIVED: foobar, 5B$"));
|
|
||||||
replay(appender);
|
|
||||||
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
|
||||||
channel.writeInbound(msg);
|
channel.writeInbound(msg);
|
||||||
verify(appender);
|
verify(appender).doAppend(argThat(new RegexLogMatcher(".+RECEIVED: foobar, 5B$")));
|
||||||
|
|
||||||
ByteBufHolder handledMsg = channel.readInbound();
|
ByteBufHolder handledMsg = channel.readInbound();
|
||||||
assertThat(msg, is(sameInstance(handledMsg)));
|
assertThat(msg, is(sameInstance(handledMsg)));
|
||||||
@ -276,21 +245,10 @@ public class LoggingHandlerTest {
|
|||||||
assertThat(channel.readInbound(), is(nullValue()));
|
assertThat(channel.readInbound(), is(nullValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Static helper method for matching Logback messages.
|
|
||||||
*
|
|
||||||
* @param toMatch the regex to match.
|
|
||||||
* @return a mocked event to pass into the {@link Appender#doAppend(Object)} method.
|
|
||||||
*/
|
|
||||||
private static ILoggingEvent matchesLog(String toMatch) {
|
|
||||||
reportMatcher(new RegexLogMatcher(toMatch));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A custom EasyMock matcher that matches on Logback messages.
|
* A custom EasyMock matcher that matches on Logback messages.
|
||||||
*/
|
*/
|
||||||
private static final class RegexLogMatcher implements IArgumentMatcher {
|
private static final class RegexLogMatcher implements ArgumentMatcher<ILoggingEvent> {
|
||||||
|
|
||||||
private final String expected;
|
private final String expected;
|
||||||
private String actualMsg;
|
private String actualMsg;
|
||||||
@ -301,23 +259,11 @@ public class LoggingHandlerTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("DynamicRegexReplaceableByCompiledPattern")
|
@SuppressWarnings("DynamicRegexReplaceableByCompiledPattern")
|
||||||
public boolean matches(Object actual) {
|
public boolean matches(ILoggingEvent actual) {
|
||||||
if (!(actual instanceof ILoggingEvent)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Match only the first line to skip the validation of hex-dump format.
|
// Match only the first line to skip the validation of hex-dump format.
|
||||||
actualMsg = ((ILoggingEvent) actual).getMessage().split("(?s)[\\r\\n]+")[0];
|
actualMsg = actual.getMessage().split("(?s)[\\r\\n]+")[0];
|
||||||
return actualMsg.matches(expected);
|
return actualMsg.matches(expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void appendTo(StringBuffer buffer) {
|
|
||||||
buffer.append("matchesLog(")
|
|
||||||
.append("expected: \"").append(expected)
|
|
||||||
.append("\", got: \"").append(actualMsg)
|
|
||||||
.append("\")");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class DisconnectingEmbeddedChannel extends EmbeddedChannel {
|
private static final class DisconnectingEmbeddedChannel extends EmbeddedChannel {
|
||||||
|
46
pom.xml
46
pom.xml
@ -471,34 +471,10 @@
|
|||||||
<version>1.3</version>
|
<version>1.3</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.easymock</groupId>
|
|
||||||
<artifactId>easymock</artifactId>
|
|
||||||
<version>3.4</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.easymock</groupId>
|
|
||||||
<artifactId>easymockclassextension</artifactId>
|
|
||||||
<version>3.2</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jmock</groupId>
|
|
||||||
<artifactId>jmock-junit4</artifactId>
|
|
||||||
<version>2.8.2</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit-dep</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-core</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<version>1.10.19</version>
|
<version>2.7.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -595,26 +571,6 @@
|
|||||||
<artifactId>hamcrest-library</artifactId>
|
<artifactId>hamcrest-library</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.easymock</groupId>
|
|
||||||
<artifactId>easymock</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.easymock</groupId>
|
|
||||||
<artifactId>easymockclassextension</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jmock</groupId>
|
|
||||||
<artifactId>jmock-junit4</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-core</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ch.qos.logback</groupId>
|
<groupId>ch.qos.logback</groupId>
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
|
@ -34,6 +34,10 @@
|
|||||||
<artifactId>netty-common</artifactId>
|
<artifactId>netty-common</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
@ -74,21 +74,6 @@
|
|||||||
<artifactId>hamcrest-library</artifactId>
|
<artifactId>hamcrest-library</artifactId>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.easymock</groupId>
|
|
||||||
<artifactId>easymock</artifactId>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.easymock</groupId>
|
|
||||||
<artifactId>easymockclassextension</artifactId>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.jmock</groupId>
|
|
||||||
<artifactId>jmock-junit4</artifactId>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-core</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
|
@ -39,6 +39,10 @@
|
|||||||
<artifactId>netty-resolver</artifactId>
|
<artifactId>netty-resolver</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
@ -17,66 +17,49 @@ package io.netty.channel;
|
|||||||
|
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
|
|
||||||
import org.easymock.Capture;
|
|
||||||
import org.easymock.IAnswer;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.*;
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
public class AbstractChannelTest {
|
public class AbstractChannelTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ensureInitialRegistrationFiresActive() throws Throwable {
|
public void ensureInitialRegistrationFiresActive() throws Throwable {
|
||||||
EventLoop eventLoop = createNiceMock(EventLoop.class);
|
EventLoop eventLoop = mock(EventLoop.class);
|
||||||
// This allows us to have a single-threaded test
|
// This allows us to have a single-threaded test
|
||||||
expect(eventLoop.inEventLoop()).andReturn(true).anyTimes();
|
when(eventLoop.inEventLoop()).thenReturn(true);
|
||||||
|
|
||||||
TestChannel channel = new TestChannel();
|
TestChannel channel = new TestChannel();
|
||||||
ChannelInboundHandler handler = createMock(ChannelInboundHandler.class);
|
ChannelInboundHandler handler = mock(ChannelInboundHandler.class);
|
||||||
handler.handlerAdded(anyObject(ChannelHandlerContext.class)); expectLastCall();
|
|
||||||
Capture<Throwable> throwable = catchHandlerExceptions(handler);
|
|
||||||
handler.channelRegistered(anyObject(ChannelHandlerContext.class));
|
|
||||||
expectLastCall().once();
|
|
||||||
handler.channelActive(anyObject(ChannelHandlerContext.class));
|
|
||||||
expectLastCall().once();
|
|
||||||
replay(handler, eventLoop);
|
|
||||||
channel.pipeline().addLast(handler);
|
channel.pipeline().addLast(handler);
|
||||||
|
|
||||||
registerChannel(eventLoop, channel);
|
registerChannel(eventLoop, channel);
|
||||||
|
|
||||||
checkForHandlerException(throwable);
|
verify(handler).handlerAdded(any(ChannelHandlerContext.class));
|
||||||
verify(handler);
|
verify(handler).channelRegistered(any(ChannelHandlerContext.class));
|
||||||
|
verify(handler).channelActive(any(ChannelHandlerContext.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ensureSubsequentRegistrationDoesNotFireActive() throws Throwable {
|
public void ensureSubsequentRegistrationDoesNotFireActive() throws Throwable {
|
||||||
final EventLoop eventLoop = createNiceMock(EventLoop.class);
|
final EventLoop eventLoop = mock(EventLoop.class);
|
||||||
// This allows us to have a single-threaded test
|
// This allows us to have a single-threaded test
|
||||||
expect(eventLoop.inEventLoop()).andReturn(true).anyTimes();
|
when(eventLoop.inEventLoop()).thenReturn(true);
|
||||||
eventLoop.execute(anyObject(Runnable.class));
|
|
||||||
expectLastCall().andAnswer(new IAnswer<Object>() {
|
doAnswer(new Answer() {
|
||||||
@Override
|
@Override
|
||||||
public Object answer() throws Throwable {
|
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
|
||||||
((Runnable) getCurrentArguments()[0]).run();
|
((Runnable) invocationOnMock.getArgument(0)).run();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}).once();
|
}).when(eventLoop).execute(any(Runnable.class));
|
||||||
|
|
||||||
final TestChannel channel = new TestChannel();
|
final TestChannel channel = new TestChannel();
|
||||||
ChannelInboundHandler handler = createMock(ChannelInboundHandler.class);
|
ChannelInboundHandler handler = mock(ChannelInboundHandler.class);
|
||||||
handler.handlerAdded(anyObject(ChannelHandlerContext.class)); expectLastCall();
|
|
||||||
Capture<Throwable> throwable = catchHandlerExceptions(handler);
|
|
||||||
handler.channelRegistered(anyObject(ChannelHandlerContext.class));
|
|
||||||
expectLastCall().times(2); // Should register twice
|
|
||||||
handler.channelActive(anyObject(ChannelHandlerContext.class));
|
|
||||||
expectLastCall().once(); // Should only fire active once
|
|
||||||
|
|
||||||
handler.channelUnregistered(anyObject(ChannelHandlerContext.class));
|
|
||||||
expectLastCall().once(); // Should register twice
|
|
||||||
|
|
||||||
replay(handler, eventLoop);
|
|
||||||
channel.pipeline().addLast(handler);
|
channel.pipeline().addLast(handler);
|
||||||
|
|
||||||
registerChannel(eventLoop, channel);
|
registerChannel(eventLoop, channel);
|
||||||
@ -84,15 +67,19 @@ public class AbstractChannelTest {
|
|||||||
|
|
||||||
registerChannel(eventLoop, channel);
|
registerChannel(eventLoop, channel);
|
||||||
|
|
||||||
checkForHandlerException(throwable);
|
verify(handler).handlerAdded(any(ChannelHandlerContext.class));
|
||||||
verify(handler);
|
|
||||||
|
// Should register twice
|
||||||
|
verify(handler, times(2)) .channelRegistered(any(ChannelHandlerContext.class));
|
||||||
|
verify(handler).channelActive(any(ChannelHandlerContext.class));
|
||||||
|
verify(handler).channelUnregistered(any(ChannelHandlerContext.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ensureDefaultChannelId() {
|
public void ensureDefaultChannelId() {
|
||||||
TestChannel channel = new TestChannel();
|
TestChannel channel = new TestChannel();
|
||||||
final ChannelId channelId = channel.id();
|
final ChannelId channelId = channel.id();
|
||||||
assertThat(channelId, instanceOf(DefaultChannelId.class));
|
assertTrue(channelId instanceof DefaultChannelId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerChannel(EventLoop eventLoop, Channel channel) throws Exception {
|
private static void registerChannel(EventLoop eventLoop, Channel channel) throws Exception {
|
||||||
@ -101,19 +88,6 @@ public class AbstractChannelTest {
|
|||||||
future.sync(); // Cause any exceptions to be thrown
|
future.sync(); // Cause any exceptions to be thrown
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Capture<Throwable> catchHandlerExceptions(ChannelInboundHandler handler) throws Exception {
|
|
||||||
Capture<Throwable> throwable = new Capture<Throwable>();
|
|
||||||
handler.exceptionCaught(anyObject(ChannelHandlerContext.class), capture(throwable));
|
|
||||||
expectLastCall().anyTimes();
|
|
||||||
return throwable;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void checkForHandlerException(Capture<Throwable> throwable) throws Throwable {
|
|
||||||
if (throwable.hasCaptured()) {
|
|
||||||
throw throwable.getValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class TestChannel extends AbstractChannel {
|
private static class TestChannel extends AbstractChannel {
|
||||||
private static final ChannelMetadata TEST_METADATA = new ChannelMetadata(false);
|
private static final ChannelMetadata TEST_METADATA = new ChannelMetadata(false);
|
||||||
private class TestUnsafe extends AbstractUnsafe {
|
private class TestUnsafe extends AbstractUnsafe {
|
||||||
|
@ -15,24 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.channel;
|
package io.netty.channel;
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.*;
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class CompleteChannelFutureTest {
|
public class CompleteChannelFutureTest {
|
||||||
|
|
||||||
private final Channel channel = createMock(Channel.class);
|
|
||||||
private CompleteChannelFuture future;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void init() {
|
|
||||||
future = new CompleteChannelFutureImpl(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
public void shouldDisallowNullChannel() {
|
public void shouldDisallowNullChannel() {
|
||||||
new CompleteChannelFutureImpl(null);
|
new CompleteChannelFutureImpl(null);
|
||||||
@ -40,15 +31,19 @@ public class CompleteChannelFutureTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotDoAnythingOnRemove() throws Exception {
|
public void shouldNotDoAnythingOnRemove() throws Exception {
|
||||||
ChannelFutureListener l = createStrictMock(ChannelFutureListener.class);
|
Channel channel = Mockito.mock(Channel.class);
|
||||||
replay(l);
|
CompleteChannelFuture future = new CompleteChannelFutureImpl(channel);
|
||||||
|
ChannelFutureListener l = Mockito.mock(ChannelFutureListener.class);
|
||||||
future.removeListener(l);
|
future.removeListener(l);
|
||||||
verify(l);
|
Mockito.verifyNoMoreInteractions(l);
|
||||||
|
Mockito.verifyZeroInteractions(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstantProperties() throws InterruptedException {
|
public void testConstantProperties() throws InterruptedException {
|
||||||
|
Channel channel = Mockito.mock(Channel.class);
|
||||||
|
CompleteChannelFuture future = new CompleteChannelFutureImpl(channel);
|
||||||
|
|
||||||
assertSame(channel, future.channel());
|
assertSame(channel, future.channel());
|
||||||
assertTrue(future.isDone());
|
assertTrue(future.isDone());
|
||||||
assertSame(future, future.await());
|
assertSame(future, future.await());
|
||||||
@ -57,6 +52,7 @@ public class CompleteChannelFutureTest {
|
|||||||
assertSame(future, future.awaitUninterruptibly());
|
assertSame(future, future.awaitUninterruptibly());
|
||||||
assertTrue(future.awaitUninterruptibly(1));
|
assertTrue(future.awaitUninterruptibly(1));
|
||||||
assertTrue(future.awaitUninterruptibly(1, TimeUnit.NANOSECONDS));
|
assertTrue(future.awaitUninterruptibly(1, TimeUnit.NANOSECONDS));
|
||||||
|
Mockito.verifyZeroInteractions(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class CompleteChannelFutureImpl extends CompleteChannelFuture {
|
private static class CompleteChannelFutureImpl extends CompleteChannelFuture {
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
package io.netty.channel;
|
package io.netty.channel;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.*;
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class FailedChannelFutureTest {
|
public class FailedChannelFutureTest {
|
||||||
@Test
|
@Test
|
||||||
public void testConstantProperties() {
|
public void testConstantProperties() {
|
||||||
Channel channel = createMock(Channel.class);
|
Channel channel = Mockito.mock(Channel.class);
|
||||||
Exception e = new Exception();
|
Exception e = new Exception();
|
||||||
FailedChannelFuture future = new FailedChannelFuture(channel, null, e);
|
FailedChannelFuture future = new FailedChannelFuture(channel, null, e);
|
||||||
|
|
||||||
@ -33,6 +33,6 @@ public class FailedChannelFutureTest {
|
|||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
public void shouldDisallowNullException() {
|
public void shouldDisallowNullException() {
|
||||||
new FailedChannelFuture(createMock(Channel.class), null, null);
|
new FailedChannelFuture(Mockito.mock(Channel.class), null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
package io.netty.channel;
|
package io.netty.channel;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.*;
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class SucceededChannelFutureTest {
|
public class SucceededChannelFutureTest {
|
||||||
@Test
|
@Test
|
||||||
public void testConstantProperties() {
|
public void testConstantProperties() {
|
||||||
Channel channel = createMock(Channel.class);
|
Channel channel = Mockito.mock(Channel.class);
|
||||||
SucceededChannelFuture future = new SucceededChannelFuture(channel, null);
|
SucceededChannelFuture future = new SucceededChannelFuture(channel, null);
|
||||||
|
|
||||||
assertTrue(future.isSuccess());
|
assertTrue(future.isSuccess());
|
||||||
|
Loading…
Reference in New Issue
Block a user