You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2011/03/07 19:21:27 UTC

svn commit: r1078883 - /openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java

Author: struberg
Date: Mon Mar  7 18:21:27 2011
New Revision: 1078883

URL: http://svn.apache.org/viewvc?rev=1078883&view=rev
Log:
OWB-530 fix test which now really fails on concurrency problems

Modified:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java?rev=1078883&r1=1078882&r2=1078883&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java Mon Mar  7 18:21:27 2011
@@ -42,8 +42,8 @@ public class InterceptorPerformanceTest 
 {
     private static final String PACKAGE_NAME = DependingInterceptorTest.class.getPackage().getName();
 
-    private static final int ITERATIONS = 3000;
-    private static final int NUM_THREADS = 50;
+    private static final int ITERATIONS = 2000;
+    private static final int NUM_THREADS = 150;
 
     private static WebBeansLogger logger = WebBeansLogger.getLogger(InterceptorPerformanceTest.class);
 
@@ -76,6 +76,7 @@ public class InterceptorPerformanceTest 
         for (int i= 0 ; i < NUM_THREADS; i++)
         {
             threads[i].join();
+            Assert.assertFalse(threads[i].isFailed());
         }
 
 
@@ -97,51 +98,57 @@ public class InterceptorPerformanceTest 
     {
         private String threadName;
 
+        private boolean failed = false;
+
         public CalculationRunner(String name)
         {
             super(name);
             threadName = name;
         }
 
+        public boolean isFailed() {
+            return failed;
+        }
+
         @Override
         public void run()
         {
-            for (int req = 0; req < 5; req++)
+            try
             {
-                WebBeansContext.currentInstance().getContextFactory().initRequestContext(null);
+                for (int req = 0; req < 5; req++)
+                {
+                    WebBeansContext.currentInstance().getContextFactory().initRequestContext(null);
 
-                Set<Bean<?>> beans = getBeanManager().getBeans(RequestScopedBean.class);
-                Assert.assertNotNull(beans);
-                Bean<RequestScopedBean> bean = (Bean<RequestScopedBean>)beans.iterator().next();
+                    Set<Bean<?>> beans = getBeanManager().getBeans(RequestScopedBean.class);
+                    Assert.assertNotNull(beans);
+                    Bean<RequestScopedBean> bean = (Bean<RequestScopedBean>)beans.iterator().next();
 
-                CreationalContext<RequestScopedBean> ctx = getBeanManager().createCreationalContext(bean);
+                    CreationalContext<RequestScopedBean> ctx = getBeanManager().createCreationalContext(bean);
 
-                Object reference1 = getBeanManager().getReference(bean, RequestScopedBean.class, ctx);
-                Assert.assertNotNull(reference1);
+                    Object reference1 = getBeanManager().getReference(bean, RequestScopedBean.class, ctx);
+                    Assert.assertNotNull(reference1);
 
-                Assert.assertTrue(reference1 instanceof RequestScopedBean);
+                    Assert.assertTrue(reference1 instanceof RequestScopedBean);
 
-                RequestScopedBean beanInstance1 = (RequestScopedBean)reference1;
+                    RequestScopedBean beanInstance1 = (RequestScopedBean)reference1;
 
-                TransactionInterceptor.count = 0;
+                    TransactionInterceptor.count = 0;
 
-                long start = System.nanoTime();
+                    long start = System.nanoTime();
 
-                long startDek = start;
-                for (int i= 1; i < ITERATIONS; i++)
-                {
-                    beanInstance1.getMyService().getJ();
-    /*X
-                    if (i % 10000 == 0)
+                    long startDek = start;
+                    for (int i= 1; i < ITERATIONS; i++)
                     {
-                        long endDek = System.nanoTime();
-                        logger.info("Thread {0}: Executing 10000 iterations took {1} ns", threadName, endDek - startDek);
-                        startDek = endDek;
+                        beanInstance1.getMyService().getJ();
                     }
-    */
-                }
 
-                WebBeansContext.currentInstance().getContextFactory().destroyRequestContext(null);
+                    WebBeansContext.currentInstance().getContextFactory().destroyRequestContext(null);
+                }
+            }
+            catch (Exception e)
+            {
+                logger.error("Concurrency problem in InterceptorPerformanceTest detected in thread " + threadName, e);
+                failed = true;
             }
         }
     }