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

reta pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/main by this push:
     new cfee0995b3 Fix flaky testGetGenericBookManyClientsInParallel & 
testGetGenericBookSingleClientInParallel test cases (under JDK-21 and above)
cfee0995b3 is described below

commit cfee0995b3a8c36b565cdf2f17c5cbe7a402b0a7
Author: Andriy Redko <[email protected]>
AuthorDate: Wed Jul 10 20:30:46 2024 -0400

    Fix flaky testGetGenericBookManyClientsInParallel & 
testGetGenericBookSingleClientInParallel test cases (under JDK-21 and above)
---
 .../systest/jaxrs/JAXRS20ClientServerBookTest.java    | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
index bee4c88c16..7362f4f7e8 100644
--- 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
@@ -99,6 +99,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.greaterThan;
 import static org.hamcrest.Matchers.hasKey;
 import static org.hamcrest.Matchers.lessThan;
+import static org.hamcrest.Matchers.lessThanOrEqualTo;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -164,8 +165,11 @@ public class JAXRS20ClientServerBookTest extends 
AbstractBusClientServerTestBase
                 .mapToObj(id -> threadMXBean.getThreadInfo(id))
                 .filter(Objects::nonNull)
                 .filter(t -> t.getThreadName().startsWith("HttpClient-"))
+                .filter(t -> t.getThreadName().endsWith("-SelectorManager"))
                 .count();
 
+        // Capture the number of client threads at start
+        final long expectedHttpClientThreads = captureHttpClientThreads.get();
         final Collection<WebClient> clients = new ArrayList<>();
         try {
             final String target = "http://localhost:"; + PORT + 
"/bookstore/genericbooks/123";
@@ -198,8 +202,8 @@ public class JAXRS20ClientServerBookTest extends 
AbstractBusClientServerTestBase
         clients.forEach(WebClient::close);
     
         // Since JDK-21, HttpClient Implements AutoCloseable
-        if (Runtime.version().feature() > 21) { 
-            assertThat(httpClientThreads.get(), equalTo(0L));
+        if (Runtime.version().feature() >= 21) { 
+            assertThat(captureHttpClientThreads.get(), 
lessThanOrEqualTo(expectedHttpClientThreads));
         }
     }
 
@@ -215,10 +219,11 @@ public class JAXRS20ClientServerBookTest extends 
AbstractBusClientServerTestBase
                 .mapToObj(id -> threadMXBean.getThreadInfo(id))
                 .filter(Objects::nonNull)
                 .filter(t -> t.getThreadName().startsWith("HttpClient-"))
+                .filter(t -> t.getThreadName().endsWith("-SelectorManager"))
                 .count();
 
         // Capture the number of client threads at start
-        final long httpClientThreads = captureHttpClientThreads.get();
+        final long expectedHttpClientThreads = captureHttpClientThreads.get();
         final WebClient client = WebClient.create(target, true);
         try {
             final Collection<Future<?>> futures = new ArrayList<>(); 
@@ -245,13 +250,13 @@ public class JAXRS20ClientServerBookTest extends 
AbstractBusClientServerTestBase
 
         pool.shutdown();
         // Since JDK-21, HttpClient Implements AutoCloseable
-        if (pool.awaitTermination(2, TimeUnit.MINUTES) && 
Runtime.version().feature() > 21) {
-            assertThat(captureHttpClientThreads.get(), 
equalTo(httpClientThreads));
+        if (pool.awaitTermination(2, TimeUnit.MINUTES) && 
Runtime.version().feature() >= 21) {
+            assertThat(captureHttpClientThreads.get(), 
lessThanOrEqualTo(expectedHttpClientThreads));
         } else {
             pool.shutdownNow();
             // Since JDK-21, HttpClient Implements AutoCloseable
-            if (pool.awaitTermination(2, TimeUnit.MINUTES) && 
Runtime.version().feature() > 21) {
-                assertThat(captureHttpClientThreads.get(), 
equalTo(httpClientThreads));
+            if (pool.awaitTermination(2, TimeUnit.MINUTES) && 
Runtime.version().feature() >= 21) {
+                assertThat(captureHttpClientThreads.get(), 
lessThanOrEqualTo(expectedHttpClientThreads));
             }
         }
     }

Reply via email to