Author: jgomes
Date: Wed Nov 12 09:47:21 2008
New Revision: 713434

URL: http://svn.apache.org/viewvc?rev=713434&view=rev
Log:
Refactored unit tests to use RowTest attributes for easier maintenance.
Unit tests are no longer inherited to be exposed.  The NUnit project should 
aggregate the separate test assemblies to run a complete test of the system.
Refactored OpenWireFormat to minimize the locking of the wire format settings.

Removed:
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/InheritedTests.cs
Modified:
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/OpenWire/OpenWireFormat.cs
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSConnectionFactoryTest.cs
    
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj

Modified: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/OpenWire/OpenWireFormat.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/OpenWire/OpenWireFormat.cs?rev=713434&r1=713433&r2=713434&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/OpenWire/OpenWireFormat.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/main/csharp/OpenWire/OpenWireFormat.cs
 Wed Nov 12 09:47:21 2008
@@ -159,59 +159,71 @@
                        }
                }
 
+               private BaseDataStreamMarshaller 
GetDataStreamMarshallerForType(byte dataType)
+               {
+                       BaseDataStreamMarshaller dsm = 
this.dataMarshallers[dataType & 0xFF];
+                       if(null == dsm)
+                       {
+                               throw new IOException("Unknown data type: " + 
dataType);
+                       }
+                       return dsm;
+               }
+
                public void Marshal(Object o, BinaryWriter ds)
                {
                        int size = 1;
                        if(o != null)
                        {
+                               DataStructure c = (DataStructure) o;
+                               byte type = c.GetDataStructureType();
+                               BaseDataStreamMarshaller dsm;
+                               bool _tightEncodingEnabled;
+                               bool _sizePrefixDisabled;
+
                                lock(this.marshalLock)
                                {
-                                       DataStructure c = (DataStructure) o;
-                                       byte type = c.GetDataStructureType();
-                                       BaseDataStreamMarshaller dsm = 
dataMarshallers[type & 0xFF];
-                                       if(null == dsm)
+                                       dsm = 
GetDataStreamMarshallerForType(type);
+                                       _tightEncodingEnabled = 
this.tightEncodingEnabled;
+                                       _sizePrefixDisabled = 
this.sizePrefixDisabled;
+                               }
+
+                               if(_tightEncodingEnabled)
+                               {
+                                       BooleanStream bs = new BooleanStream();
+                                       size += dsm.TightMarshal1(this, c, bs);
+                                       size += bs.MarshalledSize();
+
+                                       if(!_sizePrefixDisabled)
                                        {
-                                               throw new IOException("Unknown 
data type: " + type);
+                                               ds.Write(size);
                                        }
 
-                                       if(tightEncodingEnabled)
+                                       ds.Write(type);
+                                       bs.Marshal(ds);
+                                       dsm.TightMarshal2(this, c, ds, bs);
+                               }
+                               else
+                               {
+                                       BinaryWriter looseOut = ds;
+                                       MemoryStream ms = null;
+
+                                       // If we are prefixing then we need to 
first write it to memory,
+                                       // otherwise we can write direct to the 
stream.
+                                       if(!_sizePrefixDisabled)
                                        {
-                                               BooleanStream bs = new 
BooleanStream();
-                                               size += dsm.TightMarshal1(this, 
c, bs);
-                                               size += bs.MarshalledSize();
-
-                                               if(!sizePrefixDisabled)
-                                               {
-                                                       ds.Write(size);
-                                               }
-
-                                               ds.Write(type);
-                                               bs.Marshal(ds);
-                                               dsm.TightMarshal2(this, c, ds, 
bs);
+                                               ms = new MemoryStream();
+                                               looseOut = new 
OpenWireBinaryWriter(ms);
+                                               looseOut.Write(size);
                                        }
-                                       else
-                                       {
-                                               BinaryWriter looseOut = ds;
-                                               MemoryStream ms = null;
 
-                                               // If we are prefixing then we 
need to first write it to memory,
-                                               // otherwise we can write 
direct to the stream.
-                                               if(!sizePrefixDisabled)
-                                               {
-                                                       ms = new MemoryStream();
-                                                       looseOut = new 
OpenWireBinaryWriter(ms);
-                                                       looseOut.Write(size);
-                                               }
-
-                                               looseOut.Write(type);
-                                               dsm.LooseMarshal(this, c, 
looseOut);
-
-                                               if(!sizePrefixDisabled)
-                                               {
-                                                       ms.Position = 0;
-                                                       looseOut.Write((int) 
ms.Length - 4);
-                                                       
ds.Write(ms.GetBuffer(), 0, (int) ms.Length);
-                                               }
+                                       looseOut.Write(type);
+                                       dsm.LooseMarshal(this, c, looseOut);
+
+                                       if(!_sizePrefixDisabled)
+                                       {
+                                               ms.Position = 0;
+                                               looseOut.Write((int) ms.Length 
- 4);
+                                               ds.Write(ms.GetBuffer(), 0, 
(int) ms.Length);
                                        }
                                }
                        }
@@ -235,29 +247,29 @@
 
                        if(dataType != NULL_TYPE)
                        {
+                               BaseDataStreamMarshaller dsm;
+                               bool _tightEncodingEnabled;
+
                                lock(this.marshalLock)
                                {
-                                       BaseDataStreamMarshaller dsm = 
dataMarshallers[dataType & 0xFF];
-                                       if(null == dsm)
-                                       {
-                                               throw new IOException("Unknown 
data type: " + dataType);
-                                       }
+                                       dsm = 
GetDataStreamMarshallerForType(dataType);
+                                       _tightEncodingEnabled = 
this.tightEncodingEnabled;
+                               }
 
-                                       Tracer.Debug("Parsing type: " + 
dataType + " with: " + dsm);
-                                       Object data = dsm.CreateObject();
+                               Tracer.Debug("Parsing type: " + dataType + " 
with: " + dsm);
+                               Object data = dsm.CreateObject();
 
-                                       if(tightEncodingEnabled)
-                                       {
-                                               BooleanStream bs = new 
BooleanStream();
-                                               bs.Unmarshal(dis);
-                                               dsm.TightUnmarshal(this, data, 
dis, bs);
-                                               return data;
-                                       }
-                                       else
-                                       {
-                                               dsm.LooseUnmarshal(this, data, 
dis);
-                                               return data;
-                                       }
+                               if(_tightEncodingEnabled)
+                               {
+                                       BooleanStream bs = new BooleanStream();
+                                       bs.Unmarshal(dis);
+                                       dsm.TightUnmarshal(this, data, dis, bs);
+                                       return data;
+                               }
+                               else
+                               {
+                                       dsm.LooseUnmarshal(this, data, dis);
+                                       return data;
                                }
                        }
                        else
@@ -291,18 +303,14 @@
                                throw new IOException("No valid data structure 
type for: " + o + " of type: " + o.GetType());
                        }
 
+                       BaseDataStreamMarshaller dsm;
                        lock(this.marshalLock)
                        {
-                               BaseDataStreamMarshaller dsm = 
(BaseDataStreamMarshaller) dataMarshallers[type & 0xFF];
-
-                               if(null == dsm)
-                               {
-                                       throw new IOException("Unknown data 
type: " + type);
-                               }
-
-                               Tracer.Debug("Marshalling type: " + type + " 
with structure: " + o);
-                               return 1 + dsm.TightMarshal1(this, o, bs);
+                               dsm = GetDataStreamMarshallerForType(type);
                        }
+
+                       Tracer.Debug("Marshalling type: " + type + " with 
structure: " + o);
+                       return 1 + dsm.TightMarshal1(this, o, bs);
                }
 
                public void TightMarshalNestedObject2(DataStructure o, 
BinaryWriter ds, BooleanStream bs)
@@ -323,17 +331,14 @@
                        }
                        else
                        {
+                               BaseDataStreamMarshaller dsm;
+
                                lock(this.marshalLock)
                                {
-                                       BaseDataStreamMarshaller dsm = 
(BaseDataStreamMarshaller) dataMarshallers[type & 0xFF];
-
-                                       if(null == dsm)
-                                       {
-                                               throw new IOException("Unknown 
data type: " + type);
-                                       }
-
-                                       dsm.TightMarshal2(this, o, ds, bs);
+                                       dsm = 
GetDataStreamMarshallerForType(type);
                                }
+
+                               dsm.TightMarshal2(this, o, ds, bs);
                        }
                }
 
@@ -342,36 +347,31 @@
                        if(bs.ReadBoolean())
                        {
                                DataStructure data;
+                               BaseDataStreamMarshaller dsm;
+                               byte dataType = dis.ReadByte();
 
                                lock(this.marshalLock)
                                {
-                                       byte dataType = dis.ReadByte();
-                                       BaseDataStreamMarshaller dsm = 
(BaseDataStreamMarshaller) dataMarshallers[dataType & 0xFF];
-
-                                       if(null == dsm)
-                                       {
-                                               throw new IOException("Unknown 
data type: " + dataType);
-                                       }
-
-                                       data = dsm.CreateObject();
+                                       dsm = 
GetDataStreamMarshallerForType(dataType);
+                               }
 
-                                       if(data.IsMarshallAware() && 
bs.ReadBoolean())
-                                       {
-                                               dis.ReadInt32();
-                                               dis.ReadByte();
+                               data = dsm.CreateObject();
+                               if(data.IsMarshallAware() && bs.ReadBoolean())
+                               {
+                                       dis.ReadInt32();
+                                       dis.ReadByte();
 
-                                               BooleanStream bs2 = new 
BooleanStream();
-                                               bs2.Unmarshal(dis);
-                                               dsm.TightUnmarshal(this, data, 
dis, bs2);
-
-                                               // TODO: extract the sequence 
from the dis and associate it.
-                                               //                MarshallAware 
ma = (MarshallAware)data
-                                               //                
ma.setCachedMarshalledForm(this, sequence);
-                                       }
-                                       else
-                                       {
-                                               dsm.TightUnmarshal(this, data, 
dis, bs);
-                                       }
+                                       BooleanStream bs2 = new BooleanStream();
+                                       bs2.Unmarshal(dis);
+                                       dsm.TightUnmarshal(this, data, dis, 
bs2);
+
+                                       // TODO: extract the sequence from the 
dis and associate it.
+                                       //                MarshallAware ma = 
(MarshallAware)data
+                                       //                
ma.setCachedMarshalledForm(this, sequence);
+                               }
+                               else
+                               {
+                                       dsm.TightUnmarshal(this, data, dis, bs);
                                }
 
                                return data;
@@ -387,20 +387,16 @@
                        dataOut.Write(o != null);
                        if(o != null)
                        {
+                               BaseDataStreamMarshaller dsm;
                                byte type = o.GetDataStructureType();
                                dataOut.Write(type);
 
                                lock(this.marshalLock)
                                {
-                                       BaseDataStreamMarshaller dsm = 
(BaseDataStreamMarshaller) dataMarshallers[type & 0xFF];
-
-                                       if(null == dsm)
-                                       {
-                                               throw new IOException("Unknown 
data type: " + type);
-                                       }
-
-                                       dsm.LooseMarshal(this, o, dataOut);
+                                       dsm = 
GetDataStreamMarshallerForType(type);
                                }
+
+                               dsm.LooseMarshal(this, o, dataOut);
                        }
                }
 
@@ -408,22 +404,17 @@
                {
                        if(dis.ReadBoolean())
                        {
+                               BaseDataStreamMarshaller dsm;
                                byte dataType = dis.ReadByte();
                                DataStructure data;
 
                                lock(this.marshalLock)
                                {
-                                       BaseDataStreamMarshaller dsm = 
(BaseDataStreamMarshaller) dataMarshallers[dataType & 0xFF];
-
-                                       if(null == dsm)
-                                       {
-                                               throw new IOException("Unknown 
data type: " + dataType);
-                                       }
-
-                                       data = dsm.CreateObject();
-                                       dsm.LooseUnmarshal(this, data, dis);
+                                       dsm = 
GetDataStreamMarshallerForType(dataType);
                                }
 
+                               data = dsm.CreateObject();
+                               dsm.LooseUnmarshal(this, data, dis);
                                return data;
                        }
                        else

Modified: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSConnectionFactoryTest.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSConnectionFactoryTest.cs?rev=713434&r1=713433&r2=713434&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSConnectionFactoryTest.cs
 (original)
+++ 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/NMSConnectionFactoryTest.cs
 Wed Nov 12 09:47:21 2008
@@ -13,40 +13,28 @@
  * 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 Apache.NMS;
-using NUnit.Framework;
-
-namespace Apache.NMS.ActiveMQ.Test
-{
-    [TestFixture]
-    public class NMSConnectionFactoryTest 
-    {
-        [Test]
-        public void TestTcpURI()
-        {
-            NMSConnectionFactory factory = new 
NMSConnectionFactory("tcp://localhost:61616");
-            Assert.IsNotNull(factory);
-            Assert.IsNotNull(factory.ConnectionFactory);
-            Assert.IsTrue(factory.ConnectionFactory is 
Apache.NMS.ActiveMQ.ConnectionFactory);
-        }
-
-               [Test]
-        public void TestStompURI()
-        {
-            NMSConnectionFactory factory = new 
NMSConnectionFactory("stomp://localhost:61613");
-            Assert.IsNotNull(factory);
-            Assert.IsNotNull(factory.ConnectionFactory);
-            Assert.IsTrue(factory.ConnectionFactory is 
Apache.NMS.ActiveMQ.ConnectionFactory);
-        }
-
-        [Test]
-        public void TestActiveMQURI()
-        {
-            NMSConnectionFactory factory = new 
NMSConnectionFactory("activemq:tcp://localhost:61616");
-            Assert.IsNotNull(factory);
-            Assert.IsNotNull(factory.ConnectionFactory);
-            Assert.IsTrue(factory.ConnectionFactory is 
Apache.NMS.ActiveMQ.ConnectionFactory);
-        }
-    }
-}
+ */
+
+using NUnit.Framework;
+using NUnit.Framework.Extensions;
+
+namespace Apache.NMS.ActiveMQ.Test
+{
+       [TestFixture]
+       public class NMSConnectionFactoryTest
+       {
+               [RowTest]
+               [Row("tcp://localhost:61616")]
+               [Row("stomp://localhost:61613")]
+               [Row("activemq:tcp://localhost:61616")]
+               [Row("activemq:failover://localhost:61616")]
+               
[Row("activemq:failover://(tcp://localhost:61616,tcp://localhost:61616)")]
+               public void TestURI(string connectionURI)
+               {
+                       NMSConnectionFactory factory = new 
NMSConnectionFactory(connectionURI);
+                       Assert.IsNotNull(factory);
+                       Assert.IsNotNull(factory.ConnectionFactory);
+                       Assert.IsTrue(factory.ConnectionFactory is 
Apache.NMS.ActiveMQ.ConnectionFactory);
+               }
+       }
+}

Modified: 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj?rev=713434&r1=713433&r2=713434&view=diff
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj 
(original)
+++ 
activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/vs2008-activemq-test.csproj 
Wed Nov 12 09:47:21 2008
@@ -67,7 +67,6 @@
       <SubType>Code</SubType>
     </Compile>
     <Compile Include="src\test\csharp\CommonAssemblyInfo.cs" />
-    <Compile Include="src\test\csharp\InheritedTests.cs" />
     <Compile Include="src\test\csharp\NMSConnectionFactoryTest.cs" />
     <Compile Include="src\test\csharp\OpenWire\BooleanStreamTest.cs">
       <SubType>Code</SubType>


Reply via email to