You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2018/02/14 13:18:14 UTC
[isis] 02/02: ISIS-1852 testcase backported to JDK 7
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch ISIS-1852_parallel_stream_patch
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 3706fa92cf0d3668a0a18be21b759f585c187692
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Jan 30 07:10:05 2018 +0100
ISIS-1852 testcase backported to JDK 7
---
.../runtime/services/ServiceInstantiatorTest.java | 38 +++++++++++++---------
1 file changed, 22 insertions(+), 16 deletions(-)
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTest.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTest.java
index 5b39423..d12766e 100644
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTest.java
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/services/ServiceInstantiatorTest.java
@@ -24,7 +24,7 @@ import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.LongAdder;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.enterprise.context.RequestScoped;
@@ -139,34 +139,40 @@ public class ServiceInstantiatorTest {
final AccumulatingCalculator calculator =
serviceInstantiator.createInstance(AccumulatingCalculator.class);
- final LongAdder counter = new LongAdder();
-
+ final AtomicInteger counter = new AtomicInteger();
+
final int n = 100;
final int nThreads = 8;
final ExecutorService execService = Executors.newFixedThreadPool(nThreads);
// initialize the request scoped calculator on current thread ('main')
((RequestScopedService)calculator).__isis_startRequest(mockServiceInjector);
-
+
for(int i=1;i<=n;++i) {
final int j=i;
- execService.submit(()->{
- try {
-
- // access the request scoped calculator on a child thread of 'main'
- calculator.add(j);
- counter.add(calculator.getTotal());
-
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
+
+ execService.submit(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+
+ // access the request scoped calculator on a child thread of 'main'
+ calculator.add(j);
+ counter.addAndGet(calculator.getTotal());
+
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+ }
+ }
});
+
}
-
+
execService.shutdown();
execService.awaitTermination(10, TimeUnit.SECONDS);
-
+
((RequestScopedService)calculator).__isis_endRequest();
assertThat(counter.intValue(), is(n*(n+1)/2));
--
To stop receiving notification emails like this one, please contact
danhaywood@apache.org.