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

reta pushed a commit to branch 3.6.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 238470e9ae8aa9903ad4a71c40c560ad93aed676
Author: Andriy Redko <[email protected]>
AuthorDate: Sun Sep 28 14:44:59 2025 -0400

    Add more tests for sync / async client to excercise parallel calls
    
    (cherry picked from commit f7be1cfcf7ffe1c7e0158dbaf97f383cc94c3d83)
    (cherry picked from commit c0c324a325abecd5ee1bf9ba1171ffb9997a8d7c)
    
    # Conflicts:
    #       
systests/transports/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientChunkingTest.java
---
 .../jaxrs/JAXRSAsyncClientChunkingTest.java        | 41 ++++++++++++++++++
 .../cxf/systest/jaxrs/JAXRSClientChunkingTest.java | 48 ++++++++++++++++++++++
 2 files changed, 89 insertions(+)

diff --git 
a/systests/transports/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientChunkingTest.java
 
b/systests/transports/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientChunkingTest.java
index eb5f0eaf45..1780bdbd29 100644
--- 
a/systests/transports/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientChunkingTest.java
+++ 
b/systests/transports/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSAsyncClientChunkingTest.java
@@ -22,6 +22,7 @@ package org.apache.cxf.systest.jaxrs;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
@@ -29,6 +30,7 @@ import java.util.Random;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -216,6 +218,45 @@ public class JAXRSAsyncClientChunkingTest extends 
AbstractBusClientServerTestBas
 
         assertNoDuplicateLogging();
     }
+    
+    @Test
+    public void testStreamChunkingAsyncParallel() 
+            throws IOException, InterruptedException, ExecutionException, 
TimeoutException {
+        final String url = "http://localhost:"; + PORT + "/file-store/stream";
+        final WebClient webClient = WebClient.create(url).query("chunked", 
chunked);
+        
+        final ClientConfiguration config = WebClient.getConfig(webClient);
+        config.getBus().setProperty(AsyncHTTPConduit.USE_ASYNC, true);
+        config.getHttpConduit().getClient().setAllowChunking(chunked);
+        config.getHttpConduit().getClient().setAutoRedirect(autoRedirect);
+        configureLogging(config);
+
+        final byte[] bytes = new byte [32 * 1024];
+        final Random random = new Random();
+        random.nextBytes(bytes);
+
+        final Collection<Future<Response>> futures = new ArrayList<>();
+        try {
+            for (int i = 0; i < 100; ++i) {
+                try (InputStream in = new ByteArrayInputStream(bytes)) {
+                    final Entity<InputStream> entity = Entity.entity(in, 
MediaType.APPLICATION_OCTET_STREAM);
+                    futures.add(webClient.async().post(entity));
+                }
+            }
+
+            for (Future<Response> future: futures) {
+                try (Response response = future.get(10, TimeUnit.SECONDS)) {
+                    assertThat(response.getStatus(), equalTo(200));
+                    assertThat(response.getHeaderString("Transfer-Encoding"), 
equalTo(chunked ? "chunked" : null));
+                    assertThat(response.getEntity(), not(equalTo(null)));
+                }
+            }
+        } finally {
+            webClient.close();
+        }
+
+        assertNoDuplicateLogging();
+    }
 
     private void assertRedirect(String filename) {
         final String url = "http://localhost:"; + PORT + "/file-store/redirect";
diff --git 
a/systests/transports/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientChunkingTest.java
 
b/systests/transports/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientChunkingTest.java
index 536b4aecb3..c7fe82148c 100644
--- 
a/systests/transports/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientChunkingTest.java
+++ 
b/systests/transports/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientChunkingTest.java
@@ -22,16 +22,24 @@ package org.apache.cxf.systest.jaxrs;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 import java.util.Random;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 
+import org.apache.cxf.jaxrs.client.ClientConfiguration;
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.jaxrs.ext.multipart.Attachment;
 import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
@@ -114,4 +122,44 @@ public class JAXRSClientChunkingTest extends 
AbstractBusClientServerTestBase {
             webClient.close();
         }
     }
+    
+    @Test
+    public void testStreamChunkingParallel() 
+            throws IOException, InterruptedException, ExecutionException, 
TimeoutException {
+        final String url = "http://localhost:"; + PORT + "/file-store/stream";
+        final WebClient webClient = WebClient.create(url).query("chunked", 
chunked);
+        final ExecutorService pool = Executors.newFixedThreadPool(100);
+
+        final ClientConfiguration config = WebClient.getConfig(webClient);
+        config.getHttpConduit().getClient().setAllowChunking(chunked);
+
+        final byte[] bytes = new byte [32 * 1024];
+        final Random random = new Random();
+        random.nextBytes(bytes);
+
+        final Collection<Future<Response>> futures = new ArrayList<>();
+        try {
+            for (int i = 0; i < 100; ++i) {
+                try (InputStream in = new ByteArrayInputStream(bytes)) {
+                    final Entity<InputStream> entity = Entity.entity(in, 
MediaType.APPLICATION_OCTET_STREAM);
+                    futures.add(pool.submit(() -> webClient.post(entity)));
+                }
+            }
+
+            for (Future<Response> future: futures) {
+                try (Response response = future.get(10, TimeUnit.SECONDS)) {
+                    assertThat(response.getStatus(), equalTo(200));
+                    assertThat(response.getHeaderString("Transfer-Encoding"), 
equalTo(chunked ? "chunked" : null));
+                    assertThat(response.getEntity(), not(equalTo(null)));
+                }
+            }
+        } finally {
+            webClient.close();
+        }
+        
+        pool.shutdown();
+        if (!pool.awaitTermination(2, TimeUnit.MINUTES)) {
+            pool.shutdownNow();
+        }
+    }
 }

Reply via email to