openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1074499 - in /openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests: el/ELPerformanceTest.java el/RequestBean.java el/SampleBean.java interceptors/business/tests/InterceptorPerformanceTest.java
Date Fri, 25 Feb 2011 12:34:23 GMT
Author: struberg
Date: Fri Feb 25 12:34:23 2011
New Revision: 1074499

URL: http://svn.apache.org/viewvc?rev=1074499&view=rev
Log:
OWB-530 tweak InterceptorPerformanceTest and fix ELPerformanceTest


Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/RequestBean.java
      - copied, changed from r1074307, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/SampleBean.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/ELPerformanceTest.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/SampleBean.java
    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/el/ELPerformanceTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/ELPerformanceTest.java?rev=1074499&r1=1074498&r2=1074499&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/ELPerformanceTest.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/ELPerformanceTest.java
Fri Feb 25 12:34:23 2011
@@ -23,12 +23,23 @@ import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.el.WebBeansELResolver;
+import org.apache.webbeans.logger.WebBeansLogger;
 import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.junit.Assert;
 import org.junit.Test;
 
+import javax.el.ELContext;
+
 public class ELPerformanceTest extends AbstractUnitTest
 {
+    private final static int THREADS = 100;
+    private final static int ITERATIONS = 200;
+
+
+    private static WebBeansLogger logger = WebBeansLogger.getLogger(ELPerformanceTest.class);
+
     /**
      * Test our bean creation for thread safety.
      */
@@ -38,22 +49,32 @@ public class ELPerformanceTest extends A
         Collection<Class<?>> classes = new ArrayList<Class<?>>();
 
         classes.add(SampleBean.class);
+        classes.add(RequestBean.class);
+
+        // we need this to enable the EL resolver at all!
+
         startContainer(classes);
-        
+
         List<ParallelBeanStarter> strarters = new ArrayList<ParallelBeanStarter>();
         WebBeansELResolver resolver = new WebBeansELResolver();
-        for(int i=0;i<500;i++)
+
+        long start = System.nanoTime();
+
+        for(int i=0; i<THREADS; i++)
         {
             ParallelBeanStarter starter = new ParallelBeanStarter(resolver);
             strarters.add(starter);
+            starter.start();
         }
         
-        for(ParallelBeanStarter start : strarters)
+        for(ParallelBeanStarter starter : strarters)
         {
-            start.start();
+            starter.join();
         }        
         
-        System.out.println("Completed");
+        long end = System.nanoTime();
+
+        logger.info("Executing {0} threads with {1} iterations took {2} ns", THREADS, ITERATIONS,
end - start);
         
         shutDownContainer();
     }
@@ -61,6 +82,7 @@ public class ELPerformanceTest extends A
     private static class ParallelBeanStarter extends Thread
     {
         private WebBeansELResolver resolver;
+        private ELContext elctx = new MockELContext();
         private static AtomicInteger n = new AtomicInteger(0);
         
         public ParallelBeanStarter(WebBeansELResolver resolver)
@@ -71,14 +93,28 @@ public class ELPerformanceTest extends A
         @Override
         public void run()
         {
+            WebBeansContext.currentInstance().getContextFactory().initRequestContext(null);
+            WebBeansContext.currentInstance().getContextFactory().initSessionContext(null);
+
             try
             {
-                System.out.println(n.incrementAndGet());
-                resolver.getValue(new MockELContext() , null, "sampleBean");
-                
-            }catch(Exception e)
+                for (int i = 0; i < ITERATIONS; i++)
+                {
+                    SampleBean sb = (SampleBean) resolver.getValue(elctx , null, "sampleBean");
+                    sb.getRb().getY();
+                    sb.getX();
+                }
+            }
+            catch(RuntimeException e)
+            {
+                logger.error(e);
+                Assert.fail("got an exception: " + e.getMessage());
+                throw e;
+            }
+            finally
             {
-                e.printStackTrace();
+                WebBeansContext.currentInstance().getContextFactory().destroyRequestContext(null);
+                WebBeansContext.currentInstance().getContextFactory().destroySessionContext(null);
             }
         }
     }

Copied: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/RequestBean.java
(from r1074307, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/SampleBean.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/RequestBean.java?p2=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/RequestBean.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/SampleBean.java&r1=1074307&r2=1074499&rev=1074499&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/SampleBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/RequestBean.java
Fri Feb 25 12:34:23 2011
@@ -18,12 +18,21 @@
  */
 package org.apache.webbeans.newtests.el;
 
+import javax.enterprise.context.RequestScoped;
 import java.io.Serializable;
 
-import javax.enterprise.context.SessionScoped;
-import javax.inject.Named;
-
-@SessionScoped @Named public class SampleBean implements Serializable
+@RequestScoped
+public class RequestBean implements Serializable
 {
-    
+    private int y = 323;
+
+    public int getY()
+    {
+        return y;
+    }
+
+    public void setY(int y)
+    {
+        this.y = y;
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/SampleBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/SampleBean.java?rev=1074499&r1=1074498&r2=1074499&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/SampleBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/SampleBean.java
Fri Feb 25 12:34:23 2011
@@ -21,9 +21,33 @@ package org.apache.webbeans.newtests.el;
 import java.io.Serializable;
 
 import javax.enterprise.context.SessionScoped;
+import javax.inject.Inject;
 import javax.inject.Named;
 
-@SessionScoped @Named public class SampleBean implements Serializable
+@SessionScoped
+@Named
+public class SampleBean implements Serializable
 {
-    
+    private int x=121;
+    private @Inject RequestBean rb;
+
+    public int getX()
+    {
+        return x;
+    }
+
+    public void setX(int x)
+    {
+        this.x = x;
+    }
+
+    public RequestBean getRb()
+    {
+        return rb;
+    }
+
+    public void setRb(RequestBean rb)
+    {
+        this.rb = rb;
+    }
 }

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=1074499&r1=1074498&r2=1074499&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
Fri Feb 25 12:34:23 2011
@@ -42,7 +42,7 @@ public class InterceptorPerformanceTest 
 {
     private static final String PACKAGE_NAME = DependingInterceptorTest.class.getPackage().getName();
 
-    private static final int ITERATIONS = 30000;
+    private static final int ITERATIONS = 3000;
     private static final int NUM_THREADS = 50;
 
     private static WebBeansLogger logger = WebBeansLogger.getLogger(InterceptorPerformanceTest.class);
@@ -85,7 +85,7 @@ public class InterceptorPerformanceTest 
 
         shutDownContainer();
 
-        if ((end - start) / 1e6 > ITERATIONS)
+        if ((end - start) / 1e6 > ITERATIONS*5)
         {
             // if it takes longer than 1ms for each iteration, then this is really a performance
blocker! 
             Assert.fail("Performance test took more than 20 times longer than it should");
@@ -106,38 +106,43 @@ public class InterceptorPerformanceTest 
         @Override
         public void run()
         {
-            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();
-                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();
+    /*X
+                    if (i % 10000 == 0)
+                    {
+                        long endDek = System.nanoTime();
+                        logger.info("Thread {0}: Executing 10000 iterations took {1} ns",
threadName, endDek - startDek);
+                        startDek = endDek;
+                    }
+    */
                 }
-            }
 
-            WebBeansContext.currentInstance().getContextFactory().destroyRequestContext(null);
+                WebBeansContext.currentInstance().getContextFactory().destroyRequestContext(null);
+            }
         }
     }
 



Mime
View raw message