You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ar...@apache.org on 2008/10/02 17:38:44 UTC

svn commit: r701160 - in /incubator/qpid/trunk/qpid/dotnet/client-010: client/ client/transport/util/ test/ test/transport/util/

Author: arnaudsimon
Date: Thu Oct  2 08:38:43 2008
New Revision: 701160

URL: http://svn.apache.org/viewvc?rev=701160&view=rev
Log:
qpid-1277: added unit tests

Added:
    incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/ByteEncoderTest.cs
    incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/CircularBufferTest.cs
    incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/ResultFutureTest.cs
    incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/SerialTest.cs
Modified:
    incubator/qpid/trunk/qpid/dotnet/client-010/client/client.suo
    incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/ByteEncoder.cs
    incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/Functions.cs
    incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/ResultFuture.cs
    incubator/qpid/trunk/qpid/dotnet/client-010/test/Test.csproj

Modified: incubator/qpid/trunk/qpid/dotnet/client-010/client/client.suo
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/client-010/client/client.suo?rev=701160&r1=701159&r2=701160&view=diff
==============================================================================
Binary files - no diff available.

Modified: incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/ByteEncoder.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/ByteEncoder.cs?rev=701160&r1=701159&r2=701160&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/ByteEncoder.cs (original)
+++ incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/ByteEncoder.cs Thu Oct  2 08:38:43 2008
@@ -1,6 +1,24 @@
+/*
+*
+* 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.Collections.Generic;
-using System.Text;
 
 namespace org.apache.qpid.transport.util
 {
@@ -18,10 +36,7 @@
             {
                 return swapByteOrder(value);
             }
-            else
-            {
-                return value;
-            }
+            return value;
         }
 
         /// <summary>
@@ -35,10 +50,7 @@
             {
                 return swapByteOrder(value);
             }
-            else
-            {
-                return value;
-            }
+            return value;
         }
 
         /// <summary>
@@ -52,10 +64,7 @@
             {
                 return swapByteOrder(value);
             }
-            else
-            {
-                return value;
-            }
+            return value;
         }
 
         /// <summary>
@@ -69,10 +78,7 @@
             {
                 return swapByteOrder(value);
             }
-            else
-            {
-                return value;
-            }
+            return value;
         }
 
         /// <summary>
@@ -86,10 +92,7 @@
             {
                 return value;
             }
-            else
-            {
-                return swapByteOrder(value);
-            }
+            return swapByteOrder(value);
         }
 
         /// <summary>
@@ -103,10 +106,7 @@
             {
                 return value;
             }
-            else
-            {
-                return swapByteOrder(value);
-            }
+            return swapByteOrder(value);
         }
 
         /// <summary>
@@ -120,10 +120,7 @@
             {
                 return value;
             }
-            else
-            {
-                return swapByteOrder(value);
-            }
+            return swapByteOrder(value);
         }
 
         /// <summary>
@@ -131,16 +128,13 @@
         /// </summary>
         /// <param name="value">Value to encode.</param>
         /// <returns>Little-endian encoded value.</returns>
-        public static Double GetLittleEndian(long value)
+        public static long GetLittleEndian(long value)
         {
             if (BitConverter.IsLittleEndian)
             {
                 return value;
             }
-            else
-            {
-                return swapByteOrder(value);
-            }
+            return swapByteOrder(value);
         }
 
         /// <summary>

Modified: incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/Functions.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/Functions.cs?rev=701160&r1=701159&r2=701160&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/Functions.cs (original)
+++ incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/Functions.cs Thu Oct  2 08:38:43 2008
@@ -18,7 +18,6 @@
 * under the License.
 *
 */
