[jboss-cvs] JBoss Messaging SVN: r3190 - in trunk: src/main/org/jboss/jms/message and 5 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Oct 15 09:03:24 EDT 2007
Author: timfox
Date: 2007-10-15 09:03:24 -0400 (Mon, 15 Oct 2007)
New Revision: 3190
Modified:
trunk/src/main/org/jboss/jms/client/container/ClientConsumer.java
trunk/src/main/org/jboss/jms/message/BytesMessageProxy.java
trunk/src/main/org/jboss/jms/message/JBossBytesMessage.java
trunk/src/main/org/jboss/jms/message/JBossMapMessage.java
trunk/src/main/org/jboss/jms/message/JBossMessage.java
trunk/src/main/org/jboss/jms/message/JBossObjectMessage.java
trunk/src/main/org/jboss/jms/message/JBossStreamMessage.java
trunk/src/main/org/jboss/jms/message/JBossTextMessage.java
trunk/src/main/org/jboss/jms/message/MessageProxy.java
trunk/src/main/org/jboss/messaging/core/impl/JDBCPersistenceManager.java
trunk/src/main/org/jboss/messaging/core/impl/message/MessageFactory.java
trunk/src/main/org/jboss/messaging/core/impl/message/MessageSupport.java
trunk/tests/src/org/jboss/test/messaging/jms/MessageProxyTest.java
trunk/tests/src/org/jboss/test/messaging/jms/PersistenceTest.java
trunk/tests/src/org/jboss/test/messaging/jms/QueueTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/BytesMessageTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/MessageBodyTest.java
trunk/tests/src/org/jboss/test/messaging/jms/persistence/MessagePersistenceManagerTest.java
Log:
http://jira.jboss.com/jira/browse/JBMESSAGING-1079 http://jira.jboss.com/jira/browse/JBMESSAGING-1101
Modified: trunk/src/main/org/jboss/jms/client/container/ClientConsumer.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/container/ClientConsumer.java 2007-10-12 14:31:28 UTC (rev 3189)
+++ trunk/src/main/org/jboss/jms/client/container/ClientConsumer.java 2007-10-15 13:03:24 UTC (rev 3190)
@@ -640,11 +640,8 @@
proxy.setSessionDelegate(sessionDelegate, isConnectionConsumer);
+ proxy.getMessage().doBeforeReceive();
- // In some redelivery scenarios, a ByteMessage or StreamMessages needs to be reset
- // so, this call is also being made here (not just when the message is is sent)
- proxy.getMessage().doBeforeSend();
-
//Add it to the buffer
buffer.addLast(proxy, proxy.getJMSPriority());
Modified: trunk/src/main/org/jboss/jms/message/BytesMessageProxy.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/BytesMessageProxy.java 2007-10-12 14:31:28 UTC (rev 3189)
+++ trunk/src/main/org/jboss/jms/message/BytesMessageProxy.java 2007-10-15 13:03:24 UTC (rev 3190)
@@ -54,7 +54,6 @@
{
throw new MessageNotReadableException("The message body is writeonly");
}
- ((JBossBytesMessage)message).checkRead();
return ((BytesMessage)message).getBodyLength();
}
@@ -64,7 +63,6 @@
{
throw new MessageNotReadableException("The message body is writeonly");
}
- ((JBossBytesMessage)message).checkRead();
return ((BytesMessage)message).readBoolean();
}
@@ -74,7 +72,6 @@
{
throw new MessageNotReadableException("The message body is writeonly");
}
- ((JBossBytesMessage)message).checkRead();
return ((BytesMessage)message).readByte();
}
@@ -84,7 +81,6 @@
{
throw new MessageNotReadableException("The message body is writeonly");
}
- ((JBossBytesMessage)message).checkRead();
return ((BytesMessage)message).readUnsignedByte();
}
@@ -94,7 +90,6 @@
{
throw new MessageNotReadableException("The message body is writeonly");
}
- ((JBossBytesMessage)message).checkRead();
return ((BytesMessage)message).readShort();
}
@@ -104,7 +99,6 @@
{
throw new MessageNotReadableException("The message body is writeonly");
}
- ((JBossBytesMessage)message).checkRead();
return ((BytesMessage)message).readUnsignedShort();
}
@@ -114,7 +108,6 @@
{
throw new MessageNotReadableException("The message body is writeonly");
}
- ((JBossBytesMessage)message).checkRead();
return ((BytesMessage)message).readChar();
}
@@ -124,7 +117,6 @@
{
throw new MessageNotReadableException("The message body is writeonly");
}
- ((JBossBytesMessage)message).checkRead();
return ((BytesMessage)message).readInt();
}
@@ -134,7 +126,6 @@
{
throw new MessageNotReadableException("The message body is writeonly");
}
- ((JBossBytesMessage)message).checkRead();
return ((BytesMessage)message).readLong();
}
@@ -144,7 +135,6 @@
{
throw new MessageNotReadableException("The message body is writeonly");
}
- ((JBossBytesMessage)message).checkRead();
return ((BytesMessage)message).readFloat();
}
@@ -154,7 +144,6 @@
{
throw new MessageNotReadableException("The message body is writeonly");
}
- ((JBossBytesMessage)message).checkRead();
return ((BytesMessage)message).readDouble();
}
@@ -164,7 +153,6 @@
{
throw new MessageNotReadableException("The message body is writeonly");
}
- ((JBossBytesMessage)message).checkRead();
return ((BytesMessage)message).readUTF();
}
@@ -174,7 +162,6 @@
{
throw new MessageNotReadableException("The message body is writeonly");
}
- ((JBossBytesMessage)message).checkRead();
return ((BytesMessage)message).readBytes(value);
}
@@ -184,7 +171,6 @@
{
throw new MessageNotReadableException("The message body is writeonly");
}
- ((JBossBytesMessage)message).checkRead();
return ((BytesMessage)message).readBytes(value, length);
}
Modified: trunk/src/main/org/jboss/jms/message/JBossBytesMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossBytesMessage.java 2007-10-12 14:31:28 UTC (rev 3189)
+++ trunk/src/main/org/jboss/jms/message/JBossBytesMessage.java 2007-10-15 13:03:24 UTC (rev 3190)
@@ -84,8 +84,6 @@
public JBossBytesMessage(long messageID)
{
super(messageID);
- baos = new ByteArrayOutputStream();
- dos = new DataOutputStream(baos);
}
/*
@@ -100,9 +98,6 @@
byte[] payloadAsByteArray)
{
super(messageID, reliable, expiration, timestamp, priority, coreHeaders, payloadAsByteArray);
-
- baos = new ByteArrayOutputStream();
- dos = new DataOutputStream(baos);
}
/**
@@ -115,8 +110,7 @@
{
super(other);
- if (trace) { log.trace("Creating new JBossBytesMessage from other JBossBytesMessage"); }
-
+ if (trace) { log.trace("Creating new JBossBytesMessage from other JBossBytesMessage"); }
}
public JBossBytesMessage(BytesMessage foreign, long id) throws JMSException
@@ -142,11 +136,6 @@
public void read(DataInputStream in) throws Exception
{
super.read(in);
-
- // transfer the value read into payloadAsBytes by superclass to payload, since this is how
- // BytesMessage instances keep it
- copyPayloadAsByteArrayToPayload();
- clearPayloadAsByteArray();
}
// BytesMessage implementation -----------------------------------
@@ -366,6 +355,7 @@
public void writeBoolean(boolean value) throws JMSException
{
+ checkWrite();
try
{
dos.writeBoolean(value);
@@ -378,6 +368,7 @@
public void writeByte(byte value) throws JMSException
{
+ checkWrite();
try
{
dos.writeByte(value);
@@ -390,6 +381,7 @@
public void writeShort(short value) throws JMSException
{
+ checkWrite();
try
{
dos.writeShort(value);
@@ -402,6 +394,7 @@
public void writeChar(char value) throws JMSException
{
+ checkWrite();
try
{
dos.writeChar(value);
@@ -414,6 +407,7 @@
public void writeInt(int value) throws JMSException
{
+ checkWrite();
try
{
dos.writeInt(value);
@@ -426,6 +420,7 @@
public void writeLong(long value) throws JMSException
{
+ checkWrite();
try
{
dos.writeLong(value);
@@ -438,6 +433,7 @@
public void writeFloat(float value) throws JMSException
{
+ checkWrite();
try
{
dos.writeFloat(value);
@@ -450,6 +446,7 @@
public void writeDouble(double value) throws JMSException
{
+ checkWrite();
try
{
dos.writeDouble(value);
@@ -462,6 +459,7 @@
public void writeUTF(String value) throws JMSException
{
+ checkWrite();
try
{
dos.writeUTF((String)value);
@@ -474,6 +472,7 @@
public void writeBytes(byte[] value) throws JMSException
{
+ checkWrite();
try
{
dos.write(value, 0, value.length);
@@ -486,6 +485,7 @@
public void writeBytes(byte[] value, int offset, int length) throws JMSException
{
+ checkWrite();
try
{
dos.write(value, offset, length);
@@ -498,6 +498,7 @@
public void writeObject(Object value) throws JMSException
{
+ checkWrite();
try
{
if (value == null)
@@ -553,19 +554,16 @@
public void reset() throws JMSException
{
- if (trace) log.trace("reset()");
try
{
if (baos != null)
{
- if (trace) { log.trace("Flushing ostream to array"); }
-
dos.flush();
- this.setPayload(baos.toByteArray());
- this.clearPayloadAsByteArray();
+
+ payload = baos.toByteArray();
+
+ payloadAsByteArray = (byte[])payload;
- if (trace) { log.trace("Array is now: " + this.getPayload()); }
-
baos.close();
}
baos = null;
@@ -582,14 +580,15 @@
}
// MessageSupport overrides --------------------------------------
-
- /**
- * A JBossBytesMessage avoid double serialization by holding on its original payload, which is
- * a byte[] to start with.
- */
+
+ public Object getPayload()
+ {
+ return payload;
+ }
+
public byte[] getPayloadAsByteArray()
{
- return (byte[])getPayload();
+ return payloadAsByteArray;
}
// JBossMessage overrides ----------------------------------------
@@ -598,6 +597,13 @@
{
reset();
}
+
+ public void doBeforeReceive() throws JMSException
+ {
+ //We need to reset before receive too http://jira.jboss.com/jira/browse/JBMESSAGING-1079
+
+ reset();
+ }
public void clearBody() throws JMSException
{
@@ -609,10 +615,6 @@
}
else
{
- // REVIEW: istream is only initialised on a read.
- // It looks like it is possible to acknowledge
- // a message without reading it? Guard against
- // an NPE in this case.
if (bais != null)
{
bais.close();
@@ -626,17 +628,16 @@
baos = new ByteArrayOutputStream();
dos = new DataOutputStream(baos);
- this.setPayload(null);
+ payload = null;
+ payloadAsByteArray = null;
bais = null;
dis = null;
-
- super.clearBody();
}
public long getBodyLength() throws JMSException
{
checkRead();
- return ((byte[])this.getPayload()).length;
+ return payloadAsByteArray.length;
}
// Public --------------------------------------------------------
@@ -658,12 +659,15 @@
byte[] otherBytes = (byte[])payload;
if (otherBytes == null)
{
- this.setPayload(null);
+ payload = null;
}
else
{
- this.setPayload(new byte[otherBytes.length]);
- System.arraycopy(otherBytes, 0, this.getPayload(), 0, otherBytes.length);
+ payload = new byte[otherBytes.length];
+
+ System.arraycopy(otherBytes, 0, payload, 0, otherBytes.length);
+
+ payloadAsByteArray = (byte[])payload;
}
}
@@ -673,22 +677,25 @@
// Private -------------------------------------------------------
- /**
- * Check the message is readable
- *
- * @throws JMSException when not readable
- */
- void checkRead() throws JMSException
+ void checkRead()
{
// We have just received/reset() the message, and the client is trying to
// read it
- if (bais == null || dis == null)
+ if (bais == null)
{
- if (trace) { log.trace("internalArray:" + this.getPayload()); }
- bais = new ByteArrayInputStream((byte[])this.getPayload());
+ bais = new ByteArrayInputStream(payloadAsByteArray);
dis = new DataInputStream(bais);
}
}
+
+ void checkWrite()
+ {
+ if (baos == null)
+ {
+ baos = new ByteArrayOutputStream();
+ dos = new DataOutputStream(baos);
+ }
+ }
// Inner classes -------------------------------------------------
}
Modified: trunk/src/main/org/jboss/jms/message/JBossMapMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossMapMessage.java 2007-10-12 14:31:28 UTC (rev 3189)
+++ trunk/src/main/org/jboss/jms/message/JBossMapMessage.java 2007-10-15 13:03:24 UTC (rev 3190)
@@ -21,8 +21,6 @@
*/
package org.jboss.jms.message;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
@@ -32,7 +30,7 @@
import javax.jms.MapMessage;
import javax.jms.MessageFormatException;
-import org.jboss.messaging.util.StreamUtils;
+import org.jboss.logging.Logger;
import org.jboss.util.Primitives;
/**
@@ -74,8 +72,7 @@
public JBossMapMessage(long messageID)
{
super(messageID);
- this.setPayload(new HashMap());
- clearPayloadAsByteArray();
+ payload = new HashMap();
}
/*
@@ -101,8 +98,7 @@
public JBossMapMessage(MapMessage foreign, long id) throws JMSException
{
super(foreign, id);
- this.setPayload(new HashMap());
- clearPayloadAsByteArray();
+ payload = new HashMap();
Enumeration names = foreign.getMapNames();
while (names.hasMoreElements())
{
@@ -118,15 +114,12 @@
{
return JBossMapMessage.TYPE;
}
-
-
- public void copyPayload(Object payload) throws JMSException
- {
- this.setPayload(new HashMap((Map)payload));
- clearPayloadAsByteArray();
+
+ public void copyPayload(Object otherPayload) throws JMSException
+ {
+ payload = new HashMap((Map)otherPayload);
}
-
// MapMessage implementation -------------------------------------
public void setBoolean(String name, boolean value) throws JMSException
@@ -454,16 +447,12 @@
public Enumeration getMapNames() throws JMSException
{
-
return Collections.enumeration(new HashMap(((Map)getPayload())).keySet());
-
}
public boolean itemExists(String name) throws JMSException
{
-
return ((Map)getPayload()).containsKey(name);
-
}
// JBossMessage overrides ----------------------------------------
@@ -471,8 +460,8 @@
public void clearBody() throws JMSException
{
super.clearBody();
- setPayload(new HashMap());
- clearPayloadAsByteArray();
+ payload = new HashMap();
+ payloadAsByteArray = null;
}
public JBossMessage doCopy()
@@ -484,17 +473,6 @@
// Protected -----------------------------------------------------
- protected void writePayload(DataOutputStream out, Object thePayload) throws Exception
- {
- StreamUtils.writeMap(out, ((Map)getPayload()), true);
- }
-
- protected Object readPayload(DataInputStream in, int length)
- throws Exception
- {
- return StreamUtils.readMap(in, true);
- }
-
// Private -------------------------------------------------------
/**
Modified: trunk/src/main/org/jboss/jms/message/JBossMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossMessage.java 2007-10-12 14:31:28 UTC (rev 3189)
+++ trunk/src/main/org/jboss/jms/message/JBossMessage.java 2007-10-15 13:03:24 UTC (rev 3190)
@@ -581,9 +581,9 @@
public void clearBody() throws JMSException
{
- this.setPayload(null);
-
- clearPayloadAsByteArray();
+ payload = null;
+
+ payloadAsByteArray = null;
}
public boolean propertyExists(String name) throws JMSException
@@ -962,6 +962,10 @@
public void doBeforeSend() throws JMSException
{
}
+
+ public void doBeforeReceive() throws JMSException
+ {
+ }
public byte getType()
{
@@ -1102,7 +1106,7 @@
throw new JMSException("Can only set JMSXGroupId, JMSXGroupSeq, JMSXDeliveryCount");
}
}
-
+
// Protected -----------------------------------------------------
// Inner classes -------------------------------------------------
Modified: trunk/src/main/org/jboss/jms/message/JBossObjectMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossObjectMessage.java 2007-10-12 14:31:28 UTC (rev 3189)
+++ trunk/src/main/org/jboss/jms/message/JBossObjectMessage.java 2007-10-15 13:03:24 UTC (rev 3190)
@@ -108,10 +108,12 @@
public void setObject(Serializable object) throws JMSException
{
- //Store it in it's serialized form
- setPayload(object);
+ payload = object;
+
+ //Trigger serialization
getPayloadAsByteArray();
- setPayload(null);
+
+ payload = null;
}
public Serializable getObject() throws JMSException
Modified: trunk/src/main/org/jboss/jms/message/JBossStreamMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossStreamMessage.java 2007-10-12 14:31:28 UTC (rev 3189)
+++ trunk/src/main/org/jboss/jms/message/JBossStreamMessage.java 2007-10-15 13:03:24 UTC (rev 3190)
@@ -80,8 +80,7 @@
public JBossStreamMessage(long messageID)
{
super(messageID);
- setPayload(new ArrayList());
- clearPayloadAsByteArray();
+ payload = new ArrayList();
position = 0;
size = 0;
offset = 0;
@@ -113,8 +112,7 @@
foreign.reset();
- setPayload(new ArrayList());
- clearPayloadAsByteArray();
+ payload = new ArrayList();
position = 0;
size = 0;
offset = 0;
@@ -144,11 +142,18 @@
reset();
}
+ public void doBeforeReceive() throws JMSException
+ {
+ //We need to reset before receive too http://jira.jboss.com/jira/browse/JBMESSAGING-1079
+
+ reset();
+ }
+
public void copyPayload(Object other) throws JMSException
{
reset();
- setPayload(new ArrayList((List)other));
- clearPayloadAsByteArray();
+ payload = new ArrayList((List)other);
+ payloadAsByteArray = null;
}
// StreamMessage implementation ----------------------------------
@@ -658,8 +663,8 @@
{
super.clearBody();
- setPayload(new ArrayList());
- clearPayloadAsByteArray();
+ payload = new ArrayList();
+ payloadAsByteArray = null;
position = 0;
offset = 0;
size = 0;
@@ -675,17 +680,6 @@
// Protected -----------------------------------------------------
- protected void writePayload(DataOutputStream out, Object thePayload) throws Exception
- {
- StreamUtils.writeList(out, (List)thePayload);
- }
-
- protected Object readPayload(DataInputStream in, int length)
- throws Exception
- {
- return StreamUtils.readList(in);
- }
-
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
Modified: trunk/src/main/org/jboss/jms/message/JBossTextMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossTextMessage.java 2007-10-12 14:31:28 UTC (rev 3189)
+++ trunk/src/main/org/jboss/jms/message/JBossTextMessage.java 2007-10-15 13:03:24 UTC (rev 3190)
@@ -21,15 +21,11 @@
*/
package org.jboss.jms.message;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
import java.util.Map;
import javax.jms.JMSException;
import javax.jms.TextMessage;
-import org.jboss.messaging.util.SafeUTF;
-
/**
* This class implements javax.jms.TextMessage ported from SpyTextMessage in JBossMQ.
*
@@ -117,8 +113,8 @@
public void setText(String string) throws JMSException
{
- setPayload(string);
- clearPayloadAsByteArray();
+ payload = string;
+ payloadAsByteArray = null;
}
public String getText() throws JMSException
@@ -137,17 +133,6 @@
// Protected -----------------------------------------------------
- protected void writePayload(DataOutputStream out, Object thePayload) throws Exception
- {
- SafeUTF.instance.safeWriteUTF(out, (String)thePayload);
- }
-
- protected Object readPayload(DataInputStream in, int length)
- throws Exception
- {
- return SafeUTF.instance.safeReadUTF(in);
- }
-
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
Modified: trunk/src/main/org/jboss/jms/message/MessageProxy.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/MessageProxy.java 2007-10-12 14:31:28 UTC (rev 3189)
+++ trunk/src/main/org/jboss/jms/message/MessageProxy.java 2007-10-15 13:03:24 UTC (rev 3190)
@@ -30,6 +30,7 @@
import javax.jms.MessageNotWriteableException;
import org.jboss.jms.delegate.SessionDelegate;
+import org.jboss.logging.Logger;
/**
*
@@ -56,6 +57,9 @@
private static final long serialVersionUID = 5903095946142192468L;
+ protected Logger log = Logger.getLogger(MessageProxy.class);
+
+
// Static --------------------------------------------------------
// Attributes ----------------------------------------------------
@@ -486,7 +490,7 @@
if (needToCopyBody)
{
headerChange();
-
+
message.copyPayload(message.getPayload());
needToCopyBody = false;
@@ -502,7 +506,5 @@
needToCopyHeader = false;
}
-
- // Inner classes -------------------------------------------------
-
+ // Inner classes -------------------------------------------------
}
Modified: trunk/src/main/org/jboss/messaging/core/impl/JDBCPersistenceManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/JDBCPersistenceManager.java 2007-10-12 14:31:28 UTC (rev 3189)
+++ trunk/src/main/org/jboss/messaging/core/impl/JDBCPersistenceManager.java 2007-10-15 13:03:24 UTC (rev 3190)
@@ -1876,7 +1876,6 @@
if (bindBlobs)
{
bindBlobs(m, ps, 7, 8);
-
}
}
Modified: trunk/src/main/org/jboss/messaging/core/impl/message/MessageFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/message/MessageFactory.java 2007-10-12 14:31:28 UTC (rev 3189)
+++ trunk/src/main/org/jboss/messaging/core/impl/message/MessageFactory.java 2007-10-15 13:03:24 UTC (rev 3190)
@@ -41,7 +41,7 @@
public class MessageFactory
{
// Constants ------------------------------------------------------------------------------------
-
+
// Static ---------------------------------------------------------------------------------------
public static Message createMessage(byte type)
@@ -120,7 +120,7 @@
break;
}
case JBossBytesMessage.TYPE:
- {
+ {
m = new JBossBytesMessage(messageID, reliable, expiration,
timestamp, priority, headers, payload);
break;
Modified: trunk/src/main/org/jboss/messaging/core/impl/message/MessageSupport.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/message/MessageSupport.java 2007-10-12 14:31:28 UTC (rev 3189)
+++ trunk/src/main/org/jboss/messaging/core/impl/message/MessageSupport.java 2007-10-15 13:03:24 UTC (rev 3190)
@@ -41,8 +41,9 @@
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
* @version <tt>$Revision: 2740 $</tt>
*
- * Note this class is only serializable so messages can't be returned from JMX operations
+ * Note this class is only serializable so messages can be returned from JMX operations
* e.g. listAllMessages.
+ *
* For normal message transportation serialization is not used
*
* $Id: MessageSupport.java 2740 2007-05-30 11:36:28Z timfox $
@@ -70,11 +71,9 @@
protected byte priority;
- // Must be hidden from subclasses
- private transient Object payload;
+ protected transient Object payload;
- // Must be hidden from subclasses
- private byte[] payloadAsByteArray;
+ protected byte[] payloadAsByteArray;
private transient volatile boolean persisted;
@@ -110,7 +109,8 @@
if (headers == null)
{
this.headers = new HashMap();
- } else
+ }
+ else
{
this.headers = new HashMap(headers);
}
@@ -206,32 +206,21 @@
{
if (payloadAsByteArray == null && payload != null)
{
- // convert the payload into a byte array and store internally
-
- // TODO - investigate how changing the buffer size effects
- // performance
-
- // Ideally I would like to use the pre-existing DataOutputStream and
- // not create another one - but would then have to add markers on the
- // stream
- // to signify the end of the payload
- // This would have the advantage of us not having to allocate buffers
- // here
- // We could do this by creating our own FilterOutputStream that makes
- // sure
- // the end of marker sequence doesn't occur in the payload
-
final int BUFFER_SIZE = 2048;
try
{
ByteArrayOutputStream bos = new ByteArrayOutputStream(BUFFER_SIZE);
DataOutputStream daos = new DataOutputStream(bos);
- writePayload(daos, payload);
+ StreamUtils.writeObject(daos, payload, true, true);
daos.close();
- payloadAsByteArray = bos.toByteArray();
+ payloadAsByteArray = bos.toByteArray();
+
+ //Note we set payload to null - if we didn't then we'd end up with the message stored in memory twice -
+ //once as the payload, once as the byte[] - this means it would take up twice the RAM
payload = null;
- } catch (Exception e)
+ }
+ catch (Exception e)
{
RuntimeException e2 = new RuntimeException(e.getMessage());
e2.setStackTrace(e.getStackTrace());
@@ -241,27 +230,19 @@
return payloadAsByteArray;
}
- /**
- * Warning! Calling getPayload will cause the payload to be deserialized so
- * should not be called on the server.
- */
public synchronized Object getPayload()
- {
+ {
if (payload != null)
{
return payload;
}
else if (payloadAsByteArray != null)
{
- // deserialize the payload from byte[]
-
- // TODO use the same DataInputStream as in the read() method and
- // add markers on the stream to represent end of payload
ByteArrayInputStream bis = new ByteArrayInputStream(payloadAsByteArray);
DataInputStream dis = new DataInputStream(bis);
try
{
- payload = readPayload(dis, payloadAsByteArray.length);
+ payload = StreamUtils.readObject(dis, true);
}
catch (Exception e)
{
@@ -271,6 +252,7 @@
}
payloadAsByteArray = null;
+
return payload;
}
else
@@ -278,17 +260,12 @@
return null;
}
}
-
- public void setPayload(Serializable payload)
+
+ public void setPayload(Object payload)
{
this.payload = payload;
}
- protected void clearPayloadAsByteArray()
- {
- this.payloadAsByteArray = null;
- }
-
public boolean isExpired()
{
if (expiration == 0)
@@ -373,7 +350,8 @@
out.writeInt(bytes.length);
out.write(bytes);
- } else
+ }
+ else
{
out.writeInt(0);
}
@@ -399,7 +377,8 @@
{
// no payload
payloadAsByteArray = null;
- } else
+ }
+ else
{
payloadAsByteArray = new byte[length];
@@ -411,39 +390,6 @@
// Protected -----------------------------------------------------
- /**
- * Override this if you want more sophisticated payload externalization.
- *
- * @throws Exception
- * TODO
- */
- protected void writePayload(DataOutputStream out, Object thePayload)
- throws Exception
- {
- StreamUtils.writeObject(out, thePayload, true, true);
- }
-
- /**
- * Override this if you want more sophisticated payload externalization.
- *
- * @throws Exception
- * TODO
- */
- protected Object readPayload(DataInputStream in, int length)
- throws Exception
- {
- return StreamUtils.readObject(in, true);
- }
-
- /**
- * It makes sense to use this method only from within JBossBytesMessage
- * (optimization). Using it from anywhere else will lead to corrupted data.
- */
- protected final void copyPayloadAsByteArrayToPayload()
- {
- payload = payloadAsByteArray;
- }
-
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
Modified: trunk/tests/src/org/jboss/test/messaging/jms/MessageProxyTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/MessageProxyTest.java 2007-10-12 14:31:28 UTC (rev 3189)
+++ trunk/tests/src/org/jboss/test/messaging/jms/MessageProxyTest.java 2007-10-15 13:03:24 UTC (rev 3190)
@@ -191,6 +191,8 @@
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sess.createProducer(queue1);
+
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
MapMessage m = sess.createMapMessage();
@@ -296,9 +298,8 @@
removeAllMessages(queue1.getQueueName(), true, 0);
}
}
-
-
- public void testReceivedMessage() throws Exception
+
+ public void testReceivedMessage(boolean persistent) throws Exception
{
if (ServerManagement.isRemote())
{
@@ -316,6 +317,8 @@
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = sess.createProducer(queue1);
+
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
MapMessage m = sess.createMapMessage();
@@ -333,8 +336,8 @@
JBossMessage check3 = ((MessageProxy)m).getMessage();
- //Underlying message should be different
checkSameUnderlyingMessage(check1, check3, true);
+
checkSameBody(check1, check3, true);
prod.send(m);
@@ -384,7 +387,7 @@
// But the body should be the same
checkSameBody(check6, check7, true);
-
+
// Set the body
m.setString("key1", "blah");
@@ -436,10 +439,14 @@
private void checkSameBody(JBossMessage m1, JBossMessage m2, boolean same)
{
- if ((m1.getPayload() == m2.getPayload()) && !same)
- {
- fail("Body not same");
+ if (same && (m1.getPayload() != m2.getPayload()))
+ {
+ fail("Body not same");
}
+ else if (!same && (m1.getPayload() == m2.getPayload()))
+ {
+ fail("Body same");
+ }
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/PersistenceTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/PersistenceTest.java 2007-10-12 14:31:28 UTC (rev 3189)
+++ trunk/tests/src/org/jboss/test/messaging/jms/PersistenceTest.java 2007-10-15 13:03:24 UTC (rev 3190)
@@ -21,6 +21,7 @@
*/
package org.jboss.test.messaging.jms;
+import javax.jms.BytesMessage;
import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.MessageConsumer;
Modified: trunk/tests/src/org/jboss/test/messaging/jms/QueueTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/QueueTest.java 2007-10-12 14:31:28 UTC (rev 3189)
+++ trunk/tests/src/org/jboss/test/messaging/jms/QueueTest.java 2007-10-15 13:03:24 UTC (rev 3190)
@@ -24,7 +24,9 @@
import java.util.HashSet;
import java.util.Set;
+import javax.jms.BytesMessage;
import javax.jms.Connection;
+import javax.jms.DeliveryMode;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
@@ -84,7 +86,69 @@
}
}
}
+
+ //http://jira.jboss.com/jira/browse/JBMESSAGING-1101
+ public void testBytesMessagePersistence() throws Exception
+ {
+ Connection conn = null;
+
+ byte[] bytes = new byte[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 123, 55, 0, 12, -100, -11};
+
+ try
+ {
+ conn = cf.createConnection();
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer prod = sess.createProducer(queue1);
+ prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+ for (int i = 0; i < 1; i++)
+ {
+ BytesMessage bm = sess.createBytesMessage();
+
+ bm.writeBytes(bytes);
+
+ prod.send(bm);
+ }
+
+ conn.close();
+
+ ServerManagement.stopServerPeer();
+
+ ServerManagement.startServerPeer();
+
+ // Messaging server restart implies new ConnectionFactory lookup
+ deployAndLookupAdministeredObjects();
+
+ conn = cf.createConnection();
+ sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ conn.start();
+ MessageConsumer cons = sess.createConsumer(queue1);
+ for (int i = 0; i < 1; i++)
+ {
+ BytesMessage bm = (BytesMessage)cons.receive(3000);
+
+ assertNotNull(bm);
+
+ byte[] bytes2 = new byte[bytes.length];
+
+ bm.readBytes(bytes2);
+
+ for (int j = 0; j < bytes.length; j++)
+ {
+ assertEquals(bytes[j], bytes2[j]);
+ }
+ }
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+ }
+
// added for http://jira.jboss.org/jira/browse/JBMESSAGING-899
public void testClosedConsumerAfterStart() throws Exception
{
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/BytesMessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/BytesMessageTest.java 2007-10-12 14:31:28 UTC (rev 3189)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/BytesMessageTest.java 2007-10-15 13:03:24 UTC (rev 3190)
@@ -106,5 +106,4 @@
assertEquals("this is an UTF String", bm.readUTF());
}
-
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/MessageBodyTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/MessageBodyTest.java 2007-10-12 14:31:28 UTC (rev 3189)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/MessageBodyTest.java 2007-10-15 13:03:24 UTC (rev 3190)
@@ -1,24 +1,24 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.test.messaging.jms.message;
import java.io.Serializable;
@@ -44,1642 +44,1526 @@
/**
*
* A MessageBodyTest
-
+ *
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
* @version <tt>$Revision$</tt>
- *
+ *
* $Id$
- *
+ *
*/
public class MessageBodyTest extends JMSTestCase
{
- // Constants -----------------------------------------------------
+ // Constants -----------------------------------------------------
- // Static --------------------------------------------------------
+ // Static --------------------------------------------------------
- // Attributes ----------------------------------------------------
+ // Attributes ----------------------------------------------------
- protected Connection producerConnection, consumerConnection;
+ protected Connection producerConnection, consumerConnection;
- protected Session queueProducerSession, queueConsumerSession;
+ protected Session queueProducerSession, queueConsumerSession;
- protected MessageProducer queueProducer;
+ protected MessageProducer queueProducer;
- protected MessageConsumer queueConsumer;
+ protected MessageConsumer queueConsumer;
- // Constructors --------------------------------------------------
+ // Constructors --------------------------------------------------
- public MessageBodyTest(String name)
- {
- super(name);
- }
+ public MessageBodyTest(String name)
+ {
+ super(name);
+ }
- // Public --------------------------------------------------------
+ // Public --------------------------------------------------------
- public void setUp() throws Exception
- {
- super.setUp();
-
- producerConnection = cf.createConnection();
- consumerConnection = cf.createConnection();
+ public void setUp() throws Exception
+ {
+ super.setUp();
- queueProducerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- queueConsumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ producerConnection = cf.createConnection();
+ consumerConnection = cf.createConnection();
- queueProducer = queueProducerSession.createProducer(queue1);
- queueConsumer = queueConsumerSession.createConsumer(queue1);
+ queueProducerSession = producerConnection.createSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+ queueConsumerSession = consumerConnection.createSession(false,
+ Session.AUTO_ACKNOWLEDGE);
- consumerConnection.start();
- }
+ queueProducer = queueProducerSession.createProducer(queue1);
+ queueConsumer = queueConsumerSession.createConsumer(queue1);
- public void tearDown() throws Exception
- {
- producerConnection.close();
- consumerConnection.close();
-
- super.tearDown();
- }
-
- public void testSMBodyReadable() throws Exception
- {
- byte bValue = 123;
- StreamMessage sm = queueProducerSession.createStreamMessage();
- sm.writeByte(bValue);
- sm.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageEOFExceptionQTestforStreamMessage");
- queueProducer.send(sm);
+ consumerConnection.start();
+ }
- StreamMessage received = (StreamMessage)queueConsumer.receive(3000);
- received.readByte();
- }
-
- public void testBytesMessage() throws Exception
- {
- BytesMessage m = queueProducerSession.createBytesMessage();
+ public void tearDown() throws Exception
+ {
+ producerConnection.close();
+ consumerConnection.close();
- // some arbitrary values
- boolean myBool = true;
- byte myByte = -111;
- short myShort = 15321;
- int myInt = 0x71ab6c80;
- long myLong = 0x20bf1e3fb6fa31dfL;
- float myFloat = Float.MAX_VALUE - 23465;
- double myDouble = Double.MAX_VALUE - 72387633;
- String myString = "abcdef&^*&!^ghijkl\uD5E2\uCAC7\uD2BB\uB7DD\uB7C7\uB3A3\uBCE4\uB5A5";
- log.trace("String is length:" + myString.length());
- char myChar = 'q';
- byte[] myBytes = new byte[] {-23, 114, -126, -12, 74, 87};
+ super.tearDown();
+ }
- m.writeBoolean(myBool);
- m.writeByte(myByte);
- m.writeShort(myShort);
- m.writeChar(myChar);
- m.writeInt(myInt);
- m.writeLong(myLong);
- m.writeFloat(myFloat);
- m.writeDouble(myDouble);
- m.writeUTF(myString);
- m.writeBytes(myBytes);
- m.writeBytes(myBytes, 2, 3);
+ public void testSMBodyReadable() throws Exception
+ {
+ byte bValue = 123;
+ StreamMessage sm = queueProducerSession.createStreamMessage();
+ sm.writeByte(bValue);
+ sm.setStringProperty("COM_SUN_JMS_TESTNAME",
+ "xMessageEOFExceptionQTestforStreamMessage");
+ queueProducer.send(sm);
+ StreamMessage received = (StreamMessage) queueConsumer.receive(3000);
+ received.readByte();
+ }
- m.writeObject(new Boolean(myBool));
- m.writeObject(new Byte(myByte));
- m.writeObject(new Short(myShort));
- m.writeObject(new Integer(myInt));
- m.writeObject(new Long(myLong));
- m.writeObject(new Float(myFloat));
- m.writeObject(new Double(myDouble));
- m.writeObject(myString);
- m.writeObject(myBytes);
+ public void testBytesMessage() throws Exception
+ {
+ BytesMessage m = queueProducerSession.createBytesMessage();
- try
- {
- m.writeObject(new Object());
- fail();
- }
- catch (MessageFormatException e)
- {
- // OK
- }
+ // some arbitrary values
+ boolean myBool = true;
+ byte myByte = -111;
+ short myShort = 15321;
+ int myInt = 0x71ab6c80;
+ long myLong = 0x20bf1e3fb6fa31dfL;
+ float myFloat = Float.MAX_VALUE - 23465;
+ double myDouble = Double.MAX_VALUE - 72387633;
+ String myString = "abcdef&^*&!^ghijkl\uD5E2\uCAC7\uD2BB\uB7DD\uB7C7\uB3A3\uBCE4\uB5A5";
+ log.trace("String is length:" + myString.length());
+ char myChar = 'q';
+ byte[] myBytes = new byte[] { -23, 114, -126, -12, 74, 87 };
- // Reading should not be possible when message is read-write
- try
- {
- m.readBoolean();
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- // OK
- }
- try
- {
- m.readShort();
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- // OK
- }
- try
- {
- m.readChar();
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- // OK
- }
- try
- {
- m.readInt();
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- // OK
- }
- try
- {
- m.readLong();
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- // OK
- }
- try
- {
- m.readFloat();
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- // OK
- }
- try
- {
- m.readDouble();
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- // OK
- }
- try
- {
- m.readUTF();
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- // OK
- }
- try
- {
- m.readUnsignedByte();
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- // OK
- }
- try
- {
- m.readUnsignedShort();
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- // OK
- }
- try
- {
- byte[] bytes = new byte[333];
- m.readBytes(bytes);
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- // OK
- }
- try
- {
- byte[] bytes = new byte[333];
- m.readBytes(bytes, 111);
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- // OK
- }
- try
- {
- m.getBodyLength();
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- // OK
- }
+ m.writeBoolean(myBool);
+ m.writeByte(myByte);
+ m.writeShort(myShort);
+ m.writeChar(myChar);
+ m.writeInt(myInt);
+ m.writeLong(myLong);
+ m.writeFloat(myFloat);
+ m.writeDouble(myDouble);
+ m.writeUTF(myString);
+ m.writeBytes(myBytes);
+ m.writeBytes(myBytes, 2, 3);
- queueProducer.send(queue1, m);
+ m.writeObject(new Boolean(myBool));
+ m.writeObject(new Byte(myByte));
+ m.writeObject(new Short(myShort));
+ m.writeObject(new Integer(myInt));
+ m.writeObject(new Long(myLong));
+ m.writeObject(new Float(myFloat));
+ m.writeObject(new Double(myDouble));
+ m.writeObject(myString);
+ m.writeObject(myBytes);
- BytesMessage m2 = (BytesMessage)queueConsumer.receive(2000);
+ try
+ {
+ m.writeObject(new Object());
+ fail();
+ } catch (MessageFormatException e)
+ {
+ // OK
+ }
- assertNotNull(m2);
+ // Reading should not be possible when message is read-write
+ try
+ {
+ m.readBoolean();
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ // OK
+ }
+ try
+ {
+ m.readShort();
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ // OK
+ }
+ try
+ {
+ m.readChar();
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ // OK
+ }
+ try
+ {
+ m.readInt();
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ // OK
+ }
+ try
+ {
+ m.readLong();
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ // OK
+ }
+ try
+ {
+ m.readFloat();
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ // OK
+ }
+ try
+ {
+ m.readDouble();
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ // OK
+ }
+ try
+ {
+ m.readUTF();
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ // OK
+ }
+ try
+ {
+ m.readUnsignedByte();
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ // OK
+ }
+ try
+ {
+ m.readUnsignedShort();
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ // OK
+ }
+ try
+ {
+ byte[] bytes = new byte[333];
+ m.readBytes(bytes);
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ // OK
+ }
+ try
+ {
+ byte[] bytes = new byte[333];
+ m.readBytes(bytes, 111);
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ // OK
+ }
+ try
+ {
+ m.getBodyLength();
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ // OK
+ }
- assertEquals(myBool, m2.readBoolean());
- assertEquals(myByte, m2.readByte());
- assertEquals(myShort, m2.readShort());
- assertEquals(myChar, m2.readChar());
- assertEquals(myInt, m2.readInt());
- assertEquals(myLong, m2.readLong());
- assertEquals(myFloat, m2.readFloat(), 0);
- assertEquals(myDouble, m2.readDouble(), 0);
- assertEquals(myString, m2.readUTF());
+ queueProducer.send(queue1, m);
- byte[] bytes = new byte[6];
- int ret = m2.readBytes(bytes);
- assertEquals(6, ret);
+ BytesMessage m2 = (BytesMessage) queueConsumer.receive(2000);
- assertByteArraysEqual(myBytes, bytes);
+ assertNotNull(m2);
- byte[] bytes2 = new byte[3];
- ret = m2.readBytes(bytes2);
+ assertEquals(myBool, m2.readBoolean());
+ assertEquals(myByte, m2.readByte());
+ assertEquals(myShort, m2.readShort());
+ assertEquals(myChar, m2.readChar());
+ assertEquals(myInt, m2.readInt());
+ assertEquals(myLong, m2.readLong());
+ assertEquals(myFloat, m2.readFloat(), 0);
+ assertEquals(myDouble, m2.readDouble(), 0);
+ assertEquals(myString, m2.readUTF());
- assertEquals(3, ret);
+ byte[] bytes = new byte[6];
+ int ret = m2.readBytes(bytes);
+ assertEquals(6, ret);
- assertEquals(myBytes[2], bytes2[0]);
- assertEquals(myBytes[3], bytes2[1]);
- assertEquals(myBytes[4], bytes2[2]);
+ assertByteArraysEqual(myBytes, bytes);
- assertEquals(myBool, m2.readBoolean());
- assertEquals(myByte, m2.readByte());
- assertEquals(myShort, m2.readShort());
- assertEquals(myInt, m2.readInt());
- assertEquals(myLong, m2.readLong());
- assertEquals(myFloat, m2.readFloat(), 0);
- assertEquals(myDouble, m2.readDouble(), 0);
- assertEquals(myString, m2.readUTF());
+ byte[] bytes2 = new byte[3];
+ ret = m2.readBytes(bytes2);
- bytes = new byte[6];
- ret = m2.readBytes(bytes);
- assertEquals(6, ret);
- assertByteArraysEqual(myBytes, bytes);
+ assertEquals(3, ret);
- ret = m2.readBytes(bytes);
- assertEquals(-1, ret);
+ assertEquals(myBytes[2], bytes2[0]);
+ assertEquals(myBytes[3], bytes2[1]);
+ assertEquals(myBytes[4], bytes2[2]);
- // Try and read past the end of the stream
- try
- {
- m2.readBoolean();
- fail();
- }
- catch (MessageEOFException e)
- {
- // OK
- }
+ assertEquals(myBool, m2.readBoolean());
+ assertEquals(myByte, m2.readByte());
+ assertEquals(myShort, m2.readShort());
+ assertEquals(myInt, m2.readInt());
+ assertEquals(myLong, m2.readLong());
+ assertEquals(myFloat, m2.readFloat(), 0);
+ assertEquals(myDouble, m2.readDouble(), 0);
+ assertEquals(myString, m2.readUTF());
- try
- {
- m2.readByte();
- fail();
- }
- catch (MessageEOFException e)
- {
- // OK
- }
+ bytes = new byte[6];
+ ret = m2.readBytes(bytes);
+ assertEquals(6, ret);
+ assertByteArraysEqual(myBytes, bytes);
- try
- {
- m2.readChar();
- fail();
- }
- catch (MessageEOFException e)
- {
- // OK
- }
+ ret = m2.readBytes(bytes);
+ assertEquals(-1, ret);
- try
- {
- m2.readDouble();
- fail();
- }
- catch (MessageEOFException e)
- {
- // OK
- }
+ // Try and read past the end of the stream
+ try
+ {
+ m2.readBoolean();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ // OK
+ }
- try
- {
- m2.readFloat();
- fail();
- }
- catch (MessageEOFException e)
- {
- // OK
- }
+ try
+ {
+ m2.readByte();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ // OK
+ }
- try
- {
- m2.readInt();
- fail();
- }
- catch (MessageEOFException e)
- {
- // OK
- }
+ try
+ {
+ m2.readChar();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ // OK
+ }
- try
- {
- m2.readLong();
- fail();
- }
- catch (MessageEOFException e)
- {
- // OK
- }
+ try
+ {
+ m2.readDouble();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ // OK
+ }
- try
- {
- m2.readShort();
- fail();
- }
- catch (MessageEOFException e)
- {
- // OK
- }
+ try
+ {
+ m2.readFloat();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ // OK
+ }
- try
- {
- m2.readUnsignedByte();
- fail();
- }
- catch (MessageEOFException e)
- {
- // OK
- }
+ try
+ {
+ m2.readInt();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ // OK
+ }
- try
- {
- m2.readUnsignedShort();
- fail();
- }
- catch (MessageEOFException e)
- {
- // OK
- }
+ try
+ {
+ m2.readLong();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ // OK
+ }
- try
- {
- m2.readUTF();
- fail();
- }
- catch (MessageEOFException e)
- {
- // OK
- }
+ try
+ {
+ m2.readShort();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ // OK
+ }
- // Message should not be writable in read-only mode
- try
- {
- m2.writeBoolean(myBool);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- // OK
- }
- try
- {
- m2.writeByte(myByte);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- // OK
- }
- try
- {
- m2.writeShort(myShort);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- // OK
- }
- try
- {
- m2.writeChar(myChar);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- // OK
- }
+ try
+ {
+ m2.readUnsignedByte();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ // OK
+ }
- try
- {
- m2.writeInt(myInt);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- // OK
- }
- try
- {
- m2.writeLong(myLong);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- // OK
- }
- try
- {
- m2.writeFloat(myFloat);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- // OK
- }
- try
- {
- m2.writeDouble(myDouble);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- // OK
- }
- try
- {
- m2.writeUTF(myString);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- // OK
- }
+ try
+ {
+ m2.readUnsignedShort();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ // OK
+ }
- try
- {
- m2.writeBytes(myBytes);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- // OK
- }
+ try
+ {
+ m2.readUTF();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ // OK
+ }
- try
- {
- m2.writeObject(myString);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- // OK
- }
+ // Message should not be writable in read-only mode
+ try
+ {
+ m2.writeBoolean(myBool);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ // OK
+ }
+ try
+ {
+ m2.writeByte(myByte);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ // OK
+ }
+ try
+ {
+ m2.writeShort(myShort);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ // OK
+ }
+ try
+ {
+ m2.writeChar(myChar);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ // OK
+ }
- long bodyLength = m2.getBodyLength();
+ try
+ {
+ m2.writeInt(myInt);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ // OK
+ }
+ try
+ {
+ m2.writeLong(myLong);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ // OK
+ }
+ try
+ {
+ m2.writeFloat(myFloat);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ // OK
+ }
+ try
+ {
+ m2.writeDouble(myDouble);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ // OK
+ }
+ try
+ {
+ m2.writeUTF(myString);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ // OK
+ }
- assertEquals(161, bodyLength);
+ try
+ {
+ m2.writeBytes(myBytes);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ // OK
+ }
- m2.reset();
+ try
+ {
+ m2.writeObject(myString);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ // OK
+ }
- // test the unsigned reads
+ long bodyLength = m2.getBodyLength();
- m2.readBoolean();
- int unsignedByte = m2.readUnsignedByte();
+ assertEquals(161, bodyLength);
- assertEquals((int) (myByte & 0xFF), unsignedByte);
+ m2.reset();
- int unsignedShort = m2.readUnsignedShort();
+ // test the unsigned reads
- assertEquals((int) (myShort & 0xFFFF), unsignedShort);
+ m2.readBoolean();
+ int unsignedByte = m2.readUnsignedByte();
- m2.clearBody();
+ assertEquals((int) (myByte & 0xFF), unsignedByte);
- try
- {
- m2.getBodyLength();
- fail();
- }
- catch (MessageNotReadableException e)
- {
- // OK
- }
+ int unsignedShort = m2.readUnsignedShort();
- m2.reset();
+ assertEquals((int) (myShort & 0xFFFF), unsignedShort);
- assertEquals(0, m2.getBodyLength());
+ m2.clearBody();
- //Test that changing the received message doesn't affect the sent message
- m.reset();
- assertEquals(161, m.getBodyLength());
+ try
+ {
+ m2.getBodyLength();
+ fail();
+ } catch (MessageNotReadableException e)
+ {
+ // OK
+ }
- //Should be diffent object instances after sending *even* if in same JVM
- assertFalse(m == m2);
+ m2.reset();
- }
+ assertEquals(0, m2.getBodyLength());
- public void testMapMessage() throws Exception
- {
- MapMessage m1 = queueProducerSession.createMapMessage();
+ // Test that changing the received message doesn't affect the sent message
+ m.reset();
+ assertEquals(161, m.getBodyLength());
- //Some arbitrary values
- boolean myBool = true;
- byte myByte = 13;
- short myShort = 15321;
- int myInt = 0x71ab6c80;
- long myLong = 0x20bf1e3fb6fa31dfL;
- float myFloat = Float.MAX_VALUE - 23465;
- double myDouble = Double.MAX_VALUE - 72387633;
- String myString = "abcdef&^*&!^ghijkl\uD5E2\uCAC7\uD2BB\uB7DD\uB7C7\uB3A3\uBCE4\uB5A5";
+ // Should be diffent object instances after sending *even* if in same JVM
+ assertFalse(m == m2);
- m1.setBoolean("myBool", myBool);
- m1.setByte("myByte", myByte);
- m1.setShort("myShort", myShort);
- m1.setInt("myInt", myInt);
- m1.setLong("myLong", myLong);
- m1.setFloat("myFloat", myFloat);
- m1.setDouble("myDouble", myDouble);
- m1.setString("myString", myString);
+ }
- m1.setObject("myBool", new Boolean(myBool));
- m1.setObject("myByte", new Byte(myByte));
- m1.setObject("myShort", new Short(myShort));
- m1.setObject("myInt", new Integer(myInt));
- m1.setObject("myLong", new Long(myLong));
- m1.setObject("myFloat", new Float(myFloat));
- m1.setObject("myDouble", new Double(myDouble));
- m1.setObject("myString", myString);
+ public void testMapMessage() throws Exception
+ {
+ MapMessage m1 = queueProducerSession.createMapMessage();
- try
- {
- m1.setObject("myIllegal", new Object());
- fail();
- }
- catch (javax.jms.MessageFormatException e)
- {
- }
+ // Some arbitrary values
+ boolean myBool = true;
+ byte myByte = 13;
+ short myShort = 15321;
+ int myInt = 0x71ab6c80;
+ long myLong = 0x20bf1e3fb6fa31dfL;
+ float myFloat = Float.MAX_VALUE - 23465;
+ double myDouble = Double.MAX_VALUE - 72387633;
+ String myString = "abcdef&^*&!^ghijkl\uD5E2\uCAC7\uD2BB\uB7DD\uB7C7\uB3A3\uBCE4\uB5A5";
- queueProducer.send(queue1, m1);
+ m1.setBoolean("myBool", myBool);
+ m1.setByte("myByte", myByte);
+ m1.setShort("myShort", myShort);
+ m1.setInt("myInt", myInt);
+ m1.setLong("myLong", myLong);
+ m1.setFloat("myFloat", myFloat);
+ m1.setDouble("myDouble", myDouble);
+ m1.setString("myString", myString);
- MapMessage m2 = (MapMessage) queueConsumer.receive(2000);
+ m1.setObject("myBool", new Boolean(myBool));
+ m1.setObject("myByte", new Byte(myByte));
+ m1.setObject("myShort", new Short(myShort));
+ m1.setObject("myInt", new Integer(myInt));
+ m1.setObject("myLong", new Long(myLong));
+ m1.setObject("myFloat", new Float(myFloat));
+ m1.setObject("myDouble", new Double(myDouble));
+ m1.setObject("myString", myString);
- assertNotNull(m2);
+ try
+ {
+ m1.setObject("myIllegal", new Object());
+ fail();
+ } catch (javax.jms.MessageFormatException e)
+ {
+ }
- assertEquals(myBool, m2.getBoolean("myBool"));
- assertEquals(myByte, m2.getByte("myByte"));
- assertEquals(myShort, m2.getShort("myShort"));
- assertEquals(myInt, m2.getInt("myInt"));
- assertEquals(myLong, m2.getLong("myLong"));
- assertEquals(myFloat, m2.getFloat("myFloat"), 0);
- assertEquals(myDouble, m2.getDouble("myDouble"), 0);
- assertEquals(myString, m2.getString("myString"));
+ queueProducer.send(queue1, m1);
- //Properties should now be read-only
- try
- {
- m2.setBoolean("myBool", myBool);
- fail();
- }
- catch (MessageNotWriteableException e)
- {
- }
+ MapMessage m2 = (MapMessage) queueConsumer.receive(2000);
- try
- {
- m2.setByte("myByte", myByte);
- fail();
- }
- catch (MessageNotWriteableException e)
- {
- }
+ assertNotNull(m2);
- try
- {
- m2.setShort("myShort", myShort);
- fail();
- }
- catch (MessageNotWriteableException e)
- {
- }
+ assertEquals(myBool, m2.getBoolean("myBool"));
+ assertEquals(myByte, m2.getByte("myByte"));
+ assertEquals(myShort, m2.getShort("myShort"));
+ assertEquals(myInt, m2.getInt("myInt"));
+ assertEquals(myLong, m2.getLong("myLong"));
+ assertEquals(myFloat, m2.getFloat("myFloat"), 0);
+ assertEquals(myDouble, m2.getDouble("myDouble"), 0);
+ assertEquals(myString, m2.getString("myString"));
- try
- {
- m2.setInt("myInt", myInt);
- fail();
- }
- catch (MessageNotWriteableException e)
- {
- }
+ // Properties should now be read-only
+ try
+ {
+ m2.setBoolean("myBool", myBool);
+ fail();
+ } catch (MessageNotWriteableException e)
+ {
+ }
- try
- {
- m2.setLong("myLong", myLong);
- fail();
- }
- catch (MessageNotWriteableException e)
- {
- }
+ try
+ {
+ m2.setByte("myByte", myByte);
+ fail();
+ } catch (MessageNotWriteableException e)
+ {
+ }
- try
- {
- m2.setFloat("myFloat", myFloat);
- fail();
- }
- catch (MessageNotWriteableException e)
- {
- }
+ try
+ {
+ m2.setShort("myShort", myShort);
+ fail();
+ } catch (MessageNotWriteableException e)
+ {
+ }
- try
- {
- m2.setDouble("myDouble", myDouble);
- fail();
- }
- catch (MessageNotWriteableException e)
- {
- }
+ try
+ {
+ m2.setInt("myInt", myInt);
+ fail();
+ } catch (MessageNotWriteableException e)
+ {
+ }
- try
- {
- m2.setString("myString", myString);
- fail();
- }
- catch (MessageNotWriteableException e)
- {
- }
+ try
+ {
+ m2.setLong("myLong", myLong);
+ fail();
+ } catch (MessageNotWriteableException e)
+ {
+ }
- assertTrue(m2.itemExists("myBool"));
- assertTrue(m2.itemExists("myByte"));
- assertTrue(m2.itemExists("myShort"));
- assertTrue(m2.itemExists("myInt"));
- assertTrue(m2.itemExists("myLong"));
- assertTrue(m2.itemExists("myFloat"));
- assertTrue(m2.itemExists("myDouble"));
- assertTrue(m2.itemExists("myString"));
+ try
+ {
+ m2.setFloat("myFloat", myFloat);
+ fail();
+ } catch (MessageNotWriteableException e)
+ {
+ }
- assertFalse(m2.itemExists("sausages"));
+ try
+ {
+ m2.setDouble("myDouble", myDouble);
+ fail();
+ } catch (MessageNotWriteableException e)
+ {
+ }
- HashSet itemNames = new HashSet();
- Enumeration en = m2.getMapNames();
- while (en.hasMoreElements())
- {
- String propName = (String) en.nextElement();
- itemNames.add(propName);
- }
+ try
+ {
+ m2.setString("myString", myString);
+ fail();
+ } catch (MessageNotWriteableException e)
+ {
+ }
- assertEquals(8, itemNames.size());
+ assertTrue(m2.itemExists("myBool"));
+ assertTrue(m2.itemExists("myByte"));
+ assertTrue(m2.itemExists("myShort"));
+ assertTrue(m2.itemExists("myInt"));
+ assertTrue(m2.itemExists("myLong"));
+ assertTrue(m2.itemExists("myFloat"));
+ assertTrue(m2.itemExists("myDouble"));
+ assertTrue(m2.itemExists("myString"));
- assertTrue(itemNames.contains("myBool"));
- assertTrue(itemNames.contains("myByte"));
- assertTrue(itemNames.contains("myShort"));
- assertTrue(itemNames.contains("myInt"));
- assertTrue(itemNames.contains("myLong"));
- assertTrue(itemNames.contains("myFloat"));
- assertTrue(itemNames.contains("myDouble"));
- assertTrue(itemNames.contains("myString"));
+ assertFalse(m2.itemExists("sausages"));
- // Check property conversions
+ HashSet itemNames = new HashSet();
+ Enumeration en = m2.getMapNames();
+ while (en.hasMoreElements())
+ {
+ String propName = (String) en.nextElement();
+ itemNames.add(propName);
+ }
- //Boolean property can be read as String but not anything else
+ assertEquals(8, itemNames.size());
- assertEquals(String.valueOf(myBool), m2.getString("myBool"));
+ assertTrue(itemNames.contains("myBool"));
+ assertTrue(itemNames.contains("myByte"));
+ assertTrue(itemNames.contains("myShort"));
+ assertTrue(itemNames.contains("myInt"));
+ assertTrue(itemNames.contains("myLong"));
+ assertTrue(itemNames.contains("myFloat"));
+ assertTrue(itemNames.contains("myDouble"));
+ assertTrue(itemNames.contains("myString"));
- try
- {
- m2.getByte("myBool");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ // Check property conversions
- try
- {
- m2.getShort("myBool");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ // Boolean property can be read as String but not anything else
- try
- {
- m2.getInt("myBool");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ assertEquals(String.valueOf(myBool), m2.getString("myBool"));
- try
- {
- m2.getLong("myBool");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getByte("myBool");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getFloat("myBool");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getShort("myBool");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getDouble("myBool");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getInt("myBool");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- // byte item can be read as short, int, long or String
+ try
+ {
+ m2.getLong("myBool");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- assertEquals((short) myByte, m2.getShort("myByte"));
- assertEquals((int) myByte, m2.getInt("myByte"));
- assertEquals((long) myByte, m2.getLong("myByte"));
- assertEquals(String.valueOf(myByte), m2.getString("myByte"));
+ try
+ {
+ m2.getFloat("myBool");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getBoolean("myByte");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getDouble("myBool");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getFloat("myByte");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ // byte item can be read as short, int, long or String
- try
- {
- m2.getDouble("myByte");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ assertEquals((short) myByte, m2.getShort("myByte"));
+ assertEquals((int) myByte, m2.getInt("myByte"));
+ assertEquals((long) myByte, m2.getLong("myByte"));
+ assertEquals(String.valueOf(myByte), m2.getString("myByte"));
- // short item can be read as int, long or String
+ try
+ {
+ m2.getBoolean("myByte");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- assertEquals((int) myShort, m2.getInt("myShort"));
- assertEquals((long) myShort, m2.getLong("myShort"));
- assertEquals(String.valueOf(myShort), m2.getString("myShort"));
+ try
+ {
+ m2.getFloat("myByte");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getByte("myShort");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getDouble("myByte");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getBoolean("myShort");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ // short item can be read as int, long or String
- try
- {
- m2.getFloat("myShort");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ assertEquals((int) myShort, m2.getInt("myShort"));
+ assertEquals((long) myShort, m2.getLong("myShort"));
+ assertEquals(String.valueOf(myShort), m2.getString("myShort"));
- try
- {
- m2.getDouble("myShort");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getByte("myShort");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- // int item can be read as long or String
+ try
+ {
+ m2.getBoolean("myShort");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- assertEquals((long) myInt, m2.getLong("myInt"));
- assertEquals(String.valueOf(myInt), m2.getString("myInt"));
+ try
+ {
+ m2.getFloat("myShort");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getShort("myInt");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getDouble("myShort");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getByte("myInt");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ // int item can be read as long or String
- try
- {
- m2.getBoolean("myInt");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ assertEquals((long) myInt, m2.getLong("myInt"));
+ assertEquals(String.valueOf(myInt), m2.getString("myInt"));
- try
- {
- m2.getFloat("myInt");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getShort("myInt");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getDouble("myInt");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getByte("myInt");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- // long item can be read as String
+ try
+ {
+ m2.getBoolean("myInt");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- assertEquals(String.valueOf(myLong), m2.getString("myLong"));
+ try
+ {
+ m2.getFloat("myInt");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getInt("myLong");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getDouble("myInt");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getShort("myLong");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ // long item can be read as String
- try
- {
- m2.getByte("myLong");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ assertEquals(String.valueOf(myLong), m2.getString("myLong"));
- try
- {
- m2.getBoolean("myLong");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getInt("myLong");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getFloat("myLong");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getShort("myLong");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getDouble("myLong");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getByte("myLong");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- // float can be read as double or String
+ try
+ {
+ m2.getBoolean("myLong");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- assertEquals(String.valueOf(myFloat), m2.getString("myFloat"));
- assertEquals((double) myFloat, m2.getDouble("myFloat"), 0);
+ try
+ {
+ m2.getFloat("myLong");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getInt("myFloat");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getDouble("myLong");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getShort("myFloat");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ // float can be read as double or String
- try
- {
- m2.getLong("myFloat");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ assertEquals(String.valueOf(myFloat), m2.getString("myFloat"));
+ assertEquals((double) myFloat, m2.getDouble("myFloat"), 0);
- try
- {
- m2.getByte("myFloat");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getInt("myFloat");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getBoolean("myFloat");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getShort("myFloat");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- // double can be read as String
+ try
+ {
+ m2.getLong("myFloat");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- assertEquals(String.valueOf(myDouble), m2.getString("myDouble"));
+ try
+ {
+ m2.getByte("myFloat");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getFloat("myDouble");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getBoolean("myFloat");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getInt("myDouble");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ // double can be read as String
- try
- {
- m2.getShort("myDouble");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ assertEquals(String.valueOf(myDouble), m2.getString("myDouble"));
- try
- {
- m2.getByte("myDouble");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getFloat("myDouble");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getBoolean("myDouble");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getInt("myDouble");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- try
- {
- m2.getFloat("myDouble");
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ try
+ {
+ m2.getShort("myDouble");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- m2.clearBody();
+ try
+ {
+ m2.getByte("myDouble");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- assertFalse(m2.getMapNames().hasMoreElements());
+ try
+ {
+ m2.getBoolean("myDouble");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- // Test String -> Numeric and bool conversions
- MapMessage m3 = (MapMessage) queueProducerSession.createMapMessage();
+ try
+ {
+ m2.getFloat("myDouble");
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- m3.setString("myBool", String.valueOf(myBool));
- m3.setString("myByte", String.valueOf(myByte));
- m3.setString("myShort", String.valueOf(myShort));
- m3.setString("myInt", String.valueOf(myInt));
- m3.setString("myLong", String.valueOf(myLong));
- m3.setString("myFloat", String.valueOf(myFloat));
- m3.setString("myDouble", String.valueOf(myDouble));
- m3.setString("myIllegal", "xyz123");
+ m2.clearBody();
- assertEquals(myBool, m3.getBoolean("myBool"));
- assertEquals(myByte, m3.getByte("myByte"));
- assertEquals(myShort, m3.getShort("myShort"));
- assertEquals(myInt, m3.getInt("myInt"));
- assertEquals(myLong, m3.getLong("myLong"));
- assertEquals(myFloat, m3.getFloat("myFloat"), 0);
- assertEquals(myDouble, m3.getDouble("myDouble"), 0);
+ assertFalse(m2.getMapNames().hasMoreElements());
- m3.getBoolean("myIllegal");
+ // Test String -> Numeric and bool conversions
+ MapMessage m3 = (MapMessage) queueProducerSession.createMapMessage();
- try
- {
- m3.getByte("myIllegal");
- fail();
- }
- catch (NumberFormatException e)
- {
- }
- try
- {
- m3.getShort("myIllegal");
- fail();
- }
- catch (NumberFormatException e)
- {
- }
- try
- {
- m3.getInt("myIllegal");
- fail();
- }
- catch (NumberFormatException e)
- {
- }
- try
- {
- m3.getLong("myIllegal");
- fail();
- }
- catch (NumberFormatException e)
- {
- }
- try
- {
- m3.getFloat("myIllegal");
- fail();
- }
- catch (NumberFormatException e)
- {
- }
- try
- {
- m3.getDouble("myIllegal");
- fail();
- }
- catch (NumberFormatException e)
- {
- }
+ m3.setString("myBool", String.valueOf(myBool));
+ m3.setString("myByte", String.valueOf(myByte));
+ m3.setString("myShort", String.valueOf(myShort));
+ m3.setString("myInt", String.valueOf(myInt));
+ m3.setString("myLong", String.valueOf(myLong));
+ m3.setString("myFloat", String.valueOf(myFloat));
+ m3.setString("myDouble", String.valueOf(myDouble));
+ m3.setString("myIllegal", "xyz123");
- }
+ assertEquals(myBool, m3.getBoolean("myBool"));
+ assertEquals(myByte, m3.getByte("myByte"));
+ assertEquals(myShort, m3.getShort("myShort"));
+ assertEquals(myInt, m3.getInt("myInt"));
+ assertEquals(myLong, m3.getLong("myLong"));
+ assertEquals(myFloat, m3.getFloat("myFloat"), 0);
+ assertEquals(myDouble, m3.getDouble("myDouble"), 0);
- static class TestSerializable implements Serializable
- {
- private static final long serialVersionUID = -8641359255228705573L;
- String str;
- }
+ m3.getBoolean("myIllegal");
- public void testObjectMessage() throws Exception
- {
+ try
+ {
+ m3.getByte("myIllegal");
+ fail();
+ } catch (NumberFormatException e)
+ {
+ }
+ try
+ {
+ m3.getShort("myIllegal");
+ fail();
+ } catch (NumberFormatException e)
+ {
+ }
+ try
+ {
+ m3.getInt("myIllegal");
+ fail();
+ } catch (NumberFormatException e)
+ {
+ }
+ try
+ {
+ m3.getLong("myIllegal");
+ fail();
+ } catch (NumberFormatException e)
+ {
+ }
+ try
+ {
+ m3.getFloat("myIllegal");
+ fail();
+ } catch (NumberFormatException e)
+ {
+ }
+ try
+ {
+ m3.getDouble("myIllegal");
+ fail();
+ } catch (NumberFormatException e)
+ {
+ }
- TestSerializable obj = new TestSerializable();
- obj.str = "abcdefg";
+ }
- ObjectMessage m1 = queueProducerSession.createObjectMessage(obj);
+ static class TestSerializable implements Serializable
+ {
+ private static final long serialVersionUID = -8641359255228705573L;
- queueProducer.send(queue1, m1);
+ String str;
+ }
- ObjectMessage m2 = (ObjectMessage) queueConsumer.receive(2000);
+ public void testObjectMessage() throws Exception
+ {
+ TestSerializable obj = new TestSerializable();
- assertNotNull(m2);
+ obj.str = "abcdefg";
- TestSerializable obj2 = (TestSerializable) m2.getObject();
+ ObjectMessage m1 = queueProducerSession.createObjectMessage(obj);
- assertEquals(obj.str, obj2.str);
+ queueProducer.send(queue1, m1);
- ObjectMessage m3 = queueProducerSession.createObjectMessage();
- m3.setObject(obj);
+ ObjectMessage m2 = (ObjectMessage) queueConsumer.receive(2000);
- obj.str = "xyz123";
+ assertNotNull(m2);
- queueProducer.send(queue1, m3);
+ TestSerializable obj2 = (TestSerializable) m2.getObject();
- ObjectMessage m4 = (ObjectMessage) queueConsumer.receive(2000);
+ assertEquals(obj.str, obj2.str);
- assertNotNull(m4);
+ ObjectMessage m3 = queueProducerSession.createObjectMessage();
- TestSerializable obj3 = (TestSerializable) m4.getObject();
+ m3.setObject(obj);
+
+ // This basically tests that after setting the object - changing the objects fields doesn't
+ // change the set object - the object is carried in serialized form
- assertEquals("abcdefg", obj3.str);
+ obj.str = "xyz123";
- try
- {
- m4.setObject(obj);
- fail();
- }
- catch (MessageNotWriteableException e)
- {
- }
+ queueProducer.send(queue1, m3);
- m4.clearBody();
+ ObjectMessage m4 = (ObjectMessage) queueConsumer.receive(2000);
- m4.setObject(obj);
+ assertNotNull(m4);
- TestSerializable obj4 = (TestSerializable) m4.getObject();
+ TestSerializable obj3 = (TestSerializable) m4.getObject();
- assertNotNull(obj4);
+ assertEquals("abcdefg", obj3.str);
- }
+ try
+ {
+ m4.setObject(obj);
+ fail();
+ } catch (MessageNotWriteableException e)
+ {
+ }
- public void testStreamMessage() throws Exception
- {
- StreamMessage m = queueProducerSession.createStreamMessage();
+ m4.clearBody();
- //Some arbitrary values
- boolean myBool = true;
- byte myByte = -111;
- short myShort = 15321;
- int myInt = 0x71ab6c80;
- long myLong = 0x20bf1e3fb6fa31dfL;
- float myFloat = Float.MAX_VALUE - 23465;
- double myDouble = Double.MAX_VALUE - 72387633;
- String myString = "abcdef&^*&!^ghijkl\uD5E2\uCAC7\uD2BB\uB7DD\uB7C7\uB3A3\uBCE4\uB5A5";
- char myChar = 'q';
- byte[] myBytes = new byte[]
- {-23, 114, -126, -12, 74, 87};
+ m4.setObject(obj);
- m.writeBoolean(myBool);
- m.writeByte(myByte);
- m.writeShort(myShort);
- m.writeChar(myChar);
- m.writeInt(myInt);
- m.writeLong(myLong);
- m.writeFloat(myFloat);
- m.writeDouble(myDouble);
- m.writeString(myString);
- m.writeBytes(myBytes);
- m.writeBytes(myBytes, 2, 3);
+ TestSerializable obj4 = (TestSerializable) m4.getObject();
+ assertNotNull(obj4);
+ }
- m.writeObject(new Boolean(myBool));
- m.writeObject(new Byte(myByte));
- m.writeObject(new Short(myShort));
- m.writeObject(new Integer(myInt));
- m.writeObject(new Long(myLong));
- m.writeObject(new Float(myFloat));
- m.writeObject(new Double(myDouble));
- m.writeObject(myString);
- m.writeObject(myBytes);
+ public void testStreamMessage() throws Exception
+ {
+ StreamMessage m = queueProducerSession.createStreamMessage();
- try
- {
- m.writeObject(new Object());
- fail();
- }
- catch (MessageFormatException e)
- {
- }
+ // Some arbitrary values
+ boolean myBool = true;
+ byte myByte = -111;
+ short myShort = 15321;
+ int myInt = 0x71ab6c80;
+ long myLong = 0x20bf1e3fb6fa31dfL;
+ float myFloat = Float.MAX_VALUE - 23465;
+ double myDouble = Double.MAX_VALUE - 72387633;
+ String myString = "abcdef&^*&!^ghijkl\uD5E2\uCAC7\uD2BB\uB7DD\uB7C7\uB3A3\uBCE4\uB5A5";
+ char myChar = 'q';
+ byte[] myBytes = new byte[] { -23, 114, -126, -12, 74, 87 };
- //Reading should not be possible when message is read-write
- try
- {
- m.readBoolean();
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- }
- try
- {
- m.readShort();
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- }
- try
- {
- m.readChar();
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- }
- try
- {
- m.readInt();
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- }
- try
- {
- m.readLong();
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- }
- try
- {
- m.readFloat();
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- }
- try
- {
- m.readDouble();
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- }
- try
- {
- byte[] bytes = new byte[333];
- m.readBytes(bytes);
- fail();
- }
- catch (javax.jms.MessageNotReadableException e)
- {
- }
+ m.writeBoolean(myBool);
+ m.writeByte(myByte);
+ m.writeShort(myShort);
+ m.writeChar(myChar);
+ m.writeInt(myInt);
+ m.writeLong(myLong);
+ m.writeFloat(myFloat);
+ m.writeDouble(myDouble);
+ m.writeString(myString);
+ m.writeBytes(myBytes);
+ m.writeBytes(myBytes, 2, 3);
- queueProducer.send(queue1, m);
+ m.writeObject(new Boolean(myBool));
+ m.writeObject(new Byte(myByte));
+ m.writeObject(new Short(myShort));
+ m.writeObject(new Integer(myInt));
+ m.writeObject(new Long(myLong));
+ m.writeObject(new Float(myFloat));
+ m.writeObject(new Double(myDouble));
+ m.writeObject(myString);
+ m.writeObject(myBytes);
- StreamMessage m2 = (StreamMessage) queueConsumer.receive(2000);
+ try
+ {
+ m.writeObject(new Object());
+ fail();
+ } catch (MessageFormatException e)
+ {
+ }
- assertEquals(myBool, m2.readBoolean());
- assertEquals(myByte, m2.readByte());
- assertEquals(myShort, m2.readShort());
- assertEquals(myChar, m2.readChar());
- assertEquals(myInt, m2.readInt());
- assertEquals(myLong, m2.readLong());
- assertEquals(myFloat, m2.readFloat(), 0);
- assertEquals(myDouble, m2.readDouble(), 0);
- assertEquals(myString, m2.readString());
+ // Reading should not be possible when message is read-write
+ try
+ {
+ m.readBoolean();
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ }
+ try
+ {
+ m.readShort();
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ }
+ try
+ {
+ m.readChar();
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ }
+ try
+ {
+ m.readInt();
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ }
+ try
+ {
+ m.readLong();
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ }
+ try
+ {
+ m.readFloat();
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ }
+ try
+ {
+ m.readDouble();
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ }
+ try
+ {
+ byte[] bytes = new byte[333];
+ m.readBytes(bytes);
+ fail();
+ } catch (javax.jms.MessageNotReadableException e)
+ {
+ }
- byte[] bytes = new byte[6];
- int ret = m2.readBytes(bytes);
- assertEquals(6, ret);
+ queueProducer.send(queue1, m);
- assertByteArraysEqual(myBytes, bytes);
+ StreamMessage m2 = (StreamMessage) queueConsumer.receive(2000);
- ret = m2.readBytes(bytes);
- assertEquals(-1, ret);
+ assertEquals(myBool, m2.readBoolean());
+ assertEquals(myByte, m2.readByte());
+ assertEquals(myShort, m2.readShort());
+ assertEquals(myChar, m2.readChar());
+ assertEquals(myInt, m2.readInt());
+ assertEquals(myLong, m2.readLong());
+ assertEquals(myFloat, m2.readFloat(), 0);
+ assertEquals(myDouble, m2.readDouble(), 0);
+ assertEquals(myString, m2.readString());
- byte[] bytes2 = new byte[3];
- ret = m2.readBytes(bytes2);
+ byte[] bytes = new byte[6];
+ int ret = m2.readBytes(bytes);
+ assertEquals(6, ret);
- assertEquals(3, ret);
+ assertByteArraysEqual(myBytes, bytes);
- assertEquals(myBytes[2], bytes2[0]);
- assertEquals(myBytes[3], bytes2[1]);
- assertEquals(myBytes[4], bytes2[2]);
+ ret = m2.readBytes(bytes);
+ assertEquals(-1, ret);
- ret = m2.readBytes(bytes2);
- assertEquals(-1, ret);
+ byte[] bytes2 = new byte[3];
+ ret = m2.readBytes(bytes2);
- assertEquals(myBool, m2.readBoolean());
- assertEquals(myByte, m2.readByte());
- assertEquals(myShort, m2.readShort());
- assertEquals(myInt, m2.readInt());
- assertEquals(myLong, m2.readLong());
- assertEquals(myFloat, m2.readFloat(), 0);
- assertEquals(myDouble, m2.readDouble(), 0);
- assertEquals(myString, m2.readString());
+ assertEquals(3, ret);
- bytes = new byte[6];
- ret = m2.readBytes(bytes);
- assertEquals(6, ret);
- assertByteArraysEqual(myBytes, bytes);
+ assertEquals(myBytes[2], bytes2[0]);
+ assertEquals(myBytes[3], bytes2[1]);
+ assertEquals(myBytes[4], bytes2[2]);
- ret = m2.readBytes(bytes);
- assertEquals(-1, ret);
+ ret = m2.readBytes(bytes2);
+ assertEquals(-1, ret);
- //Try and read past the end of the stream
- try
- {
- m2.readBoolean();
- fail();
- }
- catch (MessageEOFException e)
- {
- }
+ assertEquals(myBool, m2.readBoolean());
+ assertEquals(myByte, m2.readByte());
+ assertEquals(myShort, m2.readShort());
+ assertEquals(myInt, m2.readInt());
+ assertEquals(myLong, m2.readLong());
+ assertEquals(myFloat, m2.readFloat(), 0);
+ assertEquals(myDouble, m2.readDouble(), 0);
+ assertEquals(myString, m2.readString());
- try
- {
- m2.readByte();
- fail();
- }
- catch (MessageEOFException e)
- {
- }
+ bytes = new byte[6];
+ ret = m2.readBytes(bytes);
+ assertEquals(6, ret);
+ assertByteArraysEqual(myBytes, bytes);
- try
- {
- m2.readChar();
- fail();
- }
- catch (MessageEOFException e)
- {
- }
+ ret = m2.readBytes(bytes);
+ assertEquals(-1, ret);
- try
- {
- m2.readDouble();
- fail();
- }
- catch (MessageEOFException e)
- {
- }
+ // Try and read past the end of the stream
+ try
+ {
+ m2.readBoolean();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ }
- try
- {
- m2.readFloat();
- fail();
- }
- catch (MessageEOFException e)
- {
- }
+ try
+ {
+ m2.readByte();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ }
- try
- {
- m2.readInt();
- fail();
- }
- catch (MessageEOFException e)
- {
- }
+ try
+ {
+ m2.readChar();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ }
- try
- {
- m2.readLong();
- fail();
- }
- catch (MessageEOFException e)
- {
- }
+ try
+ {
+ m2.readDouble();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ }
- try
- {
- m2.readShort();
- fail();
- }
- catch (MessageEOFException e)
- {
- }
+ try
+ {
+ m2.readFloat();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ }
- //Message should not be writable in read-only mode
- try
- {
- m2.writeBoolean(myBool);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- }
- try
- {
- m2.writeByte(myByte);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- }
- try
- {
- m2.writeShort(myShort);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- }
- try
- {
- m2.writeChar(myChar);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- }
+ try
+ {
+ m2.readInt();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ }
- try
- {
- m2.writeInt(myInt);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- }
- try
- {
- m2.writeLong(myLong);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- }
- try
- {
- m2.writeFloat(myFloat);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- }
- try
- {
- m2.writeDouble(myDouble);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- }
+ try
+ {
+ m2.readLong();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ }
- try
- {
- m2.writeBytes(myBytes);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- }
+ try
+ {
+ m2.readShort();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ }
- try
- {
- m2.writeObject(myString);
- fail();
- }
- catch (javax.jms.MessageNotWriteableException e)
- {
- }
+ // Message should not be writable in read-only mode
+ try
+ {
+ m2.writeBoolean(myBool);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ }
+ try
+ {
+ m2.writeByte(myByte);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ }
+ try
+ {
+ m2.writeShort(myShort);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ }
+ try
+ {
+ m2.writeChar(myChar);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ }
- m2.reset();
+ try
+ {
+ m2.writeInt(myInt);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ }
+ try
+ {
+ m2.writeLong(myLong);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ }
+ try
+ {
+ m2.writeFloat(myFloat);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ }
+ try
+ {
+ m2.writeDouble(myDouble);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ }
- // check we go back to the beginning
- assertEquals(myBool, m2.readBoolean());
- assertEquals(myByte, m2.readByte());
- assertEquals(myShort, m2.readShort());
- assertEquals(myChar, m2.readChar());
- assertEquals(myInt, m2.readInt());
- assertEquals(myLong, m2.readLong());
- assertEquals(myFloat, m2.readFloat(), 0);
- assertEquals(myDouble, m2.readDouble(), 0);
- assertEquals(myString, m2.readString());
+ try
+ {
+ m2.writeBytes(myBytes);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ }
- m2.clearBody();
+ try
+ {
+ m2.writeObject(myString);
+ fail();
+ } catch (javax.jms.MessageNotWriteableException e)
+ {
+ }
- try
- {
- //Should now be write only
- m2.readBoolean();
- fail();
- }
- catch (MessageNotReadableException e)
- {
- }
+ m2.reset();
- m2.writeBoolean(myBool);
+ // check we go back to the beginning
+ assertEquals(myBool, m2.readBoolean());
+ assertEquals(myByte, m2.readByte());
+ assertEquals(myShort, m2.readShort());
+ assertEquals(myChar, m2.readChar());
+ assertEquals(myInt, m2.readInt());
+ assertEquals(myLong, m2.readLong());
+ assertEquals(myFloat, m2.readFloat(), 0);
+ assertEquals(myDouble, m2.readDouble(), 0);
+ assertEquals(myString, m2.readString());
- m2.reset();
+ m2.clearBody();
- assertEquals(myBool, m2.readBoolean());
- try
- {
- m2.readBoolean();
- fail();
- }
- catch (MessageEOFException e)
- {
- }
+ try
+ {
+ // Should now be write only
+ m2.readBoolean();
+ fail();
+ } catch (MessageNotReadableException e)
+ {
+ }
- //Test that changing the received message doesn't affect the sent message
- m.reset();
- assertEquals(myBool, m.readBoolean());
- assertEquals(myByte, m.readByte());
- assertEquals(myShort, m.readShort());
- assertEquals(myChar, m.readChar());
- assertEquals(myInt, m.readInt());
- assertEquals(myLong, m.readLong());
- assertEquals(myFloat, m.readFloat(), 0);
- assertEquals(myDouble, m.readDouble(), 0);
- assertEquals(myString, m.readString());
+ m2.writeBoolean(myBool);
- //Should be diffent object instances after sending *even* if in same JVM
- assertFalse(m == m2);
+ m2.reset();
- }
+ assertEquals(myBool, m2.readBoolean());
+ try
+ {
+ m2.readBoolean();
+ fail();
+ } catch (MessageEOFException e)
+ {
+ }
- public void testTextMessage() throws Exception
- {
- TextMessage m = queueProducerSession.createTextMessage();
+ // Test that changing the received message doesn't affect the sent message
+ m.reset();
+ assertEquals(myBool, m.readBoolean());
+ assertEquals(myByte, m.readByte());
+ assertEquals(myShort, m.readShort());
+ assertEquals(myChar, m.readChar());
+ assertEquals(myInt, m.readInt());
+ assertEquals(myLong, m.readLong());
+ assertEquals(myFloat, m.readFloat(), 0);
+ assertEquals(myDouble, m.readDouble(), 0);
+ assertEquals(myString, m.readString());
- //Arbitrary string with some Chinese characters to make sure UTF encoding is ok
- String myString = "wwiuhdiuwhdwuhdwuhduqwhdiuwhdiuhwed8u29837482787\uD5E2\uCAC7\uD2BB\uB7DD\uB7C7\uB3A3\uBCE4\uB5A5";
+ // Should be diffent object instances after sending *even* if in same JVM
+ assertFalse(m == m2);
+ }
- m.setText(myString);
+ public void testTextMessage() throws Exception
+ {
+ TextMessage m = queueProducerSession.createTextMessage();
- queueProducer.send(queue1, m);
+ // Arbitrary string with some Chinese characters to make sure UTF encoding
+ // is ok
+ String myString = "wwiuhdiuwhdwuhdwuhduqwhdiuwhdiuhwed8u29837482787\uD5E2\uCAC7\uD2BB\uB7DD\uB7C7\uB3A3\uBCE4\uB5A5";
- TextMessage m2 = (TextMessage)queueConsumer.receive(2000);
+ m.setText(myString);
- assertEquals(myString, m2.getText());
+ queueProducer.send(queue1, m);
- m = queueProducerSession.createTextMessage(myString);
- queueProducer.send(queue1, m);
+ TextMessage m2 = (TextMessage) queueConsumer.receive(2000);
- m2 = (TextMessage)queueConsumer.receive(2000);
+ assertEquals(myString, m2.getText());
- assertEquals(myString, m2.getText());
+ m = queueProducerSession.createTextMessage(myString);
+ queueProducer.send(queue1, m);
- try
- {
- m2.setText("Should be read-only");
- fail();
- }
- catch(MessageNotWriteableException e)
- {}
+ m2 = (TextMessage) queueConsumer.receive(2000);
- m2.clearBody();
- assertNull(m2.getText());
- m2.setText("Now it is read-write");
+ assertEquals(myString, m2.getText());
+ try
+ {
+ m2.setText("Should be read-only");
+ fail();
+ } catch (MessageNotWriteableException e)
+ {
+ }
- }
+ m2.clearBody();
+ assertNull(m2.getText());
+ m2.setText("Now it is read-write");
+ }
- // Package protected ---------------------------------------------
+ // Package protected ---------------------------------------------
- // Protected -----------------------------------------------------
+ // Protected -----------------------------------------------------
- // Private -------------------------------------------------------
+ // Private -------------------------------------------------------
- private void assertByteArraysEqual(byte[] bytes1, byte[] bytes2)
- {
- if (bytes1 == null | bytes2 == null)
- {
- fail();
- }
+ private void assertByteArraysEqual(byte[] bytes1, byte[] bytes2)
+ {
+ if (bytes1 == null | bytes2 == null)
+ {
+ fail();
+ }
- if (bytes1.length != bytes2.length)
- {
- fail();
- }
+ if (bytes1.length != bytes2.length)
+ {
+ fail();
+ }
- for (int i = 0; i < bytes1.length; i++)
- {
- assertEquals(bytes1[i], bytes2[i]);
- }
+ for (int i = 0; i < bytes1.length; i++)
+ {
+ assertEquals(bytes1[i], bytes2[i]);
+ }
- }
+ }
- // Inner classes -------------------------------------------------
+ // Inner classes -------------------------------------------------
}
Modified: trunk/tests/src/org/jboss/test/messaging/jms/persistence/MessagePersistenceManagerTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/persistence/MessagePersistenceManagerTest.java 2007-10-12 14:31:28 UTC (rev 3189)
+++ trunk/tests/src/org/jboss/test/messaging/jms/persistence/MessagePersistenceManagerTest.java 2007-10-15 13:03:24 UTC (rev 3190)
@@ -135,8 +135,6 @@
m.setJMSType("testType");
setCorrelationID(m, i);
- m.setPayload(new WibblishObject());
-
return m;
}
@@ -191,9 +189,7 @@
byte[] bytes = new GUID().toString().getBytes();
m.setJMSCorrelationIDAsBytes(bytes);
}
- }
-
-
+ }
}
More information about the jboss-cvs-commits
mailing list