activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r821053 - in /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src: main/csharp/Commands/ActiveMQBytesMessage.cs main/csharp/Commands/ActiveMQMessage.cs main/csharp/Connection.cs test/csharp/Commands/ActiveMQBytesMessageTest.cs
Date Fri, 02 Oct 2009 15:21:23 GMT
Author: tabish
Date: Fri Oct  2 15:21:20 2009
New Revision: 821053

URL: http://svn.apache.org/viewvc?rev=821053&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQNET-162

Implemented the new IMessage and IBytesMessage methods in the Commands and added code to the
Connection to set the Message contents read-only on receive.  Clients must call ClearBody
and ClearProperties to reuse a Message object.

Added testing for the new methods.

Added:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Commands/ActiveMQBytesMessageTest.cs
  (with props)
Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQBytesMessage.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Connection.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQBytesMessage.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQBytesMessage.cs?rev=821053&r1=821052&r2=821053&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQBytesMessage.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQBytesMessage.cs
Fri Oct  2 15:21:20 2009
@@ -14,20 +14,491 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-using Apache.NMS;
 
+using Apache.NMS;
+using Apache.NMS.Util;
+using System;
+using System.Collections;
+using System.IO;
 
 namespace Apache.NMS.ActiveMQ.Commands
 {
     public class ActiveMQBytesMessage : ActiveMQMessage, IBytesMessage
     {
         public const byte ID_ACTIVEMQBYTESMESSAGE = 24;
-
+        
+        private EndianBinaryReader dataIn = null;
+        private EndianBinaryWriter dataOut = null;
+        private MemoryStream outputBuffer = null;
+        
+        // Need this later when we add compression to store true content length.
+        private long length = 0;
 
         public override byte GetDataStructureType()
         {
             return ID_ACTIVEMQBYTESMESSAGE;
         }
+
+        public override Object Clone()
+        {
+            StoreContent();
+            return base.Clone();
+        }
+
+        public override void OnSend()
+        {
+            base.OnSend();
+            StoreContent();                         
+        }
+        
+        public override void ClearBody()
+        {
+            base.ClearBody();
+            this.outputBuffer = null;
+            this.dataIn = null;
+            this.dataOut = null;
+            this.length = 0;
+        }
+        
+        public long BodyLength
+        { 
+            get
+            {
+                InitializeReading();
+                return this.length;
+            }
+        }
+        
+        public byte ReadByte()
+        {
+            InitializeReading();
+            try
+            {
+                return dataIn.ReadByte();
+            }
+            catch(EndOfStreamException e)
+            {
+                throw NMSExceptionSupport.createMessageEOFException(e);
+            }
+            catch(IOException e)
+            {
+                throw NMSExceptionSupport.createMessageFormatException(e);
+            }
+        }
+        
+        public void WriteByte( byte value )
+        {
+            InitializeWriting();
+            try
+            {
+                dataOut.Write( value );
+            }
+            catch(Exception e)
+            {
+                throw NMSExceptionSupport.create(e);
+            }            
+        }
+        
+        public bool ReadBoolean()
+        {
+            InitializeReading();
+            try
+            {
+                return dataIn.ReadBoolean();
+            }
+            catch(EndOfStreamException e)
+            {
+                throw NMSExceptionSupport.createMessageEOFException(e);
+            }
+            catch(IOException e)
+            {
+                throw NMSExceptionSupport.createMessageFormatException(e);
+            }
+        }
+
+        public void WriteBoolean( bool value )
+        {
+            InitializeWriting();
+            try
+            {
+                dataOut.Write( value );
+            }
+            catch(Exception e)
+            {
+                throw NMSExceptionSupport.create(e);
+            }     
+        }
+        
+        public char ReadChar()
+        {
+            InitializeReading();
+            try
+            {
+                return dataIn.ReadChar();
+            }
+            catch(EndOfStreamException e)
+            {
+                throw NMSExceptionSupport.createMessageEOFException(e);
+            }
+            catch(IOException e)
+            {
+                throw NMSExceptionSupport.createMessageFormatException(e);
+            }
+        }
+   
+        public void WriteChar( char value )
+        {
+            InitializeWriting();
+            try
+            {
+                dataOut.Write( value );
+            }
+            catch(Exception e)
+            {
+                throw NMSExceptionSupport.create(e);
+            }     
+        }
+       
+        public short ReadInt16()
+        {
+            InitializeReading();
+            try
+            {
+                return dataIn.ReadInt16();
+            }
+            catch(EndOfStreamException e)
+            {
+                throw NMSExceptionSupport.createMessageEOFException(e);
+            }
+            catch(IOException e)
+            {
+                throw NMSExceptionSupport.createMessageFormatException(e);
+            }
+        }
+        
+        public void WriteInt16( short value )
+        {
+            InitializeWriting();
+            try
+            {
+                dataOut.Write( value );
+            }
+            catch(Exception e)
+            {
+                throw NMSExceptionSupport.create(e);
+            }     
+        }
+                
+        public int ReadInt32()
+        {
+            InitializeReading();
+            try
+            {
+                return dataIn.ReadInt32();
+            }
+            catch(EndOfStreamException e)
+            {
+                throw NMSExceptionSupport.createMessageEOFException(e);
+            }
+            catch(IOException e)
+            {
+                throw NMSExceptionSupport.createMessageFormatException(e);
+            }
+        }
+            
+        public void WriteInt32( int value )
+        {
+            InitializeWriting();
+            try
+            {
+                dataOut.Write( value );
+            }
+            catch(Exception e)
+            {
+                throw NMSExceptionSupport.create(e);
+            }     
+        }
+                 
+        public long ReadInt64()
+        {
+            InitializeReading();
+            try
+            {
+                return dataIn.ReadInt64();
+            }
+            catch(EndOfStreamException e)
+            {
+                throw NMSExceptionSupport.createMessageEOFException(e);
+            }
+            catch(IOException e)
+            {
+                throw NMSExceptionSupport.createMessageFormatException(e);
+            }
+        }
+                
+        public void WriteInt64( long value )
+        {
+            InitializeWriting();
+            try
+            {
+                dataOut.Write( value );
+            }
+            catch(Exception e)
+            {
+                throw NMSExceptionSupport.create(e);
+            }     
+        }
+              
+        public float ReadSingle()
+        {
+            InitializeReading();
+            try
+            {
+                return dataIn.ReadSingle();
+            }
+            catch(EndOfStreamException e)
+            {
+                throw NMSExceptionSupport.createMessageEOFException(e);
+            }
+            catch(IOException e)
+            {
+                throw NMSExceptionSupport.createMessageFormatException(e);
+            }
+        }
+
+        public void WriteSingle( float value )
+        {
+            InitializeWriting();
+            try
+            {
+                dataOut.Write( value );
+            }
+            catch(Exception e)
+            {
+                throw NMSExceptionSupport.create(e);
+            }     
+        }
+
+        public double ReadDouble()
+        {
+            InitializeReading();
+            try
+            {
+                return dataIn.ReadDouble();
+            }
+            catch(EndOfStreamException e)
+            {
+                throw NMSExceptionSupport.createMessageEOFException(e);
+            }
+            catch(IOException e)
+            {
+                throw NMSExceptionSupport.createMessageFormatException(e);
+            }
+        }
+               
+        public void WriteDouble( double value )
+        {
+            InitializeWriting();
+            try
+            {
+                dataOut.Write( value );
+            }
+            catch(Exception e)
+            {
+                throw NMSExceptionSupport.create(e);
+            }     
+        }            
+             
+        public int ReadBytes( byte[] value )
+        {
+            InitializeReading();
+            try
+            {
+                return dataIn.Read( value, 0, value.Length );
+            }
+            catch(EndOfStreamException e)
+            {
+                throw NMSExceptionSupport.createMessageEOFException(e);
+            }
+            catch(IOException e)
+            {
+                throw NMSExceptionSupport.createMessageFormatException(e);
+            }
+        }
+                   
+        public int ReadBytes( byte[] value, int length )
+        {
+            InitializeReading();
+            try
+            {
+                return dataIn.Read( value, 0, length );
+            }
+            catch(EndOfStreamException e)
+            {
+                throw NMSExceptionSupport.createMessageEOFException(e);
+            }
+            catch(IOException e)
+            {
+                throw NMSExceptionSupport.createMessageFormatException(e);
+            }           
+        }
+              
+        public void WriteBytes( byte[] value )
+        {
+            InitializeWriting();
+            try
+            {
+                dataOut.Write( value, 0, value.Length );
+            }
+            catch(Exception e)
+            {
+                throw NMSExceptionSupport.create(e);
+            }     
+        }
+       
+        public void WriteBytes( byte[] value, int offset, int length )
+        {
+            InitializeWriting();
+            try
+            {
+                dataOut.Write( value, offset, length );
+            }
+            catch(Exception e)
+            {
+                throw NMSExceptionSupport.create(e);
+            }     
+        }
+
+        public string ReadString()
+        {
+            InitializeReading();
+            try
+            {
+                // JMS, CMS and NMS all encode the String using a 16 bit size header.
+                return dataIn.ReadString16();
+            }
+            catch(EndOfStreamException e)
+            {
+                throw NMSExceptionSupport.createMessageEOFException(e);
+            }
+            catch(IOException e)
+            {
+                throw NMSExceptionSupport.createMessageFormatException(e);
+            }
+        }
+         
+        public void WriteString( string value )
+        {
+            InitializeWriting();
+            try
+            {
+                // JMS, CMS and NMS all encode the String using a 16 bit size header.
+                dataOut.WriteString16(value);
+            }
+            catch(Exception e)
+            {
+                throw NMSExceptionSupport.create(e);
+            }   
+        }
+        
+        public void WriteObject( System.Object value )
+        {
+            InitializeWriting();
+            if( value is System.Byte )
+            {
+                this.dataOut.Write( (byte) value );
+            }
+            else if( value is Char )
+            {
+                this.dataOut.Write( (char) value );
+            }
+            else if( value is Boolean )
+            {
+                this.dataOut.Write( (bool) value );
+            }
+            else if( value is Int16 )
+            {
+                this.dataOut.Write( (short) value );
+            }
+            else if( value is Int32 )
+            {
+                this.dataOut.Write( (int) value );
+            }
+            else if( value is Int64 )
+            {
+                this.dataOut.Write( (long) value );
+            }
+            else if( value is Single )
+            {
+                this.dataOut.Write( (float) value );
+            }
+            else if( value is Double )
+            {
+                this.dataOut.Write( (double) value );
+            }
+            else if( value is byte[] )
+            {
+                this.dataOut.Write( (byte[]) value );
+            }
+            else if( value is String )
+            {
+                this.dataOut.WriteString16( (string) value );
+            }
+            else
+            {
+                throw new MessageFormatException("Cannot write non-primitive type:" + value.GetType());
+            }
+        }
+        
+        public void Reset()
+        {
+            StoreContent();
+            this.dataIn = null;
+            this.dataOut = null;
+            this.outputBuffer = null;
+            this.ReadOnlyBody = true;        
+        }
+        
+        private void InitializeReading() 
+        {
+            FailIfWriteOnlyBody();
+            if(this.dataIn == null)
+            {
+                if(this.Content != null)
+                {
+                    this.length = this.Content.Length;
+                }
+                
+                // TODO - Add support for Message Compression.
+                MemoryStream bytesIn = new MemoryStream(this.Content, false);
+                dataIn = new EndianBinaryReader(bytesIn);
+            }
+        }
+        
+        private void InitializeWriting()
+        {
+            FailIfReadOnlyBody();
+            if(this.dataOut == null) 
+            {
+                // TODO - Add support for Message Compression.
+                this.outputBuffer = new MemoryStream();
+                this.dataOut = new EndianBinaryWriter(outputBuffer);
+            }
+        }
+        
+        private void StoreContent()
+        {
+            if( dataOut != null)
+            {
+                dataOut.Close();
+                // TODO - Add support for Message Compression.
+
+                this.Content = outputBuffer.ToArray();
+                this.dataOut = null;
+                this.outputBuffer = null;
+            }
+        }
+            
     }
 }
 

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs?rev=821053&r1=821052&r2=821053&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
(original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Commands/ActiveMQMessage.cs
Fri Oct  2 15:21:20 2009
@@ -63,6 +63,35 @@
 				Acknowledger(this);
 			}
 		}
