Added some tests Project: http://git-wip-us.apache.org/repos/asf/mina/repo Commit: http://git-wip-us.apache.org/repos/asf/mina/commit/eb278615 Tree: http://git-wip-us.apache.org/repos/asf/mina/tree/eb278615 Diff: http://git-wip-us.apache.org/repos/asf/mina/diff/eb278615
Branch: refs/heads/2.0 Commit: eb2786150702bd999f6fbbba5534711d0cbb6f16 Parents: 4d4bcf7 Author: Emmanuel Lécharny <[email protected]> Authored: Mon Dec 22 09:07:33 2014 +0100 Committer: Emmanuel Lécharny <[email protected]> Committed: Mon Dec 22 09:07:33 2014 +0100 ---------------------------------------------------------------------- .../apache/mina/core/buffer/IoBufferTest.java | 85 ++++++++++++++++---- .../org/apache/mina/filter/ssl/SslTest.java | 11 ++- 2 files changed, 77 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina/blob/eb278615/mina-core/src/test/java/org/apache/mina/core/buffer/IoBufferTest.java ---------------------------------------------------------------------- diff --git a/mina-core/src/test/java/org/apache/mina/core/buffer/IoBufferTest.java b/mina-core/src/test/java/org/apache/mina/core/buffer/IoBufferTest.java index 238036d..8c663ca 100644 --- a/mina-core/src/test/java/org/apache/mina/core/buffer/IoBufferTest.java +++ b/mina-core/src/test/java/org/apache/mina/core/buffer/IoBufferTest.java @@ -43,7 +43,7 @@ import org.apache.mina.util.Bar; import org.junit.Test; /** - * Tests {@link IoBuffer}. + * Tests the {@link IoBuffer} class. * * @author <a href="http://mina.apache.org">Apache MINA Project</a> */ @@ -55,6 +55,9 @@ public class IoBufferTest { public static class NonserializableClass { } + /** + * Test the capacity(newCapacity) method. + */ @Test public void testCapacity() { IoBuffer buffer = IoBuffer.allocate(10); @@ -62,7 +65,7 @@ public class IoBufferTest { buffer.put("012345".getBytes()); buffer.flip(); - // See if we can decrease the capacity (we shouldn't) + // See if we can decrease the capacity (we shouldn't be able to go under the minimul capacity) IoBuffer newBuffer = buffer.capacity(7); assertEquals(10, newBuffer.capacity()); assertEquals(buffer, newBuffer); @@ -78,8 +81,18 @@ public class IoBufferTest { newBuffer.put(0, (byte)'9'); assertEquals((byte)'9', newBuffer.get(0)); assertEquals((byte)'9', buffer.get(0)); + + // See if we can go down when the minimum capacity is below the current capacity + // We should not. + buffer = IoBuffer.allocate(10); + buffer.capacity(5); + assertEquals(10, buffer.minimumCapacity()); + assertEquals(10, buffer.capacity()); } + /** + * Test the expand(expectedRemaining) method. + */ @Test public void testExpand() { IoBuffer buffer = IoBuffer.allocate(10); @@ -151,6 +164,9 @@ public class IoBufferTest { assertEquals(4, newBuffer.position()); } + /** + * Test the expand(position, expectedRemaining) method. + */ @Test public void testExpandPos() { IoBuffer buffer = IoBuffer.allocate(10); @@ -221,7 +237,10 @@ public class IoBufferTest { assertEquals(11, newBuffer.capacity()); assertEquals(4, newBuffer.position()); } - + + /** + * Test the normalizeCapacity(requestedCapacity) method. + */ @Test public void testNormalizeCapacity() { // A few sanity checks @@ -406,6 +425,15 @@ public class IoBufferTest { } } + /** + * Test that we can't allocate a buffser with a negative value + * @throws Exception + */ + @Test(expected=IllegalArgumentException.class) + public void testAllocateNegative() throws Exception { + IoBuffer.allocate(-1); + } + @Test public void testAutoExpand() throws Exception { IoBuffer buf = IoBuffer.allocate(1); @@ -1558,6 +1586,9 @@ public class IoBufferTest { assertEquals(0x0000000083838383L, buf.getUnsignedInt()); } + /** + * Test the IoBuffer.putUnsignedInIndex() method. + */ @Test public void testPutUnsignedIntIndex() { IoBuffer buf = IoBuffer.allocate(16); @@ -1584,7 +1615,7 @@ public class IoBufferTest { } /** - * Test the getSlice method (even if we haven't flipped the buffer + * Test the getSlice method (even if we haven't flipped the buffer) */ @Test public void testGetSlice() { @@ -1617,22 +1648,42 @@ public class IoBufferTest { assertEquals(0x03, res.get()); } + /** + * Test the IoBuffer.shrink() method. + */ @Test public void testShrink() { IoBuffer buf = IoBuffer.allocate(36); - buf.minimumCapacity(0); + buf.put( "012345".getBytes()); + buf.flip(); + buf.position(4); + buf.minimumCapacity(8); - buf.limit(18); - buf.shrink(); - buf.limit(9); - buf.shrink(); - buf.limit(4); - buf.shrink(); - buf.limit(2); - buf.shrink(); - buf.limit(1); - buf.shrink(); - buf.limit(0); - buf.shrink(); + IoBuffer newBuf = buf.shrink(); + assertEquals(4, newBuf.position()); + assertEquals(6, newBuf.limit()); + assertEquals(9, newBuf.capacity()); + assertEquals(8, newBuf.minimumCapacity()); + + buf = IoBuffer.allocate(6); + buf.put( "012345".getBytes()); + buf.flip(); + buf.position(4); + + newBuf = buf.shrink(); + assertEquals(4, newBuf.position()); + assertEquals(6, newBuf.limit()); + assertEquals(6, newBuf.capacity()); + assertEquals(6, newBuf.minimumCapacity()); + } + + + /** + * Test the IoBuffer.position(newPosition) method. + */ + @Test + public void testSetPosition() + { + } } http://git-wip-us.apache.org/repos/asf/mina/blob/eb278615/mina-core/src/test/java/org/apache/mina/filter/ssl/SslTest.java ---------------------------------------------------------------------- diff --git a/mina-core/src/test/java/org/apache/mina/filter/ssl/SslTest.java b/mina-core/src/test/java/org/apache/mina/filter/ssl/SslTest.java index 135c7e1..5f577dd 100644 --- a/mina-core/src/test/java/org/apache/mina/filter/ssl/SslTest.java +++ b/mina-core/src/test/java/org/apache/mina/filter/ssl/SslTest.java @@ -79,7 +79,14 @@ public class SslTest { Thread.sleep(1500); } else if (line.startsWith("send")) { System.out.println("Server got: 'send', sending 'data'"); - session.write("data"); + StringBuilder sb = new StringBuilder(); + + for ( int i = 0; i < 10000; i++) { + sb.append('A'); + } + + session.write(sb.toString()); + session.close(true); } } } @@ -127,7 +134,7 @@ public class SslTest { System.out.println("Client sending: hello"); socket.getOutputStream().write("hello \n".getBytes()); socket.getOutputStream().flush(); - socket.setSoTimeout(10000); + socket.setSoTimeout(1000000); System.out.println("Client sending: send"); socket.getOutputStream().write("send\n".getBytes());
