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

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

commit 0d749cec1c964b903150988d5e1457bda65f185e
Author: Dan Haywood <d...@haywood-associates.co.uk>
AuthorDate: Wed Feb 14 13:56:23 2018 +0000

    ISIS-1852: fixes unit test
    
    the algorithm was wrong, I think
---
 .../core/runtime/services/ServiceInstantiator.java |  2 +-
 .../runtime/services/ServiceInstantiatorTest.java  | 47 ++++++++++++----------
 2 files changed, 26 insertions(+), 23 deletions(-)

diff --git 
a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/ServiceInstantiator.java
 
b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/ServiceInstantiator.java
index 77adb02..1643c2d 100644
--- 
a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/ServiceInstantiator.java
+++ 
b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/ServiceInstantiator.java
@@ -160,7 +160,7 @@ public final class ServiceInstantiator {
                // Allow serviceByThread to be propagated from the thread that 
starts the request 
                // to any child-threads, hence InheritableThreadLocal.
                private InheritableThreadLocal<T> serviceByThread = new 
InheritableThreadLocal<>();
-                
+
                 @Override
                 public Object invoke(final Object proxied, final Method 
proxyMethod, final Method proxiedMethod, final Object[] args) throws Throwable {
 
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 d12766e..6bf03e7 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
@@ -16,26 +16,30 @@
  */
 package org.apache.isis.core.runtime.services;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
+import java.util.Collections;
+import java.util.List;
 import java.util.concurrent.BrokenBarrierException;
 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.AtomicInteger;
 
 import javax.enterprise.context.RequestScoped;
 
-import org.apache.isis.core.commons.config.IsisConfigurationDefault;
-import org.apache.isis.core.metamodel.services.ServicesInjector;
-import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
+import com.google.common.collect.Lists;
+
 import org.jmock.auto.Mock;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import org.apache.isis.core.commons.config.IsisConfigurationDefault;
+import org.apache.isis.core.metamodel.services.ServicesInjector;
+import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
 public class ServiceInstantiatorTest {
 
        @Rule
@@ -139,7 +143,8 @@ public class ServiceInstantiatorTest {
                final AccumulatingCalculator calculator = 
                                
serviceInstantiator.createInstance(AccumulatingCalculator.class);
 
-               final AtomicInteger counter = new AtomicInteger();
+
+               final List<Integer> interimTotals = 
Collections.synchronizedList(Lists.newArrayList());
 
                final int n = 100;
                final int nThreads = 8;
@@ -151,21 +156,17 @@ public class ServiceInstantiatorTest {
                for(int i=1;i<=n;++i) {
                        final int j=i;
 
-                       execService.submit(new Runnable() {
-
-                               @Override
-                               public void run() {
-                                       try {
+                       execService.submit(() -> {
+                try {
 
-                                               // access the request scoped 
calculator on a child thread of 'main'
-                                               calculator.add(j);
-                                               
counter.addAndGet(calculator.getTotal());
+                    // access the request scoped calculator on a child thread 
of 'main'
+                    calculator.add(j);
+                    interimTotals.add(calculator.getTotal());
 
-                                       } catch (Exception e) {
-                                               
System.err.println(e.getMessage());
-                                       } 
-                               }
-                       });
+                } catch (Exception e) {
+                    System.err.println(e.getMessage());
+                }
+            });
 
                }
 
@@ -175,7 +176,9 @@ public class ServiceInstantiatorTest {
 
                ((RequestScopedService)calculator).__isis_endRequest();
 
-               assertThat(counter.intValue(), is(n*(n+1)/2));
+               assertThat(interimTotals.size(), is(n));
+               final Integer maxTotal = Collections.max(interimTotals);
+               assertThat(maxTotal, is(n*(n+1)/2));
        }
 
        public static class SingletonCalculator {

-- 
To stop receiving notification emails like this one, please contact
danhayw...@apache.org.

Reply via email to