|
37 | 37 | import java.io.IOException; |
38 | 38 | import java.util.List; |
39 | 39 | import java.util.ArrayList; |
| 40 | +import java.util.Hashtable; |
40 | 41 |
|
41 | 42 | public class Routing extends BrokerTestCase |
42 | 43 | { |
@@ -164,6 +165,58 @@ public void testTopicRouting() throws Exception { |
164 | 165 | } |
165 | 166 | } |
166 | 167 |
|
| 168 | + public void testHeadersRouting() throws Exception { |
| 169 | + Hashtable<String, Object> spec = new Hashtable<String, Object>(); |
| 170 | + spec.put("h1", "12345"); |
| 171 | + spec.put("h2", "bar"); |
| 172 | + // See bug 20154: no current way to add a "Void"-typed spec pattern. |
| 173 | + spec.put("x-match", "all"); |
| 174 | + channel.queueBind(Q1, "amq.match", "", spec); |
| 175 | + spec.put("x-match", "any"); |
| 176 | + channel.queueBind(Q2, "amq.match", "", spec); |
| 177 | + |
| 178 | + AMQP.BasicProperties props = new AMQP.BasicProperties(); |
| 179 | + |
| 180 | + channel.basicPublish("amq.match", "", null, "0".getBytes()); |
| 181 | + channel.basicPublish("amq.match", "", props, "0b".getBytes()); |
| 182 | + |
| 183 | + props.headers = new Hashtable<String, Object>(); |
| 184 | + props.headers.put("h1", "12345"); |
| 185 | + channel.basicPublish("amq.match", "", props, "1".getBytes()); |
| 186 | + |
| 187 | + props.headers = new Hashtable<String, Object>(); |
| 188 | + props.headers.put("h1", 12345); |
| 189 | + channel.basicPublish("amq.match", "", props, "1b".getBytes()); |
| 190 | + |
| 191 | + props.headers = new Hashtable<String, Object>(); |
| 192 | + props.headers.put("h2", "bar"); |
| 193 | + channel.basicPublish("amq.match", "", props, "2".getBytes()); |
| 194 | + |
| 195 | + props.headers = new Hashtable<String, Object>(); |
| 196 | + props.headers.put("h1", "12345"); |
| 197 | + props.headers.put("h2", "bar"); |
| 198 | + channel.basicPublish("amq.match", "", props, "3".getBytes()); |
| 199 | + |
| 200 | + props.headers = new Hashtable<String, Object>(); |
| 201 | + props.headers.put("h1", "12345"); |
| 202 | + props.headers.put("h2", "quux"); |
| 203 | + channel.basicPublish("amq.match", "", props, "4".getBytes()); |
| 204 | + |
| 205 | + props.headers = new Hashtable<String, Object>(); |
| 206 | + props.headers.put("h1", "zot"); |
| 207 | + props.headers.put("h2", "quux"); |
| 208 | + channel.basicPublish("amq.match", "", props, "5".getBytes()); |
| 209 | + |
| 210 | + checkGet(Q1, true); // 3 |
| 211 | + checkGet(Q1, false); |
| 212 | + |
| 213 | + checkGet(Q2, true); // 1 |
| 214 | + checkGet(Q2, true); // 2 |
| 215 | + checkGet(Q2, true); // 3 |
| 216 | + checkGet(Q2, true); // 4 |
| 217 | + checkGet(Q2, false); |
| 218 | + } |
| 219 | + |
167 | 220 | public void testUnbind() throws Exception { |
168 | 221 | AMQP.Queue.DeclareOk ok = channel.queueDeclare(); |
169 | 222 | String queue = ok.getQueue(); |
|
0 commit comments