openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1074502 - in /openwebbeans/branches/owb_1.0.x/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:40:44 GMT
Author: struberg
Date: Fri Feb 25 12:40:43 2011
New Revision: 1074502

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

Added:
    openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/RequestBean.java
  (with props)
Modified:
    openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/ELPerformanceTest.java
    openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/SampleBean.java
    openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java

Modified: openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/ELPerformanceTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/ELPerformanceTest.java?rev=1074502&r1=1074501&r2=1074502&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/ELPerformanceTest.java
(original)
+++ openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/ELPerformanceTest.java
Fri Feb 25 12:40:43 2011
@@ -23,12 +23,23 @@ import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.apache.webbeans.context.ContextFactory;
+import org.apache.webbeans.logger.WebBeansLogger;
 import org.apache.webbeans.el.WebBeansELResolver;
 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,15 +93,30 @@ public class ELPerformanceTest extends A
         @Override
         public void run()
         {
+            ContextFactory.initRequestContext(null);
+            ContextFactory.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();
+                ContextFactory.destroyRequestContext(null);
+                ContextFactory.destroySessionContext(null);
             }
         }
     }
 }
+

Added: openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/RequestBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/RequestBean.java?rev=1074502&view=auto
==============================================================================
--- openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/RequestBean.java
(added)
+++ openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/RequestBean.java
Fri Feb 25 12:40:43 2011
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.newtests.el;
+
+import javax.enterprise.context.RequestScoped;
+import java.io.Serializable;
+
+@RequestScoped
+public class RequestBean implements Serializable
+{
+    private int y = 323;
+
+    public int getY()
+    {
+        return y;
+    }
+
+    public void setY(int y)
+    {
+        this.y = y;
+    }
+}
+

Propchange: openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/RequestBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/SampleBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/SampleBean.java?rev=1074502&r1=1074501&r2=1074502&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/SampleBean.java
(original)
+++ openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/el/SampleBean.java
Fri Feb 25 12:40:43 2011
@@ -21,9 +21,34 @@ 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/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java?rev=1074502&r1=1074501&r2=1074502&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java
(original)
+++ openwebbeans/branches/owb_1.0.x/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java
Fri Feb 25 12:40:43 2011
@@ -43,7 +43,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);
@@ -86,7 +86,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");
@@ -107,38 +107,42 @@ public class InterceptorPerformanceTest 
         @Override
         public void run()
         {
-            ContextFactory.initRequestContext(null);
-
-            Set<Bean<?>> beans = getBeanManager().getBeans(RequestScopedBean.class);
-            Assert.assertNotNull(beans);
-            Bean<RequestScopedBean> bean = (Bean<RequestScopedBean>)beans.iterator().next();
+            for (int req = 0; req < 5; req++)
+            {
+                ContextFactory.initRequestContext(null);
 
-            CreationalContext<RequestScopedBean> ctx = getBeanManager().createCreationalContext(bean);
+                Set<Bean<?>> beans = getBeanManager().getBeans(RequestScopedBean.class);
+                Assert.assertNotNull(beans);
+                Bean<RequestScopedBean> bean = (Bean<RequestScopedBean>)beans.iterator().next();
+                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;
+                    }
+                    */
+                    }
 
-            ContextFactory.destroyRequestContext(null);
+                ContextFactory.destroyRequestContext(null);
+	    }
         }
     }
 



Mime
View raw message