Skip to content

Commit 1fdb0a4

Browse files
committed
Test link refusal
References rabbitmq/rabbitmq-server#14389
1 parent 9241f9f commit 1fdb0a4

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

.github/workflows/test-pr.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88
jobs:
99
build:
1010
runs-on: ubuntu-24.04
11-
1211
steps:
1312
- uses: actions/checkout@v5
1413
- name: Checkout tls-gen
@@ -24,6 +23,8 @@ jobs:
2423
cache: 'maven'
2524
- name: Start broker
2625
run: ci/start-broker.sh
26+
env:
27+
RABBITMQ_IMAGE: pivotalrabbitmq/rabbitmq:pr-14389-otp28
2728
- name: Start toxiproxy
2829
run: ci/start-toxiproxy.sh
2930
- name: Display Java version

src/test/java/com/rabbitmq/client/amqp/impl/ClientTest.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import static org.apache.qpid.protonj2.client.DeliveryState.released;
2727
import static org.assertj.core.api.Assertions.*;
2828
import static org.assertj.core.api.Assertions.assertThat;
29+
import static org.assertj.core.api.InstanceOfAssertFactories.*;
2930

3031
import com.rabbitmq.client.amqp.Environment;
3132
import com.rabbitmq.client.amqp.Management;
@@ -423,4 +424,72 @@ void dynamicReceiver() throws Exception {
423424
assertThat(delivery.message().body()).isEqualTo(body);
424425
}
425426
}
427+
428+
@Test
429+
void refuseLinkSenderToMissingExchangeShouldReturnNotFound() throws Exception {
430+
try (Client client = client()) {
431+
org.apache.qpid.protonj2.client.Connection c = connection(client);
432+
Session s = c.openSession();
433+
assertThatThrownBy(
434+
() -> ExceptionUtils.wrapGet(s.openSender("/exchanges/missing").openFuture()))
435+
.isInstanceOf(ClientLinkRemotelyClosedException.class)
436+
.asInstanceOf(throwable(ClientLinkRemotelyClosedException.class))
437+
.matches(e -> "amqp:not-found".equals(e.getErrorCondition().condition()));
438+
checkSession(s);
439+
}
440+
}
441+
442+
@Test
443+
void refuseLinkSenderToInvalidAddressShouldReturnInvalidField() throws Exception {
444+
try (Client client = client()) {
445+
org.apache.qpid.protonj2.client.Connection c = connection(client);
446+
Session s = c.openSession();
447+
assertThatThrownBy(() -> ExceptionUtils.wrapGet(s.openSender("/fruit/orange").openFuture()))
448+
.isInstanceOf(ClientLinkRemotelyClosedException.class)
449+
.asInstanceOf(throwable(ClientLinkRemotelyClosedException.class))
450+
.matches(e -> "amqp:invalid-field".equals(e.getErrorCondition().condition()));
451+
checkSession(s);
452+
}
453+
}
454+
455+
@Test
456+
void refuseLinkReceiverToMissingQueueShouldReturnNotFound() throws Exception {
457+
try (Client client = client()) {
458+
org.apache.qpid.protonj2.client.Connection c = connection(client);
459+
Session s = c.openSession().openFuture().get(10, SECONDS);
460+
assertThatThrownBy(
461+
() ->
462+
ExceptionUtils.wrapGet(
463+
s.openReceiver("/queues/missing", new ReceiverOptions().creditWindow(0))
464+
.openFuture()))
465+
.isInstanceOf(ClientLinkRemotelyClosedException.class)
466+
.asInstanceOf(throwable(ClientLinkRemotelyClosedException.class))
467+
.matches(e -> "amqp:not-found".equals(e.getErrorCondition().condition()));
468+
checkSession(s);
469+
}
470+
}
471+
472+
@Test
473+
void refuseLinkReceiverToInvalidAddressShouldReturnInvalidField() throws Exception {
474+
try (Client client = client()) {
475+
org.apache.qpid.protonj2.client.Connection c = connection(client);
476+
Session s = c.openSession().openFuture().get(10, SECONDS);
477+
assertThatThrownBy(
478+
() ->
479+
ExceptionUtils.wrapGet(
480+
s.openReceiver("/fruit/orange", new ReceiverOptions().creditWindow(0))
481+
.openFuture()))
482+
.isInstanceOf(ClientLinkRemotelyClosedException.class)
483+
.asInstanceOf(throwable(ClientLinkRemotelyClosedException.class))
484+
.matches(e -> "amqp:invalid-field".equals(e.getErrorCondition().condition()));
485+
checkSession(s);
486+
}
487+
}
488+
489+
private static void checkSession(Session s) throws Exception {
490+
ReceiverOptions receiverOptions = new ReceiverOptions();
491+
receiverOptions.sourceOptions().capabilities("temporary-queue");
492+
Receiver receiver = s.openDynamicReceiver(receiverOptions);
493+
receiver.openFuture().get(10, SECONDS);
494+
}
426495
}

0 commit comments

Comments
 (0)