SPRNET-1020 - Consumer caching was not taking place for queues.

This commit is contained in:
markpollack
2008-09-04 18:29:40 +00:00
parent c9fcc24a2a
commit dff26cbcde
6 changed files with 108 additions and 10 deletions

View File

@@ -42,6 +42,16 @@ namespace Spring.Messaging.Nms.Connections
this.target = target;
}
/// <summary>
/// Gets the target MessageConsumer, the consumer we are 'wrapping'
/// </summary>
/// <value>The target MessageConsumer.</value>
public IMessageConsumer Target
{
get { return target; }
}
/// <summary>
/// Register for message events.
/// </summary>

View File

@@ -444,7 +444,7 @@ namespace Spring.Messaging.Nms.Connections
}
else
{
return target.CreateConsumer(destination, selector);
consumer = target.CreateConsumer(destination, selector);
}
if (LOG.IsDebugEnabled)
{

View File

@@ -21,6 +21,7 @@
#region Imports
using Apache.NMS;
using Apache.NMS.ActiveMQ.Commands;
using NUnit.Framework;
using Rhino.Mocks;
@@ -208,6 +209,53 @@ namespace Spring.Messaging.Nms.Connections
mocks.VerifyAll();
}
/// <summary>
/// Tests that the same underlying instance of the message consumer is returned after
/// creating a session, creating the consumer (A), closing the session, and creating another
/// consumer (B). Assert that (A)=(B).
/// </summary>
[Test]
public void CachedMessageConsumer()
{
IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory));
IConnection connection = new TestConnection();
Expect.Call(connectionFactory.CreateConnection()).Return(connection).Repeat.Once();
mocks.ReplayAll();
CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
cachingConnectionFactory.TargetConnectionFactory = connectionFactory;
IConnection con1 = cachingConnectionFactory.CreateConnection();
ISession sessionA = con1.CreateSession(AcknowledgementMode.Transactional);
IDestination destination = new ActiveMQQueue("test.dest");
IMessageConsumer consumerA = sessionA.CreateConsumer(destination);
TestMessageConsumer tmpA = GetTestMessageConsumer(consumerA);
sessionA.Close();
ISession sessionB = con1.CreateSession(AcknowledgementMode.Transactional);
IMessageConsumer consumerB = sessionB.CreateConsumer(destination);
TestMessageConsumer tmpB = GetTestMessageConsumer(consumerB);
Assert.AreSame(tmpA, tmpB);
mocks.VerifyAll();
}
private static TestMessageConsumer GetTestMessageConsumer(IMessageConsumer consumer)
{
CachedMessageConsumer cmp1 = consumer as CachedMessageConsumer;
Assert.IsNotNull(cmp1);
TestMessageConsumer tmp1 = cmp1.Target as TestMessageConsumer;
Assert.IsNotNull(tmp1);
return tmp1;
}
private static TestMessageProducer GetTestMessageProducer(IMessageProducer producer1)
{
CachedMessageProducer cmp1 = producer1 as CachedMessageProducer;

View File

@@ -0,0 +1,38 @@
using System;
using Apache.NMS;
namespace Spring.Messaging.Nms.Connections
{
public class TestMessageConsumer : IMessageConsumer
{
public event MessageListener Listener;
public IMessage Receive()
{
throw new NotImplementedException();
}
public IMessage Receive(TimeSpan timeout)
{
throw new NotImplementedException();
}
public IMessage ReceiveNoWait()
{
throw new NotImplementedException();
}
public void Close()
{
throw new NotImplementedException();
}
public void Dispose()
{
throw new NotImplementedException();
}
}
}

View File

@@ -66,46 +66,47 @@ namespace Spring.Messaging.Nms.Connections
public IMessageConsumer CreateConsumer(IDestination destination)
{
throw new NotImplementedException();
return new TestMessageConsumer();
}
public IMessageConsumer CreateConsumer(IDestination destination, TimeSpan requestTimeout)
{
throw new NotImplementedException();
return new TestMessageConsumer();
}
public IMessageConsumer CreateConsumer(IDestination destination, string selector)
{
return new TestMessageConsumer();
//IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory));
IMessageConsumer msgConsumer = (IMessageConsumer) mocks.CreateMock(typeof (IMessageConsumer));
return msgConsumer;
//IMessageConsumer msgConsumer = (IMessageConsumer) mocks.CreateMock(typeof (IMessageConsumer));
//return msgConsumer;
}
public IMessageConsumer CreateConsumer(IDestination destination, string selector, TimeSpan requestTimeout)
{
throw new NotImplementedException();
return new TestMessageConsumer();
}
public IMessageConsumer CreateConsumer(IDestination destination, string selector, bool noLocal)
{
throw new NotImplementedException();
return new TestMessageConsumer();
}
public IMessageConsumer CreateConsumer(IDestination destination, string selector, bool noLocal,
TimeSpan requestTimeout)
{
throw new NotImplementedException();
return new TestMessageConsumer();
}
public IMessageConsumer CreateDurableConsumer(ITopic destination, string name, string selector, bool noLocal)
{
throw new NotImplementedException();
return new TestMessageConsumer();
}
public IMessageConsumer CreateDurableConsumer(ITopic destination, string name, string selector, bool noLocal,
TimeSpan requestTimeout)
{
throw new NotImplementedException();
return new TestMessageConsumer();
}
public void DeleteDurableConsumer(string name)

View File

@@ -94,6 +94,7 @@
<Compile Include="Messaging\Nms\Connections\SingleConnectionFactoryTests.cs" />
<Compile Include="Messaging\Nms\Connections\TestConnection.cs" />
<Compile Include="Messaging\Nms\Connections\TestExceptionListener.cs" />
<Compile Include="Messaging\Nms\Connections\TestMessageConsumer.cs" />
<Compile Include="Messaging\Nms\Connections\TestMessageListener.cs" />
<Compile Include="Messaging\Nms\Connections\TestMessageProducer.cs" />
<Compile Include="Messaging\Nms\Connections\TestSession.cs" />