[jboss-cvs] JBossAS SVN: r61636 - in projects/aop/trunk/aop/src: main/org/jboss/aop/advice and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Mar 23 07:46:35 EDT 2007


Author: kabir.khan at jboss.com
Date: 2007-03-23 07:46:35 -0400 (Fri, 23 Mar 2007)
New Revision: 61636

Added:
   projects/aop/trunk/aop/src/resources/test/stress/perinstancemethodinvocation/
   projects/aop/trunk/aop/src/resources/test/stress/perinstancemethodinvocation/jboss-aop.xml
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/ScenarioTestDelegate.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/perinstancemethodinvocation/
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/perinstancemethodinvocation/POJO.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/perinstancemethodinvocation/PerInstanceAspect.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/perinstancemethodinvocation/PerInstanceInterceptor.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/perinstancemethodinvocation/PerInstanceTestCase.java
Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedInstanceAdvisorMixin.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AspectDefinition.java
   projects/aop/trunk/aop/src/resources/test/stress/config.properties
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/ScenarioRunner.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/ScenarioTest.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/methodinvocation/MethodInvocationTestCase.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/simple/SimpleReflectToJavassistTestCase.java
Log:
[JBAOP-377] Make sure that per instance advisors get released from AspectDefinition. More stress tests

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedInstanceAdvisorMixin.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedInstanceAdvisorMixin.java	2007-03-23 11:29:06 UTC (rev 61635)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedInstanceAdvisorMixin.java	2007-03-23 11:46:35 UTC (rev 61636)
@@ -29,6 +29,7 @@
 import org.jboss.aop.joinpoint.Joinpoint;
 import org.jboss.aop.metadata.SimpleMetaData;
 
+import java.lang.ref.WeakReference;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
@@ -46,7 +47,7 @@
 
    protected ArrayList insertedInterceptors = null;
    protected ArrayList appendedInterceptors = null;
-   protected Object instance;
+   protected WeakReference instanceRef;
    public boolean hasInstanceAspects = false;
    private InterceptorChainObserver interceptorChainObserver;
    InstanceAdvisorDelegate delegate;
