Author: aidan
Date: Thu Jun 12 07:05:12 2008
New Revision: 667097

URL: http://svn.apache.org/viewvc?rev=667097&view=rev
Log:
QPID-1135: Fix multi-frame message handling. This fix is suboptimal since it 
creates an extra copy, as a result it's slower and less memory efficent. But it 
is correct.

Qpid.Buffer/SlicedByteBuffer.cs: Make sure that we only request the right part 
of the array when returning a slice

Qpid.Integration.Tests/Qpid.Integration.Tests.csproj: add ByteMessageTest

Qpid.Integration.Tests/testcases/BaseMessagingTestFixture.cs: Add 
ConsumeNMessage and ConsumeMessages variants that take byte[] instead of string

Qpid.Integration.Tests/testcases/ByteMessageTest.cs: add tests for various 
sizes of messages

Added:
    
incubator/qpid/branches/M2.1.x/dotnet/Qpid.Integration.Tests/testcases/ByteMessageTest.cs
   (with props)
Modified:
    incubator/qpid/branches/M2.1.x/dotnet/Qpid.Buffer/SlicedByteBuffer.cs
    
incubator/qpid/branches/M2.1.x/dotnet/Qpid.Integration.Tests/Qpid.Integration.Tests.csproj
    
incubator/qpid/branches/M2.1.x/dotnet/Qpid.Integration.Tests/testcases/BaseMessagingTestFixture.cs

Modified: incubator/qpid/branches/M2.1.x/dotnet/Qpid.Buffer/SlicedByteBuffer.cs
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1.x/dotnet/Qpid.Buffer/SlicedByteBuffer.cs?rev=667097&r1=667096&r2=667097&view=diff
==============================================================================
--- incubator/qpid/branches/M2.1.x/dotnet/Qpid.Buffer/SlicedByteBuffer.cs 
(original)
+++ incubator/qpid/branches/M2.1.x/dotnet/Qpid.Buffer/SlicedByteBuffer.cs Thu 
Jun 12 07:05:12 2008
@@ -27,6 +27,7 @@
       private ByteBuffer _buffer;
       private int _capacity;
       private int _startPos;
+      private byte[] _array = null;
 
       public override int Capacity
       {
@@ -35,7 +36,17 @@
 
       public override byte[] Array
       {
-         get { return _buffer.Array; }
+       get 
+       {
+               if (_array == null)
+               {
+                       // FIXME: this creates an unnecessary copy of the data, 
+                       // which is expensive and gross. A sliced clone() would 
be better
+                       _array = new byte[Limit];
+                       _buffer.GetBytes(_startPos, _array, 0, Limit);
+               }
+               return _array;
+       }
       }
 
       /// <summary>

Modified: 
incubator/qpid/branches/M2.1.x/dotnet/Qpid.Integration.Tests/Qpid.Integration.Tests.csproj
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1.x/dotnet/Qpid.Integration.Tests/Qpid.Integration.Tests.csproj?rev=667097&r1=667096&r2=667097&view=diff
==============================================================================
--- 
incubator/qpid/branches/M2.1.x/dotnet/Qpid.Integration.Tests/Qpid.Integration.Tests.csproj
 (original)
+++ 
incubator/qpid/branches/M2.1.x/dotnet/Qpid.Integration.Tests/Qpid.Integration.Tests.csproj
 Thu Jun 12 07:05:12 2008
@@ -40,6 +40,7 @@
     <Compile Include="interop\TestCases\TestCase1DummyRun.cs" />
     <Compile Include="interop\TestCases\TestCase3BasicPubSub.cs" />
     <Compile Include="testcases\BaseMessagingTestFixture.cs" />
+    <Compile Include="testcases\ByteMessageTest.cs" />
     <Compile Include="testcases\ChannelQueueTest.cs" />
     <Compile Include="testcases\CommitRollbackTest.cs" />
     <Compile Include="testcases\ConnectionTest.cs" />

Modified: 
incubator/qpid/branches/M2.1.x/dotnet/Qpid.Integration.Tests/testcases/BaseMessagingTestFixture.cs
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1.x/dotnet/Qpid.Integration.Tests/testcases/BaseMessagingTestFixture.cs?rev=667097&r1=667096&r2=667097&view=diff
==============================================================================
--- 
incubator/qpid/branches/M2.1.x/dotnet/Qpid.Integration.Tests/testcases/BaseMessagingTestFixture.cs
 (original)
+++ 
incubator/qpid/branches/M2.1.x/dotnet/Qpid.Integration.Tests/testcases/BaseMessagingTestFixture.cs
 Thu Jun 12 07:05:12 2008
@@ -230,6 +230,46 @@
             }
         }
 