+        
+        public virtual void ClearBody()
+        {
+            this.Content = null;
+            this.readOnlyMsgBody = false;
+        }
+        
+        public virtual void ClearProperties()
+        {
+            this.MarshalledProperties = null;
+            this.Properties.Clear();
+            this.readOnlyMsgProperties = false;
+        }
+        
+        protected void FailIfReadOnlyBody()
+        {
+            if(ReadOnlyBody == true)
+            {
+                throw new MessageNotWriteableException("Message is in Read-Only mode.");
+            }
+        }
+
+        protected void FailIfWriteOnlyBody()
+        {
+            if( ReadOnlyBody == false )
+            {
+                throw new MessageNotReadableException("Message is in Write-Only mode.");
+            }
+        }
 
 		#region Properties
 

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Connection.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Connection.cs?rev=821053&r1=821052&r2=821053&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Connection.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/Connection.cs Fri Oct
 2 15:21:20 2009
@@ -572,6 +572,9 @@
 			// This is a bit of a hack since we should really be sending the entire dispatch to
 			// the Consumer.
 			dispatch.Message.Destination = dispatch.Destination;
+            dispatch.Message.ReadOnlyBody = true;
+            dispatch.Message.ReadOnlyProperties = true;
+            dispatch.Message.RedeliveryCounter = dispatch.RedeliveryCounter;
 
 			lock(sessions.SyncRoot)
 			{

Added: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Commands/ActiveMQBytesMessageTest.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Commands/ActiveMQBytesMessageTest.cs?rev=821053&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Commands/ActiveMQBytesMessageTest.cs
(added)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Commands/ActiveMQBytesMessageTest.cs
Fri Oct  2 15:21:20 2009
@@ -0,0 +1,526 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using NUnit.Framework;
+using System;
+using System.Text;
+using Apache.NMS.ActiveMQ.Commands;
+
+namespace Apache.NMS.ActiveMQ.Test.Commands
+{
+    [TestFixture]
+	public class ActiveMQBytesMessageTest
+	{
+		[Test]
+		public void TestCommand()
+		{
+			ActiveMQBytesMessage message = new ActiveMQBytesMessage();
+			
+			Assert.IsNull( message.Content );
+			Assert.IsTrue( !message.ReadOnlyBody );
+			Assert.IsTrue( !message.ReadOnlyProperties );
+		}
+
+		[Test]
+	    public void TestGetBodyLength() 
+		{
+	        ActiveMQBytesMessage msg = new ActiveMQBytesMessage();
+	        int len = 10;
+
+            for(int i = 0; i < len; i++)
+			{
+                msg.WriteInt64(5L);
+            }
+
+            msg.Reset();
+            Assert.IsTrue(msg.BodyLength == (len * 8));
+	    }
+
+		[Test]
+	    public void TestReadBoolean() 
+		{
+	        ActiveMQBytesMessage msg = new ActiveMQBytesMessage();
+            msg.WriteBoolean(true);
+            msg.Reset();
+            Assert.IsTrue(msg.ReadBoolean());
+	    }
+	
+		[Test]
+	    public void TestReadByte()
+		{
+	        ActiveMQBytesMessage msg = new ActiveMQBytesMessage();
+            msg.WriteByte( (byte)2 );
+            msg.Reset();
+            Assert.IsTrue( msg.ReadByte() == 2 );
+	    }
+	
+		[Test]
+	    public void TestReadShort() {
+	        ActiveMQBytesMessage msg = new ActiveMQBytesMessage();
+            msg.WriteInt16((short) 3000);
+            msg.Reset();
+            Assert.IsTrue(msg.ReadInt16() == 3000);
+	    }
+	
+		[Test]
+	    public void TestReadChar() {
+	        ActiveMQBytesMessage msg = new ActiveMQBytesMessage();
+            msg.WriteChar('a');
+            msg.Reset();
+            Assert.IsTrue(msg.ReadChar() == 'a');
+	    }
+	
+		[Test]
+	    public void TestReadInt() {
+	        ActiveMQBytesMessage msg = new ActiveMQBytesMessage();
+            msg.WriteInt32(3000);
+            msg.Reset();
+            Assert.IsTrue(msg.ReadInt32() == 3000);
+	    }
+	
+		[Test]
+	    public void TestReadLong() {
+	        ActiveMQBytesMessage msg = new ActiveMQBytesMessage();
+            msg.WriteInt64(3000);
+            msg.Reset();
+            Assert.IsTrue(msg.ReadInt64() == 3000);
+	    }
+	
+		[Test]
+	    public void TestReadFloat() {
+	        ActiveMQBytesMessage msg = new ActiveMQBytesMessage();
+            msg.WriteSingle(3.3f);
+            msg.Reset();
+            Assert.IsTrue(msg.ReadSingle() == 3.3f);
+	    }
+	
+		[Test]
+	    public void TestReadDouble() {
+	        ActiveMQBytesMessage msg = new ActiveMQBytesMessage();
+            msg.WriteDouble(3.3d);
+            msg.Reset();
+            Assert.IsTrue(msg.ReadDouble() == 3.3d);
+	    }
+	
+		[Test]
+	    public void TestReadString() {
+	        ActiveMQBytesMessage msg = new ActiveMQBytesMessage();
+            string str = "this is a test";
+            msg.WriteString(str);
+            msg.Reset();
+            Assert.IsTrue(msg.ReadString() == str);
+	    }
+	
+		[Test]
+	    public void TestReadBytesbyteArray() 
+		{
+	        ActiveMQBytesMessage msg = new ActiveMQBytesMessage();
+            byte[] data = new byte[50];
+            for(int i = 0; i < data.Length; i++) 
+			{
+                data[i] = (byte) i;
+            }
+            msg.WriteBytes(data);
+            msg.Reset();
+            byte[] test = new byte[data.Length];
+            msg.ReadBytes(test);
+            for(int i = 0; i < test.Length; i++) 
+			{
+                Assert.IsTrue(test[i] == i);
+            }
+	    }
+	
+		[Test]
+	    public void TestWriteObject()
+		{
+	        ActiveMQBytesMessage msg = new ActiveMQBytesMessage();
+			
+	        try
+			{
+	            msg.WriteObject("fred");
+	            msg.WriteObject((Boolean) true);
+	            msg.WriteObject((Char) 'q');
+	            msg.WriteObject((Byte) ((byte) 1));
+	            msg.WriteObject((Int16) ((short) 3));
+	            msg.WriteObject((Int32) 3 );
+	            msg.WriteObject((Int64) 300L);
+	            msg.WriteObject((Single) 3.3f );
+	            msg.WriteObject((Double) 3.3 );
+	            msg.WriteObject((Object) new byte[3]);
+	        } 
+			catch(MessageFormatException) 
+			{
+	            Assert.Fail("objectified primitives should be allowed");
+	        }
+			
+	        try 
+			{
+	            msg.WriteObject(new Object());
+	            Assert.Fail("only objectified primitives are allowed");
+	        } 
+			catch(MessageFormatException ) 
+			{
+	        }
+	    }
+
+		[Test]
+	    public void TestClearBody() {
+	        ActiveMQBytesMessage bytesMessage = new ActiveMQBytesMessage();
+	        try {
+	            bytesMessage.WriteInt32(1);
+	            bytesMessage.ClearBody();
+	            Assert.IsFalse(bytesMessage.ReadOnlyBody);
+	            bytesMessage.WriteInt32(1);
+	            bytesMessage.ReadInt32();
+	        } 
+			catch(MessageNotReadableException) 
+			{
+	        } 
+			catch(MessageNotWriteableException)
+			{
+	            Assert.IsTrue(false);
+	        }
+	    }
+
+		[Test]
+	    public void TestReset() {
+
+			ActiveMQBytesMessage message = new ActiveMQBytesMessage();
+	        
+			try 
+			{
+	            message.WriteDouble(24.5);
+	            message.WriteInt64(311);
+	        } 
+			catch(MessageNotWriteableException)
+			{
+	            Assert.Fail("should be writeable");
+	        }
+	        
+			message.Reset();
+	        
+			try {
+	            Assert.IsTrue(message.ReadOnlyBody);
+	            Assert.AreEqual(message.ReadDouble(), 24.5, 0);
+	            Assert.AreEqual(message.ReadInt64(), 311);
+	        } 
+			catch(MessageNotReadableException) 
+			{
+	            Assert.Fail("should be readable");
+	        }
+	        
+			try
+			{
+	            message.WriteInt32(33);
+	            Assert.Fail("should throw exception");
+	        }
+			catch(MessageNotWriteableException)
+			{
+	        }
+	    }
+	
+		[Test]
+	    public void TestReadOnlyBody()
+		{
+	        ActiveMQBytesMessage message = new ActiveMQBytesMessage();
+	        try {
+	            message.WriteBoolean(true);
+	            message.WriteByte((byte) 1);
+	            message.WriteBytes(new byte[1]);
+	            message.WriteBytes(new byte[3], 0, 2);
+	            message.WriteChar('a');
+	            message.WriteDouble(1.5);
+	            message.WriteSingle((float) 1.5);
+	            message.WriteInt32(1);
+	            message.WriteInt64(1);
+	            message.WriteObject("stringobj");
+	            message.WriteInt16((short) 1);
+	            message.WriteString("utfstring");
+	        }
+			catch(MessageNotWriteableException)
+			{
+	            Assert.Fail("Should be writeable");
+	        }
+			
+	        message.Reset();
+	        
+			try
+			{
+	            message.ReadBoolean();
+	            message.ReadByte();
+	            message.ReadBytes(new byte[1]);
+	            message.ReadBytes(new byte[2], 2);
+	            message.ReadChar();
+	            message.ReadDouble();
+	            message.ReadSingle();
+	            message.ReadInt32();
+	            message.ReadInt64();
+	            message.ReadString();
+	            message.ReadInt16();
+	            message.ReadString();
+	        } 
+			catch(MessageNotReadableException) 
+			{
+	            Assert.Fail("Should be readable");
+	        }
+			
+	        try 
+			{
+	            message.WriteBoolean(true);
+	            Assert.Fail("Should have thrown exception");
+	        } 
+			catch(MessageNotWriteableException) 
+			{
+	        }
+			
+	        try
+			{
+	            message.WriteByte((byte) 1);
+	            Assert.Fail("Should have thrown exception");
+	        } 
+			catch(MessageNotWriteableException) 
+			{
+	        }
+			
+	        try
+			{
+	            message.WriteBytes(new byte[1]);
+	            Assert.Fail("Should have thrown exception");
+	        } 
+			catch(MessageNotWriteableException) 
+			{
+	        }
+			
+	        try 
+			{
+	            message.WriteBytes(new byte[3], 0, 2);
+	            Assert.Fail("Should have thrown exception");
+	        } 
+			catch(MessageNotWriteableException) 
+			{
+	        }
+			
+	        try 
+			{
+	            message.WriteChar('a');
+	            Assert.Fail("Should have thrown exception");
+	        } 
+			catch(MessageNotWriteableException) 
+			{
+	        }
+			
+	        try 
+			{
+	            message.WriteDouble(1.5);
+	            Assert.Fail("Should have thrown exception");
+	        }
+			catch(MessageNotWriteableException)
+			{
+	        }
+			
+	        try
+			{
+	            message.WriteSingle((float) 1.5);
+	            Assert.Fail("Should have thrown exception");
+	        } 
+			catch(MessageNotWriteableException)
+			{
+	        }
+			
+	        try 
+			{
+	            message.WriteInt32(1);
+	            Assert.Fail("Should have thrown exception");
+	        } 
+			catch(MessageNotWriteableException) 
+			{
+	        }
+			
+	        try 
+			{
+	            message.WriteInt64(1);
+	            Assert.Fail("Should have thrown exception");
+	        } 
+			catch(MessageNotWriteableException) 
+			{
+	        }
+			
+	        try
+			{
+	            message.WriteObject("stringobj");
+	            Assert.Fail("Should have thrown exception");
+	        }
+			catch(MessageNotWriteableException) 
+			{
+	        }
+			
+	        try 
+			{
+	            message.WriteInt16((short) 1);
+	            Assert.Fail("Should have thrown exception");
+	        } 
+			catch(MessageNotWriteableException)
+			{
+	        }
+			
+	        try
+			{
+	            message.WriteString("utfstring");
+	            Assert.Fail("Should have thrown exception");
+	        } 
+			catch(MessageNotWriteableException)
+			{
+	        }
+	    }
+	
+		[Test]
+	    public void TestWriteOnlyBody() 
+		{
+	        ActiveMQBytesMessage message = new ActiveMQBytesMessage();
+	        message.ClearBody();
+	        
+			try
+			{
+	            message.WriteBoolean(true);
+	            message.WriteByte((byte) 1);
+	            message.WriteBytes(new byte[1]);
+	            message.WriteBytes(new byte[3], 0, 2);
+	            message.WriteChar('a');
+	            message.WriteDouble(1.5);
+	            message.WriteSingle((float) 1.5);
+	            message.WriteInt32(1);
+	            message.WriteInt64(1);
+	            message.WriteObject("stringobj");
+	            message.WriteInt16((short) 1);
+	            message.WriteString("utfstring");
+	        }
+			catch(MessageNotWriteableException)
+			{
+	            Assert.Fail("Should be writeable");
+	        }
+			
+	        try
+			{
+	            message.ReadBoolean();
+	            Assert.Fail("Should have thrown exception");
+	        }
+			catch(MessageNotReadableException)
+			{
+	        }
+	        
+			try
+			{
+	            message.ReadByte();
+	            Assert.Fail("Should have thrown exception");
+	        }
+			catch(MessageNotReadableException)
+			{
+	        }
+	        
+			try
+			{
+	            message.ReadBytes(new byte[1]);
+	            Assert.Fail("Should have thrown exception");
+	        }
+			catch(MessageNotReadableException)
+			{
+	        }
+	        
+			try
+			{
+	            message.ReadBytes(new byte[2], 2);
+	            Assert.Fail("Should have thrown exception");
+	        }
+			catch(MessageNotReadableException)
+			{
+	        }
+	        
+			try
+			{
+	            message.ReadChar();
+	            Assert.Fail("Should have thrown exception");
+	        }
+			catch(MessageNotReadableException)
+			{
+	        }
+	        
+			try
+			{
+	            message.ReadDouble();
+	            Assert.Fail("Should have thrown exception");
+	        }
+			catch(MessageNotReadableException)
+			{
+	        }
+	        
+			try 
+			{
+	            message.ReadSingle();
+	            Assert.Fail("Should have thrown exception");
+	        }
+			catch(MessageNotReadableException)
+			{
+	        }
+	        
+			try
+			{
+	            message.ReadInt32();
+	            Assert.Fail("Should have thrown exception");
+	        }
+			catch(MessageNotReadableException)
+			{
+	        }
+	        
+			try
+			{
+	            message.ReadInt64();
+	            Assert.Fail("Should have thrown exception");
+	        }
+			catch(MessageNotReadableException)
+			{
+	        }
+	        
+			try
+			{
+	            message.ReadString();
+	            Assert.Fail("Should have thrown exception");
+	        }
+			catch(MessageNotReadableException)
+			{
+	        }
+	        
+			try
+			{
+	            message.ReadInt16();
+	            Assert.Fail("Should have thrown exception");
+	        }
+			catch(MessageNotReadableException)
+			{
+	        }
+	        
+			try 
+			{
+	            message.ReadString();
+	            Assert.Fail("Should have thrown exception");
+	        } 
+			catch(MessageNotReadableException) 
+			{
+	        }
+	    }		
+
+	}
+}

Propchange: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/Commands/ActiveMQBytesMessageTest.cs
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message