@@ -57,7 +58,7 @@
 
    public GeneratedInstanceAdvisorMixin(Object instance, GeneratedClassAdvisor genadvisor)
    {
-      this.instance = instance;
+      this.instanceRef = new WeakReference(instance);
       delegate = new InstanceAdvisorDelegate(genadvisor, this);
       delegate.initialize();
       this.interceptorChainObserver = ((ClassAdvisor) genadvisor).getInterceptorChainObserver();
@@ -291,9 +292,10 @@
       if (stack == null) throw new RuntimeException("Stack " + stackName + " not found.");
 
       ClassAdvisor classAdvisor = null;
-      if (instance instanceof Advised)
+      Object inst = getInstance();
+      if (inst instanceof Advised)
       {
-         Advised advised = (Advised) instance;
+         Advised advised = (Advised) inst;
          classAdvisor = ((ClassAdvisor) advised._getAdvisor());
       }
       int interceptorsAdded = 0;
@@ -318,9 +320,10 @@
       if (stack == null) throw new RuntimeException("Stack " + stackName + " not found.");
 
       ClassAdvisor classAdvisor = null;
-      if (instance instanceof Advised)
+      Object inst = getInstance();
+      if (inst instanceof Advised)
       {
-         Advised advised = (Advised) instance;
+         Advised advised = (Advised) inst;
          classAdvisor = ((ClassAdvisor) advised._getAdvisor());
       }
       int interceptorsAdded = 0;
@@ -345,9 +348,10 @@
       if (stack == null) throw new RuntimeException("Stack " + stackName + " not found.");
 
       ClassAdvisor classAdvisor = null;
-      if (instance instanceof Advised)
+      Object inst = getInstance();
+      if (inst instanceof Advised)
       {
-         Advised advised = (Advised) instance;
+         Advised advised = (Advised) inst;
          classAdvisor = ((ClassAdvisor) advised._getAdvisor());
       }
       int interceptorsRemoved = 0;
@@ -390,7 +394,12 @@
    
    public Object getInstance()
    {
-      return instance;
+      if (instanceRef != null)
+      {
+         Object instance = instanceRef.get();
+         return instance;
+      }
+      return null;
    }
 
    public class InstanceInterceptorFactory implements InterceptorFactory

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AspectDefinition.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AspectDefinition.java	2007-03-23 11:29:06 UTC (rev 61635)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/AspectDefinition.java	2007-03-23 11:46:35 UTC (rev 61636)
@@ -21,13 +21,13 @@
   */
 package org.jboss.aop.advice;
 
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.WeakHashMap;
 
 import org.jboss.aop.Advisor;
 
-import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
-
 /**
  * Contains definition of aspect or interceptor
  * Scope defaults to PER_VM if it is null.
@@ -45,7 +45,7 @@
    /**
     * @deprecated should not call this directly
     */
-   public Map advisors = new ConcurrentReaderHashMap();
+   public Map advisors = new WeakHashMap();
 
    /**
     * @param name
@@ -71,20 +71,23 @@
          for (Iterator it = advisors.keySet().iterator() ; it.hasNext() ; )
          {
             Advisor advisor = (Advisor)it.next();
-            if (advisors.remove(advisor) !=  null)
+            if (advisor != null)
             {
-               if (scope == Scope.PER_INSTANCE)
+               if (advisors.remove(advisor) !=  null)
                {
-                  advisor.removePerInstanceAspect(this);
+                  if (scope == Scope.PER_INSTANCE)
+                  {
+                     advisor.removePerInstanceAspect(this);
+                  }
+                  else if (scope == Scope.PER_JOINPOINT)
+                  {
+                     advisor.removePerInstanceJoinpointAspect(this);
+                  }
+                  else if (scope == Scope.PER_CLASS)
+                  {
+                     advisor.removePerClassAspect(this);
+                  }
                }
-               else if (scope == Scope.PER_JOINPOINT)
-               {
-                  advisor.removePerInstanceJoinpointAspect(this);
-               }
-               else if (scope == Scope.PER_CLASS)
-               {
-                  advisor.removePerClassAspect(this);
-               }
             }
          }
          advisors.clear();

Modified: projects/aop/trunk/aop/src/resources/test/stress/config.properties
===================================================================
--- projects/aop/trunk/aop/src/resources/test/stress/config.properties	2007-03-23 11:29:06 UTC (rev 61635)
+++ projects/aop/trunk/aop/src/resources/test/stress/config.properties	2007-03-23 11:46:35 UTC (rev 61636)
@@ -1,5 +1,6 @@
-loops=50000000
-threads=1
+warmup=0
+loops=1
+threads=3
 random_sleep_interval=false
 sleeptime_millis=0
 logging=false

Added: projects/aop/trunk/aop/src/resources/test/stress/perinstancemethodinvocation/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/stress/perinstancemethodinvocation/jboss-aop.xml	                        (rev 0)
+++ projects/aop/trunk/aop/src/resources/test/stress/perinstancemethodinvocation/jboss-aop.xml	2007-03-23 11:46:35 UTC (rev 61636)
@@ -0,0 +1,12 @@
+<aop>
+   <interceptor name="Int1" class="org.jboss.test.aop.stress.perinstancemethodinvocation.PerInstanceInterceptor" scope="PER_INSTANCE"/>
+   <aspect name="Aspect1" class="org.jboss.test.aop.stress.perinstancemethodinvocation.PerInstanceAspect" scope="PER_INSTANCE"/>
+   
+   <bind pointcut="execution(* org.jboss.test.aop.stress.perinstancemethodinvocation.POJO->method1())">
+      <interceptor-ref name="Int1"/>
+   </bind>
+   
+   <bind pointcut="execution(* org.jboss.test.aop.stress.perinstancemethodinvocation.POJO->method2())">
+      <advice aspect="Aspect1" name="invoke"/>
+   </bind>
+</aop>
\ No newline at end of file

Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/ScenarioRunner.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/ScenarioRunner.java	2007-03-23 11:29:06 UTC (rev 61635)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/ScenarioRunner.java	2007-03-23 11:46:35 UTC (rev 61636)
@@ -37,46 +37,39 @@
  */
 public class ScenarioRunner
 {
+   private static final String WARMUP = "warmup";
    private static final String LOOPS = "loops";
    private static final String THREADS = "threads";
    private static final String RANDOM_SLEEP_INTERVAL = "random_sleep_interval";
    private static final String SLEEPTIME_MILLIS = "sleeptime_millis";
    private static final String LOGGING = "logging";
-   
+
+   private Properties properties = new Properties();
+
+   private int warmup;
    private int loops;
    private int threads;
    private boolean randomSleepInterval;
    private int sleeptimeMillis;
    Random random = new Random(10);
    boolean logging;
-
    
    public ScenarioRunner()
    {
       try
       {
-         URL url = this.getClass().getProtectionDomain().getCodeSource().getLocation();
-         System.out.println("class url: " + url);
-         String location = url.toString();
-         int index = location.indexOf("/output/");
-         location = location.substring(0, index);
+         initialiseProperties();
          
-         location = location + "/src/resources/test/stress/config.properties";
-         url = new URL(location);
-         InputStream in = new FileInputStream(url.getFile());
-         Properties properties = new Properties();
-         properties.load(in);
+         warmup = getIntProperty(WARMUP, "100000");
+         loops = getIntProperty(LOOPS, "10");
+         threads = getIntProperty(THREADS, "10");
+         randomSleepInterval = getBooleanProperty(RANDOM_SLEEP_INTERVAL, "false");
+         sleeptimeMillis = getIntProperty(SLEEPTIME_MILLIS, "100");
+         logging = getBooleanProperty(LOGGING, "false");
          
-         loops = Integer.parseInt(properties.getProperty(LOOPS, "10"));
-         threads = Integer.parseInt(properties.getProperty(THREADS, "10"));
-         String bool = properties.getProperty(RANDOM_SLEEP_INTERVAL, "false");
-         randomSleepInterval = bool.equals("true");
-         sleeptimeMillis = Integer.parseInt(properties.getProperty(SLEEPTIME_MILLIS, "100"));
-         bool = properties.getProperty(LOGGING, "false");
-         logging = bool.equals("true");
-         
          System.out.println("============================================");
          System.out.println("Configured ScenarioRunner");
+         System.out.println("   warmup:                  " + warmup);
          System.out.println("   loops:                   " + loops);
          System.out.println("   threads:                 " + threads);
          System.out.println("   Random sleep Interval:   " + randomSleepInterval);
@@ -90,12 +83,63 @@
       }
    }
 
+   private void initialiseProperties() throws Exception
+   {
+      URL url = this.getClass().getProtectionDomain().getCodeSource().getLocation();
+      System.out.println("class url: " + url);
+      String location = url.toString();
+      int index = location.indexOf("/output/");
+      location = location.substring(0, index);
+      
+      location = location + "/src/resources/test/stress/config.properties";
+      url = new URL(location);
+      InputStream in = new FileInputStream(url.getFile());
+      properties = new Properties();
+      properties.load(in);
+      
+   }
+   
+   private int getIntProperty(String key, String defaultValue)
+   {
+      return Integer.parseInt(getProperty(key, defaultValue));  
+   }
+   
+   private boolean getBooleanProperty(String key, String defaultValue)
+   {
+      return "true".equals(getProperty(key, defaultValue));
+   }
+   
+   private String getProperty(String key, String defaultValue)
+   {
+      String val = System.getProperty(key);
+      if (val != null)
+      {
+         return val;
+      }
+      
+      val = properties.getProperty(key);
+      if (val != null)
+      {
+         return val;
+      }
+      
+      return defaultValue;
+   }
+   
    public void executeScenario(Scenario scenario) throws Exception
    {
       Scenario[] scenarios = new Scenario[] {scenario};
+      warmupScenario(scenarios);
       executeScenarios(scenarios);
    }
 
+   private void warmupScenario(Scenario[] scenarios) throws Exception
+   {
+      ScenarioLoader loader = getLoader(0, scenarios);
+      loader.start();
+      loader.join();
+   }
+   
    public void executeScenarios(Scenario[] scenarios) throws Exception
    {
       System.out.println("Starting run with Scenarios " + Arrays.asList(scenarios));
@@ -134,6 +178,11 @@
       
       System.out.println("--- DONE --- test took " + (end - start) + " ms");
       
+      for (int thread = 0 ; thread < loaders.length ; thread++)
+      {
+         loaders[thread] = null;
+      }
+      
       if (hadExceptions)
       {
          throw new Exception("Exceptions occurred, see System.err");

Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/ScenarioTest.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/ScenarioTest.java	2007-03-23 11:29:06 UTC (rev 61635)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/ScenarioTest.java	2007-03-23 11:46:35 UTC (rev 61636)
@@ -21,21 +21,32 @@
 */ 
 package org.jboss.test.aop.stress;
 
-import org.jboss.test.aop.AOPTestWithSetup;
+import org.jboss.test.AbstractTestCaseWithSetup;
+import org.jboss.test.AbstractTestDelegate;
 
 /**
  * 
  * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  * @version $Revision$
  */
-public class ScenarioTest extends AOPTestWithSetup
+public class ScenarioTest extends AbstractTestCaseWithSetup
 {
-   protected ScenarioRunner runner;
    
    public ScenarioTest(String arg0)
    {
-      // FIXME ScenarioTest constructor
       super(arg0);
-      runner = new ScenarioRunner();
+//      runner = new ScenarioRunner();
    }
+
+   public static AbstractTestDelegate getDelegate(Class clazz) throws Exception
+   {
+      ScenarioTestDelegate delegate = new ScenarioTestDelegate(clazz);
+      return delegate;
+   }
+
+   
+   protected ScenarioRunner getRunner()
+   {
+      return ((ScenarioTestDelegate)getDelegate()).getRunner();
+   }
 }

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/ScenarioTestDelegate.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/ScenarioTestDelegate.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/ScenarioTestDelegate.java	2007-03-23 11:46:35 UTC (rev 61636)
@@ -0,0 +1,43 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.aop.stress;
+
+import org.jboss.test.AbstractTestDelegate;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ScenarioTestDelegate extends AbstractTestDelegate
+{
+   ScenarioRunner runner = new ScenarioRunner(); 
+   public ScenarioTestDelegate(Class clazz)
+   {
+      super(clazz);
+   }
+
+   public ScenarioRunner getRunner()
+   {
+      return runner;
+   }
+}

Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/methodinvocation/MethodInvocationTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/methodinvocation/MethodInvocationTestCase.java	2007-03-23 11:29:06 UTC (rev 61635)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/methodinvocation/MethodInvocationTestCase.java	2007-03-23 11:46:35 UTC (rev 61636)
@@ -46,8 +46,7 @@
    
    public void testStaticWovenNoAdvice() throws Exception
    {
-      POJO.staticMethodNoAdvice();//in case of generated advisors generate the joinpoint class
-      super.runner.executeScenario(new StaticWovenNoAdviceScenario());
+      getRunner().executeScenario(new StaticWovenNoAdviceScenario());
    }
    
    private class StaticWovenNoAdviceScenario implements Scenario
@@ -61,9 +60,7 @@
    
    public void testNonStaticWovenNoAdvice() throws Exception
    {
-      POJO pojo = new POJO();
-      pojo.nonStaticMethodNoAdvice();//in case of generated advisors generate the joinpoint class
-      super.runner.executeScenario(new NonStaticWovenNoAdviceScenario());
+      getRunner().executeScenario(new NonStaticWovenNoAdviceScenario());
    }
 
    private class NonStaticWovenNoAdviceScenario implements Scenario
@@ -79,9 +76,9 @@
    {
       POJO pojo = new POJO();
       PlainInterceptor.called = 0;
-      pojo.oneInterceptor();//in case of generated advisors generate the joinpoint class
+      pojo.oneInterceptor();
       assertEquals(1, PlainInterceptor.called);
-      super.runner.executeScenario(new NonStaticWithOneInterceptorScenario());
+      getRunner().executeScenario(new NonStaticWithOneInterceptorScenario());
    }
    
    private class NonStaticWithOneInterceptorScenario implements Scenario
@@ -97,9 +94,9 @@
    {
       POJO pojo = new POJO();
       PlainInterceptor.called = 0;
-      pojo.fiveInterceptors();//in case of generated advisors generate the joinpoint class
+      pojo.fiveInterceptors();
       assertEquals(5, PlainInterceptor.called);
-      super.runner.executeScenario(new NonStaticWithFiveInterceptorsScenario());
+      getRunner().executeScenario(new NonStaticWithFiveInterceptorsScenario());
    }
    
    private class NonStaticWithFiveInterceptorsScenario implements Scenario
@@ -115,9 +112,9 @@
    {
       POJO pojo = new POJO();
       PlainAspect.called = 0;
-      pojo.oneAdvice();//in case of generated advisors generate the joinpoint class
+      pojo.oneAdvice();
       assertEquals(1, PlainAspect.called);
-      super.runner.executeScenario(new NonStaticWithOneAdviceScenario());
+      getRunner().executeScenario(new NonStaticWithOneAdviceScenario());
    }
    
    private class NonStaticWithOneAdviceScenario implements Scenario
@@ -133,9 +130,9 @@
    {
       POJO pojo = new POJO();
       PlainAspect.called = 0;
-      pojo.fiveAdvices();//in case of generated advisors generate the joinpoint class
+      pojo.fiveAdvices();
       assertEquals(5, PlainAspect.called);
-      super.runner.executeScenario(new NonStaticWithFiveAdvicesScenario());
+      getRunner().executeScenario(new NonStaticWithFiveAdvicesScenario());
    }
    
    private class NonStaticWithFiveAdvicesScenario implements Scenario

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/perinstancemethodinvocation/POJO.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/perinstancemethodinvocation/POJO.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/perinstancemethodinvocation/POJO.java	2007-03-23 11:46:35 UTC (rev 61636)
@@ -0,0 +1,33 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.aop.stress.perinstancemethodinvocation;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class POJO
+{
+   public void method1() {}
+   public void method2() {}
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/perinstancemethodinvocation/PerInstanceAspect.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/perinstancemethodinvocation/PerInstanceAspect.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/perinstancemethodinvocation/PerInstanceAspect.java	2007-03-23 11:46:35 UTC (rev 61636)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.aop.stress.perinstancemethodinvocation;
+
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class PerInstanceAspect
+{
+   public static int called;
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      called++;
+      return invocation.invokeNext();
+   }
+
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/perinstancemethodinvocation/PerInstanceInterceptor.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/perinstancemethodinvocation/PerInstanceInterceptor.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/perinstancemethodinvocation/PerInstanceInterceptor.java	2007-03-23 11:46:35 UTC (rev 61636)
@@ -0,0 +1,46 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.aop.stress.perinstancemethodinvocation;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class PerInstanceInterceptor implements Interceptor
+{
+   public static int called;
+
+   public String getName()
+   {
+      return PerInstanceInterceptor.class.getName();
+   }
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      called++;
+      return invocation.invokeNext();
+   }
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/perinstancemethodinvocation/PerInstanceTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/perinstancemethodinvocation/PerInstanceTestCase.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/perinstancemethodinvocation/PerInstanceTestCase.java	2007-03-23 11:46:35 UTC (rev 61636)
@@ -0,0 +1,117 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.test.aop.stress.perinstancemethodinvocation;
+
+import org.jboss.test.aop.stress.Scenario;
+import org.jboss.test.aop.stress.ScenarioTest;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class PerInstanceTestCase extends ScenarioTest
+{
+   public static void main(String[] args)
+   {
+      junit.textui.TestRunner.run(PerInstanceTestCase.class);
+   }
+
+   public PerInstanceTestCase(String name)
+   {
+      // FIXME PerInstanceTestCase constructor
+      super(name);
+   }
+
+   public void testPerInstanceInterceptor() throws Exception
+   {
+      POJO pojo = new POJO();
+      PerInstanceInterceptor.called = 0;
+      pojo.method1();
+      assertEquals(1, PerInstanceInterceptor.called);
+      getRunner().executeScenario(new PerInstanceInterceptorScenario());
+   }
+   
+   private class PerInstanceInterceptorScenario implements Scenario
+   {
+      POJO pojo = new POJO();
+      public void execute(int thread, int loop) throws Exception
+      {
+         pojo.method1();
+      }
+   }
+
+   public void testPerInstanceAspect() throws Exception
+   {
+      POJO pojo = new POJO();
+      PerInstanceAspect.called = 0;
+      pojo.method2();
+      assertEquals(1, PerInstanceAspect.called);
+      getRunner().executeScenario(new PerInstanceAspectScenario());
+   }
+   
+   private class PerInstanceAspectScenario implements Scenario
+   {
+      POJO pojo = new POJO();
+      public void execute(int thread, int loop) throws Exception
+      {
+         pojo.method2();
+      }
+   }
+
+   public void testPerInstanceInterceptorRepeatInstantiation() throws Exception
+   {
+      POJO pojo = new POJO();
+      PerInstanceInterceptor.called = 0;
+      pojo.method1();
+      pojo.method1();
+      assertEquals(2, PerInstanceInterceptor.called);
+      getRunner().executeScenario(new PerInstanceInterceptorRepeatInstantiationScenario());
+   }
+   
+   private class PerInstanceInterceptorRepeatInstantiationScenario implements Scenario
+   {
+      public void execute(int thread, int loop) throws Exception
+      {
+         POJO pojo = new POJO();
+         pojo.method1();
+      }
+   }
+
+   public void testPerInstanceAspectRepeatInstantiation() throws Exception
+   {
+      POJO pojo = new POJO();
+      PerInstanceAspect.called = 0;
+      pojo.method2();
+      assertEquals(1, PerInstanceAspect.called);
+      getRunner().executeScenario(new PerInstanceAspectRepeatInstantiationScenario());
+   }
+   
+   private class PerInstanceAspectRepeatInstantiationScenario implements Scenario
+   {
+      public void execute(int thread, int loop) throws Exception
+      {
+         POJO pojo = new POJO();
+         pojo.method2();
+      }
+   }
+}

Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/simple/SimpleReflectToJavassistTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/simple/SimpleReflectToJavassistTestCase.java	2007-03-23 11:29:06 UTC (rev 61635)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/stress/simple/SimpleReflectToJavassistTestCase.java	2007-03-23 11:46:35 UTC (rev 61636)
@@ -52,7 +52,7 @@
       boolean exception = false;
       try
       {
-         super.runner.executeScenario(new ExceptionScenario());
+         getRunner().executeScenario(new ExceptionScenario());
       }
       catch (Exception e)
       {
@@ -69,7 +69,7 @@
         new SimpleFieldToJavassistScenario(),
         new SimpleMethodToJavassistScenario()};
       
-      super.runner.executeScenarios(scenarios);
+      getRunner().executeScenarios(scenarios);
    }
 
    private class ExceptionScenario implements Scenario




More information about the jboss-cvs-commits mailing list