Package org.apache.qpid.test.testcases

Source Code of org.apache.qpid.test.testcases.ImmediateMessageTest

/*
*
* 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.
*
*/
package org.apache.qpid.test.testcases;

import org.apache.qpid.test.framework.AMQPPublisher;
import org.apache.qpid.test.framework.Circuit;
import org.apache.qpid.test.framework.FrameworkBaseCase;
import org.apache.qpid.test.framework.MessagingTestConfigProperties;
import static org.apache.qpid.test.framework.MessagingTestConfigProperties.*;
import org.apache.qpid.test.framework.sequencers.CircuitFactory;

import org.apache.qpid.junit.extensions.util.TestContextProperties;

/**
* ImmediateMessageTest tests for the desired behaviour of immediate messages. Immediate messages are a non-JMS
* feature. A message may be marked with an immediate delivery flag, which means that a consumer must be connected
* to receive the message, through a valid route, when it is sent, or when its transaction is committed in the case
* of transactional messaging. If this is not the case, the broker should return the message with a NO_CONSUMERS code.
*
* <p><table id="crc"><caption>CRC Card</caption>
* <tr><th> Responsibilities <th> Collaborations
* <tr><td> Check that an immediate message is sent succesfully not using transactions when a consumer is connected.
* <tr><td> Check that an immediate message is committed succesfully in a transaction when a consumer is connected.
* <tr><td> Check that an immediate message results in no consumers code, not using transactions, when a consumer is
*          disconnected.
* <tr><td> Check that an immediate message results in no consumers code, in a transaction, when a consumer is
*          disconnected.
* <tr><td> Check that an immediate message results in no route code, not using transactions, when no outgoing route is
*          connected.
* <tr><td> Check that an immediate message results in no route code, upon transaction commit, when no outgoing route is
*          connected.
* <tr><td> Check that an immediate message is sent succesfully not using transactions when a consumer is connected.
* <tr><td> Check that an immediate message is committed succesfully in a transaction when a consumer is connected.
* <tr><td> Check that an immediate message results in no consumers code, not using transactions, when a consumer is
*          disconnected.
* <tr><td> Check that an immediate message results in no consumers code, in a transaction, when a consumer is
*          disconnected.
* <tr><td> Check that an immediate message results in no route code, not using transactions, when no outgoing route is
*          connected.
* <tr><td> Check that an immediate message results in no route code, upon transaction commit, when no outgoing route is
*          connected.
* </table>
*
* @todo All of these test cases will be generated by a test generator that thoroughly tests all combinations of test
*       circuits.
*/
public class ImmediateMessageTest extends FrameworkBaseCase
{
    /**
     * Creates a new test case with the specified name.
     *
     * @param name The test case name.
     */
    public ImmediateMessageTest(String name)
    {
        super(name);
    }

    /** Check that an immediate message is sent succesfully not using transactions when a consumer is connected. */
    public void test_QPID_517_ImmediateOkNoTxP2P() throws Exception
    {
        // Ensure transactional sessions are off.
        getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, false);
        getTestProps().setProperty(PUBSUB_PROPNAME, false);

