/* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. * */ using System; using System.Threading; using log4net; using NUnit.Framework; using Apache.Qpid.Messaging; using Apache.Qpid.Client.Qms; using Apache.Qpid.Client; namespace Apache.Qpid.Integration.Tests.testcases { /// /// CommitRollbackTest /// ///

///
CRC Card
Responsibilities Collaborations ///
Check that an uncommitted send cannot be received. ///
Check that a committed send can be received. ///
Check that a rolled back send cannot be received. ///
Check that an uncommitted receive can be re-received. ///
Check that a committed receive cannot be re-received. ///
Check that a rolled back receive can be re-received. ///
///

[TestFixture, Category("Integration")] public class CommitRollbackTest : BaseMessagingTestFixture { /// Used for debugging purposes. private static ILog log = LogManager.GetLogger(typeof(CommitRollbackTest)); /// Defines the name of the test topic to use with the tests. public const string TEST_ROUTING_KEY = "commitrollbacktestkey"; [SetUp] public override void Init() { base.Init(); // Create one producer and one consumer, p2p, tx, consumer with queue bound to producers routing key. SetUpEndPoint(0, true, false, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.DIRECT, true, false, null); SetUpEndPoint(1, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.DIRECT, true, false, null); } [TearDown] public override void Shutdown() { try { // Clean up after the test. CloseEndPoint(0); CloseEndPoint(1); } finally { base.Shutdown(); } } /// Check that an uncommitted send cannot be received. [Test] public void TestUncommittedSendNotReceived() { // Send messages. testProducer[0].Send(testChannel[0].CreateTextMessage("A")); // Try to receive messages. ConsumeNMessagesOnly(0, "A", testConsumer[1]); testChannel[1].Commit(); } /// Check that a committed send can be received. [Test] public void TestCommittedSendReceived() { // Send messages. testProducer[0].Send(testChannel[0].CreateTextMessage("A")); testChannel[0].Commit(); // Try to receive messages. ConsumeNMessagesOnly(1, "A", testConsumer[1]); testChannel[1].Commit(); } /// Check that a rolled back send cannot be received. [Test] public void TestRolledBackSendNotReceived() { // Send messages. testProducer[0].Send(testChannel[0].CreateTextMessage("A")); testChannel[0].Rollback(); // Try to receive messages. ConsumeNMessagesOnly(0, "A", testConsumer[1]); testChannel[1].Commit(); } /// Check that an uncommitted receive can be re-received. [Test] public void TestUncommittedReceiveCanBeRereceived() { // Create a third end-point as an alternative delivery route for the message. SetUpEndPoint(2, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.DIRECT, true, false, null); // Send messages. testProducer[0].Send(testChannel[0].CreateTextMessage("A")); testChannel[0].Commit(); // Try to receive messages. ConsumeNMessagesOnly(1, "A", testConsumer[1]); // Close end-point 1 without committing the message, then re-open to consume again. CloseEndPoint(1); // Check that the message was released from the rolled back end-point an can be received on the alternative one instead. ConsumeNMessagesOnly(1, "A", testConsumer[2]); CloseEndPoint(2); } /// Check that a committed receive cannot be re-received. [Test] public void TestCommittedReceiveNotRereceived() { // Send messages. testProducer[0].Send(testChannel[0].CreateTextMessage("A")); testChannel[0].Commit(); // Try to receive messages. ConsumeNMessagesOnly(1, "A", testConsumer[1]); testChannel[1].Commit(); // Try to receive messages. ConsumeNMessagesOnly(0, "A", testConsumer[1]); } /// Check that a rolled back receive can be re-received. [Test] public void TestRolledBackReceiveCanBeRereceived() { // Create a third end-point as an alternative delivery route for the message. SetUpEndPoint(2, false, true, TEST_ROUTING_KEY + testId, AcknowledgeMode.AutoAcknowledge, true, ExchangeNameDefaults.DIRECT, true, false, null); // Send messages. testProducer[0].Send(testChannel[0].CreateTextMessage("A")); testChannel[0].Commit(); // Try to receive messages. ConsumeNMessagesOnly(1, "A", testConsumer[1]); testChannel[1].Rollback(); // Try to receive messages. ConsumeNMessagesOnly(1, "A", testConsumer[2]); CloseEndPoint(2); } } }