Sync to trunk implementations in Java (post 2.5.6 atm)

CachedMessageProducer initializes its deliveryMode, priority and timeToLive fields with the target's settings 
NmsResourceHolder remove all Connections and Sessions after closing 
CachingConnectionFactory rolls back cached transacted JMS Sessions on logical close if no commit/rollback was issued
CachingConnectionFactory explicitly closes cached JMS Sessions on Connection close
CachingConnectionFactory consistently rollback and physically close Sessions on close() 
CachingConnectionFactory also caches MessageConsumers (controlled through "cache…
CachedMessageProducers pass on "disableMessageID" and "disableMessageTimestamp" properties 
SingleConnectionFactory only calls "Connection.Stop()" on reset when the shared Connection has actually been started
This commit is contained in:
markpollack
2008-08-12 19:09:13 +00:00
parent 63aebbf99c
commit 06e1dfdbe0
15 changed files with 637 additions and 90 deletions

View File

@@ -32,7 +32,6 @@ namespace Spring.Messaging.Nms.Connections
/// This class contains tests for
/// </summary>
/// <author>Mark Pollack</author>
/// <version>$Id:$</version>
[TestFixture]
public class CachingConnectionFactoryTests
{

View File

@@ -232,5 +232,64 @@ namespace Spring.Messaging.Nms.Connections
Assert.AreEqual(2, con.CloseCount);
Assert.AreEqual(1, listener.Count);
}
[Test]
public void CachingConnectionFactory()
{
IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory));
IConnection connection = (IConnection)mocks.CreateMock(typeof(IConnection));
ISession txSession = (ISession)mocks.CreateMock(typeof(ISession));
ISession nonTxSession = (ISession)mocks.CreateMock(typeof(ISession));
Expect.Call(connectionFactory.CreateConnection()).Return(connection).Repeat.Once();
Expect.Call(connection.CreateSession(AcknowledgementMode.Transactional)).Return(txSession).Repeat.Once();
Expect.Call(txSession.Transacted).Return(true).Repeat.Twice();
txSession.Rollback();
LastCall.Repeat.Once();
txSession.Commit();
LastCall.Repeat.Once();
txSession.Close();
LastCall.Repeat.Once();
Expect.Call(connection.CreateSession(AcknowledgementMode.ClientAcknowledge)).Return(nonTxSession).Repeat.Once();
nonTxSession.Close();
LastCall.Repeat.Once();
connection.Start();
LastCall.Repeat.Twice();
connection.Stop();
LastCall.Repeat.Once();
connection.Close();
LastCall.Repeat.Once();
mocks.ReplayAll();
CachingConnectionFactory scf = new CachingConnectionFactory(connectionFactory);
scf.ReconnectOnException = false;
IConnection con1 = scf.CreateConnection();
ISession session1 = con1.CreateSession(AcknowledgementMode.Transactional);
bool b = session1.Transacted;
session1.Close(); // should be ignored
session1 = con1.CreateSession(AcknowledgementMode.ClientAcknowledge);
session1.Close(); // should be ignored
con1.Start();
con1.Close(); // should be ignored
IConnection con2 = scf.CreateConnection();
ISession session2 = con2.CreateSession(AcknowledgementMode.ClientAcknowledge);
session2.Close(); // should be ignored
session2 = con2.CreateSession(AcknowledgementMode.Transactional);
session2.Commit();
session2.Close(); // should be ignored
con2.Start();
con2.Close();
scf.Dispose();
mocks.Verify(connectionFactory);
mocks.Verify(connection);
mocks.Verify(txSession);
mocks.Verify(nonTxSession);
}
}
}

View File

@@ -26,6 +26,9 @@ namespace Spring.Messaging.Nms.Connections
public class TestMessageProducer : IMessageProducer
{
private bool persistent;
private TimeSpan timeToLive = new TimeSpan(0,0,0,60,0);
public void Send(IMessage message)
{
throw new NotImplementedException();
@@ -83,20 +86,20 @@ namespace Spring.Messaging.Nms.Connections
public bool Persistent
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
get { return persistent; }
set { persistent = value; }
}
public TimeSpan TimeToLive
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
get { return timeToLive; }
set { timeToLive = value; }
}
public byte Priority
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
get { return 1; }
set { }
}
public bool DisableMessageID

View File

@@ -143,17 +143,17 @@ namespace Spring.Messaging.Nms.Connections
public void Commit()
{
throw new NotImplementedException();
}
public void Rollback()
{
throw new NotImplementedException();
}
public bool Transacted
{
get { throw new NotImplementedException(); }
get { return true; }
}
public AcknowledgementMode AcknowledgementMode