Skip to content

Commit 3cd2ce3

Browse files
authored
Merge pull request #241 from rabbitmq/refuse-link
Test link refusal
2 parents 5c96b31 + b6cda74 commit 3cd2ce3

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

.github/workflows/test-pr.yml

Lines changed: 0 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

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919

2020
import static com.rabbitmq.client.amqp.Management.ExchangeType.FANOUT;
2121
import static com.rabbitmq.client.amqp.impl.TestConditions.BrokerVersion.RABBITMQ_4_1_0;
22+
import static com.rabbitmq.client.amqp.impl.TestConditions.BrokerVersion.RABBITMQ_4_2_0;
2223
import static com.rabbitmq.client.amqp.impl.TestUtils.*;
2324
import static java.nio.charset.StandardCharsets.*;
2425
import static java.util.concurrent.TimeUnit.SECONDS;
2526
import static org.apache.qpid.protonj2.client.DeliveryMode.AT_LEAST_ONCE;
2627
import static org.apache.qpid.protonj2.client.DeliveryState.released;
2728
import static org.assertj.core.api.Assertions.*;
2829
import static org.assertj.core.api.Assertions.assertThat;
30+
import static org.assertj.core.api.InstanceOfAssertFactories.*;
2931

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

0 commit comments

Comments
 (0)