[jboss-cvs] JBoss Messaging SVN: r4403 - in trunk: tests/src/org/jboss/messaging/tests/integration/core/remoting/mina and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jun 6 09:47:45 EDT 2008
Author: jmesnil
Date: 2008-06-06 09:47:44 -0400 (Fri, 06 Jun 2008)
New Revision: 4403
Modified:
trunk/src/main/org/jboss/messaging/util/ByteBufferWrapper.java
trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/IoBufferWrapperTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/MessagingBufferTestBase.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/util/ByteBufferWrapperTest.java
Log:
added unit tests for ByteBufferWrapper + bug fixes
Modified: trunk/src/main/org/jboss/messaging/util/ByteBufferWrapper.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/ByteBufferWrapper.java 2008-06-06 13:02:50 UTC (rev 4402)
+++ trunk/src/main/org/jboss/messaging/util/ByteBufferWrapper.java 2008-06-06 13:47:44 UTC (rev 4403)
@@ -210,12 +210,10 @@
int b = buffer.get();
if (b == NULL)
{
- return null;
+ return null;
+ } else {
+ return getSimpleString();
}
- else
- {
- return getSimpleString();
- }
}
public void putNullableSimpleString(final SimpleString string)
@@ -226,6 +224,7 @@
}
else
{
+ buffer.put(NOT_NULL);
putSimpleString(string);
}
}
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/IoBufferWrapperTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/IoBufferWrapperTest.java 2008-06-06 13:02:50 UTC (rev 4402)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/IoBufferWrapperTest.java 2008-06-06 13:47:44 UTC (rev 4403)
@@ -23,8 +23,6 @@
// Attributes ----------------------------------------------------
- private IoBuffer buffer;
-
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
@@ -36,17 +34,11 @@
@Override
protected MessagingBuffer createBuffer()
{
- buffer = IoBuffer.allocate(512);
+ IoBuffer buffer = IoBuffer.allocate(512);
buffer.setAutoExpand(true);
return new IoBufferWrapper(buffer);
}
- @Override
- protected void flipBuffer()
- {
- buffer.flip();
- }
-
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/MessagingBufferTestBase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/MessagingBufferTestBase.java 2008-06-06 13:02:50 UTC (rev 4402)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/MessagingBufferTestBase.java 2008-06-06 13:47:44 UTC (rev 4403)
@@ -6,21 +6,19 @@
*/
package org.jboss.messaging.tests.integration.core.remoting.mina;
-import static java.util.UUID.randomUUID;
import static org.jboss.messaging.tests.unit.core.remoting.impl.wireformat.CodecAssert.assertEqualsByteArrays;
import static org.jboss.messaging.tests.util.RandomUtil.randomByte;
import static org.jboss.messaging.tests.util.RandomUtil.randomBytes;
import static org.jboss.messaging.tests.util.RandomUtil.randomDouble;
import static org.jboss.messaging.tests.util.RandomUtil.randomFloat;
import static org.jboss.messaging.tests.util.RandomUtil.randomInt;
+import static org.jboss.messaging.tests.util.RandomUtil.randomLong;
import static org.jboss.messaging.tests.util.RandomUtil.randomString;
import junit.framework.TestCase;
-import org.apache.mina.common.IoBuffer;
-import org.jboss.messaging.core.remoting.impl.mina.IoBufferWrapper;
-import org.jboss.messaging.tests.unit.core.remoting.impl.wireformat.CodecAssert;
import org.jboss.messaging.tests.util.RandomUtil;
import org.jboss.messaging.util.MessagingBuffer;
+import org.jboss.messaging.util.SimpleString;
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
@@ -54,13 +52,12 @@
}
protected abstract MessagingBuffer createBuffer();
- protected abstract void flipBuffer();
public void testNullString() throws Exception
{
assertNull(putAndGetNullableString(null));
}
-
+
public void testEmptyString() throws Exception
{
String result = putAndGetNullableString("");
@@ -71,20 +68,43 @@
public void testNonEmptyString() throws Exception
{
- String junk = randomUUID().toString();
-
+ String junk = randomString();
+
String result = putAndGetNullableString(junk);
assertNotNull(result);
assertEquals(junk, result);
}
+ public void testNullSimpleString() throws Exception
+ {
+ assertNull(putAndGetNullableSimpleString(null));
+ }
+
+ public void testEmptySimpleString() throws Exception
+ {
+ SimpleString emptySimpleString = new SimpleString("");
+ SimpleString result = putAndGetNullableSimpleString(emptySimpleString);
+
+ assertNotNull(result);
+ assertEqualsByteArrays(emptySimpleString.getData(), result.getData());
+ }
+
+ public void testNonEmptySimpleString() throws Exception
+ {
+ SimpleString junk = RandomUtil.randomSimpleString();
+ SimpleString result = putAndGetNullableSimpleString(junk);
+
+ assertNotNull(result);
+ assertEqualsByteArrays(junk.getData(), result.getData());
+ }
+
public void testByte() throws Exception
{
byte b = randomByte();
wrapper.putByte(b);
- flipBuffer();
+ wrapper.flip();
assertEquals(b, wrapper.getByte());
}
@@ -94,18 +114,18 @@
byte[] bytes = randomBytes();
wrapper.putBytes(bytes);
- flipBuffer();
+ wrapper.flip();
byte[] b = new byte[bytes.length];
wrapper.getBytes(b);
assertEqualsByteArrays(bytes, b);
}
-
+
public void testPutTrueBoolean() throws Exception
{
wrapper.putBoolean(true);
- flipBuffer();
+ wrapper.flip();
assertTrue(wrapper.getBoolean());
}
@@ -114,7 +134,7 @@
{
wrapper.putBoolean(false);
- flipBuffer();
+ wrapper.flip();
assertFalse(wrapper.getBoolean());
}
@@ -123,7 +143,7 @@
{
wrapper.putChar('a');
- flipBuffer();
+ wrapper.flip();
assertEquals('a', wrapper.getChar());
}
@@ -133,16 +153,42 @@
int i = randomInt();
wrapper.putInt(i);
- flipBuffer();
+ wrapper.flip();
assertEquals(i, wrapper.getInt());
}
+ public void testIntAtPosition() throws Exception
+ {
+ int firstInt = randomInt();
+ int secondInt = randomInt();
+
+ wrapper.putInt(secondInt);
+ wrapper.putInt(secondInt);
+ // rewrite firstInt at the beginning
+ wrapper.putInt(0, firstInt);
+
+ wrapper.flip();
+
+ assertEquals(firstInt, wrapper.getInt());
+ assertEquals(secondInt, wrapper.getInt());
+ }
+
+ public void testLong() throws Exception
+ {
+ long l = randomLong();
+ wrapper.putLong(l);
+
+ wrapper.flip();
+
+ assertEquals(l, wrapper.getLong());
+ }
+
public void testShort() throws Exception
{
wrapper.putShort((short) 1);
- flipBuffer();
+ wrapper.flip();
assertEquals((short)1, wrapper.getShort());
}
@@ -152,7 +198,7 @@
double d = randomDouble();
wrapper.putDouble(d);
- flipBuffer();
+ wrapper.flip();
assertEquals(d, wrapper.getDouble());
}
@@ -162,7 +208,7 @@
float f = randomFloat();
wrapper.putFloat(f);
- flipBuffer();
+ wrapper.flip();
assertEquals(f, wrapper.getFloat());
}
@@ -172,7 +218,7 @@
String str = randomString();
wrapper.putUTF(str);
- flipBuffer();
+ wrapper.flip();
assertEquals(str, wrapper.getUTF());
}
@@ -187,9 +233,19 @@
{
wrapper.putNullableString(nullableString);
- flipBuffer();
+ wrapper.flip();
return wrapper.getNullableString();
}
+
+ private SimpleString putAndGetNullableSimpleString(SimpleString nullableSimpleString) throws Exception
+ {
+ wrapper.putNullableSimpleString(nullableSimpleString);
+
+ wrapper.flip();
+
+ return wrapper.getNullableSimpleString();
+ }
+
// Inner classes -------------------------------------------------
}
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/util/ByteBufferWrapperTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/util/ByteBufferWrapperTest.java 2008-06-06 13:02:50 UTC (rev 4402)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/util/ByteBufferWrapperTest.java 2008-06-06 13:47:44 UTC (rev 4403)
@@ -25,8 +25,6 @@
// Attributes ----------------------------------------------------
- private ByteBuffer buffer;
-
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
@@ -38,15 +36,8 @@
@Override
protected MessagingBuffer createBuffer()
{
- buffer = ByteBuffer.allocate(256);
- return new ByteBufferWrapper(buffer);
+ return new ByteBufferWrapper(ByteBuffer.allocate(512));
}
-
- @Override
- protected void flipBuffer()
- {
- buffer.flip();
- }
// Package protected ---------------------------------------------
More information about the jboss-cvs-commits
mailing list