cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [cxf] branch master updated: CXF-7784: Adding test case for concurrent invocations of the Invocation.Builder instance
Date Sun, 22 Jul 2018 22:55:16 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 7d61137  CXF-7784: Adding test case for concurrent invocations of the Invocation.Builder
instance
7d61137 is described below

commit 7d611371e968258830cd7cec4cdbb03bff79fc12
Author: reta <drreta@gmail.com>
AuthorDate: Sun Jul 22 18:55:03 2018 -0400

    CXF-7784: Adding test case for concurrent invocations of the Invocation.Builder instance
---
 .../cxf/jaxrs/client/spec/ClientImplTest.java      | 50 ++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/spec/ClientImplTest.java
b/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/spec/ClientImplTest.java
index 88cf9da..1f502e4 100644
--- a/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/spec/ClientImplTest.java
+++ b/rt/rs/client/src/test/java/org/apache/cxf/jaxrs/client/spec/ClientImplTest.java
@@ -20,12 +20,22 @@ package org.apache.cxf.jaxrs.client.spec;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.List;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import java.util.logging.Handler;
 import java.util.logging.LogRecord;
 
 import javax.ws.rs.client.Client;
 import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Invocation;
 import javax.ws.rs.client.WebTarget;
 
 import org.apache.cxf.common.logging.LogUtils;
@@ -187,4 +197,44 @@ public class ClientImplTest extends Assert {
         }
         fail("did not log expected message");
     }
+    
+    /**
+     * This test cases creates a single WebTarget instance and than calls
+     * the request() method concurrently from different threads verifying that
+     * its behavior is thread-safe.
+     */
+    @Test
+    public void testAccessInvocationBuilderConcurrently() {
+        String address = "http://localhost:8080/bookstore/{a}/simple";
+        Client client = ClientBuilder.newClient();
+        
+        final Invocation.Builder builder = client
+                .target(address)
+                .resolveTemplate("a", "bookheaders")
+                .request("application/xml")
+                .header("a", "b");
+        
+        final ExecutorService executor = Executors.newFixedThreadPool(20);
+        final CyclicBarrier barrier = new CyclicBarrier(20);
+        
+        final Collection<CompletableFuture<?>> futures = new ArrayList<>();
+        for (int i = 0; i < 20; ++i) {
+            futures.add(CompletableFuture.supplyAsync(() -> {
+                try {
+                    barrier.await(1, TimeUnit.SECONDS);
+                    return builder.buildGet();
+                } catch (final InterruptedException ex) {
+                    Thread.interrupted();
+                    throw new CompletionException(ex);
+                } catch (BrokenBarrierException | TimeoutException ex) {
+                    throw new CompletionException(ex);
+                }
+            }, executor));
+        }
+        
+        CompletableFuture
+            .allOf(futures.toArray(new CompletableFuture<?>[0]))
+            .join();
+    }
+        
 }


Mime
View raw message