This is an automated email from the ASF dual-hosted git repository. cshannon pushed a commit to branch activemq-5.19.x in repository https://gitbox.apache.org/repos/asf/activemq.git
commit 7b71fc6289e6f26c200988df3cf9c0f5093dadf8 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 | 34 ++++++++++++++-------- 1 file changed, 22 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 91b927ad04..0c895a4a2a 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 @@ -23,8 +23,11 @@ import static org.junit.Assert.assertTrue; 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 javax.jms.TextMessage; import javax.management.ObjectName; @@ -87,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