+        /// <summary>
+        /// Consumes n messages, checking that the n+1th is not available 
within a timeout, and that the consumed messages
+        /// are text messages with contents equal to the specified message 
body.
+        /// </summary>
+        ///
+        /// <param name="n">The number of messages to consume.</param>
+        /// <param name="body">The body text to match against all 
messages.</param>
+        /// <param name="consumer">The message consumer to recieve the 
messages on.</param>
+        public static void ConsumeNMessagesOnly(int n, byte[] body, 
IMessageConsumer consumer)
+        {
+            ConsumeNMessages(n, body, consumer);
+            
+            // Check that one more than n cannot be received.
+            IMessage msg = consumer.Receive(RECEIVE_WAIT);
+            Assert.IsNull(msg, "Consumer got more messages than the number 
requested (" + n + ").");
+        }
+
+        /// <summary>
+        /// Consumes n messages, checking that the n+1th is not available 
within a timeout, and that the consumed messages
+        /// are text messages with contents equal to the specified message 
body.
+        /// </summary>
+        ///
+        /// <param name="n">The number of messages to consume.</param>
+        /// <param name="body">The body text to match against all 
messages.</param>
+        /// <param name="consumer">The message consumer to recieve the 
messages on.</param>
+        public static void ConsumeNMessages(int n, byte[] body, 
IMessageConsumer consumer)
+        {
+            IMessage msg;
+            
+            // Try to receive n messages.
+            for (int i = 0; i < n; i++)
+            {
+               msg = consumer.Receive(RECEIVE_WAIT);
+               byte[] msgbody = new byte[((IBytesMessage)msg).BodyLength];
+               ((IBytesMessage)msg).ReadBytes(msgbody);
+                Assert.IsNotNull(msg, "Consumer did not receive message 
number: " + i);
+                Assert.AreEqual(body, msgbody, "Incorrect Message received on 
consumer.");
+            }
+        }
+        
         /// <summary>Creates the requested number of bytes of dummy text. 
Usually used for filling test messages. </summary>
         ///
         /// <param name="size">The number of bytes of dummy text to 
generate.</param>

Added: 
incubator/qpid/branches/M2.1.x/dotnet/Qpid.Integration.Tests/testcases/ByteMessageTest.cs
URL: 
http://svn.apache.org/viewvc/incubator/qpid/branches/M2.1.x/dotnet/Qpid.Integration.Tests/testcases/ByteMessageTest.cs?rev=667097&view=auto
==============================================================================
--- 
incubator/qpid/branches/M2.1.x/dotnet/Qpid.Integration.Tests/testcases/ByteMessageTest.cs
 (added)
+++ 
incubator/qpid/branches/M2.1.x/dotnet/Qpid.Integration.Tests/testcases/ByteMessageTest.cs
 Thu Jun 12 07:05:12 2008
@@ -0,0 +1,123 @@
+/*
+ *
+ * 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 System;
+using System.Threading;
+using log4net;
+using NUnit.Framework;
+using Apache.Qpid.Messaging;
+using Apache.Qpid.Client.Qms;
+using Apache.Qpid.Client;
+
+namespace Apache.Qpid.Integration.Tests.testcases
+{
+       /// <summary>
+       /// Checks that byte messages can be produced and received properly.
+       /// </summary>
+       [TestFixture, Category("Integration")]
+       public class ByteMessageTest : BaseMessagingTestFixture
+               
+       {
+               private static ILog log = 
LogManager.GetLogger(typeof(ByteMessageTest));
+               private static string TEST_ROUTING_KEY = 
"BYTE_MESSAGE_TEST_QUEUE";
+               
+               [SetUp]
+        public override void Init()
+        {
+            base.Init();
+
+            // Create one producer and one consumer, p2p, tx, consumer with 
queue bound to producers routing key.
+            SetUpEndPoint(0, true, false, TEST_ROUTING_KEY + testId, 
AcknowledgeMode.AutoAcknowledge, false, ExchangeNameDefaults.DIRECT, 
+                          true, false, null);
+            SetUpEndPoint(1, false, true, TEST_ROUTING_KEY + testId, 
AcknowledgeMode.AutoAcknowledge, false, ExchangeNameDefaults.DIRECT, 
+                          true, false, null);
+        }
+               
+               [TearDown]
+        public override void Shutdown()
+        {
+            try
+            {
+                // Clean up after the test.
+                CloseEndPoint(0);
+                CloseEndPoint(1);
+            } 
+            finally 
+            {
+                base.Shutdown();
+            }
+        }
+
+        /// <summary> Send the byte message and get it back. </summary>
+        private void TestAnyByteMessage(int size)
+        {
+               byte[] content = new byte[size];
+               
+               for (int i = 0; i < content.Length; i++)
+               {
+                       content[i] = (byte)i;
+               }
+            // Send messages.
+            IBytesMessage msg = testChannel[0].CreateBytesMessage();
+            msg.WriteBytes(content);
+            testProducer[0].Send(msg);
+          
+            // Try to receive messages.
+            ConsumeNMessagesOnly(1, content, testConsumer[1]);
+        }
+               
+        [Test]
+        /// <summary> Send a small byte message and get it back. </summary>
+        public void TestSmallByteMessage()
+        {
+               TestAnyByteMessage(4);
+        }
+        
+        [Test]
+        /// <summary> Send a byte message just under the frame boundry and get 
it back. </summary>
+        public void TestByteMessageUnderFrameBoundry()
+        {
+               TestAnyByteMessage((int) Math.Pow(2,16) - 32);
+        }
+        
+        [Test]
+        /// <summary> Send a byte message on the frame boundry and get it 
back. </summary>
+        public void TestByteMessageOnFrameBoundry()
+        {
+               TestAnyByteMessage((int) Math.Pow(2,16) - 2);
+        }
+        
+        [Test]
+        /// <summary> Send a byte message on the frame boundry and get it 
back. </summary>
+        public void TestByteMessageOverFrameBoundry()
+        {
+               TestAnyByteMessage((int) Math.Pow(2,16) - 1);
+        }
+        
+        [Test]
+        /// <summary> Send a byte message on the frame boundry and get it 
back. </summary>
+        public void TestByteMessageWellOverFrameBoundry()
+        {
+               TestAnyByteMessage((int) Math.Pow(2,17));
+        }
+        
+       }
+}

Propchange: 
incubator/qpid/branches/M2.1.x/dotnet/Qpid.Integration.Tests/testcases/ByteMessageTest.cs
------------------------------------------------------------------------------
    svn:executable = *


Reply via email to