[jboss-cvs] JBossAS SVN: r64921 - in projects/aop/trunk/aop/src: resources/test/rebuildingchain and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 28 14:14:15 EDT 2007


Author: stalep
Date: 2007-08-28 14:14:15 -0400 (Tue, 28 Aug 2007)
New Revision: 64921

Added:
   projects/aop/trunk/aop/src/resources/test/rebuildingchain/
   projects/aop/trunk/aop/src/resources/test/rebuildingchain/jboss-aop.xml
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildingchain/
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildingchain/RebuildThread.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildingchain/RebuildingChainTestCase.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildingchain/SyncInterceptor.java
   projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildingchain/SyncThread.java
Log:
[JBAOP-380] added a test that reproduces the problem (not yet included in base-tests.xml)

Added: projects/aop/trunk/aop/src/resources/test/rebuildingchain/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/rebuildingchain/jboss-aop.xml	                        (rev 0)
+++ projects/aop/trunk/aop/src/resources/test/rebuildingchain/jboss-aop.xml	2007-08-28 18:14:15 UTC (rev 64921)
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<aop>
+  <prepare expr="execution(* org.jboss.test.aop.rebuildingchain.SyncThread->checkStatus())" />
+</aop>

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildingchain/RebuildThread.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildingchain/RebuildThread.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildingchain/RebuildThread.java	2007-08-28 18:14:15 UTC (rev 64921)
@@ -0,0 +1,130 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.rebuildingchain;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.advice.AdviceBinding;
+import org.jboss.aop.advice.AdviceFactory;
+import org.jboss.aop.advice.AspectDefinition;
+import org.jboss.aop.advice.AspectFactory;
+import org.jboss.aop.advice.GenericAspectFactory;
+import org.jboss.aop.advice.Scope;
+import org.jboss.aop.pointcut.ast.ParseException;
+
+/**
+ * A RebuildThread.
+ * 
+ * @author <a href="stalep at gmail.com">Stale W. Pedersen</a>
+ * @version $Revision: 1.1 $
+ */
+public class RebuildThread implements Runnable
+{
+   private static Boolean done = false;
+
+   private static int id = 0;
+   
+   @Override
+   public void run()
+   {
+
+      while(!isDone());
+      {
+//       System.out.println("Inside rebuildthread");
+         if(id > 0)
+         {
+            unlinkAdvice();
+            linkNewAdvice();
+         }
+//       linkNewAdvice();
+
+//       try
+//       {
+//       Thread.sleep(2);
+//       }
+//       catch(InterruptedException ie)
+//       {
+//       System.err.println("Exception during sleep "+ie.getMessage());
+//       }
+      }
+      System.out.println("RebuildingThread jumping out of run()");
+   }
+   
+   public synchronized  void setDone(boolean b)
+   {
+      done = b;
+   }
+   
+   public synchronized Boolean isDone()
+   {
+      return done;
+   }
+   
+   public static void linkNewAdvice()
+   {
+      System.out.println("adding new advice");
+      AdviceBinding binding1 = null;
+      try
+      {
+         binding1 = new AdviceBinding("execution(* org.jboss.test.aop.rebuildingchain.SyncThread->checkStatus())", null);
+      }
+      catch (ParseException e)
+      {
+         // TODO Auto-generated catch block
+         e.printStackTrace();
+      }
+      binding1.addInterceptor(SyncInterceptor.class);
+      binding1.setName(Integer.toString(id));
+      AspectManager.instance().addBinding(binding1);
+      id++;
+   }
+   
+   public static void unlinkAdvice()
+   {
+//      System.out.println("unlinking "+id); 
+      AspectManager.instance().removeBinding(Integer.toString((id-1)));
+   }
+   
+   
+//   public static void link(String aspect_id, String methodname, String binding, String binding_id)
+//   {
+//      System.out.println("link aspect_id=" + aspect_id + " method=" + methodname + " binding=" + binding
+//            + " binding_id=" + binding_id);
+//      AdviceBinding adviceBinding = null;
+//      try
+//      {
+//         adviceBinding = new AdviceBinding(binding, null);
+//      }
+//      catch (ParseException e)
+//      {
+//         // TODO Auto-generated catch block 
+//         e.printStackTrace();
+//      }
+//
+//      AspectDefinition ad = AspectManager.instance().getAspectDefinition(aspect_id);
+//      adviceBinding.addInterceptorFactory(new AdviceFactory(ad, methodname));
+//      adviceBinding.setName(binding_id);
+//      AspectManager.instance().addBinding(adviceBinding);
+//   }
+ 
+   
+
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildingchain/RebuildingChainTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildingchain/RebuildingChainTestCase.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildingchain/RebuildingChainTestCase.java	2007-08-28 18:14:15 UTC (rev 64921)
@@ -0,0 +1,107 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.rebuildingchain;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.test.aop.AOPTestWithSetup;
+import org.jboss.test.aop.override.OverrideTestCase;
+
+/**
+ * A TestRebuildingChain.
+ * 
+ * @author <a href="stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ * @version $Revision: 1.1 $
+ */
+public class RebuildingChainTestCase extends AOPTestWithSetup
+{
+
+   private static boolean failed = false;
+   
+   public RebuildingChainTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("RebuildingChainTestCase");
+      suite.addTestSuite(RebuildingChainTestCase.class);
+      return suite;
+   }
+   
+   public void testRebuildingChain() throws Exception
+   {
+      System.out.println("testing rebuildingchain!");
+      AspectManager.instance().verbose = true;
+      RebuildThread.linkNewAdvice();
+//      RebuildThread.unlinkAdvice();
+//      RebuildThread.linkNewAdvice();
+      
+      Thread t1 = new Thread(new SyncThread());
+      RebuildThread rt = new RebuildThread();
+      Thread t2 = new Thread(rt);
+      t1.start();
+      t2.start();
+      try
+      {
+         long start = System.currentTimeMillis();
+         Thread.sleep(20);
+         System.out.println("Slept for: "+(System.currentTimeMillis()-start));
+      }
+      catch(InterruptedException ie)
+      {
+         System.err.println("BAH "+ie.getMessage());
+      }
+      
+      SyncThread.setDone(false);
+      rt.setDone(true);
+      
+      t2.join();
+      if(t2.isAlive())
+         System.out.println("rebuildingthread is still alive!!");
+      
+      t1.start();
+      
+      try
+      {
+         long start = System.currentTimeMillis();
+         Thread.sleep(20);
+         System.out.println("Slept for: "+(System.currentTimeMillis()-start));
+      }
+      catch(InterruptedException ie)
+      {
+         System.err.println("BAH "+ie.getMessage());
+      }
+      
+      SyncThread.setDone(false);
+      
+      assertFalse("All well....", failed);
+   }
+   
+   public static void setTestFailed()
+   {
+      failed = true;
+   }
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildingchain/SyncInterceptor.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildingchain/SyncInterceptor.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildingchain/SyncInterceptor.java	2007-08-28 18:14:15 UTC (rev 64921)
@@ -0,0 +1,62 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.rebuildingchain;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ * A SyncInterceptor.
+ * 
+ * @author <a href="stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ * @version $Revision: 1.1 $
+ */
+public class SyncInterceptor implements Interceptor
+{
+   
+   @Override
+   public String getName()
+   {
+      return this.getClass().getName();
+   }
+
+   @Override
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      try
+      {
+         SyncThread.setStatus(true);
+         return invocation.invokeNext();
+      }
+      catch(Exception e)
+      {
+         throw e;
+      }
+      finally
+      {
+         SyncThread.setStatus(false);
+      }
+   }
+   
+   
+
+}

Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildingchain/SyncThread.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildingchain/SyncThread.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/rebuildingchain/SyncThread.java	2007-08-28 18:14:15 UTC (rev 64921)
@@ -0,0 +1,75 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.rebuildingchain;
+
+/**
+ * A SynchThread.
+ * 
+ * @author <a href="stale.pedersen at jboss.org">Stale W. Pedersen</a>
+ * @version $Revision: 1.1 $
+ */
+public class SyncThread implements Runnable
+{
+   private static boolean status = false;
+   private static boolean done = false;
+
+   @Override
+   public void run()
+   {
+      while(!done)
+      {
+         checkStatus();
+//        try
+//        {
+//           Thread.sleep(2);
+//        }
+//        catch(InterruptedException ie)
+//        {
+//           System.err.println("Exception during sleep "+ie.getMessage());
+//        }
+      }
+   }
+   
+   private void checkStatus()
+   {
+      if(getStatus() == false)
+      {
+         RebuildingChainTestCase.setTestFailed();
+         throw new RuntimeException("Status wasnt true!!!!");
+      }
+   }
+
+   public static boolean getStatus()
+   {
+      return status;
+   }
+   
+   public static void setStatus(boolean b)
+   {
+      status = b;
+   }
+   
+   public synchronized static void setDone(boolean b)
+   {
+      done = b;
+   }
+}




More information about the jboss-cvs-commits mailing list