|
| 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 at |
| 4 | +// 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 the |
| 8 | +// License for the specific language governing rights and limitations |
| 9 | +// under the License. |
| 10 | +// |
| 11 | +// The Original Code is RabbitMQ. |
| 12 | +// |
| 13 | +// The Initial Developers of the Original Code are LShift Ltd, |
| 14 | +// Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd. |
| 15 | +// |
| 16 | +// Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, |
| 17 | +// Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd |
| 18 | +// are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial |
| 19 | +// Technologies LLC, and Rabbit Technologies Ltd. |
| 20 | +// |
| 21 | +// Portions created by LShift Ltd are Copyright (C) 2007-2010 LShift |
| 22 | +// Ltd. Portions created by Cohesive Financial Technologies LLC are |
| 23 | +// Copyright (C) 2007-2010 Cohesive Financial Technologies |
| 24 | +// LLC. Portions created by Rabbit Technologies Ltd are Copyright |
| 25 | +// (C) 2007-2010 Rabbit Technologies Ltd. |
| 26 | +// |
| 27 | +// All Rights Reserved. |
| 28 | +// |
| 29 | +// Contributor(s): ______________________________________. |
| 30 | +// |
| 31 | + |
| 32 | +package com.rabbitmq.client.test.functional; |
| 33 | + |
| 34 | +import com.rabbitmq.client.AMQP; |
| 35 | +import com.rabbitmq.client.DefaultConsumer; |
| 36 | +import com.rabbitmq.client.GetResponse; |
| 37 | +import com.rabbitmq.client.test.BrokerTestCase; |
| 38 | + |
| 39 | +import java.io.IOException; |
| 40 | +import java.util.Arrays; |
| 41 | + |
| 42 | + |
| 43 | +// |
| 44 | +// Functional test demonstrating use of an internal exchange in an exchange to |
| 45 | +// exchange routing scenario. The routing topology is: |
| 46 | +// |
| 47 | +// ------- ------- |
| 48 | +// -/ \- -/ \- |
| 49 | +// / \ / \ +-------------+ |
| 50 | +// | e0 +------| e1 +-----------+ q1 | |
| 51 | +// \ / \ / +-------------+ |
| 52 | +// -\ /- -\ /- |
| 53 | +// ------- ------- |
| 54 | +// (internal) |
| 55 | +// |
| 56 | +// Where a non-internal exchange is bound to an internal exchange, which in |
| 57 | +// turn is bound to a queue. A client should be able to publish to e0, but |
| 58 | +// not to e1, and publications to e0 should be delivered into q1. |
| 59 | +// |
| 60 | +public class InternalExchange extends BrokerTestCase |
| 61 | +{ |
| 62 | + private final String[] queues = new String[] { "q1" }; |
| 63 | + private final String[] exchanges = new String[] { "e0", "e1" }; |
| 64 | + |
| 65 | + protected void createResources() throws IOException |
| 66 | + { |
| 67 | + // The queues and exchange we create here are all auto-delete, so we |
| 68 | + // don't need to override releaseResources() with their deletions... |
| 69 | + for (String q : queues) |
| 70 | + { |
| 71 | + channel.queueDeclare(q, false, true, true, null); |
| 72 | + } |
| 73 | + |
| 74 | + // The second exchange, "e1", will be an 'internal' one. |
| 75 | + for ( String e : exchanges ) |
| 76 | + { |
| 77 | + channel.exchangeDeclare(e, "direct", |
| 78 | + false, true, |
| 79 | + !e.equals("e0"), |
| 80 | + null); |
| 81 | + } |
| 82 | + |
| 83 | + channel.exchangeBind("e1", "e0", ""); |
| 84 | + channel.queueBind("q1", "e1", ""); |
| 85 | + } |
| 86 | + |
| 87 | + |
| 88 | + public void testTryPublishingToInternalExchange() |
| 89 | + throws IOException |
| 90 | + { |
| 91 | + byte[] testDataBody = "test-data".getBytes(); |
| 92 | + |
| 93 | + // We should be able to publish to the non-internal exchange as usual |
| 94 | + // and see our message land in the queue... |
| 95 | + channel.basicPublish("e0", "", null, testDataBody); |
| 96 | + GetResponse r = channel.basicGet("q1", true); |
| 97 | + assertTrue(Arrays.equals(r.getBody(), testDataBody)); |
| 98 | + |
| 99 | + // Publishing to the internal exchange will not be allowed... |
| 100 | + channel.basicPublish("e1", "", null, testDataBody); |
| 101 | + |
| 102 | + expectError(AMQP.ACCESS_REFUSED); |
| 103 | + } |
| 104 | +} |
0 commit comments