[jboss-cvs] JBoss Messaging SVN: r4382 - in trunk: src/main/org/jboss/messaging/util and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jun 4 11:26:53 EDT 2008
Author: jmesnil
Date: 2008-06-04 11:26:53 -0400 (Wed, 04 Jun 2008)
New Revision: 4382
Modified:
trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/BufferWrapper.java
trunk/src/main/org/jboss/messaging/util/ByteBufferWrapper.java
trunk/src/main/org/jboss/messaging/util/MessagingBuffer.java
trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/BufferWrapperTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/wireformat/CodecAssert.java
trunk/tests/src/org/jboss/messaging/tests/util/RandomUtil.java
Log:
cleaned up MessagingBuffer interface & implementation + unit tests
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/BufferWrapper.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/BufferWrapper.java 2008-06-04 15:16:01 UTC (rev 4381)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/BufferWrapper.java 2008-06-04 15:26:53 UTC (rev 4382)
@@ -183,11 +183,6 @@
return buffer.getInt();
}
- public long getUnsignedInt()
- {
- return buffer.getUnsignedInt();
- }
-
public long getLong()
{
return buffer.getLong();
@@ -340,12 +335,7 @@
{
return buffer.getPrefixedString(utf8.newDecoder());
}
-
- public Object getUnderlyingBuffer()
- {
- return buffer;
- }
-
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Modified: trunk/src/main/org/jboss/messaging/util/ByteBufferWrapper.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/ByteBufferWrapper.java 2008-06-04 15:16:01 UTC (rev 4381)
+++ trunk/src/main/org/jboss/messaging/util/ByteBufferWrapper.java 2008-06-04 15:26:53 UTC (rev 4382)
@@ -114,11 +114,6 @@
return buffer.getInt();
}
- public long getUnsignedInt()
- {
- return buffer.getInt() & 0xFFFFFFFFL;
- }
-
public long getLong()
{
return buffer.getLong();
@@ -331,10 +326,4 @@
{
return buffer.remaining();
}
-
- public Object getUnderlyingBuffer()
- {
- return buffer;
- }
-
}
Modified: trunk/src/main/org/jboss/messaging/util/MessagingBuffer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/MessagingBuffer.java 2008-06-04 15:16:01 UTC (rev 4381)
+++ trunk/src/main/org/jboss/messaging/util/MessagingBuffer.java 2008-06-04 15:26:53 UTC (rev 4382)
@@ -57,8 +57,6 @@
int getInt();
- long getUnsignedInt();
-
long getLong();
short getShort();
@@ -101,8 +99,5 @@
void rewind();
- MessagingBuffer slice();
-
- Object getUnderlyingBuffer();
-
+ MessagingBuffer slice();
}
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/BufferWrapperTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/BufferWrapperTest.java 2008-06-04 15:16:01 UTC (rev 4381)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/BufferWrapperTest.java 2008-06-04 15:26:53 UTC (rev 4382)
@@ -7,10 +7,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.randomString;
import junit.framework.TestCase;
import org.apache.mina.common.IoBuffer;
import org.jboss.messaging.core.remoting.impl.mina.BufferWrapper;
+import org.jboss.messaging.tests.unit.core.remoting.impl.wireformat.CodecAssert;
+import org.jboss.messaging.tests.util.RandomUtil;
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
@@ -71,6 +80,28 @@
assertEquals(junk, result);
}
+ public void testByte() throws Exception
+ {
+ byte b = randomByte();
+ wrapper.putByte(b);
+
+ buffer.flip();
+
+ assertEquals(b, wrapper.getByte());
+ }
+
+ public void testBytes() throws Exception
+ {
+ byte[] bytes = randomBytes();
+ wrapper.putBytes(bytes);
+
+ buffer.flip();
+
+ byte[] b = new byte[bytes.length];
+ wrapper.getBytes(b);
+ assertEqualsByteArrays(bytes, b);
+ }
+
public void testPutTrueBoolean() throws Exception
{
wrapper.putBoolean(true);
@@ -88,6 +119,64 @@
assertFalse(wrapper.getBoolean());
}
+
+ public void testChar() throws Exception
+ {
+ wrapper.putChar('a');
+
+ buffer.flip();
+
+ assertEquals('a', wrapper.getChar());
+ }
+
+ public void testInt() throws Exception
+ {
+ int i = randomInt();
+ wrapper.putInt(i);
+
+ buffer.flip();
+
+ assertEquals(i, wrapper.getInt());
+ }
+
+ public void testShort() throws Exception
+ {
+ wrapper.putShort((short) 1);
+
+ buffer.flip();
+
+ assertEquals((short)1, wrapper.getShort());
+ }
+
+ public void testDouble() throws Exception
+ {
+ double d = randomDouble();
+ wrapper.putDouble(d);
+
+ buffer.flip();
+
+ assertEquals(d, wrapper.getDouble());
+ }
+
+ public void testFloat() throws Exception
+ {
+ float f = randomFloat();
+ wrapper.putFloat(f);
+
+ buffer.flip();
+
+ assertEquals(f, wrapper.getFloat());
+ }
+
+ public void testUTF() throws Exception
+ {
+ String str = randomString();
+ wrapper.putUTF(str);
+
+ buffer.flip();
+
+ assertEquals(str, wrapper.getUTF());
+ }
// Package protected ---------------------------------------------
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/wireformat/CodecAssert.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/wireformat/CodecAssert.java 2008-06-04 15:16:01 UTC (rev 4381)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/wireformat/CodecAssert.java 2008-06-04 15:26:53 UTC (rev 4382)
@@ -44,7 +44,7 @@
}
}
- static void assertEqualsByteArrays(byte[] expected, byte[] actual)
+ public static void assertEqualsByteArrays(byte[] expected, byte[] actual)
{
assertEquals(expected.length, actual.length);
for (int i = 0; i < expected.length; i++)
Modified: trunk/tests/src/org/jboss/messaging/tests/util/RandomUtil.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/util/RandomUtil.java 2008-06-04 15:16:01 UTC (rev 4381)
+++ trunk/tests/src/org/jboss/messaging/tests/util/RandomUtil.java 2008-06-04 15:26:53 UTC (rev 4382)
@@ -60,7 +60,16 @@
return randomString().getBytes();
}
+ public static double randomDouble()
+ {
+ return random.nextDouble();
+ }
+ public static float randomFloat()
+ {
+ return random.nextFloat();
+ }
+
public static Xid randomXid()
{
return new XidImpl(randomBytes(), randomInt(), randomBytes());
More information about the jboss-cvs-commits
mailing list