You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/01/30 06:10:11 UTC
[isis] branch ISIS-1852_parallel_stream_patch updated: ISIS-1852
testcase backported to JDK 7
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch ISIS-1852_parallel_stream_patch
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/ISIS-1852_parallel_stream_patch by this push:
new 7a70623 ISIS-1852 testcase backported to JDK 7
7a70623 is described below
commit 7a706232067fb60bf8d96d533cdd96198224680a
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
ahuber@apache.org.