This is an automated email from the ASF dual-hosted git repository. cshannon pushed a commit to branch activemq-6.2.x in repository https://gitbox.apache.org/repos/asf/activemq.git
commit c85b6b85cc492aa15582f53051a26942021409c2 Author: Christopher L. Shannon <[email protected]> AuthorDate: Wed Dec 17 11:24:28 2025 -0500 AMQ-9819 - Rework Rest test fix (cherry picked from commit ef2795f79336847100abcde9bd9401dd3b611f3e) --- .../java/org/apache/activemq/web/RestTest.java | 33 ++++++++++++++-------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/activemq-web-demo/src/test/java/org/apache/activemq/web/RestTest.java b/activemq-web-demo/src/test/java/org/apache/activemq/web/RestTest.java index 4bd6ba7758..1c94219712 100644 --- a/activemq-web-demo/src/test/java/org/apache/activemq/web/RestTest.java +++ b/activemq-web-demo/src/test/java/org/apache/activemq/web/RestTest.java @@ -24,9 +24,11 @@ import java.util.Random; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; +import java.util.stream.Stream; import jakarta.jms.TextMessage; import javax.management.ObjectName; @@ -88,23 +90,30 @@ public class RestTest extends JettyTestSupport { httpClient.start(); // AMQ-9330 - test no 500 error on timeout and instead 204 error - Future<Result> result = - asyncRequest(httpClient, "http://localhost:" + port + "/message/test?readTimeout=1000&type=queue&clientId=test", new StringBuffer()); - // try a second request while the first is running, this should get a 500 error since the first is still running and - // concurrent access to the same consumer is not allowed - Future<Result> errorResult = asyncRequest(httpClient, "http://localhost:" + port + "/message/test?readTimeout=10000&type=queue&clientId=test", new StringBuffer()); - int status1 = result.get().getResponse().getStatus(); - int status2 = errorResult.get().getResponse().getStatus(); + Set<Integer> results = + Stream.of(asyncRequest(httpClient, "http://localhost:" + port + "/message/test?readTimeout=1000&type=queue&clientId=test", new StringBuffer()), + // try a second request while the first is running, this should get a 500 error since the first is still running and + // concurrent access to the same consumer is not allowed + asyncRequest(httpClient, "http://localhost:" + port + "/message/test?readTimeout=10000&type=queue&clientId=test", new StringBuffer())) + .map(RestTest::getStatus).collect(Collectors.toSet()); + // Order of arrival is nondeterministic; one must fail (500) while the other times out (204). - assertTrue("Expected one 204 and one 500 but got " + status1 + " and " + status2, - (status1 == HttpStatus.NO_CONTENT_204 && status2 == HttpStatus.INTERNAL_SERVER_ERROR_500) || - (status2 == HttpStatus.NO_CONTENT_204 && status1 == HttpStatus.INTERNAL_SERVER_ERROR_500)); + assertEquals("Expected one 204 and one 500 but got " + results, + Set.of(HttpStatus.NO_CONTENT_204, HttpStatus.INTERNAL_SERVER_ERROR_500), results); // AMQ-9481 - test to make sure we can re-use the consumer after timeout by trying again and ensuring // no 500 error. Before the fix in AMQ-9418 this would fail even after the previous request timed out - result = + Future<Result> result = asyncRequest(httpClient, "http://localhost:" + port + "/message/test?readTimeout=1000&type=queue&clientId=test", new StringBuffer()); - assertEquals(HttpStatus.NO_CONTENT_204, result.get().getResponse().getStatus()); + assertEquals(HttpStatus.NO_CONTENT_204, getStatus(result)); + } + + private static int getStatus(Future<Result> result) { + try { + return result.get().getResponse().getStatus(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } } @Test(timeout = 60 * 1000) --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information, visit: https://activemq.apache.org/contact
