|
| 1 | +// The contents of this file are subject to the Mozilla Public License |
| 2 | +// Version 1.1 (the "License"); you may not use this file except in |
| 3 | +// compliance with the License. You may obtain a copy of the License |
| 4 | +// at http://www.mozilla.org/MPL/ |
| 5 | +// |
| 6 | +// Software distributed under the License is distributed on an "AS IS" |
| 7 | +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See |
| 8 | +// the License for the specific language governing rights and |
| 9 | +// limitations under the License. |
| 10 | +// |
| 11 | +// The Original Code is RabbitMQ. |
| 12 | +// |
| 13 | +// The Initial Developer of the Original Code is VMware, Inc. |
| 14 | +// Copyright (c) 2007-2012 VMware, Inc. All rights reserved. |
| 15 | +// |
| 16 | + |
| 17 | + |
| 18 | +package com.rabbitmq.client.test.server; |
| 19 | + |
| 20 | +import com.rabbitmq.client.AMQP; |
| 21 | +import com.rabbitmq.client.test.functional.ClusteredTestBase; |
| 22 | +import com.rabbitmq.tools.Host; |
| 23 | + |
| 24 | +import java.io.IOException; |
| 25 | + |
| 26 | +/** |
| 27 | + * This tests whether 'absent' queues - durable queues whose home node |
| 28 | + * is down - are handled properly. |
| 29 | + */ |
| 30 | +public class AbsentQueue extends ClusteredTestBase { |
| 31 | + |
| 32 | + private static final String Q = "absent-queue"; |
| 33 | + |
| 34 | + @Override protected void setUp() throws IOException { |
| 35 | + super.setUp(); |
| 36 | + if (clusteredConnection != null) |
| 37 | + Host.executeCommand("cd ../rabbitmq-test; make stop-secondary-app"); |
| 38 | + } |
| 39 | + |
| 40 | + @Override protected void tearDown() throws IOException { |
| 41 | + if (clusteredConnection != null) |
| 42 | + Host.executeCommand("cd ../rabbitmq-test; make start-secondary-app"); |
| 43 | + super.tearDown(); |
| 44 | + } |
| 45 | + |
| 46 | + @Override protected void createResources() throws IOException { |
| 47 | + alternateChannel.queueDeclare(Q, true, false, false, null); |
| 48 | + } |
| 49 | + |
| 50 | + @Override protected void releaseResources() throws IOException { |
| 51 | + alternateChannel.queueDelete(Q); |
| 52 | + } |
| 53 | + |
| 54 | + public void testNotFound() throws IOException { |
| 55 | + assertNotFound(new Task() { |
| 56 | + public void run() throws IOException { |
| 57 | + channel.queueDeclare(Q, true, false, false, null); |
| 58 | + } |
| 59 | + }); |
| 60 | + assertNotFound(new Task() { |
| 61 | + public void run() throws IOException { |
| 62 | + channel.queueDeclarePassive(Q); |
| 63 | + } |
| 64 | + }); |
| 65 | + assertNotFound(new Task() { |
| 66 | + public void run() throws IOException { |
| 67 | + channel.queuePurge(Q); |
| 68 | + } |
| 69 | + }); |
| 70 | + assertNotFound(new Task() { |
| 71 | + public void run() throws IOException { |
| 72 | + channel.basicGet(Q, true); |
| 73 | + } |
| 74 | + }); |
| 75 | + assertNotFound(new Task() { |
| 76 | + public void run() throws IOException { |
| 77 | + channel.queueBind(Q, "amq.fanout", "", null); |
| 78 | + } |
| 79 | + }); |
| 80 | + } |
| 81 | + |
| 82 | + protected void assertNotFound(Task t) throws IOException { |
| 83 | + if (clusteredChannel == null) return; |
| 84 | + try { |
| 85 | + t.run(); |
| 86 | + if (!HATests.HA_TESTS_RUNNING) fail("expected not_found"); |
| 87 | + } catch (IOException ioe) { |
| 88 | + assertFalse(HATests.HA_TESTS_RUNNING); |
| 89 | + checkShutdownSignal(AMQP.NOT_FOUND, ioe); |
| 90 | + channel = connection.createChannel(); |
| 91 | + } |
| 92 | + |
| 93 | + } |
| 94 | + |
| 95 | + private interface Task { |
| 96 | + public void run() throws IOException; |
| 97 | + } |
| 98 | + |
| 99 | +} |
0 commit comments