[jboss-cvs] JBoss Messaging SVN: r4385 - in trunk: src/main/org/jboss/messaging/core/remoting/impl/mina and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jun 4 12:17:40 EDT 2008
Author: jmesnil
Date: 2008-06-04 12:17:39 -0400 (Wed, 04 Jun 2008)
New Revision: 4385
Added:
trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/IoBufferWrapper.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
Removed:
trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/BufferWrapper.java
trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/BufferWrapperTest.java
Modified:
trunk/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MessagingCodec.java
trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java
trunk/src/main/org/jboss/messaging/jms/client/JBossStreamMessage.java
trunk/src/main/org/jboss/messaging/util/ByteBufferWrapper.java
trunk/tests/src/org/jboss/messaging/tests/performance/persistence/impl/StorageManagerTimingTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/message/impl/MessageTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/wireformat/PacketTypeTest.java
Log:
- renamed BufferWrapper to IoBufferWrapper
- refactored tests to factorize test for IoBufferWrapper & ByteBufferWrapper in MessagingBufferTestBase
Modified: trunk/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java 2008-06-04 15:36:38 UTC (rev 4384)
+++ trunk/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java 2008-06-04 16:17:39 UTC (rev 4385)
@@ -30,7 +30,7 @@
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.message.Message;
-import org.jboss.messaging.core.remoting.impl.mina.BufferWrapper;
+import org.jboss.messaging.core.remoting.impl.mina.IoBufferWrapper;
import org.jboss.messaging.util.MessagingBuffer;
import org.jboss.messaging.util.SimpleString;
import org.jboss.messaging.util.TypedProperties;
@@ -91,7 +91,7 @@
this.expiration = expiration;
this.timestamp = timestamp;
this.priority = priority;
- this.body = new BufferWrapper(1024);
+ this.body = new IoBufferWrapper(1024);
}
/*
@@ -151,7 +151,7 @@
//TODO - this can be optimised
byte[] bytes = new byte[len];
buffer.getBytes(bytes);
- body = new BufferWrapper(len);
+ body = new IoBufferWrapper(len);
body.putBytes(bytes);
}
Deleted: 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:36:38 UTC (rev 4384)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/BufferWrapper.java 2008-06-04 16:17:39 UTC (rev 4385)
@@ -1,346 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.impl.mina;
-
-import static org.jboss.messaging.util.DataConstants.FALSE;
-import static org.jboss.messaging.util.DataConstants.NOT_NULL;
-import static org.jboss.messaging.util.DataConstants.NULL;
-import static org.jboss.messaging.util.DataConstants.TRUE;
-
-import java.nio.charset.Charset;
-
-import org.apache.mina.common.IoBuffer;
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.util.MessagingBuffer;
-import org.jboss.messaging.util.SimpleString;
-
-/**
- *
- * A BufferWrapper
- *
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class BufferWrapper implements MessagingBuffer
-{
- // Constants -----------------------------------------------------
-
- private static final Charset utf8 = Charset.forName("UTF-8");
-
- private static final Logger log = Logger.getLogger(BufferWrapper.class);
-
- // Attributes ----------------------------------------------------
-
- private final IoBuffer buffer;
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public BufferWrapper(final int size)
- {
- buffer = IoBuffer.allocate(size);
-
- buffer.setAutoExpand(true);
- }
-
- public BufferWrapper(final IoBuffer buffer)
- {
- this.buffer = buffer;
- }
-
- // Public --------------------------------------------------------
-
- // MessagingBuffer implementation ----------------------------------------------
-
- public byte[] array()
- {
- return buffer.array();
- }
-
- public int position()
- {
- return buffer.position();
- }
-
- public void position(final int position)
- {
- buffer.position(position);
- }
-
- public int limit()
- {
- return buffer.limit();
- }
-
- public void limit(final int limit)
- {
- buffer.limit(limit);
- }
-
- public int capacity()
- {
- return buffer.capacity();
- }
-
- public void flip()
- {
- buffer.flip();
- }
-
- public MessagingBuffer slice()
- {
- return new BufferWrapper(buffer.slice());
- }
-
- public int remaining()
- {
- return buffer.remaining();
- }
-
- public void rewind()
- {
- buffer.rewind();
- }
-
- public void putByte(byte byteValue)
- {
- buffer.put(byteValue);
- }
-
- public void putBytes(final byte[] byteArray)
- {
- buffer.put(byteArray);
- }
-
- public void putBytes(final byte[] bytes, int offset, int length)
- {
- buffer.put(bytes, offset, length);
- }
-
- public void putInt(final int intValue)
- {
- buffer.putInt(intValue);
- }
-
- public void putInt(final int pos, final int intValue)
- {
- buffer.putInt(pos, intValue);
- }
-
- public void putLong(final long longValue)
- {
- buffer.putLong(longValue);
- }
-
- public void putFloat(final float floatValue)
- {
- buffer.putFloat(floatValue);
- }
-
- public void putDouble(final double d)
- {
- buffer.putDouble(d);
- }
-
- public void putShort(final short s)
- {
- buffer.putShort(s);
- }
-
- public void putChar(final char chr)
- {
- buffer.putChar(chr);
- }
-
- public byte getByte()
- {
- return buffer.get();
- }
-
- public short getUnsignedByte()
- {
- return buffer.getUnsigned();
- }
-
- public void getBytes(final byte[] b)
- {
- buffer.get(b);
- }
-
- public void getBytes(final byte[] b, final int offset, final int length)
- {
- buffer.get(b, offset, length);
- }
-
- public int getInt()
- {
- return buffer.getInt();
- }
-
- public long getLong()
- {
- return buffer.getLong();
- }
-
- public float getFloat()
- {
- return buffer.getFloat();
- }
-
- public short getShort()
- {
- return buffer.getShort();
- }
-
- public int getUnsignedShort()
- {
- return buffer.getUnsignedShort();
- }
-
- public double getDouble()
- {
- return buffer.getDouble();
- }
-
- public char getChar()
- {
- return buffer.getChar();
- }
-
- public void putBoolean(final boolean b)
- {
- if (b)
- {
- buffer.put(TRUE);
- } else
- {
- buffer.put(FALSE);
- }
- }
-
- public boolean getBoolean()
- {
- byte b = buffer.get();
- return (b == TRUE);
- }
-
- public void putString(final String nullableString)
- {
- buffer.putInt(nullableString.length());
-
- for (int i = 0; i < nullableString.length(); i++)
- {
- buffer.putChar(nullableString.charAt(i));
- }
- }
-
- public void putNullableString(final String nullableString)
- {
- if (nullableString == null)
- {
- buffer.put(NULL);
- }
- else
- {
- buffer.put(NOT_NULL);
-
- putString(nullableString);
- }
- }
-
- public String getString()
- {
- int len = buffer.getInt();
-
- char[] chars = new char[len];
-
- for (int i = 0; i < len; i++)
- {
- chars[i] = buffer.getChar();
- }
-
- return new String(chars);
- }
-
- public String getNullableString()
- {
- byte check = buffer.get();
-
- if (check == NULL)
- {
- return null;
- }
- else
- {
- return getString();
- }
- }
-
- public void putUTF(final String str) throws Exception
- {
- buffer.putPrefixedString(str, utf8.newEncoder());
- }
-
- public void putNullableSimpleString(final SimpleString string)
- {
- if (string == null)
- {
- buffer.put(NULL);
- }
- else
- {
- buffer.put(NOT_NULL);
- putSimpleString(string);
- }
- }
-
- public void putSimpleString(final SimpleString string)
- {
- byte[] data = string.getData();
-
- buffer.putInt(data.length);
- buffer.put(data);
- }
-
- public SimpleString getSimpleString()
- {
- int len = buffer.getInt();
-
- byte[] data = new byte[len];
- buffer.get(data);
-
- return new SimpleString(data);
- }
-
- public SimpleString getNullableSimpleString()
- {
- int b = buffer.get();
- if (b == NULL)
- {
- return null;
- }
- else
- {
- return getSimpleString();
- }
- }
-
- public String getUTF() throws Exception
- {
- return buffer.getPrefixedString(utf8.newDecoder());
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
\ No newline at end of file
Copied: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/IoBufferWrapper.java (from rev 4382, trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/BufferWrapper.java)
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/IoBufferWrapper.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/IoBufferWrapper.java 2008-06-04 16:17:39 UTC (rev 4385)
@@ -0,0 +1,346 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.core.remoting.impl.mina;
+
+import static org.jboss.messaging.util.DataConstants.FALSE;
+import static org.jboss.messaging.util.DataConstants.NOT_NULL;
+import static org.jboss.messaging.util.DataConstants.NULL;
+import static org.jboss.messaging.util.DataConstants.TRUE;
+
+import java.nio.charset.Charset;
+
+import org.apache.mina.common.IoBuffer;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.util.MessagingBuffer;
+import org.jboss.messaging.util.SimpleString;
+
+/**
+ *
+ * A BufferWrapper
+ *
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class IoBufferWrapper implements MessagingBuffer
+{
+ // Constants -----------------------------------------------------
+
+ private static final Charset utf8 = Charset.forName("UTF-8");
+
+ private static final Logger log = Logger.getLogger(IoBufferWrapper.class);
+
+ // Attributes ----------------------------------------------------
+
+ private final IoBuffer buffer;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ public IoBufferWrapper(final int size)
+ {
+ buffer = IoBuffer.allocate(size);
+
+ buffer.setAutoExpand(true);
+ }
+
+ public IoBufferWrapper(final IoBuffer buffer)
+ {
+ this.buffer = buffer;
+ }
+
+ // Public --------------------------------------------------------
+
+ // MessagingBuffer implementation ----------------------------------------------
+
+ public byte[] array()
+ {
+ return buffer.array();
+ }
+
+ public int position()
+ {
+ return buffer.position();
+ }
+
+ public void position(final int position)
+ {
+ buffer.position(position);
+ }
+
+ public int limit()
+ {
+ return buffer.limit();
+ }
+
+ public void limit(final int limit)
+ {
+ buffer.limit(limit);
+ }
+
+ public int capacity()
+ {
+ return buffer.capacity();
+ }
+
+ public void flip()
+ {
+ buffer.flip();
+ }
+
+ public MessagingBuffer slice()
+ {
+ return new IoBufferWrapper(buffer.slice());
+ }
+
+ public int remaining()
+ {
+ return buffer.remaining();
+ }
+
+ public void rewind()
+ {
+ buffer.rewind();
+ }
+
+ public void putByte(byte byteValue)
+ {
+ buffer.put(byteValue);
+ }
+
+ public void putBytes(final byte[] byteArray)
+ {
+ buffer.put(byteArray);
+ }
+
+ public void putBytes(final byte[] bytes, int offset, int length)
+ {
+ buffer.put(bytes, offset, length);
+ }
+
+ public void putInt(final int intValue)
+ {
+ buffer.putInt(intValue);
+ }
+
+ public void putInt(final int pos, final int intValue)
+ {
+ buffer.putInt(pos, intValue);
+ }
+
+ public void putLong(final long longValue)
+ {
+ buffer.putLong(longValue);
+ }
+
+ public void putFloat(final float floatValue)
+ {
+ buffer.putFloat(floatValue);
+ }
+
+ public void putDouble(final double d)
+ {
+ buffer.putDouble(d);
+ }
+
+ public void putShort(final short s)
+ {
+ buffer.putShort(s);
+ }
+
+ public void putChar(final char chr)
+ {
+ buffer.putChar(chr);
+ }
+
+ public byte getByte()
+ {
+ return buffer.get();
+ }
+
+ public short getUnsignedByte()
+ {
+ return buffer.getUnsigned();
+ }
+
+ public void getBytes(final byte[] b)
+ {
+ buffer.get(b);
+ }
+
+ public void getBytes(final byte[] b, final int offset, final int length)
+ {
+ buffer.get(b, offset, length);
+ }
+
+ public int getInt()
+ {
+ return buffer.getInt();
+ }
+
+ public long getLong()
+ {
+ return buffer.getLong();
+ }
+
+ public float getFloat()
+ {
+ return buffer.getFloat();
+ }
+
+ public short getShort()
+ {
+ return buffer.getShort();
+ }
+
+ public int getUnsignedShort()
+ {
+ return buffer.getUnsignedShort();
+ }
+
+ public double getDouble()
+ {
+ return buffer.getDouble();
+ }
+
+ public char getChar()
+ {
+ return buffer.getChar();
+ }
+
+ public void putBoolean(final boolean b)
+ {
+ if (b)
+ {
+ buffer.put(TRUE);
+ } else
+ {
+ buffer.put(FALSE);
+ }
+ }
+
+ public boolean getBoolean()
+ {
+ byte b = buffer.get();
+ return (b == TRUE);
+ }
+
+ public void putString(final String nullableString)
+ {
+ buffer.putInt(nullableString.length());
+
+ for (int i = 0; i < nullableString.length(); i++)
+ {
+ buffer.putChar(nullableString.charAt(i));
+ }
+ }
+
+ public void putNullableString(final String nullableString)
+ {
+ if (nullableString == null)
+ {
+ buffer.put(NULL);
+ }
+ else
+ {
+ buffer.put(NOT_NULL);
+
+ putString(nullableString);
+ }
+ }
+
+ public String getString()
+ {
+ int len = buffer.getInt();
+
+ char[] chars = new char[len];
+
+ for (int i = 0; i < len; i++)
+ {
+ chars[i] = buffer.getChar();
+ }
+
+ return new String(chars);
+ }
+
+ public String getNullableString()
+ {
+ byte check = buffer.get();
+
+ if (check == NULL)
+ {
+ return null;
+ }
+ else
+ {
+ return getString();
+ }
+ }
+
+ public void putUTF(final String str) throws Exception
+ {
+ buffer.putPrefixedString(str, utf8.newEncoder());
+ }
+
+ public void putNullableSimpleString(final SimpleString string)
+ {
+ if (string == null)
+ {
+ buffer.put(NULL);
+ }
+ else
+ {
+ buffer.put(NOT_NULL);
+ putSimpleString(string);
+ }
+ }
+
+ public void putSimpleString(final SimpleString string)
+ {
+ byte[] data = string.getData();
+
+ buffer.putInt(data.length);
+ buffer.put(data);
+ }
+
+ public SimpleString getSimpleString()
+ {
+ int len = buffer.getInt();
+
+ byte[] data = new byte[len];
+ buffer.get(data);
+
+ return new SimpleString(data);
+ }
+
+ public SimpleString getNullableSimpleString()
+ {
+ int b = buffer.get();
+ if (b == NULL)
+ {
+ return null;
+ }
+ else
+ {
+ return getSimpleString();
+ }
+ }
+
+ public String getUTF() throws Exception
+ {
+ return buffer.getPrefixedString(utf8.newDecoder());
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MessagingCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MessagingCodec.java 2008-06-04 15:36:38 UTC (rev 4384)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MessagingCodec.java 2008-06-04 16:17:39 UTC (rev 4385)
@@ -110,7 +110,7 @@
iobuf.setAutoExpand(true);
- MessagingBuffer buffer = new BufferWrapper(iobuf);
+ MessagingBuffer buffer = new IoBufferWrapper(iobuf);
packet.encode(buffer);
@@ -425,7 +425,7 @@
}
}
- MessagingBuffer buff = new BufferWrapper(in.slice());
+ MessagingBuffer buff = new IoBufferWrapper(in.slice());
packet.decode(buff);
Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java 2008-06-04 15:36:38 UTC (rev 4384)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java 2008-06-04 16:17:39 UTC (rev 4385)
@@ -31,7 +31,7 @@
import org.jboss.messaging.core.client.ClientMessage;
import org.jboss.messaging.core.client.ClientSession;
import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.remoting.impl.mina.BufferWrapper;
+import org.jboss.messaging.core.remoting.impl.mina.IoBufferWrapper;
/**
* This class implements javax.jms.BytesMessage.
@@ -406,7 +406,7 @@
{
super.clearBody();
- body = new BufferWrapper(1024);
+ body = new IoBufferWrapper(1024);
}
public long getBodyLength() throws JMSException
Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossStreamMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossStreamMessage.java 2008-06-04 15:36:38 UTC (rev 4384)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossStreamMessage.java 2008-06-04 16:17:39 UTC (rev 4385)
@@ -31,7 +31,7 @@
import org.jboss.messaging.core.client.ClientMessage;
import org.jboss.messaging.core.client.ClientSession;
import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.remoting.impl.mina.BufferWrapper;
+import org.jboss.messaging.core.remoting.impl.mina.IoBufferWrapper;
import org.jboss.messaging.util.DataConstants;
/**
@@ -561,7 +561,7 @@
{
super.clearBody();
- body = new BufferWrapper(1024);
+ body = new IoBufferWrapper(1024);
}
public void doBeforeSend() throws Exception
Modified: trunk/src/main/org/jboss/messaging/util/ByteBufferWrapper.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/ByteBufferWrapper.java 2008-06-04 15:36:38 UTC (rev 4384)
+++ trunk/src/main/org/jboss/messaging/util/ByteBufferWrapper.java 2008-06-04 16:17:39 UTC (rev 4385)
@@ -164,7 +164,7 @@
//TODO This is quite inefficient - can be improved using a method similar to what MINA IOBuffer does
//(putPrefixedString)
ByteBuffer bb = utf8.encode(str);
- buffer.putInt(bb.capacity());
+ buffer.putInt(bb.limit() - bb.position());
buffer.put(bb);
}
Deleted: 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:36:38 UTC (rev 4384)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/BufferWrapperTest.java 2008-06-04 16:17:39 UTC (rev 4385)
@@ -1,196 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-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>.
- *
- * @version <tt>$Revision$</tt>
- */
-public class BufferWrapperTest extends TestCase
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- private BufferWrapper wrapper;
- private IoBuffer buffer;
-
- @Override
- protected void setUp() throws Exception
- {
- buffer = IoBuffer.allocate(256);
- buffer.setAutoExpand(true);
- wrapper = new BufferWrapper(buffer);
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- wrapper = null;
- buffer = null;
-
- }
-
- public void testNullString() throws Exception
- {
- assertNull(putAndGetNullableString(null));
- }
-
- public void testEmptyString() throws Exception
- {
- String result = putAndGetNullableString("");
-
- assertNotNull(result);
- assertEquals("", result);
- }
-
- public void testNonEmptyString() throws Exception
- {
- String junk = randomUUID().toString();
-
- String result = putAndGetNullableString(junk);
-
- assertNotNull(result);
- 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);
-
- buffer.flip();
-
- assertTrue(wrapper.getBoolean());
- }
-
- public void testPutFalseBoolean() throws Exception
- {
- wrapper.putBoolean(false);
-
- buffer.flip();
-
- 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 ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- private String putAndGetNullableString(String nullableString) throws Exception
- {
- wrapper.putNullableString(nullableString);
-
- buffer.flip();
-
- return wrapper.getNullableString();
- }
- // Inner classes -------------------------------------------------
-}
Added: 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 (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/IoBufferWrapperTest.java 2008-06-04 16:17:39 UTC (rev 4385)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.tests.integration.core.remoting.mina;
+
+import org.apache.mina.common.IoBuffer;
+import org.jboss.messaging.core.remoting.impl.mina.IoBufferWrapper;
+import org.jboss.messaging.util.MessagingBuffer;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ */
+public class IoBufferWrapperTest extends MessagingBufferTestBase
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private IoBuffer buffer;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ // BufferWrapperBase overrides -----------------------------------
+
+ @Override
+ protected MessagingBuffer createBuffer()
+ {
+ buffer = IoBuffer.allocate(512);
+ buffer.setAutoExpand(true);
+ return new IoBufferWrapper(buffer);
+ }
+
+ @Override
+ protected void flipBuffer()
+ {
+ buffer.flip();
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
Added: 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 (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/MessagingBufferTestBase.java 2008-06-04 16:17:39 UTC (rev 4385)
@@ -0,0 +1,195 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+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.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;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
+ *
+ * @version <tt>$Revision$</tt>
+ */
+public abstract class MessagingBufferTestBase extends TestCase
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ private MessagingBuffer wrapper;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ wrapper = createBuffer();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ wrapper = null;
+ }
+
+ protected abstract MessagingBuffer createBuffer();
+ protected abstract void flipBuffer();
+
+ public void testNullString() throws Exception
+ {
+ assertNull(putAndGetNullableString(null));
+ }
+
+ public void testEmptyString() throws Exception
+ {
+ String result = putAndGetNullableString("");
+
+ assertNotNull(result);
+ assertEquals("", result);
+ }
+
+ public void testNonEmptyString() throws Exception
+ {
+ String junk = randomUUID().toString();
+
+ String result = putAndGetNullableString(junk);
+
+ assertNotNull(result);
+ assertEquals(junk, result);
+ }
+
+ public void testByte() throws Exception
+ {
+ byte b = randomByte();
+ wrapper.putByte(b);
+
+ flipBuffer();
+
+ assertEquals(b, wrapper.getByte());
+ }
+
+ public void testBytes() throws Exception
+ {
+ byte[] bytes = randomBytes();
+ wrapper.putBytes(bytes);
+
+ flipBuffer();
+
+ byte[] b = new byte[bytes.length];
+ wrapper.getBytes(b);
+ assertEqualsByteArrays(bytes, b);
+ }
+
+ public void testPutTrueBoolean() throws Exception
+ {
+ wrapper.putBoolean(true);
+
+ flipBuffer();
+
+ assertTrue(wrapper.getBoolean());
+ }
+
+ public void testPutFalseBoolean() throws Exception
+ {
+ wrapper.putBoolean(false);
+
+ flipBuffer();
+
+ assertFalse(wrapper.getBoolean());
+ }
+
+ public void testChar() throws Exception
+ {
+ wrapper.putChar('a');
+
+ flipBuffer();
+
+ assertEquals('a', wrapper.getChar());
+ }
+
+ public void testInt() throws Exception
+ {
+ int i = randomInt();
+ wrapper.putInt(i);
+
+ flipBuffer();
+
+ assertEquals(i, wrapper.getInt());
+ }
+
+ public void testShort() throws Exception
+ {
+ wrapper.putShort((short) 1);
+
+ flipBuffer();
+
+ assertEquals((short)1, wrapper.getShort());
+ }
+
+ public void testDouble() throws Exception
+ {
+ double d = randomDouble();
+ wrapper.putDouble(d);
+
+ flipBuffer();
+
+ assertEquals(d, wrapper.getDouble());
+ }
+
+ public void testFloat() throws Exception
+ {
+ float f = randomFloat();
+ wrapper.putFloat(f);
+
+ flipBuffer();
+
+ assertEquals(f, wrapper.getFloat());
+ }
+
+ public void testUTF() throws Exception
+ {
+ String str = randomString();
+ wrapper.putUTF(str);
+
+ flipBuffer();
+
+ assertEquals(str, wrapper.getUTF());
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ private String putAndGetNullableString(String nullableString) throws Exception
+ {
+ wrapper.putNullableString(nullableString);
+
+ flipBuffer();
+
+ return wrapper.getNullableString();
+ }
+ // Inner classes -------------------------------------------------
+}
Modified: trunk/tests/src/org/jboss/messaging/tests/performance/persistence/impl/StorageManagerTimingTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/performance/persistence/impl/StorageManagerTimingTest.java 2008-06-04 15:36:38 UTC (rev 4384)
+++ trunk/tests/src/org/jboss/messaging/tests/performance/persistence/impl/StorageManagerTimingTest.java 2008-06-04 16:17:39 UTC (rev 4385)
@@ -31,7 +31,7 @@
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.message.impl.MessageImpl;
import org.jboss.messaging.core.persistence.impl.journal.JournalStorageManager;
-import org.jboss.messaging.core.remoting.impl.mina.BufferWrapper;
+import org.jboss.messaging.core.remoting.impl.mina.IoBufferWrapper;
import org.jboss.messaging.core.server.JournalType;
import org.jboss.messaging.core.server.Queue;
import org.jboss.messaging.core.server.impl.ServerMessageImpl;
@@ -142,7 +142,7 @@
}
- final BufferWrapper buffer = new BufferWrapper(1024);
+ final IoBufferWrapper buffer = new IoBufferWrapper(1024);
buffer.putBytes(bytes);
final AtomicLong transactionGenerator = new AtomicLong(1);
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/message/impl/MessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/message/impl/MessageTest.java 2008-06-04 15:36:38 UTC (rev 4384)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/message/impl/MessageTest.java 2008-06-04 16:17:39 UTC (rev 4385)
@@ -27,7 +27,7 @@
import org.jboss.messaging.core.client.impl.ClientMessageImpl;
import org.jboss.messaging.core.journal.EncodingSupport;
import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.remoting.impl.mina.BufferWrapper;
+import org.jboss.messaging.core.remoting.impl.mina.IoBufferWrapper;
import org.jboss.messaging.core.server.MessageReference;
import org.jboss.messaging.core.server.Queue;
import org.jboss.messaging.core.server.QueueFactory;
@@ -279,7 +279,7 @@
public void testEncodingMessage() throws Exception
{
byte[] bytes = new byte[]{(byte)1, (byte)2, (byte)3};
- final BufferWrapper bufferBody = new BufferWrapper(bytes.length);
+ final IoBufferWrapper bufferBody = new IoBufferWrapper(bytes.length);
bufferBody.putBytes(bytes);
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/wireformat/PacketTypeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/wireformat/PacketTypeTest.java 2008-06-04 15:36:38 UTC (rev 4384)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/wireformat/PacketTypeTest.java 2008-06-04 16:17:39 UTC (rev 4385)
@@ -78,7 +78,7 @@
import org.jboss.messaging.core.exception.MessagingException;
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.remoting.Packet;
-import org.jboss.messaging.core.remoting.impl.mina.BufferWrapper;
+import org.jboss.messaging.core.remoting.impl.mina.IoBufferWrapper;
import org.jboss.messaging.core.remoting.impl.mina.MessagingCodec;
import org.jboss.messaging.core.remoting.impl.wireformat.ConnectionCreateSessionMessage;
import org.jboss.messaging.core.remoting.impl.wireformat.ConnectionCreateSessionResponseMessage;
@@ -148,7 +148,7 @@
private static MessagingBuffer encode(int length, Object... args)
throws Exception
{
- BufferWrapper buffer = new BufferWrapper(length);
+ IoBufferWrapper buffer = new IoBufferWrapper(length);
for (Object arg : args)
{
if (arg instanceof Byte)
@@ -262,7 +262,7 @@
private static MessagingBuffer encode(final Packet packet) throws Exception
{
- MessagingBuffer buffer = new BufferWrapper(512);
+ MessagingBuffer buffer = new IoBufferWrapper(512);
packet.encode(buffer);
assertNotNull(buffer);
Added: trunk/tests/src/org/jboss/messaging/tests/unit/core/util/ByteBufferWrapperTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/util/ByteBufferWrapperTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/util/ByteBufferWrapperTest.java 2008-06-04 16:17:39 UTC (rev 4385)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.tests.unit.core.util;
+
+import java.nio.ByteBuffer;
+
+import org.jboss.messaging.tests.integration.core.remoting.mina.MessagingBufferTestBase;
+import org.jboss.messaging.util.ByteBufferWrapper;
+import org.jboss.messaging.util.MessagingBuffer;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ */
+public class ByteBufferWrapperTest extends MessagingBufferTestBase
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private ByteBuffer buffer;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ // MessagingBufferTestBase overrides -----------------------------
+
+ @Override
+ protected MessagingBuffer createBuffer()
+ {
+ buffer = ByteBuffer.allocate(256);
+ return new ByteBufferWrapper(buffer);
+ }
+
+ @Override
+ protected void flipBuffer()
+ {
+ buffer.flip();
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+}
More information about the jboss-cvs-commits
mailing list