openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1361679 - in /openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests: decorators/multiple/ decorators/tests/ interceptors/business/tests/
Date Sun, 15 Jul 2012 10:26:35 GMT
Author: struberg
Date: Sun Jul 15 10:26:34 2012
New Revision: 1361679

URL: http://svn.apache.org/viewvc?rev=1361679&view=rev
Log:
OWB-672 add preliminary Decorator test (disabled for now)

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutsideBean.java
  (with props)
Modified:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator1.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator2.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/IOutputProvider.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutputInterceptor.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutputProvider.java
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/tests/DecoratorAndInterceptorStackTests.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/decorators/multiple/Decorator1.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator1.java?rev=1361679&r1=1361678&r2=1361679&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator1.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator1.java
Sun Jul 15 10:26:34 2012
@@ -20,17 +20,21 @@ package org.apache.webbeans.newtests.dec
 
 import javax.decorator.Decorator;
 import javax.decorator.Delegate;
-import javax.enterprise.inject.Any;
 import javax.inject.Inject;
 
 @Decorator
 public class Decorator1 implements IOutputProvider
 {
 
-    @Inject @Delegate @Any IOutputProvider op;
+    @Inject @Delegate IOutputProvider op;
     
     @Inject RequestStringBuilder rsb;
 
+    public void init()
+    {
+        System.out.println("decorator created!");
+    }
+
     public String getOutput()
     {
         rsb.addOutput("Decorator1\n");
@@ -45,4 +49,10 @@ public class Decorator1 implements IOutp
     {
         return "Decorator1/otherMethod," + op.otherMethod();
     }
+
+    @Override
+    public String getDelayedOutput() throws InterruptedException
+    {
+        return op.getDelayedOutput();
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator2.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator2.java?rev=1361679&r1=1361678&r2=1361679&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator2.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/Decorator2.java
Sun Jul 15 10:26:34 2012
@@ -47,4 +47,10 @@ public class Decorator2 implements IOutp
     {
         return "Decorator2/otherMethod," + op.otherMethod();
     }
+
+    @Override
+    public String getDelayedOutput() throws InterruptedException
+    {
+        return op.getDelayedOutput();
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/IOutputProvider.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/IOutputProvider.java?rev=1361679&r1=1361678&r2=1361679&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/IOutputProvider.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/IOutputProvider.java
Sun Jul 15 10:26:34 2012
@@ -25,4 +25,5 @@ public interface IOutputProvider
     public String trace();
     public String otherMethod();
 
+    public String getDelayedOutput() throws InterruptedException;
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutputInterceptor.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutputInterceptor.java?rev=1361679&r1=1361678&r2=1361679&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutputInterceptor.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutputInterceptor.java
Sun Jul 15 10:26:34 2012
@@ -25,13 +25,13 @@ import javax.interceptor.InvocationConte
 
 @MyIntercept @Interceptor
 public class OutputInterceptor {
-	
-	@Inject RequestStringBuilder rb;
-	
-	@AroundInvoke
-	public Object myHook(InvocationContext ctx) throws Exception{
-		rb.addOutput("OutputInterceptor\n");
-		return ctx.proceed();
-	}
+
+    @Inject RequestStringBuilder rb;
+
+    @AroundInvoke
+    public Object myHook(InvocationContext ctx) throws Exception{
+        rb.addOutput("OutputInterceptor\n");
+        return ctx.proceed();
+    }
 
 }

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutputProvider.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutputProvider.java?rev=1361679&r1=1361678&r2=1361679&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutputProvider.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutputProvider.java
Sun Jul 15 10:26:34 2012
@@ -18,11 +18,11 @@
  */
 package org.apache.webbeans.newtests.decorators.multiple;
 
-import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
 
-@RequestScoped
+@ApplicationScoped
 @Named("op")
 public class OutputProvider implements IOutputProvider
 {
@@ -33,7 +33,6 @@ public class OutputProvider implements I
     @MyIntercept
     public String getOutput()
     {
-
         rsb.addOutput("OutputProvider\n");
         return rsb.toString();
     }
@@ -46,4 +45,14 @@ public class OutputProvider implements I
     public String otherMethod() {
         return "delegate/otherMethod";
     }
+
+
+    @MyIntercept
+    public String getDelayedOutput() throws InterruptedException
+    {
+        Thread.sleep(5L);
+        rsb.addOutput("OutputProvider\n");
+        return rsb.toString();
+    }
+
 }

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutsideBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutsideBean.java?rev=1361679&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutsideBean.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutsideBean.java
Sun Jul 15 10:26:34 2012
@@ -0,0 +1,34 @@
+/*
+ * 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.decorators.multiple;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+
+@ApplicationScoped
+//X @MyIntercept
+public class OutsideBean
+{
+    private @Inject IOutputProvider outputProvider;
+
+    public void doThaStuff() throws Exception
+    {
+        outputProvider.getDelayedOutput();
+    }
+}

Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/multiple/OutsideBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/tests/DecoratorAndInterceptorStackTests.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/tests/DecoratorAndInterceptorStackTests.java?rev=1361679&r1=1361678&r2=1361679&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/tests/DecoratorAndInterceptorStackTests.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/decorators/tests/DecoratorAndInterceptorStackTests.java
Sun Jul 15 10:26:34 2012
@@ -20,6 +20,8 @@ package org.apache.webbeans.newtests.dec
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import javax.enterprise.inject.Default;
 import javax.enterprise.inject.spi.Bean;
@@ -27,6 +29,7 @@ import javax.enterprise.util.AnnotationL
 
 import junit.framework.Assert;
 
+import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.newtests.AbstractUnitTest;
 import org.apache.webbeans.newtests.decorators.multiple.Decorator1;
 import org.apache.webbeans.newtests.decorators.multiple.Decorator2;
@@ -34,6 +37,7 @@ import org.apache.webbeans.newtests.deco
 import org.apache.webbeans.newtests.decorators.multiple.MyIntercept;
 import org.apache.webbeans.newtests.decorators.multiple.OutputInterceptor;
 import org.apache.webbeans.newtests.decorators.multiple.OutputProvider;
+import org.apache.webbeans.newtests.decorators.multiple.OutsideBean;
 import org.apache.webbeans.newtests.decorators.multiple.RequestStringBuilder;
 import org.junit.Test;
 
@@ -41,6 +45,9 @@ public class DecoratorAndInterceptorStac
 {
 
     public static final String PACKAGE_NAME = DecoratorAndInterceptorStackTests.class.getPackage().getName();
+    private static final int NUM_THREADS = 50;
+
+    private static final Logger log = Logger.getLogger(DecoratorAndInterceptorStackTests.class.getName());
 
     @Test
     public void testDecoratorStack()
@@ -73,4 +80,77 @@ public class DecoratorAndInterceptorStac
         // Verify that the Interceptors and Decorators were called in order, and in a stack.
         Assert.assertTrue(result.equalsIgnoreCase("OutputInterceptor\nDecorator1\nDecorator2\nOutputProvider\n"));
     }
+
+
+    //X TODO @Test
+    public void testParallelInterceptorInvocation() throws Exception
+    {
+        Collection<Class<?>> classes = new ArrayList<Class<?>>();
+        classes.add(Decorator1.class);
+        classes.add(IOutputProvider.class);
+        classes.add(OutputProvider.class);
+        classes.add(RequestStringBuilder.class);
+        classes.add(MyIntercept.class);
+        classes.add(OutsideBean.class);
+        classes.add(OutputInterceptor.class);
+
+        Collection<String> xmls = new ArrayList<String>();
+        xmls.add(getXmlPath(PACKAGE_NAME, "DecoratorAndInterceptorStack"));
+
+        startContainer(classes, xmls);
+
+        OutsideBean outsideBean = getInstance(OutsideBean.class);
+        Assert.assertNotNull(outsideBean);
+
+        InterceptorTestRunner[] threads = new InterceptorTestRunner[NUM_THREADS];
+        for (int i= 0 ; i < NUM_THREADS; i++)
+        {
+            threads[i] = new InterceptorTestRunner(outsideBean);
+            threads[i].start();
+        }
+
+        for (int i= 0 ; i < NUM_THREADS; i++)
+        {
+            threads[i].join();
+            Assert.assertFalse(threads[i].isFailed());
+        }
+
+    }
+
+
+    public static class InterceptorTestRunner extends Thread
+    {
+        private OutsideBean outsideBean;
+        private boolean failed = false;
+
+        public InterceptorTestRunner(OutsideBean outsideBean)
+        {
+            this.outsideBean = outsideBean;
+        }
+
+        @Override
+        public void run()
+        {
+            try
+            {
+                // this starts the RequestContext for this very thread
+                WebBeansContext.currentInstance().getContextFactory().initRequestContext(null);
+
+                for (int i=0; i < 5; i++)
+                {
+                    outsideBean.doThaStuff();
+                }
+            }
+            catch (Exception e)
+            {
+                log.log(Level.SEVERE, "Error while executing Decorators in parallel!", e);
+                failed = true;
+            }
+        }
+
+        public boolean isFailed()
+        {
+            return failed;
+        }
+    }
 }

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=1361679&r1=1361678&r2=1361679&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
Sun Jul 15 10:26:34 2012
@@ -65,7 +65,7 @@ public class InterceptorPerformanceTest 
 
         long start = System.nanoTime();
 
-        //X TODO START THREADS
+        // START THREADS
         CalculationRunner[] threads = new CalculationRunner[NUM_THREADS];
         for (int i= 0 ; i < NUM_THREADS; i++)
         {



Mime
View raw message