From 69a7589ad5ab8105c341824eee987a97469282cd Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Thu, 4 Apr 2013 08:56:04 +0000 Subject: [PATCH] Fixed synchronization bug git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1464365 13f79535-47bb-0310-9956-ffa450edef68 --- .../TestFutureRequestExecutionService.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/httpclient/src/test/java/org/apache/http/impl/client/TestFutureRequestExecutionService.java b/httpclient/src/test/java/org/apache/http/impl/client/TestFutureRequestExecutionService.java index 34306f97b..d624d09e7 100644 --- a/httpclient/src/test/java/org/apache/http/impl/client/TestFutureRequestExecutionService.java +++ b/httpclient/src/test/java/org/apache/http/impl/client/TestFutureRequestExecutionService.java @@ -38,6 +38,7 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import junit.framework.Assert; @@ -150,9 +151,9 @@ public class TestFutureRequestExecutionService { latch.await(10, TimeUnit.SECONDS); - Assert.assertEquals(100, callback.completed); - Assert.assertEquals(0, callback.cancelled); - Assert.assertEquals(0, callback.failed); + Assert.assertEquals(100, callback.completed.get()); + Assert.assertEquals(0, callback.cancelled.get()); + Assert.assertEquals(0, callback.failed.get()); } @@ -160,9 +161,9 @@ public class TestFutureRequestExecutionService { private final CountDownLatch latch; - int failed=0; - int cancelled=0; - int completed=0; + AtomicInteger failed = new AtomicInteger(0); + AtomicInteger cancelled = new AtomicInteger(0); + AtomicInteger completed = new AtomicInteger(0); CountingCallback(final CountDownLatch latch) { super(); @@ -171,17 +172,17 @@ public class TestFutureRequestExecutionService { public void failed(final Exception ex) { latch.countDown(); - failed++; + failed.incrementAndGet(); } public void completed(final Boolean result) { latch.countDown(); - completed++; + completed.incrementAndGet(); } public void cancelled() { latch.countDown(); - cancelled++; + cancelled.incrementAndGet(); } }