Skip to content

Commit e553866

Browse files
committed
add test for basic.return{immediate=true} failure
and move 'mandatory' tests over to junit
1 parent 8727dc5 commit e553866

File tree

2 files changed

+36
-29
lines changed

2 files changed

+36
-29
lines changed

test/src/com/rabbitmq/client/test/functional/Routing.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import com.rabbitmq.client.test.BrokerTestCase;
2121
import com.rabbitmq.client.AMQP;
2222
import com.rabbitmq.client.GetResponse;
23+
import com.rabbitmq.client.ReturnListener;
24+
import com.rabbitmq.utility.BlockingCell;
2325

2426
import java.io.IOException;
2527
import java.util.List;
@@ -34,6 +36,8 @@ public class Routing extends BrokerTestCase
3436
protected final String Q1 = "foo";
3537
protected final String Q2 = "bar";
3638

39+
private volatile BlockingCell<Integer> returnCell;
40+
3741
protected void createResources() throws IOException {
3842
channel.exchangeDeclare(E, "direct");
3943
channel.queueDeclare(Q1, false, false, false, null);
@@ -228,5 +232,36 @@ public void testHeadersRouting() throws Exception {
228232
checkGet(Q2, false);
229233
}
230234

231-
}
235+
public void testBasicReturn() throws Exception {
236+
channel.addReturnListener(new ReturnListener() {
237+
public void handleReturn(int replyCode,
238+
String replyText,
239+
String exchange,
240+
String routingKey,
241+
AMQP.BasicProperties properties,
242+
byte[] body)
243+
throws IOException {
244+
Routing.this.returnCell.set(replyCode);
245+
}
246+
});
247+
returnCell = new BlockingCell<Integer>();
248+
channel.basicPublish("", "unknown", true, false, null, "mandatory1".getBytes());
249+
int replyCode = returnCell.uninterruptibleGet();
250+
assertEquals(replyCode, AMQP.NO_ROUTE);
251+
252+
returnCell = new BlockingCell<Integer>();
253+
channel.basicPublish("", Q1, true, false, null, "mandatory2".getBytes());
254+
GetResponse r = channel.basicGet(Q1, true);
255+
assertNotNull(r);
256+
assertEquals(new String(r.getBody()), "mandatory2");
257+
258+
channel.basicPublish("", Q1, false, true, null, "immediate".getBytes());
259+
try {
260+
channel.basicQos(0); //flush
261+
fail("basic.publish{immediate=true} should not be supported");
262+
} catch (IOException ioe) {
263+
checkShutdownSignal(AMQP.NOT_IMPLEMENTED, ioe);
264+
}
265+
}
232266

267+
}

test/src/com/rabbitmq/examples/TestMain.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ public void run() throws IOException {
248248
_ch1.basicCancel(cTag2);
249249

250250
tryTopics();
251-
tryBasicReturn();
252251

253252
queueName =_ch1.queueDeclare().getQueue();
254253
sendLotsOfTrivialMessages(batchSize, queueName);
@@ -449,33 +448,6 @@ public void doBasicReturn(BlockingCell<Object> cell, int expectedCode) {
449448
}
450449
}
451450

452-
public void tryBasicReturn() throws IOException {
453-
log("About to try mandatory publications");
454-
455-
String mx = "mandatoryTestExchange";
456-
_ch1.exchangeDeclare(mx, "fanout", false, true, null);
457-
458-
setChannelReturnListener();
459-
460-
returnCell = new BlockingCell<Object>();
461-
_ch1.basicPublish(mx, "", true, false, null, "one".getBytes());
462-
doBasicReturn(returnCell, AMQP.NO_ROUTE);
463-
464-
String mq = "mandatoryTestQueue";
465-
_ch1.queueDeclare(mq, false, false, true, null);
466-
_ch1.queueBind(mq, mx, "");
467-
468-
returnCell = new BlockingCell<Object>();
469-
_ch1.basicPublish(mx, "", true, false, null, "two".getBytes());
470-
drain(1, mq, true);
471-
_ch1.queueDelete(mq, true, true);
472-
473-
unsetChannelReturnListener();
474-
475-
log("Completed basic.return testing.");
476-
477-
}
478-
479451
private void unsetChannelReturnListener() {
480452
_ch1.clearReturnListeners();
481453
log("ReturnListeners unset");

0 commit comments

Comments
 (0)