]> source.dussan.org Git - aspectj.git/commitdiff
Expand "asynchronous proceed for nested around-advice" to 4 scenarios:
authorAlexander Kriegisch <Alexander@Kriegisch.name>
Mon, 28 Feb 2022 11:44:07 +0000 (18:44 +0700)
committerAlexander Kriegisch <Alexander@Kriegisch.name>
Wed, 23 Mar 2022 08:39:14 +0000 (15:39 +0700)
1. @AspectJ syntax, threads created inside advice code
2. @AspectJ syntax, submit runnable to thread pool
3. native syntax, threads created inside advice code
4. native syntax, submit runnable to thread pool

Scenarios 1, 3 and 4 are passing, while 2 is failing.

Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
tests/bugs198/github_128/Application.java
tests/bugs198/github_128/MarkerAAspect.aj
tests/bugs198/github_128/MarkerANativeAspect.aj [new file with mode: 0644]
tests/bugs198/github_128/MarkerBAspect.aj
tests/bugs198/github_128/MarkerBNativeAspect.aj [new file with mode: 0644]
tests/src/test/java/org/aspectj/systemtest/ajc198/Bugs198Tests.java
tests/src/test/resources/org/aspectj/systemtest/ajc198/ajc198.xml

index d42b0fee472020ac652a05737594c399015e4aba..9a4a7312fc18e24a5c91be27251475ab18abcaac 100644 (file)
@@ -1,14 +1,42 @@
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
 public class Application {
+  static int proceedTimesOuter;
+  static int proceedTimesInner;
+  static boolean useThreadPool = false;
+  static ExecutorService executorService = Executors.newFixedThreadPool(2);
+
   @MarkerA
   @MarkerB
   public void doSomething() {
     System.out.println("        Doing something");
   }
 
-  public static void main(String[] args) throws InterruptedException {
-    MarkerAAspect.proceedTimes = Integer.parseInt(args[0]);
-    MarkerBAspect.proceedTimes = Integer.parseInt(args[1]);
+  public static void main(String[] args) throws ExecutionException, InterruptedException {
+    proceedTimesOuter = Integer.parseInt(args[0]);
+    proceedTimesInner = Integer.parseInt(args[1]);
+    useThreadPool = args.length > 2 && args[2].trim().equalsIgnoreCase("true");
+    if (useThreadPool)
+      prepopulateFixedThreadPool();
+
     new Application().doSomething();
     Thread.sleep(500);
   }
+
+  private static void prepopulateFixedThreadPool() throws InterruptedException, ExecutionException {
+    Future<?> future1 = executorService.submit(() -> {
+      try { Thread.sleep(250); }
+      catch (InterruptedException e) { e.printStackTrace(); }
+    });
+    Future<?> future2 = executorService.submit(() -> {
+      try { Thread.sleep(250); }
+      catch (InterruptedException e) { e.printStackTrace(); }
+    });
+    future1.get();
+    future2.get();
+  }
+
 }
index b2eb6321143e28673fe760d0de8e9c51c6e4cbaf..d090ed9ea9255a805249675bf96d8bdffac28b50 100644 (file)
@@ -6,13 +6,11 @@ import org.aspectj.lang.annotation.DeclarePrecedence;
 @Aspect
 @DeclarePrecedence("MarkerAAspect, MarkerBAspect")
 public class MarkerAAspect {
-  public static int proceedTimes = 1;
-
   @Around("@annotation(MarkerA) && execution(* *(..))")
   public Object intercept(ProceedingJoinPoint thisJoinPoint) throws Throwable {
     System.out.println(">> Outer intercept");
     Object result = null;
-    for (int i = 0; i < proceedTimes; i++) {
+    for (int i = 0; i < Application.proceedTimesOuter; i++) {
       System.out.println("  >> Outer proceed");
       result = thisJoinPoint.proceed();
       System.out.println("  << Outer proceed");
diff --git a/tests/bugs198/github_128/MarkerANativeAspect.aj b/tests/bugs198/github_128/MarkerANativeAspect.aj
new file mode 100644 (file)
index 0000000..37d9f2f
--- /dev/null
@@ -0,0 +1,16 @@
+public aspect MarkerANativeAspect {
+  declare precedence : MarkerANativeAspect, MarkerBNativeAspect;
+  public static int proceedTimes = 1;
+
+  Object around() : @annotation(MarkerA) && execution(* *(..)) {
+    System.out.println(">> Outer intercept");
+    Object result = null;
+    for (int i = 0; i < Application.proceedTimesOuter; i++) {
+      System.out.println("  >> Outer proceed");
+      result = proceed();
+      System.out.println("  << Outer proceed");
+    }
+    System.out.println("<< Outer intercept");
+    return result;
+  }
+}
index 1381d5f77df511fb7d572920f5235df953b2569f..d5548f9da5349c2341ed8f24b7a4580d54b649a4 100644 (file)
@@ -2,18 +2,19 @@ import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.annotation.Around;
 import org.aspectj.lang.annotation.Aspect;
 
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
 @Aspect
 public class MarkerBAspect {
-  public static int proceedTimes = 1;
-
   @Around("@annotation(MarkerB) && execution(* *(..))")
   public Object intercept(ProceedingJoinPoint thisJoinPoint) throws Throwable {
-    System.out.println("    >> Inner intercept");
-    new Thread(new Runnable() {
+    Runnable runnable = new Runnable() {
       @Override
       public void run() {
         try {
-          for (int i = 0; i < proceedTimes; i++) {
+          for (int i = 0; i < Application.proceedTimesInner; i++) {
             System.out.println("      >> Inner proceed");
             thisJoinPoint.proceed();
             System.out.println("      << Inner proceed");
@@ -23,7 +24,13 @@ public class MarkerBAspect {
           throwable.printStackTrace(System.out);
         }
       }
-    }).start();
+    };
+
+    System.out.println("    >> Inner intercept");
+    if (Application.useThreadPool)
+      Application.executorService.submit(runnable);
+    else
+      new Thread(runnable).start();
     System.out.println("    << Inner intercept");
     return null;
   }
diff --git a/tests/bugs198/github_128/MarkerBNativeAspect.aj b/tests/bugs198/github_128/MarkerBNativeAspect.aj
new file mode 100644 (file)
index 0000000..6bd4b86
--- /dev/null
@@ -0,0 +1,31 @@
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public aspect MarkerBNativeAspect {
+  Object around() : @annotation(MarkerB) && execution(* *(..)) {
+    Runnable runnable = new Runnable() {
+      @Override
+      public void run() {
+        try {
+          for (int i = 0; i < Application.proceedTimesInner; i++) {
+            System.out.println("      >> Inner proceed");
+            proceed();
+            System.out.println("      << Inner proceed");
+          }
+        }
+        catch (Throwable throwable) {
+          throwable.printStackTrace(System.out);
+        }
+      }
+    };
+
+    System.out.println("    >> Inner intercept");
+    if (Application.useThreadPool)
+      Application.executorService.submit(runnable);
+    else
+      new Thread(runnable).start();
+    System.out.println("    << Inner intercept");
+    return null;
+  }
+}
index ac151b127c011e43e220cae5ed48d3ed90d1f5c8..9421f4aeeadcdd7907dcb6db7f560714f6296f85 100644 (file)
@@ -49,7 +49,19 @@ public class Bugs198Tests extends XMLBasedAjcTestCase {
   }
 
   public void testAsyncProceedNestedAroundAdvice_gh128() {
-    runTest("asynchronous proceed for nested around-advice chain");
+    runTest("asynchronous proceed for nested around-advice (@AspectJ)");
+  }
+
+  public void testAsyncProceedNestedAroundAdviceThreadPool_gh128() {
+    runTest("asynchronous proceed for nested around-advice (@AspectJ, thread pool)");
+  }
+
+  public void testAsyncProceedNestedAroundAdviceNative_gh128() {
+    runTest("asynchronous proceed for nested around-advice (native)");
+  }
+
+  public void testAsyncProceedNestedAroundAdviceNativeThreadPool_gh128() {
+    runTest("asynchronous proceed for nested around-advice (native, thread pool)");
   }
 
   public static Test suite() {
index aadf36f9212767a8354d5b3acc2b398cdf128310..0e113278204529b7070d35ee81474e70433d8761 100644 (file)
                </run>
        </ajc-test>
 
-       <ajc-test dir="bugs198/github_128" title="asynchronous proceed for nested around-advice chain">
+       <ajc-test dir="bugs198/github_128" title="asynchronous proceed for nested around-advice (@AspectJ)">
                <compile files="Application.java MarkerA.java MarkerAAspect.aj MarkerB.java MarkerBAspect.aj" options="-1.8" />
                <run class="Application" options="1,1">
                        <stdout ordered="no">
                </run>
        </ajc-test>
 
+       <ajc-test dir="bugs198/github_128" title="asynchronous proceed for nested around-advice (@AspectJ, thread pool)">
+               <compile files="Application.java MarkerA.java MarkerAAspect.aj MarkerB.java MarkerBAspect.aj" options="-1.8" />
+               <run class="Application" options="1,1,true">
+                       <stdout ordered="no">
+                               <line text=">> Outer intercept"/>
+                               <line text="  >> Outer proceed"/>
+                               <line text="    >> Inner intercept"/>
+                               <line text="    &lt;&lt; Inner intercept"/>
+                               <line text="  &lt;&lt; Outer proceed"/>
+                               <line text="&lt;&lt; Outer intercept"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                       </stdout>
+               </run>
+               <run class="Application" options="2,1,true">
+                       <stdout ordered="no">
+                               <line text=">> Outer intercept"/>
+                               <line text="  >> Outer proceed"/>
+                               <line text="    >> Inner intercept"/>
+                               <line text="    &lt;&lt; Inner intercept"/>
+                               <line text="  &lt;&lt; Outer proceed"/>
+                               <line text="  >> Outer proceed"/>
+                               <line text="    >> Inner intercept"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="    &lt;&lt; Inner intercept"/>
+                               <line text="  &lt;&lt; Outer proceed"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="&lt;&lt; Outer intercept"/>
+                       </stdout>
+               </run>
+               <run class="Application" options="1,2,true">
+                       <stdout ordered="no">
+                               <line text=">> Outer intercept"/>
+                               <line text="  >> Outer proceed"/>
+                               <line text="    >> Inner intercept"/>
+                               <line text="    &lt;&lt; Inner intercept"/>
+                               <line text="  &lt;&lt; Outer proceed"/>
+                               <line text="&lt;&lt; Outer intercept"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                       </stdout>
+               </run>
+               <run class="Application" options="2,2,true">
+                       <stdout ordered="no">
+                               <line text=">> Outer intercept"/>
+                               <line text="  >> Outer proceed"/>
+                               <line text="    >> Inner intercept"/>
+                               <line text="    &lt;&lt; Inner intercept"/>
+                               <line text="  &lt;&lt; Outer proceed"/>
+                               <line text="  >> Outer proceed"/>
+                               <line text="    >> Inner intercept"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="    &lt;&lt; Inner intercept"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="  &lt;&lt; Outer proceed"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="&lt;&lt; Outer intercept"/>
+                       </stdout>
+               </run>
+       </ajc-test>
+
+       <ajc-test dir="bugs198/github_128" title="asynchronous proceed for nested around-advice (native)">
+               <compile files="Application.java MarkerA.java MarkerANativeAspect.aj MarkerB.java MarkerBNativeAspect.aj" options="-1.8" />
+               <run class="Application" options="1,1">
+                       <stdout ordered="no">
+                               <line text=">> Outer intercept"/>
+                               <line text="  >> Outer proceed"/>
+                               <line text="    >> Inner intercept"/>
+                               <line text="    &lt;&lt; Inner intercept"/>
+                               <line text="  &lt;&lt; Outer proceed"/>
+                               <line text="&lt;&lt; Outer intercept"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                       </stdout>
+               </run>
+               <run class="Application" options="2,1">
+                       <stdout ordered="no">
+                               <line text=">> Outer intercept"/>
+                               <line text="  >> Outer proceed"/>
+                               <line text="    >> Inner intercept"/>
+                               <line text="    &lt;&lt; Inner intercept"/>
+                               <line text="  &lt;&lt; Outer proceed"/>
+                               <line text="  >> Outer proceed"/>
+                               <line text="    >> Inner intercept"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="    &lt;&lt; Inner intercept"/>
+                               <line text="  &lt;&lt; Outer proceed"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="&lt;&lt; Outer intercept"/>
+                       </stdout>
+               </run>
+               <run class="Application" options="1,2">
+                       <stdout ordered="no">
+                               <line text=">> Outer intercept"/>
+                               <line text="  >> Outer proceed"/>
+                               <line text="    >> Inner intercept"/>
+                               <line text="    &lt;&lt; Inner intercept"/>
+                               <line text="  &lt;&lt; Outer proceed"/>
+                               <line text="&lt;&lt; Outer intercept"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                       </stdout>
+               </run>
+               <run class="Application" options="2,2">
+                       <stdout ordered="no">
+                               <line text=">> Outer intercept"/>
+                               <line text="  >> Outer proceed"/>
+                               <line text="    >> Inner intercept"/>
+                               <line text="    &lt;&lt; Inner intercept"/>
+                               <line text="  &lt;&lt; Outer proceed"/>
+                               <line text="  >> Outer proceed"/>
+                               <line text="    >> Inner intercept"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="    &lt;&lt; Inner intercept"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="  &lt;&lt; Outer proceed"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="&lt;&lt; Outer intercept"/>
+                       </stdout>
+               </run>
+       </ajc-test>
+
+       <ajc-test dir="bugs198/github_128" title="asynchronous proceed for nested around-advice (native, thread pool)">
+               <compile files="Application.java MarkerA.java MarkerANativeAspect.aj MarkerB.java MarkerBNativeAspect.aj" options="-1.8" />
+               <run class="Application" options="1,1,true">
+                       <stdout ordered="no">
+                               <line text=">> Outer intercept"/>
+                               <line text="  >> Outer proceed"/>
+                               <line text="    >> Inner intercept"/>
+                               <line text="    &lt;&lt; Inner intercept"/>
+                               <line text="  &lt;&lt; Outer proceed"/>
+                               <line text="&lt;&lt; Outer intercept"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                       </stdout>
+               </run>
+               <run class="Application" options="2,1,true">
+                       <stdout ordered="no">
+                               <line text=">> Outer intercept"/>
+                               <line text="  >> Outer proceed"/>
+                               <line text="    >> Inner intercept"/>
+                               <line text="    &lt;&lt; Inner intercept"/>
+                               <line text="  &lt;&lt; Outer proceed"/>
+                               <line text="  >> Outer proceed"/>
+                               <line text="    >> Inner intercept"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="    &lt;&lt; Inner intercept"/>
+                               <line text="  &lt;&lt; Outer proceed"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="&lt;&lt; Outer intercept"/>
+                       </stdout>
+               </run>
+               <run class="Application" options="1,2,true">
+                       <stdout ordered="no">
+                               <line text=">> Outer intercept"/>
+                               <line text="  >> Outer proceed"/>
+                               <line text="    >> Inner intercept"/>
+                               <line text="    &lt;&lt; Inner intercept"/>
+                               <line text="  &lt;&lt; Outer proceed"/>
+                               <line text="&lt;&lt; Outer intercept"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                       </stdout>
+               </run>
+               <run class="Application" options="2,2,true">
+                       <stdout ordered="no">
+                               <line text=">> Outer intercept"/>
+                               <line text="  >> Outer proceed"/>
+                               <line text="    >> Inner intercept"/>
+                               <line text="    &lt;&lt; Inner intercept"/>
+                               <line text="  &lt;&lt; Outer proceed"/>
+                               <line text="  >> Outer proceed"/>
+                               <line text="    >> Inner intercept"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="    &lt;&lt; Inner intercept"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="  &lt;&lt; Outer proceed"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="      >> Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="        Doing something"/>
+                               <line text="      &lt;&lt; Inner proceed"/>
+                               <line text="&lt;&lt; Outer intercept"/>
+                       </stdout>
+               </run>
+       </ajc-test>
+
 </suite>