-using System;
 
 namespace org.apache.qpid.transport.util
 {

Modified: incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/ResultFuture.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/ResultFuture.cs?rev=701160&r1=701159&r2=701160&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/ResultFuture.cs (original)
+++ incubator/qpid/trunk/qpid/dotnet/client-010/client/transport/util/ResultFuture.cs Thu Oct  2 08:38:43 2008
@@ -18,11 +18,11 @@
             {
                 DateTime start = DateTime.Now;
                 long elapsed = 0;
-                while (! _session.Closed && _timeout - elapsed > 0 && _result == null)
+                while (! _session.Closed && timeout - elapsed > 0 && _result == null)
                 {
                         log.debug("{0} waiting for result: {1}", _session, this );
                         Monitor.Wait(this, (int) (timeout - elapsed));
-                        elapsed = DateTime.Now.Subtract( start ).Milliseconds;                   
+                        elapsed = (long) (DateTime.Now.Subtract(start)).TotalMilliseconds;
                 }
             }
             if( _session.Closed )

Modified: incubator/qpid/trunk/qpid/dotnet/client-010/test/Test.csproj
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/client-010/test/Test.csproj?rev=701160&r1=701159&r2=701160&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/client-010/test/Test.csproj (original)
+++ incubator/qpid/trunk/qpid/dotnet/client-010/test/Test.csproj Thu Oct  2 08:38:43 2008
@@ -46,6 +46,10 @@
     <Compile Include="interop\Message.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="interop\TestCase.cs" />
+    <Compile Include="transport\util\ByteEncoderTest.cs" />
+    <Compile Include="transport\util\CircularBufferTest.cs" />
+    <Compile Include="transport\util\ResultFutureTest.cs" />
+    <Compile Include="transport\util\SerialTest.cs" />
     <Compile Include="transport\util\UUIDTest.cs" />
   </ItemGroup>
   <ItemGroup>

Added: incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/ByteEncoderTest.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/ByteEncoderTest.cs?rev=701160&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/ByteEncoderTest.cs (added)
+++ incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/ByteEncoderTest.cs Thu Oct  2 08:38:43 2008
@@ -0,0 +1,106 @@
+/*
+*
+* 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 NUnit.Framework;
+using org.apache.qpid.transport.util;
+
+
+namespace test.transport.util
+{
+    [TestFixture]
+
+    public class ByteEncoderTest
+    {        
+        private static readonly Logger _log = Logger.get(typeof(ByteEncoderTest));
+
+        [Test]
+        public void GetBigEndianInt32()
+        {
+            _log.debug("Running: GetBigEndianInt32");
+            const int anInt = -12345;
+            Int32 aNewInt = ByteEncoder.GetBigEndian(anInt);
+            Assert.IsTrue( anInt == ByteEncoder.GetBigEndian(aNewInt) );
+        }
+
+        [Test]
+        public void GetBigEndianUInt16()
+        {
+            _log.debug("Running: GetBigEndianUInt16");
+            const UInt16 anInt = 123;
+            UInt16 aNewInt = ByteEncoder.GetBigEndian(anInt);
+            Assert.IsTrue(anInt == ByteEncoder.GetBigEndian(aNewInt));
+        }
+
+        [Test]
+        public void GetBigEndianUInt32()
+        {
+            _log.debug("Running: GetBigEndianUInt32");
+            const UInt32 anInt = 12345;
+            UInt32 aNewInt = ByteEncoder.GetBigEndian(anInt);
+            Assert.IsTrue(anInt == ByteEncoder.GetBigEndian(aNewInt));
+        }
+
+        [Test]
+        public void GetBigEndianlong()
+        {
+            _log.debug("Running: GetBigEndianlong");
+            const long anInt = 123456660700770;
+            long aNewInt = ByteEncoder.GetBigEndian(anInt);
+            Assert.IsTrue(anInt == ByteEncoder.GetBigEndian(aNewInt));
+        }
+
+        [Test]
+        public void GetLittleEndianInt32()
+        {
+            _log.debug("Running: GetBigEndianInt32");
+            const int anInt = -12345;
+            Int32 aNewInt = ByteEncoder.GetLittleEndian(anInt);
+            Assert.IsTrue(anInt == ByteEncoder.GetLittleEndian(aNewInt));
+        }
+
+        [Test]
+        public void GetLittleEndianUInt16()
+        {
+            _log.debug("Running: GetLittleEndianUInt16");
+            const UInt16 anInt = 123;
+            UInt16 aNewInt = ByteEncoder.GetLittleEndian(anInt);
+            Assert.IsTrue(anInt == ByteEncoder.GetLittleEndian(aNewInt));
+        }
+
+        [Test]
+        public void GetLittleEndianUInt32()
+        {
+            _log.debug("Running: GetLittleEndianUInt32");
+            const UInt32 anInt = 12345;
+            UInt32 aNewInt = ByteEncoder.GetLittleEndian(anInt);
+            Assert.IsTrue(anInt == ByteEncoder.GetLittleEndian(aNewInt));
+        }
+
+        [Test]
+        public void GetLittleEndianlong()
+        {
+            _log.debug("Running: GetLittleEndianlong");
+            const long anInt = 123456660700770;
+            long aNewInt = ByteEncoder.GetLittleEndian(anInt);
+            Assert.IsTrue(anInt == ByteEncoder.GetLittleEndian(aNewInt));
+        }
+    }
+}

Added: incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/CircularBufferTest.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/CircularBufferTest.cs?rev=701160&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/CircularBufferTest.cs (added)
+++ incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/CircularBufferTest.cs Thu Oct  2 08:38:43 2008
@@ -0,0 +1,89 @@
+/*
+*
+* 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 common.org.apache.qpid.transport.util;
+using NUnit.Framework;
+using org.apache.qpid.transport.util;
+
+namespace test.transport.util
+{
+    [TestFixture]
+
+    public class CircularBufferTest
+    {
+        private CircularBuffer<Object> _buf;
+        private static readonly Logger _log = Logger.get(typeof(CircularBufferTest));
+
+        [Test]
+        public void BlockingEnqueue()
+        {
+            _log.debug("Running: BlockingEnqueue");
+            const int size = 10;
+            _buf = new CircularBuffer<Object>(size);
+            // add size element anc check that the size +1 add blocks 
+            for (int i = 1; i < size; i++ )
+            {
+                _buf.Enqueue(new object());
+            }
+            // check tha the buffer is now full 
+            Thread t = new Thread(Go);
+            t.Start();
+            Thread.Sleep(100);
+            // the trhead t should block until an element is dequeued 
+            Assert.IsTrue(t.ThreadState == ThreadState.WaitSleepJoin);           
+            _buf.Dequeue();
+            // t should now be stopped 
+            Thread.Sleep(100);
+            Assert.IsTrue(t.ThreadState == ThreadState.Stopped);           
+        }
+
+        [Test]
+        public void Close()
+        {
+            _log.debug("Running: BlockingEnqueue");
+            const int size = 10;
+            _buf = new CircularBuffer<Object>(size);
+            // add size element anc check that the size +1 add blocks 
+            for (int i = 1; i < size; i++)
+            {
+                _buf.Enqueue(new object());
+            }
+            // check tha the buffer is now full 
+            Thread t = new Thread(Go);
+            t.Start();
+            Thread.Sleep(1000);
+            // the trhead t should block until the buffer is closed             
+            Assert.IsTrue(t.ThreadState == ThreadState.WaitSleepJoin);
+            _buf.close();
+            Thread.Sleep(100);
+            // t should now be stopped 
+            Assert.IsTrue(t.ThreadState == ThreadState.Stopped);           
+        }
+
+        void Go()
+        {
+            _buf.Enqueue(new object());
+        }
+
+    }
+}

Added: incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/ResultFutureTest.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/ResultFutureTest.cs?rev=701160&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/ResultFutureTest.cs (added)
+++ incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/ResultFutureTest.cs Thu Oct  2 08:38:43 2008
@@ -0,0 +1,103 @@
+/*
+*
+* 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.Collections.Generic;
+using System.Threading;
+using common.org.apache.qpid.transport.util;
+using NUnit.Framework;
+using org.apache.qpid.transport;
+using org.apache.qpid.transport.codec;
+using org.apache.qpid.transport.util;
+
+
+namespace test.transport.util
+{
+    [TestFixture]
+    public class ResultFutureTest
+    {
+        private static readonly Logger _log = Logger.get(typeof (ByteEncoderTest));
+        private static ResultFuture _future;
+
+        [Test]
+        public void getFutureTimeout()
+        {
+            _log.debug("Running: getFutureTimeout");                        
+            _future = new ResultFuture();
+            _future.Session = new Session(new byte[1]);
+            DateTime start = DateTime.Now;
+            Struct result = _future.get(1000);
+            Assert.IsTrue(DateTime.Now.Subtract(start).TotalMilliseconds >= 1000);
+            Assert.IsNull(result);           
+        }
+
+        [Test]
+        public void getFuture()
+        {
+            _log.debug("Running: getFuture");
+            _future = new ResultFuture();
+            _future.Session = new Session(new byte[1]);
+            Thread t = new Thread(Go);
+            t.Start();
+            Struct result = _future.get(2000);
+            Assert.IsNotNull(result);
+        }
+
+
+        void Go()
+        {
+            Thread.Sleep(500);
+            _future.Result = new myStruct();
+        }
+    }
+
+    public class myStruct:Struct
+    {
+        public override int getStructType()
+        {
+            throw new System.NotImplementedException();
+        }
+
+        public override int getSizeWidth()
+        {
+            throw new System.NotImplementedException();
+        }
+
+        public override int getPackWidth()
+        {
+            throw new System.NotImplementedException();
+        }
+
+        public override void read(Decoder dec)
+        {
+            throw new System.NotImplementedException();
+        }
+
+        public override void write(Encoder enc)
+        {
+            throw new System.NotImplementedException();
+        }
+
+        public override Dictionary<string, object> Fields
+        {
+            get { throw new System.NotImplementedException(); }
+        }
+    }
+}

Added: incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/SerialTest.cs
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/SerialTest.cs?rev=701160&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/SerialTest.cs (added)
+++ incubator/qpid/trunk/qpid/dotnet/client-010/test/transport/util/SerialTest.cs Thu Oct  2 08:38:43 2008
@@ -0,0 +1,75 @@
+/*
+*
+* 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 org.apache.qpid.transport.util;
+
+namespace test.transport.util
+{
+    [TestFixture]
+    public class SerialTest
+    {
+        private static readonly Logger _log = Logger.get(typeof (SerialTest));
+
+        [Test]
+        ///
+        /// Test the key boundaries where wraparound occurs.
+        ///
+        public void testBoundaries()
+        {
+            Assert.IsTrue(Serial.gt(1, 0));
+            Assert.IsTrue(Serial.lt(0, 1));
+
+            Assert.IsTrue(Serial.gt(int.MaxValue, int.MaxValue - 1));
+            Assert.IsTrue(Serial.lt(int.MaxValue - 1, int.MaxValue));
+        }
+
+        ///
+        /// Test the first Corollary of RFC 1982
+        /// For any sequence number s and any integer n such that addition of n
+        /// to s is well defined, (s + n) >= s.  Further (s + n) == s only when
+        /// n == 0, in all other defined cases, (s + n) > s.
+        ///
+        public void testCorollary1()
+        {
+            int wrapcount = 0;
+
+            int s = 0;
+
+            for (int i = 0; i < 67108664; i++)
+            {
+                for (int n = 1; n < 4096; n += 512)
+                {
+                    Assert.IsTrue(Serial.gt(s + n, s));
+                    Assert.IsTrue(Serial.lt(s, s + n));
+                }
+
+                s += 1024;
+
+                if (s == 0)
+                {
+                    wrapcount += 1;
+                }
+            }
+
+            Assert.IsTrue(wrapcount > 0);
+        }
+    }
+}