openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r959579 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/intercept/ test/java/org/apache/webbeans/newtests/interceptors/beans/ test/java/org/apache/webbeans/newtests/interceptors/business/tests/
Date Thu, 01 Jul 2010 09:54:03 GMT
Author: struberg
Date: Thu Jul  1 09:54:03 2010
New Revision: 959579

URL: http://svn.apache.org/viewvc?rev=959579&view=rev
Log:
OWB-398 add a InterceptorPerformanceTest

A first performance test does pretty well: ~3ms for 
100 Interceptor calls.

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/beans/RequestScopedBean.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java?rev=959579&r1=959578&r2=959579&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
Thu Jul  1 09:54:03 2010
@@ -200,7 +200,6 @@ public abstract class InterceptorHandler
                 if (InterceptorUtil.isWebBeansBusinessMethod(method))
                 {
                     List<Object> decorators = null;
-                    logger.debug("Decorator stack for target {0}", injectionTarget.getDecoratorStack());
                     if (injectionTarget.getDecoratorStack().size() > 0)
                     {
                         Class<?> proxyClass = JavassistProxyFactory.getInterceptorProxyClasses().get(bean);

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/beans/RequestScopedBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/beans/RequestScopedBean.java?rev=959579&r1=959578&r2=959579&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/beans/RequestScopedBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/beans/RequestScopedBean.java
Thu Jul  1 09:54:03 2010
@@ -23,29 +23,29 @@ import javax.inject.Inject;
 @RequestScoped
 public class RequestScopedBean {
 
-	private int i=0;
-	private @Inject ApplicationScopedBean myService;
+    private int i=0;
+    private @Inject ApplicationScopedBean myService;
+
+    /** we need this trick, since the injected beans itself are only proxies... */
+    public RequestScopedBean getInstance() {
+        return this;
+    }
+
+    public int getI() {
+        return i;
+    }
+
+    public void setI(int i) {
+        this.i = i;
+    }
+
+    public ApplicationScopedBean getMyService() {
+        return myService;
+    }
+
+    public void setMyService(ApplicationScopedBean myService) {
+        this.myService = myService;
+    }
+
 
-	/** we need this trick, since the injected beans itself are only proxies... */
-	public RequestScopedBean getInstance() {
-		return this;
-	}
-	
-	public int getI() {
-		return i;
-	}
-
-	public void setI(int i) {
-		this.i = i;
-	}
-
-	public ApplicationScopedBean getMyService() {
-		return myService;
-	}
-
-	public void setMyService(ApplicationScopedBean myService) {
-		this.myService = myService;
-	}
-	
-	
 }

Added: 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=959579&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/business/tests/InterceptorPerformanceTest.java
Thu Jul  1 09:54:03 2010
@@ -0,0 +1,107 @@
+/*
+ * 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.interceptors.business.tests;
+
+import junit.framework.Assert;
+import org.apache.webbeans.context.ContextFactory;
+import org.apache.webbeans.logger.WebBeansLogger;
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.apache.webbeans.newtests.interceptors.beans.ApplicationScopedBean;
+import org.apache.webbeans.newtests.interceptors.beans.RequestScopedBean;
+import org.apache.webbeans.newtests.interceptors.common.TransactionInterceptor;
+import org.junit.Test;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Set;
+
+/**
+ * This test checks the performance of simple interceptor invocations.
+ * It is usually enabled with only a few iteration cycles.
+ */
+@SuppressWarnings("unchecked")
+public class InterceptorPerformanceTest extends AbstractUnitTest
+{
+    private static final String PACKAGE_NAME = DependingInterceptorTest.class.getPackage().getName();
+
+    private static final int ITERATIONS = 10000;
+
+    private static WebBeansLogger logger = WebBeansLogger.getLogger(InterceptorPerformanceTest.class);
+
+
+    @Test
+    public void testInterceptorPerformance()
+    {
+        Collection<URL> beanXmls = new ArrayList<URL>();
+        beanXmls.add(getXMLUrl(PACKAGE_NAME, "DependingInterceptorTest"));
+
+        Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+        beanClasses.add(TransactionInterceptor.class);
+        beanClasses.add(ApplicationScopedBean.class);
+        beanClasses.add(RequestScopedBean.class);
+
+        TransactionInterceptor.count = 0;
+
+        startContainer(beanClasses, beanXmls);
+
+        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);
+
+        Assert.assertTrue(reference1 instanceof RequestScopedBean);
+
+        RequestScopedBean beanInstance1 = (RequestScopedBean)reference1;
+
+        TransactionInterceptor.count = 0;
+
+        long start = System.nanoTime();
+        long startDek = start;
+        for (int i= 1; i < ITERATIONS; i++)
+        {
+            beanInstance1.getMyService().getJ();
+            if (i % 100 == 0)
+            {
+                long endDek = System.nanoTime();
+                logger.info("Executing 100 iterations took {0} ns", endDek - startDek);
+                startDek = endDek;
+            }
+        }
+        long end = System.nanoTime();
+
+        logger.info("Executing {0} iterations took {1} ns", ITERATIONS, end - start);
+
+        shutDownContainer();
+
+        if ((end - start) / 1e6 > ITERATIONS)
+        {
+            // 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");
+        }
+
+    }
+
+}
\ No newline at end of file



Mime
View raw message