Apache.NMS.Test.TransactionTest.TestRedispatchOfUncommittedTx C# (CSharp) Method

TestRedispatchOfUncommittedTx() private method

private TestRedispatchOfUncommittedTx ( [ deliveryMode ) : void
deliveryMode [
return void
        public void TestRedispatchOfUncommittedTx(
			[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
			MsgDeliveryMode deliveryMode)
        {
            using(IConnection connection = CreateConnection(GetTestClientId()))
            {
                connection.Start();
                ISession session = connection.CreateSession(AcknowledgementMode.Transactional);
                IQueue destination = session.GetQueue("TestRedispatchOfUncommittedTx:"+Guid.NewGuid());

                SendMessages(connection, destination, deliveryMode, 2);

                IMessageConsumer consumer = session.CreateConsumer(destination);
                Assert.IsNotNull(consumer.Receive(TimeSpan.FromMilliseconds(2000)));
                Assert.IsNotNull(consumer.Receive(TimeSpan.FromMilliseconds(2000)));

                // install another consumer while message dispatch is unacked/uncommitted
                ISession redispatchSession = connection.CreateSession(AcknowledgementMode.Transactional);
                IMessageConsumer redispatchConsumer = redispatchSession.CreateConsumer(destination);

                // no commit so will auto rollback and get re-dispatched to redisptachConsumer
                session.Close();

                IMessage msg = redispatchConsumer.Receive(TimeSpan.FromMilliseconds(2000));
                Assert.IsNotNull(msg);
                Assert.IsTrue(msg.NMSRedelivered);
                Assert.AreEqual(2, msg.Properties.GetLong("NMSXDeliveryCount"));

                msg = redispatchConsumer.Receive(TimeSpan.FromMilliseconds(2000));
                Assert.IsNotNull(msg);
                Assert.IsTrue(msg.NMSRedelivered);
                Assert.AreEqual(2, msg.Properties.GetLong("NMSXDeliveryCount"));
                redispatchSession.Commit();

                Assert.IsNull(redispatchConsumer.Receive(TimeSpan.FromMilliseconds(500)));
                redispatchSession.Close();
            }
        }