        // Run the default test sequence over the test circuit checking for no errors.
        CircuitFactory circuitFactory = getCircuitFactory();
        Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps());

        assertNoFailures(testCircuit.test(1, assertionList(testCircuit.getPublisher().noExceptionsAssertion(getTestProps()))));
    }

    /** Check that an immediate message is committed succesfully in a transaction when a consumer is connected. */
    public void test_QPID_517_ImmediateOkTxP2P() throws Exception
    {
        // Ensure transactional sessions are off.
        getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, true);
        getTestProps().setProperty(PUBSUB_PROPNAME, false);

        // Send one message with no errors.
        CircuitFactory circuitFactory = getCircuitFactory();
        Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps());

        assertNoFailures(testCircuit.test(1, assertionList(testCircuit.getPublisher().noExceptionsAssertion(getTestProps()))));
    }

    /** Check that an immediate message results in no consumers code, not using transactions, when a consumer is disconnected. */
    public void test_QPID_517_ImmediateFailsConsumerDisconnectedNoTxP2P() throws Exception
    {
        // Ensure transactional sessions are off.
        getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, false);
        getTestProps().setProperty(PUBSUB_PROPNAME, false);

        // Disconnect the consumer.
        getTestProps().setProperty(RECEIVER_CONSUMER_ACTIVE_PROPNAME, false);

        CircuitFactory circuitFactory = getCircuitFactory();
        Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps());

        // Send one message and get a linked no consumers exception.
        assertNoFailures(testCircuit.test(1,
                assertionList(((AMQPPublisher) testCircuit.getPublisher()).noConsumersAssertion(getTestProps()))));
    }

    /** Check that an immediate message results in no consumers code, in a transaction, when a consumer is disconnected. */
    public void test_QPID_517_ImmediateFailsConsumerDisconnectedTxP2P() throws Exception
    {
        // Ensure transactional sessions are on.
        getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, true);
        getTestProps().setProperty(PUBSUB_PROPNAME, false);

        // Disconnect the consumer.
        getTestProps().setProperty(RECEIVER_CONSUMER_ACTIVE_PROPNAME, false);

        CircuitFactory circuitFactory = getCircuitFactory();
        Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps());

        // Send one message and get a linked no consumers exception.
        assertNoFailures(testCircuit.test(1,
                assertionList(((AMQPPublisher) testCircuit.getPublisher()).noConsumersAssertion(getTestProps()))));
    }

    /** Check that an immediate message results in no route code, not using transactions, when no outgoing route is connected. */
    public void test_QPID_517_ImmediateFailsNoRouteNoTxP2P() throws Exception
    {
        // Ensure transactional sessions are off.
        getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, false);
        getTestProps().setProperty(PUBSUB_PROPNAME, false);

        // Set up the messaging topology so that only the publishers producer is bound (do not set up the receivers to
        // collect its messages).
        getTestProps().setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, false);

        // Send one message and get a linked no route exception.
        CircuitFactory circuitFactory = getCircuitFactory();
        Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps());

        assertNoFailures(testCircuit.test(1,
                assertionList(((AMQPPublisher) testCircuit.getPublisher()).noRouteAssertion(getTestProps()))));
    }

    /** Check that an immediate message results in no route code, upon transaction commit, when no outgoing route is connected. */
    public void test_QPID_517_ImmediateFailsNoRouteTxP2P() throws Exception
    {
        // Ensure transactional sessions are on.
        getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, true);
        getTestProps().setProperty(PUBSUB_PROPNAME, false);

        // Set up the messaging topology so that only the publishers producer is bound (do not set up the receivers to
        // collect its messages).
        getTestProps().setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, false);

        // Send one message and get a linked no route exception.
        CircuitFactory circuitFactory = getCircuitFactory();
        Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps());

        assertNoFailures(testCircuit.test(1,
                assertionList(((AMQPPublisher) testCircuit.getPublisher()).noRouteAssertion(getTestProps()))));
    }

    /** Check that an immediate message is sent succesfully not using transactions when a consumer is connected. */
    public void test_QPID_517_ImmediateOkNoTxPubSub() throws Exception
    {
        // Ensure transactional sessions are off.
        getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, false);
        getTestProps().setProperty(PUBSUB_PROPNAME, true);

        // Send one message with no errors.
        CircuitFactory circuitFactory = getCircuitFactory();
        Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps());

        assertNoFailures(testCircuit.test(1,
                assertionList(((AMQPPublisher) testCircuit.getPublisher()).noExceptionsAssertion(getTestProps()))));
    }

    /** Check that an immediate message is committed succesfully in a transaction when a consumer is connected. */
    public void test_QPID_517_ImmediateOkTxPubSub() throws Exception
    {
        // Ensure transactional sessions are off.
        getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, true);
        getTestProps().setProperty(PUBSUB_PROPNAME, true);

        // Send one message with no errors.
        CircuitFactory circuitFactory = getCircuitFactory();
        Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps());

        assertNoFailures(testCircuit.test(1,
                assertionList(((AMQPPublisher) testCircuit.getPublisher()).noExceptionsAssertion(getTestProps()))));
    }

    /** Check that an immediate message results in no consumers code, not using transactions, when a consumer is disconnected. */
    public void test_QPID_517_ImmediateFailsConsumerDisconnectedNoTxPubSub() throws Exception
    {
        // Ensure transactional sessions are off.
        getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, false);
        getTestProps().setProperty(PUBSUB_PROPNAME, true);

        // Use durable subscriptions, so that the route remains open with no subscribers.
        getTestProps().setProperty(DURABLE_SUBSCRIPTION_PROPNAME, true);

        // Disconnect the consumer.
        getTestProps().setProperty(RECEIVER_CONSUMER_ACTIVE_PROPNAME, false);

        CircuitFactory circuitFactory = getCircuitFactory();
        Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps());

        // Send one message and get a linked no consumers exception.
        assertNoFailures(testCircuit.test(1,
                assertionList(((AMQPPublisher) testCircuit.getPublisher()).noConsumersAssertion(getTestProps()))));
    }

    /** Check that an immediate message results in no consumers code, in a transaction, when a consumer is disconnected. */
    public void test_QPID_517_ImmediateFailsConsumerDisconnectedTxPubSub() throws Exception
    {
        // Ensure transactional sessions are on.
        getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, true);
        getTestProps().setProperty(PUBSUB_PROPNAME, true);

        // Use durable subscriptions, so that the route remains open with no subscribers.
        getTestProps().setProperty(DURABLE_SUBSCRIPTION_PROPNAME, true);

        // Disconnect the consumer.
        getTestProps().setProperty(RECEIVER_CONSUMER_ACTIVE_PROPNAME, false);

        CircuitFactory circuitFactory = getCircuitFactory();
        Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps());

        // Send one message and get a linked no consumers exception.
        assertNoFailures(testCircuit.test(1,
                assertionList(((AMQPPublisher) testCircuit.getPublisher()).noConsumersAssertion(getTestProps()))));
    }

    /** Check that an immediate message results in no route code, not using transactions, when no outgoing route is connected. */
    public void test_QPID_517_ImmediateFailsNoRouteNoTxPubSub() throws Exception
    {
        // Ensure transactional sessions are off.
        getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, false);
        getTestProps().setProperty(PUBSUB_PROPNAME, true);

        // Set up the messaging topology so that only the publishers producer is bound (do not set up the receivers to
        // collect its messages).
        getTestProps().setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, false);

        // Send one message and get a linked no route exception.
        CircuitFactory circuitFactory = getCircuitFactory();
        Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps());

        assertNoFailures(testCircuit.test(1,
                assertionList(((AMQPPublisher) testCircuit.getPublisher()).noRouteAssertion(getTestProps()))));
    }

    /** Check that an immediate message results in no route code, upon transaction commit, when no outgoing route is connected. */
    public void test_QPID_517_ImmediateFailsNoRouteTxPubSub() throws Exception
    {
        // Ensure transactional sessions are on.
        getTestProps().setProperty(TRANSACTED_PUBLISHER_PROPNAME, true);
        getTestProps().setProperty(PUBSUB_PROPNAME, true);

        // Set up the messaging topology so that only the publishers producer is bound (do not set up the receivers to
        // collect its messages).
        getTestProps().setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, false);

        // Send one message and get a linked no route exception.
        CircuitFactory circuitFactory = getCircuitFactory();
        Circuit testCircuit = circuitFactory.createCircuit(getConnection(), getTestProps());

        assertNoFailures(testCircuit.test(1,
                assertionList(((AMQPPublisher) testCircuit.getPublisher()).noRouteAssertion(getTestProps()))));
    }

    protected void setUp() throws Exception
    {
        super.setUp();

        setTestProps(TestContextProperties.getInstance(MessagingTestConfigProperties.defaults));

        /** All these tests should have the immediate flag on. */
        getTestProps().setProperty(IMMEDIATE_PROPNAME, true);
        getTestProps().setProperty(MANDATORY_PROPNAME, false);

        /** Bind the receivers consumer by default. */
        getTestProps().setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, true);
        getTestProps().setProperty(RECEIVER_CONSUMER_ACTIVE_PROPNAME, true);
    }
}
TOP

Related Classes of org.apache.qpid.test.testcases.ImmediateMessageTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.