From c280eab531711cb587e530f5ae7cf730ba6e99d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Cogolu=C3=A8gnes?= <514737+acogoluegnes@users.noreply.github.com> Date: Mon, 18 Aug 2025 10:18:13 +0200 Subject: [PATCH 1/2] Test link refusal References rabbitmq/rabbitmq-server#14389 --- .github/workflows/test-pr.yml | 3 +- .../rabbitmq/client/amqp/impl/ClientTest.java | 69 +++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml index 8d4e899d69..b4d693318c 100644 --- a/.github/workflows/test-pr.yml +++ b/.github/workflows/test-pr.yml @@ -8,7 +8,6 @@ on: jobs: build: runs-on: ubuntu-24.04 - steps: - uses: actions/checkout@v5 - name: Checkout tls-gen @@ -24,6 +23,8 @@ jobs: cache: 'maven' - name: Start broker run: ci/start-broker.sh + env: + RABBITMQ_IMAGE: pivotalrabbitmq/rabbitmq:pr-14389-otp28 - name: Start toxiproxy run: ci/start-toxiproxy.sh - name: Display Java version diff --git a/src/test/java/com/rabbitmq/client/amqp/impl/ClientTest.java b/src/test/java/com/rabbitmq/client/amqp/impl/ClientTest.java index 0cce5c1203..4554a2223d 100644 --- a/src/test/java/com/rabbitmq/client/amqp/impl/ClientTest.java +++ b/src/test/java/com/rabbitmq/client/amqp/impl/ClientTest.java @@ -26,6 +26,7 @@ import static org.apache.qpid.protonj2.client.DeliveryState.released; import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.InstanceOfAssertFactories.*; import com.rabbitmq.client.amqp.Environment; import com.rabbitmq.client.amqp.Management; @@ -423,4 +424,72 @@ void dynamicReceiver() throws Exception { assertThat(delivery.message().body()).isEqualTo(body); } } + + @Test + void refuseLinkSenderToMissingExchangeShouldReturnNotFound() throws Exception { + try (Client client = client()) { + org.apache.qpid.protonj2.client.Connection c = connection(client); + Session s = c.openSession(); + assertThatThrownBy( + () -> ExceptionUtils.wrapGet(s.openSender("/exchanges/missing").openFuture())) + .isInstanceOf(ClientLinkRemotelyClosedException.class) + .asInstanceOf(throwable(ClientLinkRemotelyClosedException.class)) + .matches(e -> "amqp:not-found".equals(e.getErrorCondition().condition())); + checkSession(s); + } + } + + @Test + void refuseLinkSenderToInvalidAddressShouldReturnInvalidField() throws Exception { + try (Client client = client()) { + org.apache.qpid.protonj2.client.Connection c = connection(client); + Session s = c.openSession(); + assertThatThrownBy(() -> ExceptionUtils.wrapGet(s.openSender("/fruit/orange").openFuture())) + .isInstanceOf(ClientLinkRemotelyClosedException.class) + .asInstanceOf(throwable(ClientLinkRemotelyClosedException.class)) + .matches(e -> "amqp:invalid-field".equals(e.getErrorCondition().condition())); + checkSession(s); + } + } + + @Test + void refuseLinkReceiverToMissingQueueShouldReturnNotFound() throws Exception { + try (Client client = client()) { + org.apache.qpid.protonj2.client.Connection c = connection(client); + Session s = c.openSession().openFuture().get(10, SECONDS); + assertThatThrownBy( + () -> + ExceptionUtils.wrapGet( + s.openReceiver("/queues/missing", new ReceiverOptions().creditWindow(0)) + .openFuture())) + .isInstanceOf(ClientLinkRemotelyClosedException.class) + .asInstanceOf(throwable(ClientLinkRemotelyClosedException.class)) + .matches(e -> "amqp:not-found".equals(e.getErrorCondition().condition())); + checkSession(s); + } + } + + @Test + void refuseLinkReceiverToInvalidAddressShouldReturnInvalidField() throws Exception { + try (Client client = client()) { + org.apache.qpid.protonj2.client.Connection c = connection(client); + Session s = c.openSession().openFuture().get(10, SECONDS); + assertThatThrownBy( + () -> + ExceptionUtils.wrapGet( + s.openReceiver("/fruit/orange", new ReceiverOptions().creditWindow(0)) + .openFuture())) + .isInstanceOf(ClientLinkRemotelyClosedException.class) + .asInstanceOf(throwable(ClientLinkRemotelyClosedException.class)) + .matches(e -> "amqp:invalid-field".equals(e.getErrorCondition().condition())); + checkSession(s); + } + } + + private static void checkSession(Session s) throws Exception { + ReceiverOptions receiverOptions = new ReceiverOptions(); + receiverOptions.sourceOptions().capabilities("temporary-queue"); + Receiver receiver = s.openDynamicReceiver(receiverOptions); + receiver.openFuture().get(10, SECONDS); + } } From b6cda74add0084f38d17d9ba4ef3aee88c75f888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Cogolu=C3=A8gnes?= <514737+acogoluegnes@users.noreply.github.com> Date: Tue, 2 Sep 2025 08:56:27 +0200 Subject: [PATCH 2/2] Test link refusal on 4.2+ --- .github/workflows/test-pr.yml | 2 -- src/test/java/com/rabbitmq/client/amqp/impl/ClientTest.java | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml index b4d693318c..90a6557958 100644 --- a/.github/workflows/test-pr.yml +++ b/.github/workflows/test-pr.yml @@ -23,8 +23,6 @@ jobs: cache: 'maven' - name: Start broker run: ci/start-broker.sh - env: - RABBITMQ_IMAGE: pivotalrabbitmq/rabbitmq:pr-14389-otp28 - name: Start toxiproxy run: ci/start-toxiproxy.sh - name: Display Java version diff --git a/src/test/java/com/rabbitmq/client/amqp/impl/ClientTest.java b/src/test/java/com/rabbitmq/client/amqp/impl/ClientTest.java index 4554a2223d..a80ab7c1e8 100644 --- a/src/test/java/com/rabbitmq/client/amqp/impl/ClientTest.java +++ b/src/test/java/com/rabbitmq/client/amqp/impl/ClientTest.java @@ -19,6 +19,7 @@ import static com.rabbitmq.client.amqp.Management.ExchangeType.FANOUT; import static com.rabbitmq.client.amqp.impl.TestConditions.BrokerVersion.RABBITMQ_4_1_0; +import static com.rabbitmq.client.amqp.impl.TestConditions.BrokerVersion.RABBITMQ_4_2_0; import static com.rabbitmq.client.amqp.impl.TestUtils.*; import static java.nio.charset.StandardCharsets.*; import static java.util.concurrent.TimeUnit.SECONDS; @@ -426,6 +427,7 @@ void dynamicReceiver() throws Exception { } @Test + @BrokerVersionAtLeast(RABBITMQ_4_2_0) void refuseLinkSenderToMissingExchangeShouldReturnNotFound() throws Exception { try (Client client = client()) { org.apache.qpid.protonj2.client.Connection c = connection(client); @@ -440,6 +442,7 @@ void refuseLinkSenderToMissingExchangeShouldReturnNotFound() throws Exception { } @Test + @BrokerVersionAtLeast(RABBITMQ_4_2_0) void refuseLinkSenderToInvalidAddressShouldReturnInvalidField() throws Exception { try (Client client = client()) { org.apache.qpid.protonj2.client.Connection c = connection(client); @@ -453,6 +456,7 @@ void refuseLinkSenderToInvalidAddressShouldReturnInvalidField() throws Exception } @Test + @BrokerVersionAtLeast(RABBITMQ_4_2_0) void refuseLinkReceiverToMissingQueueShouldReturnNotFound() throws Exception { try (Client client = client()) { org.apache.qpid.protonj2.client.Connection c = connection(client); @@ -470,6 +474,7 @@ void refuseLinkReceiverToMissingQueueShouldReturnNotFound() throws Exception { } @Test + @BrokerVersionAtLeast(RABBITMQ_4_2_0) void refuseLinkReceiverToInvalidAddressShouldReturnInvalidField() throws Exception { try (Client client = client()) { org.apache.qpid.protonj2.client.Connection c = connection(client);