public void CachedMessageProducerTwoRequests() { IConnectionFactory connectionFactory = CreateConnectionFactory(); CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(); cachingConnectionFactory.TargetConnectionFactory = connectionFactory; IConnection con1 = cachingConnectionFactory.CreateConnection(); ISession sessionA = con1.CreateSession(AcknowledgementMode.Transactional); IMessageProducer producerA = sessionA.CreateProducer(); TestMessageProducer tmpA = GetTestMessageProducer(producerA); ISession sessionB = con1.CreateSession(AcknowledgementMode.Transactional); IMessageProducer producerB = sessionB.CreateProducer(); TestMessageProducer tmpB = GetTestMessageProducer(producerB); Assert.AreNotSame(tmpA, tmpB); sessionA.Close(); ISession sessionC = con1.CreateSession(AcknowledgementMode.Transactional); IMessageProducer producerC = sessionC.CreateProducer(); TestMessageProducer tmpC = GetTestMessageProducer(producerC); Assert.AreSame(tmpA, tmpC); }
public void CachedSession() { IConnectionFactory connectionFactory = CreateConnectionFactory(); mocks.ReplayAll(); CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(); cachingConnectionFactory.TargetConnectionFactory = connectionFactory; IConnection con1 = cachingConnectionFactory.CreateConnection(); ISession session1 = con1.CreateSession(AcknowledgementMode.Transactional); TestSession testSession = GetTestSession(session1); Assert.AreEqual(1, testSession.CreatedCount); Assert.AreEqual(0, testSession.CloseCount); session1.Close(); // won't close, will put in session cache. Assert.AreEqual(0, testSession.CloseCount); ISession session2 = con1.CreateSession(AcknowledgementMode.Transactional); TestSession testSession2 = GetTestSession(session2); Assert.AreSame(testSession, testSession2); Assert.AreEqual(1, testSession.CreatedCount); Assert.AreEqual(0, testSession.CloseCount); mocks.VerifyAll(); //don't explicitly call close on }
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(); }
public void CachedSession() { IConnectionFactory connectionFactory = CreateConnectionFactory(); CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(); cachingConnectionFactory.TargetConnectionFactory = connectionFactory; IConnection con1 = cachingConnectionFactory.CreateConnection(); ISession session1 = con1.CreateSession(AcknowledgementMode.Transactional); TestSession testSession = GetTestSession(session1); Assert.AreEqual(1, testSession.CreatedCount); Assert.AreEqual(0, testSession.CloseCount); session1.Close(); // won't close, will put in session cache. Assert.AreEqual(0, testSession.CloseCount); ISession session2 = con1.CreateSession(AcknowledgementMode.Transactional); TestSession testSession2 = GetTestSession(session2); Assert.AreSame(testSession, testSession2); Assert.AreEqual(1, testSession.CreatedCount); Assert.AreEqual(0, testSession.CloseCount); //don't explicitly call close on }
public void CachedMessageProducer() { 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); IMessageProducer producerA = sessionA.CreateProducer(); TestMessageProducer tmpA = GetTestMessageProducer(producerA); sessionA.Close(); ISession sessionB = con1.CreateSession(AcknowledgementMode.Transactional); IMessageProducer producerB = sessionB.CreateProducer(); TestMessageProducer tmpB = GetTestMessageProducer(producerB); Assert.AreSame(tmpA, tmpB); mocks.VerifyAll(); }
public void CachedMessageConsumer() { IConnectionFactory connectionFactory = CreateConnectionFactory(); 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(); }
public void CachingConnectionFactory() { IConnectionFactory connectionFactory = mocks.StrictMock <IConnectionFactory>(); IConnection connection = mocks.StrictMock <IConnection>(); ISession txSession = mocks.StrictMock <ISession>(); ISession nonTxSession = mocks.StrictMock <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); }
/// <summary> /// Initializes a new instance of the <see cref="CachedSession"/> class. /// </summary> /// <param name="targetSession">The target session.</param> /// <param name="sessionList">The session list.</param> /// <param name="ccf">The CachingConnectionFactory.</param> public CachedSession(ISession targetSession, LinkedList sessionList, CachingConnectionFactory ccf) { target = targetSession; this.sessionList = sessionList; sessionCacheSize = ccf.SessionCacheSize; shouldCacheProducers = ccf.CacheProducers; shouldCacheConsumers = ccf.CacheConsumers; this.ccf = ccf; }
/// <summary> /// Initializes a new instance of the <see cref="CachedSession"/> class. /// </summary> /// <param name="targetSession">The target session.</param> /// <param name="sessionList">The session list.</param> /// <param name="ccf">The CachingConnectionFactory.</param> public CachedSession(ISession targetSession, LinkedList sessionList, CachingConnectionFactory ccf) { target = targetSession; this.sessionList = sessionList; this.sessionCacheSize = ccf.SessionCacheSize; shouldCacheProducers = ccf.CacheProducers; shouldCacheConsumers = ccf.CacheConsumers; this.ccf = ccf; }
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); }
public void CachingConnectionFactory() { IConnectionFactory connectionFactory = A.Fake <IConnectionFactory>(); IConnection connection = A.Fake <IConnection>(); ISession txSession = A.Fake <ISession>(); ISession nonTxSession = A.Fake <ISession>(); A.CallTo(() => connectionFactory.CreateConnection()).Returns(connection).Once(); A.CallTo(() => connection.CreateSession(AcknowledgementMode.Transactional)).Returns(txSession).Once(); A.CallTo(() => txSession.Transacted).Returns(true).Twice(); A.CallTo(() => connection.CreateSession(AcknowledgementMode.ClientAcknowledge)).Returns(nonTxSession).Once(); 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(); A.CallTo(() => txSession.Rollback()).MustHaveHappenedOnceExactly(); A.CallTo(() => txSession.Commit()).MustHaveHappenedOnceExactly(); A.CallTo(() => txSession.Close()).MustHaveHappenedOnceExactly(); A.CallTo(() => nonTxSession.Close()).MustHaveHappenedOnceExactly(); A.CallTo(() => connection.Start()).MustHaveHappenedTwiceExactly(); A.CallTo(() => connection.Stop()).MustHaveHappenedOnceExactly(); A.CallTo(() => connection.Close()).MustHaveHappenedOnceExactly(); }
public void CachedSessionTwoRequests() { 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 session1 = con1.CreateSession(AcknowledgementMode.Transactional); TestSession testSession1 = GetTestSession(session1); Assert.AreEqual(1, testSession1.CreatedCount); Assert.AreEqual(0, testSession1.CloseCount); //will create a new one, not in the cache. ISession session2 = con1.CreateSession(AcknowledgementMode.Transactional); TestSession testSession2 = GetTestSession(session2); Assert.AreEqual(1, testSession2.CreatedCount); Assert.AreEqual(0, testSession2.CloseCount); Assert.AreNotSame(testSession1, testSession2); Assert.AreNotSame(session1, session2); session1.Close(); // will be put in the cache ISession session3 = con1.CreateSession(AcknowledgementMode.Transactional); TestSession testSession3 = GetTestSession(session3); Assert.AreSame(testSession1, testSession3); Assert.AreSame(session1, session3); Assert.AreEqual(1, testSession1.CreatedCount); Assert.AreEqual(0, testSession1.CloseCount); mocks.VerifyAll(); }
public void CachedSession() { 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 session1 = con1.CreateSession(AcknowledgementMode.Transactional); TestSession testSession = GetTestSession(session1); Assert.AreEqual(1, testSession.CreatedCount); Assert.AreEqual(0, testSession.CloseCount); session1.Close(); // won't close, will put in session cache. Assert.AreEqual(0, testSession.CloseCount); ISession session2 = con1.CreateSession(AcknowledgementMode.Transactional); TestSession testSession2 = GetTestSession(session2); Assert.AreSame(testSession, testSession2); Assert.AreEqual(1, testSession.CreatedCount); Assert.AreEqual(0, testSession.CloseCount); mocks.VerifyAll(); //don't explicitly call close on }
public void CachedSessionTwoRequests() { IConnectionFactory connectionFactory = CreateConnectionFactory(); CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(); cachingConnectionFactory.TargetConnectionFactory = connectionFactory; IConnection con1 = cachingConnectionFactory.CreateConnection(); ISession session1 = con1.CreateSession(AcknowledgementMode.Transactional); TestSession testSession1 = GetTestSession(session1); Assert.AreEqual(1, testSession1.CreatedCount); Assert.AreEqual(0, testSession1.CloseCount); //will create a new one, not in the cache. ISession session2 = con1.CreateSession(AcknowledgementMode.Transactional); TestSession testSession2 = GetTestSession(session2); Assert.AreEqual(1, testSession2.CreatedCount); Assert.AreEqual(0, testSession2.CloseCount); Assert.AreNotSame(testSession1, testSession2); Assert.AreNotSame(session1, session2); session1.Close(); // will be put in the cache ISession session3 = con1.CreateSession(AcknowledgementMode.Transactional); TestSession testSession3 = GetTestSession(session3); Assert.AreSame(testSession1, testSession3); Assert.AreSame(session1, session3); Assert.AreEqual(1, testSession1.CreatedCount); Assert.AreEqual(0, testSession1.CloseCount); }
public void CachedSessionTwoRequests() { IConnectionFactory connectionFactory = CreateConnectionFactory(); mocks.ReplayAll(); CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(); cachingConnectionFactory.TargetConnectionFactory = connectionFactory; IConnection con1 = cachingConnectionFactory.CreateConnection(); ISession session1 = con1.CreateSession(AcknowledgementMode.Transactional); TestSession testSession1 = GetTestSession(session1); Assert.AreEqual(1, testSession1.CreatedCount); Assert.AreEqual(0, testSession1.CloseCount); //will create a new one, not in the cache. ISession session2 = con1.CreateSession(AcknowledgementMode.Transactional); TestSession testSession2 = GetTestSession(session2); Assert.AreEqual(1, testSession2.CreatedCount); Assert.AreEqual(0, testSession2.CloseCount); Assert.AreNotSame(testSession1, testSession2); Assert.AreNotSame(session1, session2); session1.Close(); // will be put in the cache ISession session3 = con1.CreateSession(AcknowledgementMode.Transactional); TestSession testSession3 = GetTestSession(session3); Assert.AreSame(testSession1, testSession3); Assert.AreSame(session1, session3); Assert.AreEqual(1, testSession1.CreatedCount); Assert.AreEqual(0, testSession1.CloseCount); mocks.VerifyAll(); }
public void CachedMessageProducerTwoRequests() { IConnectionFactory connectionFactory = CreateConnectionFactory(); mocks.ReplayAll(); CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(); cachingConnectionFactory.TargetConnectionFactory = connectionFactory; IConnection con1 = cachingConnectionFactory.CreateConnection(); ISession sessionA = con1.CreateSession(AcknowledgementMode.Transactional); IMessageProducer producerA = sessionA.CreateProducer(); TestMessageProducer tmpA = GetTestMessageProducer(producerA); ISession sessionB = con1.CreateSession(AcknowledgementMode.Transactional); IMessageProducer producerB = sessionB.CreateProducer(); TestMessageProducer tmpB = GetTestMessageProducer(producerB); Assert.AreNotSame(tmpA, tmpB); sessionA.Close(); ISession sessionC = con1.CreateSession(AcknowledgementMode.Transactional); IMessageProducer producerC = sessionC.CreateProducer(); TestMessageProducer tmpC = GetTestMessageProducer(producerC); Assert.AreSame(tmpA, tmpC); mocks.VerifyAll(); }