summaryrefslogtreecommitdiff
path: root/qpid/java/systests/src/main/java/org/apache/qpid/test/testcases/MandatoryMessageTest.java
blob: b4c4eb91b41e27171dd367f82bea6f90a0cf7b50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/*
 *
 * 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.ParsedProperties;
import org.apache.qpid.junit.extensions.util.TestContextProperties;

/**
 * MandatoryMessageTest tests for the desired behaviour of mandatory messages. Mandatory messages are a non-JMS
 * feature. A message may be marked with a mandatory delivery flag, which means that a valid route for the message
 * must exist, 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 mandatory message is sent succesfully not using transactions when a consumer is connected.
 * <tr><td> Check that an mandatory message is committed succesfully in a transaction when a consumer is connected.
 * <tr><td> Check that a mandatory message is sent succesfully, not using transactions, when a consumer is disconnected
 *          but the route exists.
 * <tr><td> Check that a mandatory message is sent succesfully, in a transaction, when a consumer is disconnected but
 *          the route exists.
 * <tr><td> Check that an mandatory message results in no route code, not using transactions, when no consumer is
 *          connected.
 * <tr><td> Check that an mandatory message results in no route code, upon transaction commit, when a consumer is
 *          connected.
 * <tr><td> Check that an mandatory message is sent succesfully not using transactions when a consumer is connected.
 * <tr><td> Check that an mandatory message is committed succesfully in a transaction when a consumer is connected.
 * <tr><td> Check that a mandatory message is sent succesfully, not using transactions, when a consumer is disconnected
 *          but the route exists.
 * <tr><td> Check that a mandatory message is sent succesfully, in a transaction, when a consumer is disconnected but
 *          the route exists.
 * <tr><td> Check that an mandatory message results in no route code, not using transactions, when no consumer is
 *          connected.
 * <tr><td> Check that an mandatory message results in no route code, upon transaction commit, when a consumer 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 MandatoryMessageTest extends FrameworkBaseCase
{
    /** Used to read the tests configurable properties through. */
    ParsedProperties testProps;

    /**
     * Creates a new test case with the specified name.
     *
     * @param name The test case name.
     */
    public MandatoryMessageTest(String name)
    {
        super(name);
    }

    /** Check that an mandatory message is sent succesfully not using transactions when a consumer is connected. */
    public void test_QPID_508_MandatoryOkNoTxP2P() throws Exception
    {
        // Ensure transactional sessions are off.
        testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, false);
        testProps.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(), testProps);

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

    /** Check that an mandatory message is committed succesfully in a transaction when a consumer is connected. */
    public void test_QPID_508_MandatoryOkTxP2P() throws Exception
    {
        // Ensure transactional sessions are off.
        testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, true);
        testProps.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(), testProps);

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

    /**
     * Check that a mandatory message is sent succesfully, not using transactions, when a consumer is disconnected but
     * the route exists.
     */
    public void test_QPID_517_MandatoryOkConsumerDisconnectedNoTxP2P() throws Exception
    {
        // Ensure transactional sessions are off.
        testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, false);
        testProps.setProperty(PUBSUB_PROPNAME, false);

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

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

        // Send one message with no errors.
        assertNoFailures(testCircuit.test(1,
                assertionList(((AMQPPublisher) testCircuit.getPublisher()).noExceptionsAssertion(testProps))));
    }

    /**
     * Check that a mandatory message is sent succesfully, in a transaction, when a consumer is disconnected but
     * the route exists.
     */
    public void test_QPID_517_MandatoryOkConsumerDisconnectedTxP2P() throws Exception
    {
        // Ensure transactional sessions are on.
        testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, true);
        testProps.setProperty(PUBSUB_PROPNAME, false);

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

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

        // Send one message with no errors.
        assertNoFailures(testCircuit.test(1,
                assertionList(((AMQPPublisher) testCircuit.getPublisher()).noExceptionsAssertion(testProps))));
    }

    /** Check that an mandatory message results in no route code, not using transactions, when no consumer is connected. */
    public void test_QPID_508_MandatoryFailsNoRouteNoTxP2P() throws Exception
    {
        // Ensure transactional sessions are off.
        testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, false);
        testProps.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).
        testProps.setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, false);

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

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

    /** Check that an mandatory message results in no route code, upon transaction commit, when a consumer is connected. */
    public void test_QPID_508_MandatoryFailsNoRouteTxP2P() throws Exception
    {
        // Ensure transactional sessions are on.
        testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, true);
        testProps.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).
        testProps.setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, false);

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

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

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

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

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

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

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

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

    /**
     * Check that a mandatory message is sent succesfully, not using transactions, when a consumer is disconnected but
     * the route exists.
     */
    public void test_QPID_517_MandatoryOkConsumerDisconnectedNoTxPubSub()  throws Exception
    {
        // Ensure transactional sessions are off.
        testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, false);
        testProps.setProperty(PUBSUB_PROPNAME, true);

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

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

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

        // Send one message with no errors.
        assertNoFailures(testCircuit.test(1,
                assertionList(((AMQPPublisher) testCircuit.getPublisher()).noExceptionsAssertion(testProps))));
    }

    /**
     * Check that a mandatory message is sent succesfully, in a transaction, when a consumer is disconnected but
     * the route exists.
     */
    public void test_QPID_517_MandatoryOkConsumerDisconnectedTxPubSub() throws Exception
    {
        // Ensure transactional sessions are on.
        testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, true);
        testProps.setProperty(PUBSUB_PROPNAME, true);

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

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

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

        // Send one message with no errors.
        assertNoFailures(testCircuit.test(1,
                assertionList(((AMQPPublisher) testCircuit.getPublisher()).noExceptionsAssertion(testProps))));
    }

    /** Check that an mandatory message results in no route code, not using transactions, when no consumer is connected. */
    public void test_QPID_508_MandatoryFailsNoRouteNoTxPubSub() throws Exception
    {
        // Ensure transactional sessions are off.
        testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, false);
        testProps.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).
        testProps.setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, false);

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

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

    /** Check that an mandatory message results in no route code, upon transaction commit, when a consumer is connected. */
    public void test_QPID_508_MandatoryFailsNoRouteTxPubSub() throws Exception
    {
        // Ensure transactional sessions are on.
        testProps.setProperty(TRANSACTED_PUBLISHER_PROPNAME, true);
        testProps.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).
        testProps.setProperty(RECEIVER_CONSUMER_BIND_PROPNAME, false);

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

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

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

        testProps = TestContextProperties.getInstance(MessagingTestConfigProperties.defaults);

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

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