This is an automated email from the ASF dual-hosted git repository.

robbie pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/main by this push:
     new f5ecc5e219 ARTEMIS-4790: un-nest test classes to simplify
f5ecc5e219 is described below

commit f5ecc5e219bb66239f2dbdc318bb2cb895194c0b
Author: Robbie Gemmell <[email protected]>
AuthorDate: Tue Jun 4 12:55:00 2024 +0100

    ARTEMIS-4790: un-nest test classes to simplify
---
 ...iverDispositionRejectAsUnmodifiedModeTests.java |  76 ++++++
 .../amqp/AmqpReceiverDispositionTest.java          | 271 +++++++++------------
 2 files changed, 188 insertions(+), 159 deletions(-)

diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpReceiverDispositionRejectAsUnmodifiedModeTests.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpReceiverDispositionRejectAsUnmodifiedModeTests.java
new file mode 100644
index 0000000000..ae4ffb6e02
--- /dev/null
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpReceiverDispositionRejectAsUnmodifiedModeTests.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.tests.integration.amqp;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.activemq.transport.amqp.client.AmqpClient;
+import org.apache.activemq.transport.amqp.client.AmqpConnection;
+import org.apache.activemq.transport.amqp.client.AmqpMessage;
+import org.apache.activemq.transport.amqp.client.AmqpReceiver;
+import org.apache.activemq.transport.amqp.client.AmqpSession;
+import org.apache.qpid.proton.message.Message;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+
+public class AmqpReceiverDispositionRejectAsUnmodifiedModeTests extends 
AmqpClientTestSupport {
+
+   @Override
+   protected void configureAMQPAcceptorParameters(Map<String, Object> params) {
+      params.put("amqpTreatRejectAsUnmodifiedDeliveryFailed", true);
+   }
+
+   @Test
+   @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
+   public void testRejectedDisposition() throws Exception {
+      sendMessages(getQueueName(), 1);
+
+      AmqpClient client = createAmqpClient();
+      AmqpConnection connection = addConnection(client.connect());
+      AmqpSession session = connection.createSession();
+
+      AmqpReceiver receiver1 = session.createReceiver(getQueueName());
+      receiver1.flow(1);
+
+      AmqpMessage message = receiver1.receive(5, TimeUnit.SECONDS);
+      assertNotNull(message, "did not receive message first time");
+      assertEquals("MessageID:0", message.getMessageId());
+
+      Message protonMessage = message.getWrappedMessage();
+      assertNotNull(protonMessage);
+      assertEquals(0, protonMessage.getDeliveryCount(), "Unexpected initial 
value for AMQP delivery-count");
+
+      // Owing to the config, the reject should be treat as if it were a
+      // Unmodified delivery-failed=true
+      message.reject();
+      receiver1.flow(1);
+
+      message = receiver1.receive(5, TimeUnit.SECONDS);
+      assertNotNull(message, "did not receive message after reject");
+      assertEquals("MessageID:0", message.getMessageId());
+
+      protonMessage = message.getWrappedMessage();
+      assertNotNull(protonMessage);
+      assertEquals(1, protonMessage.getDeliveryCount(), "Unexpected value for 
AMQP delivery-count after redelivery");
+
+      connection.close();
+   }
+}
\ No newline at end of file
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpReceiverDispositionTest.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpReceiverDispositionTest.java
index e0916bc3c7..12169cac6f 100644
--- 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpReceiverDispositionTest.java
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/AmqpReceiverDispositionTest.java
@@ -20,7 +20,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
 
-import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.activemq.transport.amqp.client.AmqpClient;
@@ -29,209 +28,163 @@ import 
org.apache.activemq.transport.amqp.client.AmqpMessage;
 import org.apache.activemq.transport.amqp.client.AmqpReceiver;
 import org.apache.activemq.transport.amqp.client.AmqpSession;
 import org.apache.qpid.proton.message.Message;
-import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.Timeout;
 
 /**
  * Test various behaviors of AMQP receivers with the broker.
+ *
+ * See also {@link AmqpReceiverDispositionRejectAsUnmodifiedModeTests} for
+ * some testing of configurable alternative behaviour.
  */
 
-public class AmqpReceiverDispositionTest {
-
-   @Nested
-   public class AmqpReceiverDispositionOrdinaryTests extends 
AmqpClientTestSupport {
-      @Test
-      @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
-      public void testReleasedDisposition() throws Exception {
-         sendMessages(getQueueName(), 1);
-
-         AmqpClient client = createAmqpClient();
-         AmqpConnection connection = addConnection(client.connect());
-         AmqpSession session = connection.createSession();
-
-         AmqpReceiver receiver1 = session.createReceiver(getQueueName());
-         receiver1.flow(1);
-
-         AmqpMessage message = receiver1.receive(5, TimeUnit.SECONDS);
-
-         AmqpReceiver receiver2 = session.createReceiver(getQueueName());
+public class AmqpReceiverDispositionTest extends AmqpClientTestSupport {
 
-         assertNotNull(message, "did not receive message first time");
-         assertEquals("MessageID:0", message.getMessageId());
+   @Test
+   @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
+   public void testReleasedDisposition() throws Exception {
+      sendMessages(getQueueName(), 1);
 
-         Message protonMessage = message.getWrappedMessage();
-         assertNotNull(protonMessage);
-         assertEquals(0, protonMessage.getDeliveryCount(), "Unexpected initial 
value for AMQP delivery-count");
+      AmqpClient client = createAmqpClient();
+      AmqpConnection connection = addConnection(client.connect());
+      AmqpSession session = connection.createSession();
 
-         receiver2.flow(1);
-         message.release();
+      AmqpReceiver receiver1 = session.createReceiver(getQueueName());
+      receiver1.flow(1);
 
-         // Read the message again and validate its state
-         message = receiver2.receive(10, TimeUnit.SECONDS);
-         assertNotNull(message, "did not receive message again");
-         assertEquals("MessageID:0", message.getMessageId());
+      AmqpMessage message = receiver1.receive(5, TimeUnit.SECONDS);
 
-         message.accept();
+      AmqpReceiver receiver2 = session.createReceiver(getQueueName());
 
-         protonMessage = message.getWrappedMessage();
-         assertNotNull(protonMessage);
-         assertEquals(0, protonMessage.getDeliveryCount(), "Unexpected updated 
value for AMQP delivery-count");
+      assertNotNull(message, "did not receive message first time");
+      assertEquals("MessageID:0", message.getMessageId());
 
-         connection.close();
-      }
+      Message protonMessage = message.getWrappedMessage();
+      assertNotNull(protonMessage);
+      assertEquals(0, protonMessage.getDeliveryCount(), "Unexpected initial 
value for AMQP delivery-count");
 
-      @Test
-      @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
-      public void testRejectedDisposition() throws Exception {
-         sendMessages(getQueueName(), 1);
+      receiver2.flow(1);
+      message.release();
 
-         AmqpClient client = createAmqpClient();
-         AmqpConnection connection = addConnection(client.connect());
-         AmqpSession session = connection.createSession();
-
-         AmqpReceiver receiver1 = session.createReceiver(getQueueName());
-         receiver1.flow(1);
+      // Read the message again and validate its state
+      message = receiver2.receive(10, TimeUnit.SECONDS);
+      assertNotNull(message, "did not receive message again");
+      assertEquals("MessageID:0", message.getMessageId());
 
-         AmqpMessage message = receiver1.receive(5, TimeUnit.SECONDS);
-         assertNotNull(message, "did not receive message first time");
-         assertEquals("MessageID:0", message.getMessageId());
+      message.accept();
 
-         Message protonMessage = message.getWrappedMessage();
-         assertNotNull(protonMessage);
-         assertEquals(0, protonMessage.getDeliveryCount(), "Unexpected initial 
value for AMQP delivery-count");
-
-         message.reject();
-
-         // Reject is a terminal outcome and should not be redelivered to the 
rejecting receiver
-         // or any other as it should move to the archived state.
-         receiver1.flow(1);
-         message = receiver1.receiveNoWait();
-         assertNull(message, "Should not receive message again");
-
-         // Attempt to Read the message again with another receiver to 
validate it is archived.
-         AmqpReceiver receiver2 = session.createReceiver(getQueueName());
-         receiver2.flow(1);
-         assertNull(receiver2.receiveNoWait());
-
-         connection.close();
-      }
-
-      @Test
-      @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
-      public void 
testModifiedDispositionWithDeliveryFailedWithoutUndeliverableHereFieldsSet() 
throws Exception {
-         doModifiedDispositionTestImpl(Boolean.TRUE, null);
-      }
+      protonMessage = message.getWrappedMessage();
+      assertNotNull(protonMessage);
+      assertEquals(0, protonMessage.getDeliveryCount(), "Unexpected updated 
value for AMQP delivery-count");
 
-      @Test
-      @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
-      public void 
testModifiedDispositionWithoutDeliveryFailedWithoutUndeliverableHereFieldsSet() 
throws Exception {
-         doModifiedDispositionTestImpl(null, null);
-      }
+      connection.close();
+   }
 
-      @Test
-      @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
-      public void 
testModifiedDispositionWithoutDeliveryFailedWithUndeliverableHereFieldsSet() 
throws Exception {
-         doModifiedDispositionTestImpl(null, Boolean.TRUE);
-      }
+   @Test
+   @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
+   public void testRejectedDisposition() throws Exception {
+      sendMessages(getQueueName(), 1);
 
-      @Test
-      @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
-      public void 
testModifiedDispositionWithDeliveryFailedWithUndeliverableHereFieldsSet() 
throws Exception {
-         doModifiedDispositionTestImpl(Boolean.TRUE, Boolean.TRUE);
-      }
+      AmqpClient client = createAmqpClient();
+      AmqpConnection connection = addConnection(client.connect());
+      AmqpSession session = connection.createSession();
 
-      private void doModifiedDispositionTestImpl(Boolean deliveryFailed, 
Boolean undeliverableHere) throws Exception {
-         sendMessages(getQueueName(), 1);
+      AmqpReceiver receiver1 = session.createReceiver(getQueueName());
+      receiver1.flow(1);
 
-         AmqpClient client = createAmqpClient();
-         AmqpConnection connection = addConnection(client.connect());
-         AmqpSession session = connection.createSession();
+      AmqpMessage message = receiver1.receive(5, TimeUnit.SECONDS);
+      assertNotNull(message, "did not receive message first time");
+      assertEquals("MessageID:0", message.getMessageId());
 
-         AmqpReceiver receiver1 = session.createReceiver(getQueueName());
-         receiver1.flow(1);
+      Message protonMessage = message.getWrappedMessage();
+      assertNotNull(protonMessage);
+      assertEquals(0, protonMessage.getDeliveryCount(), "Unexpected initial 
value for AMQP delivery-count");
 
-         AmqpMessage message = receiver1.receive(5, TimeUnit.SECONDS);
-         assertNotNull(message, "did not receive message first time");
+      message.reject();
 
-         Message protonMessage = message.getWrappedMessage();
-         assertNotNull(protonMessage);
-         assertEquals(0, protonMessage.getDeliveryCount(), "Unexpected initial 
value for AMQP delivery-count");
+      // Reject is a terminal outcome and should not be redelivered to the 
rejecting receiver
+      // or any other as it should move to the archived state.
+      receiver1.flow(1);
+      message = receiver1.receiveNoWait();
+      assertNull(message, "Should not receive message again");
 
-         message.modified(deliveryFailed, undeliverableHere);
+      // Attempt to Read the message again with another receiver to validate 
it is archived.
+      AmqpReceiver receiver2 = session.createReceiver(getQueueName());
+      receiver2.flow(1);
+      assertNull(receiver2.receiveNoWait());
 
-         // Remote must not redispatch to the client if undeliverable here is 
true
-         if (Boolean.TRUE.equals(undeliverableHere)) {
-            receiver1.flow(1);
-            message = receiver1.receive(1, TimeUnit.SECONDS);
-            assertNull(message, "Should not receive message again");
-         }
+      connection.close();
+   }
 
-         AmqpReceiver receiver2 = session.createReceiver(getQueueName());
-         receiver2.flow(1);
+   @Test
+   @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
+   public void 
testModifiedDispositionWithDeliveryFailedWithoutUndeliverableHereFieldsSet() 
throws Exception {
+      doModifiedDispositionTestImpl(Boolean.TRUE, null);
+   }
 
-         message = receiver2.receive(5, TimeUnit.SECONDS);
-         assertNotNull(message, "did not receive message again");
+   @Test
+   @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
+   public void 
testModifiedDispositionWithoutDeliveryFailedWithoutUndeliverableHereFieldsSet() 
throws Exception {
+      doModifiedDispositionTestImpl(null, null);
+   }
 
-         int expectedDeliveryCount = 0;
-         if (Boolean.TRUE.equals(deliveryFailed)) {
-            expectedDeliveryCount = 1;
-         }
+   @Test
+   @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
+   public void 
testModifiedDispositionWithoutDeliveryFailedWithUndeliverableHereFieldsSet() 
throws Exception {
+      doModifiedDispositionTestImpl(null, Boolean.TRUE);
+   }
 
-         message.accept();
+   @Test
+   @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
+   public void 
testModifiedDispositionWithDeliveryFailedWithUndeliverableHereFieldsSet() 
throws Exception {
+      doModifiedDispositionTestImpl(Boolean.TRUE, Boolean.TRUE);
+   }
 
-         Message protonMessage2 = message.getWrappedMessage();
-         assertNotNull(protonMessage2);
-         assertEquals(expectedDeliveryCount,
-                      protonMessage2.getDeliveryCount(),
-                      "Unexpected updated value for AMQP delivery-count");
+   private void doModifiedDispositionTestImpl(Boolean deliveryFailed, Boolean 
undeliverableHere) throws Exception {
+      sendMessages(getQueueName(), 1);
 
-         connection.close();
-      }
-   }
+      AmqpClient client = createAmqpClient();
+      AmqpConnection connection = addConnection(client.connect());
+      AmqpSession session = connection.createSession();
 
-   @Nested
-   public class AmqpReceiverDispositionRejectAsUnmodifiedModeTests extends 
AmqpClientTestSupport {
+      AmqpReceiver receiver1 = session.createReceiver(getQueueName());
+      receiver1.flow(1);
 
-      @Override
-      protected void configureAMQPAcceptorParameters(Map<String, Object> 
params) {
-         params.put("amqpTreatRejectAsUnmodifiedDeliveryFailed", true);
-      }
+      AmqpMessage message = receiver1.receive(5, TimeUnit.SECONDS);
+      assertNotNull(message, "did not receive message first time");
 
-      @Test
-      @Timeout(value = 30000, unit = TimeUnit.MILLISECONDS)
-      public void testRejectedDisposition() throws Exception {
-         sendMessages(getQueueName(), 1);
+      Message protonMessage = message.getWrappedMessage();
+      assertNotNull(protonMessage);
+      assertEquals(0, protonMessage.getDeliveryCount(), "Unexpected initial 
value for AMQP delivery-count");
 
-         AmqpClient client = createAmqpClient();
-         AmqpConnection connection = addConnection(client.connect());
-         AmqpSession session = connection.createSession();
+      message.modified(deliveryFailed, undeliverableHere);
 
-         AmqpReceiver receiver1 = session.createReceiver(getQueueName());
+      // Remote must not redispatch to the client if undeliverable here is true
+      if (Boolean.TRUE.equals(undeliverableHere)) {
          receiver1.flow(1);
+         message = receiver1.receive(1, TimeUnit.SECONDS);
+         assertNull(message, "Should not receive message again");
+      }
 
-         AmqpMessage message = receiver1.receive(5, TimeUnit.SECONDS);
-         assertNotNull(message, "did not receive message first time");
-         assertEquals("MessageID:0", message.getMessageId());
+      AmqpReceiver receiver2 = session.createReceiver(getQueueName());
+      receiver2.flow(1);
 
-         Message protonMessage = message.getWrappedMessage();
-         assertNotNull(protonMessage);
-         assertEquals(0, protonMessage.getDeliveryCount(), "Unexpected initial 
value for AMQP delivery-count");
+      message = receiver2.receive(5, TimeUnit.SECONDS);
+      assertNotNull(message, "did not receive message again");
 
-         // Owing to the config, the reject should be treat as if it were a
-         // Unmodified delivery-failed=true
-         message.reject();
-         receiver1.flow(1);
+      int expectedDeliveryCount = 0;
+      if (Boolean.TRUE.equals(deliveryFailed)) {
+         expectedDeliveryCount = 1;
+      }
 
-         message = receiver1.receive(5, TimeUnit.SECONDS);
-         assertNotNull(message, "did not receive message after reject");
-         assertEquals("MessageID:0", message.getMessageId());
+      message.accept();
 
-         protonMessage = message.getWrappedMessage();
-         assertNotNull(protonMessage);
-         assertEquals(1, protonMessage.getDeliveryCount(), "Unexpected value 
for AMQP delivery-count after redelivery");
+      Message protonMessage2 = message.getWrappedMessage();
+      assertNotNull(protonMessage2);
+      assertEquals(expectedDeliveryCount,
+            protonMessage2.getDeliveryCount(),
+            "Unexpected updated value for AMQP delivery-count");
 
-         connection.close();
-      }
+      connection.close();
    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to