Create a NMS IMessageProducer for the given ISession and IDestination,
/// configuring it to disable message ids and/or timestamps (if necessary).
/// Delegates to doCreateProducer for creation of the raw
@@ -498,18 +431,7 @@ namespace Spring.Messaging.Nms
/// NMSException if thrown by NMS API methods
protected virtual IMessageProducer DoCreateProducer(ISession session, IDestination destination)
{
- if (CacheNmsResources)
- {
- if (jmsResources.MessageProducer == null)
- {
- jmsResources.MessageProducer = session.CreateProducer(destination);
- }
- return jmsResources.MessageProducer;
- }
- else
- {
- return session.CreateProducer(destination);
- }
+ return session.CreateProducer(destination);
}
/// Create a NMS IMessageConsumer for the given ISession and IDestination.
@@ -595,19 +517,12 @@ namespace Spring.Messaging.Nms
}
}
finally
- {
- CloseProducer(producer);
- }
- }
-
- private void CloseProducer(IMessageProducer producer)
- {
- if (!CacheNmsResources)
{
NmsUtils.CloseMessageProducer(producer);
}
}
+
/// Actually send the given NMS message.
/// the NMS IMessageProducer to send with
///
diff --git a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Support/NmsAccessor.cs b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Support/NmsAccessor.cs
index 29b816a8..fe17bd6c 100644
--- a/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Support/NmsAccessor.cs
+++ b/src/Spring/Spring.Messaging.Nms/Messaging/Nms/Support/NmsAccessor.cs
@@ -112,8 +112,14 @@ namespace Spring.Messaging.Nms.Support
///
public bool SessionTransacted
{
- get { return sessionTransacted; }
- set { sessionTransacted = value; }
+ get { return SessionAcknowledgeMode == AcknowledgementMode.Transactional; }
+ set
+ {
+ if (value)
+ {
+ sessionAcknowledgeMode = AcknowledgementMode.Transactional;
+ }
+ }
}
#endregion
@@ -126,5 +132,19 @@ namespace Spring.Messaging.Nms.Support
throw new ArgumentException("ConnectionFactory is required");
}
}
+
+ ///
+ /// Creates the connection via the ConnectionFactory.
+ ///
+ ///
+ protected virtual IConnection CreateConnection()
+ {
+ return ConnectionFactory.CreateConnection();
+ }
+
+ protected virtual ISession CreateSession(IConnection con)
+ {
+ return con.CreateSession(SessionAcknowledgeMode);
+ }
}
}
diff --git a/src/Spring/Spring.Messaging.Nms/Spring.Messaging.Nms.2005.csproj b/src/Spring/Spring.Messaging.Nms/Spring.Messaging.Nms.2005.csproj
index 8c56ff7c..e61716dd 100644
--- a/src/Spring/Spring.Messaging.Nms/Spring.Messaging.Nms.2005.csproj
+++ b/src/Spring/Spring.Messaging.Nms/Spring.Messaging.Nms.2005.csproj
@@ -48,7 +48,10 @@
+
+
+
@@ -74,6 +77,10 @@
+
+ {3A3A4E65-45A6-4B20-B460-0BEDC302C02C}
+ Spring.Aop.2005
+
{710961A3-0DF4-49E4-A26E-F5B9C044AC84}
Spring.Core.2005
diff --git a/test/Spring/Spring.Data.Integration.Tests/Data/NativeAdoTests.cs b/test/Spring/Spring.Data.Integration.Tests/Data/NativeAdoTests.cs
index 447233e7..80959118 100644
--- a/test/Spring/Spring.Data.Integration.Tests/Data/NativeAdoTests.cs
+++ b/test/Spring/Spring.Data.Integration.Tests/Data/NativeAdoTests.cs
@@ -53,6 +53,7 @@ namespace Spring.Data
SqlConnection conn = new SqlConnection(connString);
conn.Open();
+ conn.Open();
//conn.BeginTransaction(IsolationLevel.Unspecified);
SqlTransaction trans = conn.BeginTransaction();
Console.WriteLine(trans.IsolationLevel);
diff --git a/test/Spring/Spring.Data.NHibernate.Integration.Tests/Spring.Data.NHibernate.Integration.Tests.dll.config b/test/Spring/Spring.Data.NHibernate.Integration.Tests/Spring.Data.NHibernate.Integration.Tests.dll.config
index 12e5ecbf..63079081 100644
--- a/test/Spring/Spring.Data.NHibernate.Integration.Tests/Spring.Data.NHibernate.Integration.Tests.dll.config
+++ b/test/Spring/Spring.Data.NHibernate.Integration.Tests/Spring.Data.NHibernate.Integration.Tests.dll.config
@@ -4,9 +4,6 @@
-
-
-
diff --git a/test/Spring/Spring.Messaging.Nms.Tests/AssemblyInfo.cs b/test/Spring/Spring.Messaging.Nms.Tests/AssemblyInfo.cs
index 177a4f0e..b81fdfc0 100644
--- a/test/Spring/Spring.Messaging.Nms.Tests/AssemblyInfo.cs
+++ b/test/Spring/Spring.Messaging.Nms.Tests/AssemblyInfo.cs
@@ -1,58 +1,5 @@
using System.Reflection;
using System.Runtime.CompilerServices;
-//
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-//
-[assembly: AssemblyTitle("")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("")]
-[assembly: AssemblyCopyright("")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-//
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Revision and Build Numbers
-// by using the '*' as shown below:
-
-[assembly: AssemblyVersion("1.0.*")]
-
-//
-// In order to sign your assembly you must specify a key to use. Refer to the
-// Microsoft .NET Framework documentation for more information on assembly signing.
-//
-// Use the attributes below to control which key is used for signing.
-//
-// Notes:
-// (*) If no key is specified, the assembly is not signed.
-// (*) KeyName refers to a key that has been installed in the Crypto Service
-// Provider (CSP) on your machine. KeyFile refers to a file which contains
-// a key.
-// (*) If the KeyFile and the KeyName values are both specified, the
-// following processing occurs:
-// (1) If the KeyName can be found in the CSP, that key is used.
-// (2) If the KeyName does not exist and the KeyFile does exist, the key
-// in the KeyFile is installed into the CSP and used.
-// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
-// When specifying the KeyFile, the location of the KeyFile should be
-// relative to the project output directory which is
-// %Project Directory%\obj\. For example, if your KeyFile is
-// located in the project directory, you would specify the AssemblyKeyFile
-// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
-// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
-// documentation for more information on this.
-//
-[assembly: AssemblyDelaySign(false)]
-[assembly: AssemblyKeyFile("")]
-[assembly: AssemblyKeyName("")]
+[assembly: AssemblyTitle("Spring.Messaging.Nms Tests")]
+[assembly: AssemblyDescription("Unit tests for Spring.Messaging.Nms assembly")]
diff --git a/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/NmsTransactionManagerTests.cs b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/NmsTransactionManagerTests.cs
new file mode 100644
index 00000000..6633e7e9
--- /dev/null
+++ b/test/Spring/Spring.Messaging.Nms.Tests/Messaging/Nms/Connections/NmsTransactionManagerTests.cs
@@ -0,0 +1,338 @@
+#region License
+
+/*
+ * Copyright © 2002-2007 the original author or authors.
+ *
+ * Licensed 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.
+ */
+
+#endregion
+
+#region Imports
+
+using System;
+using Apache.NMS;
+using NUnit.Framework;
+using Rhino.Mocks;
+using Spring.Messaging.Nms.IConnections;
+using Spring.Transaction;
+using Spring.Transaction.Support;
+
+#endregion
+
+namespace Spring.Messaging.Nms.Connections
+{
+ ///
+ /// This class contains tests for
+ ///
+ /// Mark Pollack
+ /// $Id:$
+ [TestFixture]
+ public class NmsTransactionManagerTests
+ {
+ private MockRepository mocks;
+
+ [SetUp]
+ public void Setup()
+ {
+ mocks = new MockRepository();
+ }
+
+ [Test]
+ public void TransactionCommit()
+ {
+ IConnectionFactory connectionFactory = (IConnectionFactory) mocks.CreateMock(typeof (IConnectionFactory));
+ IConnection connection = (IConnection) mocks.CreateMock(typeof (IConnection));
+ ISession session = (ISession) mocks.CreateMock(typeof (ISession));
+
+ using (mocks.Ordered())
+ {
+ SetupCommitExpectations(connection, connectionFactory, session);
+ }
+
+ mocks.ReplayAll();
+
+ NmsTransactionManager tm = new NmsTransactionManager(connectionFactory);
+ ITransactionStatus ts = tm.GetTransaction(new DefaultTransactionDefinition());
+ NmsTemplate nt = new NmsTemplate(connectionFactory);
+ nt.Execute(new AssertSessionCallback(session));
+ tm.Commit(ts);
+
+ mocks.VerifyAll();
+
+ }
+
+ [Test]
+ public void TransactionRollback()
+ {
+ IConnectionFactory connectionFactory = (IConnectionFactory) mocks.CreateMock(typeof (IConnectionFactory));
+ IConnection connection = (IConnection) mocks.CreateMock(typeof (IConnection));
+ ISession session = (ISession) mocks.CreateMock(typeof (ISession));
+
+ SetupRollbackExpectations(connection, connectionFactory, session);
+
+ mocks.ReplayAll();
+
+ NmsTransactionManager tm = new NmsTransactionManager(connectionFactory);
+ ITransactionStatus ts = tm.GetTransaction(new DefaultTransactionDefinition());
+ NmsTemplate nt = new NmsTemplate(connectionFactory);
+ nt.Execute(new AssertSessionCallback(session));
+ tm.Rollback(ts);
+
+ mocks.VerifyAll();
+ }
+
+ /**
+ * TODO because using anonymous delegates - refactor to support .net 1.1 later.
+ */
+#if NET_2_0
+ [Test]
+ public void ParticipatingTransactionWithCommit()
+ {
+ IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory));
+ IConnection connection = (IConnection)mocks.CreateMock(typeof(IConnection));
+ ISession session = (ISession)mocks.CreateMock(typeof(ISession));
+
+ using (mocks.Ordered())
+ {
+ SetupCommitExpectations(connection, connectionFactory, session);
+ }
+
+ mocks.ReplayAll();
+
+
+ NmsTransactionManager tm = new NmsTransactionManager(connectionFactory);
+ ITransactionStatus ts = tm.GetTransaction(new DefaultTransactionDefinition());
+ NmsTemplate nt = new NmsTemplate(connectionFactory);
+ nt.Execute(new AssertSessionCallback(session));
+
+ TransactionTemplate tt = new TransactionTemplate(tm);
+ tt.Execute(delegate(ITransactionStatus status)
+ {
+ nt.Execute(new AssertSessionCallback(session));
+ return null;
+ });
+
+ tm.Commit(ts);
+
+ mocks.VerifyAll();
+
+ }
+
+ [Test]
+ public void ParticipatingTransactionWithRollback()
+ {
+ IConnectionFactory connectionFactory = (IConnectionFactory) mocks.CreateMock(typeof (IConnectionFactory));
+ IConnection connection = (IConnection) mocks.CreateMock(typeof (IConnection));
+ ISession session = (ISession) mocks.CreateMock(typeof (ISession));
+
+ using (mocks.Ordered())
+ {
+ SetupRollbackExpectations(connection, connectionFactory, session);
+ }
+
+ mocks.ReplayAll();
+
+ NmsTransactionManager tm = new NmsTransactionManager(connectionFactory);
+ ITransactionStatus ts = tm.GetTransaction(new DefaultTransactionDefinition());
+ NmsTemplate nt = new NmsTemplate(connectionFactory);
+ nt.Execute(new AssertSessionCallback(session));
+
+ TransactionTemplate tt = new TransactionTemplate(tm);
+ tt.Execute(delegate(ITransactionStatus status)
+ {
+ nt.Execute(new AssertSessionCallback(session));
+ status.RollbackOnly = true;
+ return null;
+ });
+ try
+ {
+ tm.Commit(ts);
+ Assert.Fail("Should have thrown UnexpectedRollbackException");
+ } catch (UnexpectedRollbackException)
+ {
+
+ }
+
+ mocks.VerifyAll();
+ }
+
+ [Test]
+ public void SuspendedTransaction()
+ {
+ IConnectionFactory connectionFactory = (IConnectionFactory) mocks.CreateMock(typeof (IConnectionFactory));
+ IConnection connection = (IConnection) mocks.CreateMock(typeof (IConnection));
+ ISession session = (ISession) mocks.CreateMock(typeof (ISession));
+ ISession session2 = (ISession)mocks.CreateMock(typeof(ISession));
+
+ Expect.Call(connectionFactory.CreateConnection()).Return(connection).Repeat.Twice();
+ Expect.Call(connection.CreateSession(AcknowledgementMode.Transactional)).Return(session).Repeat.Once();
+ Expect.Call(connection.CreateSession(AcknowledgementMode.AutoAcknowledge)).Return(session2).Repeat.Once();
+
+ session.Commit();
+ LastCall.On(session).Repeat.Once();
+ session.Close();
+ LastCall.On(session).Repeat.Once();
+
+ session2.Close();
+ LastCall.On(session2).Repeat.Once();
+
+ connection.Close();
+ LastCall.On(connection).Repeat.Twice();
+
+ mocks.ReplayAll();
+
+ NmsTransactionManager tm = new NmsTransactionManager(connectionFactory);
+ ITransactionStatus ts = tm.GetTransaction(new DefaultTransactionDefinition());
+ NmsTemplate nt = new NmsTemplate(connectionFactory);
+ nt.Execute(new AssertSessionCallback(session));
+
+ TransactionTemplate tt = new TransactionTemplate(tm);
+ tt.PropagationBehavior = TransactionPropagation.NotSupported;
+ tt.Execute(delegate(ITransactionStatus status)
+ {
+ nt.Execute(new AssertNotSameSessionCallback(session));
+ return null;
+ });
+
+ nt.Execute(new AssertSessionCallback(session));
+
+ tm.Commit(ts);
+
+ mocks.VerifyAll();
+
+ }
+
+ [Test]
+ public void TransactionSuspension()
+ {
+ IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory));
+ IConnection connection = (IConnection)mocks.CreateMock(typeof(IConnection));
+ ISession session = (ISession)mocks.CreateMock(typeof(ISession));
+ ISession session2 = (ISession)mocks.CreateMock(typeof(ISession));
+
+
+ Expect.Call(connectionFactory.CreateConnection()).Return(connection).Repeat.Twice();
+ Expect.Call(connection.CreateSession(AcknowledgementMode.Transactional)).Return(session).Repeat.Once();
+ Expect.Call(connection.CreateSession(AcknowledgementMode.Transactional)).Return(session2).Repeat.Once();
+
+ session.Commit();
+ LastCall.On(session).Repeat.Once();
+ session2.Commit();
+ LastCall.On(session2).Repeat.Once();
+
+ session.Close();
+ LastCall.On(session).Repeat.Once();
+ session2.Close();
+ LastCall.On(session2).Repeat.Once();
+
+ connection.Close();
+ LastCall.On(connection).Repeat.Twice();
+
+ mocks.ReplayAll();
+
+ NmsTransactionManager tm = new NmsTransactionManager(connectionFactory);
+ ITransactionStatus ts = tm.GetTransaction(new DefaultTransactionDefinition());
+ NmsTemplate nt = new NmsTemplate(connectionFactory);
+
+
+ TransactionTemplate tt = new TransactionTemplate(tm);
+ tt.PropagationBehavior = TransactionPropagation.RequiresNew;
+ tt.Execute(delegate(ITransactionStatus status)
+ {
+ nt.Execute(new AssertNotSameSessionCallback(session));
+ return null;
+ });
+
+ nt.Execute(new AssertSessionCallback(session));
+
+ tm.Commit(ts);
+
+ mocks.VerifyAll();
+
+ }
+#endif
+
+ private static void SetupRollbackExpectations(IConnection connection, IConnectionFactory connectionFactory, ISession session)
+ {
+ Expect.Call(connectionFactory.CreateConnection()).Return(connection).Repeat.Once();
+ Expect.Call(connection.CreateSession(AcknowledgementMode.Transactional)).Return(session).Repeat.Once();
+ session.Rollback();
+ LastCall.On(session).Repeat.Once();
+ session.Close();
+ LastCall.On(session).Repeat.Once();
+ connection.Close();
+ LastCall.On(connection).Repeat.Once();
+ }
+
+ private static void SetupCommitExpectations(IConnection connection, IConnectionFactory connectionFactory, ISession session)
+ {
+ Expect.Call(connectionFactory.CreateConnection()).Return(connection).Repeat.Once();
+ Expect.Call(connection.CreateSession(AcknowledgementMode.Transactional)).Return(session).Repeat.Once();
+ session.Commit();
+ LastCall.On(session).Repeat.Once();
+ session.Close();
+ LastCall.On(session).Repeat.Once();
+ connection.Close();
+ LastCall.On(connection).Repeat.Once();
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ Assert.IsTrue(TransactionSynchronizationManager.ResourceDictionary.Count == 0);
+ Assert.IsFalse(TransactionSynchronizationManager.SynchronizationActive);
+
+ }
+
+
+ }
+
+ internal class AssertSessionCallback : ISessionCallback
+ {
+ private ISession session;
+ public AssertSessionCallback(ISession session)
+ {
+ this.session = session;
+ }
+
+ #region ISessionCallback Members
+
+ public object DoInNms(ISession session)
+ {
+ Assert.IsTrue(this.session == session);
+ return null;
+ }
+
+ #endregion
+ }
+
+ internal class AssertNotSameSessionCallback : ISessionCallback
+ {
+ private ISession session;
+ public AssertNotSameSessionCallback(ISession session)
+ {
+ this.session = session;
+ }
+
+ #region ISessionCallback Members
+
+ public object DoInNms(ISession session)
+ {
+ Assert.IsTrue(this.session != session);
+ return null;
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/test/Spring/Spring.Messaging.Nms.Tests/Spring.Messaging.Nms.Tests.2005.csproj b/test/Spring/Spring.Messaging.Nms.Tests/Spring.Messaging.Nms.Tests.2005.csproj
index fed9eaac..7c5acc53 100644
--- a/test/Spring/Spring.Messaging.Nms.Tests/Spring.Messaging.Nms.Tests.2005.csproj
+++ b/test/Spring/Spring.Messaging.Nms.Tests/Spring.Messaging.Nms.Tests.2005.csproj
@@ -15,7 +15,7 @@
full
false
..\..\..\build\VS.NET.2005\Spring.Messaging.Nms.Tests\Debug\
- DEBUG;TRACE
+ TRACE;DEBUG;NET_2_0
prompt
4
@@ -28,24 +28,61 @@
4
+
False
..\..\..\lib\net\2.0\antlr.runtime.dll
+
+ False
+ ..\..\..\lib\Net\2.0\Apache.NMS.dll
+
+
+ False
+ ..\..\..\lib\Net\2.0\Common.Logging.dll
+
+
+ False
+ ..\..\..\lib\Net\2.0\Common.Logging.Log4Net.dll
+
+
+ False
+ ..\..\..\lib\Net\2.0\log4net.dll
+
False
..\..\..\lib\net\2.0\nunit.framework.dll
+
+ False
+ ..\..\..\lib\Net\2.0\Rhino.Mocks.dll
+
+
+ {710961A3-0DF4-49E4-A26E-F5B9C044AC84}
+ Spring.Core.2005
+
+
+ {AE00E5AB-C39A-436F-86D2-33BFE33E2E40}
+ Spring.Data.2005
+
{AEB1578C-9018-4D49-B440-789F38DD2F29}
Spring.Messaging.Nms.2005
+
+
+
+
+
+ Always
+
+
diff --git a/test/Spring/Spring.Messaging.Nms.Tests/Spring.Messaging.Nms.Tests.build b/test/Spring/Spring.Messaging.Nms.Tests/Spring.Messaging.Nms.Tests.build
index 12cdae9b..293830e7 100644
--- a/test/Spring/Spring.Messaging.Nms.Tests/Spring.Messaging.Nms.Tests.build
+++ b/test/Spring/Spring.Messaging.Nms.Tests/Spring.Messaging.Nms.Tests.build
@@ -20,7 +20,7 @@
-
+
diff --git a/test/Spring/Spring.Messaging.Nms.Tests/Spring.Messaging.Nms.Tests.dll.config b/test/Spring/Spring.Messaging.Nms.Tests/Spring.Messaging.Nms.Tests.dll.config
new file mode 100644
index 00000000..98ee661f
--- /dev/null
+++ b/test/Spring/Spring.Messaging.Nms.Tests/Spring.Messaging.Nms.Tests.dll.config
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2005.csproj b/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2005.csproj
index 6cd494bb..765a7fa6 100644
--- a/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2005.csproj
+++ b/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2005.csproj
@@ -192,7 +192,7 @@
echo "Copying .xml files for tests"
-xcopy "$(ProjectDir)Data" ..\..\..\..\build\VS.Net.2005\Spring.Web.Tests\$(ConfigurationName)\ /y /s /q /d
+%25SystemRoot%25\system32\xcopy "$(ProjectDir)Data" ..\..\..\..\build\VS.Net.2005\Spring.Web.Tests\$(ConfigurationName)\ /y /s /q /d
\ No newline at end of file