]> source.dussan.org Git - aspectj.git/commitdiff
Add test "asynchronous proceed for nested around-advice chain"
authorAlexander Kriegisch <Alexander@Kriegisch.name>
Mon, 28 Feb 2022 02:25:46 +0000 (09:25 +0700)
committerAlexander Kriegisch <Alexander@Kriegisch.name>
Wed, 23 Mar 2022 08:39:14 +0000 (15:39 +0700)
Relates to #128.

Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
tests/bugs198/github_128/Application.java [new file with mode: 0644]
tests/bugs198/github_128/MarkerA.java [new file with mode: 0644]
tests/bugs198/github_128/MarkerAAspect.aj [new file with mode: 0644]
tests/bugs198/github_128/MarkerB.java [new file with mode: 0644]
tests/bugs198/github_128/MarkerBAspect.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

diff --git a/tests/bugs198/github_128/Application.java b/tests/bugs198/github_128/Application.java
new file mode 100644 (file)
index 0000000..d42b0fe
--- /dev/null
@@ -0,0 +1,14 @@
+public class Application {
+  @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]);
+    new Application().doSomething();
+    Thread.sleep(500);
+  }
+}
diff --git a/tests/bugs198/github_128/MarkerA.java b/tests/bugs198/github_128/MarkerA.java
new file mode 100644 (file)
index 0000000..89e6097
--- /dev/null
@@ -0,0 +1,9 @@
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+@Retention(RUNTIME)
+@Target(METHOD)
+public @interface MarkerA {}
diff --git a/tests/bugs198/github_128/MarkerAAspect.aj b/tests/bugs198/github_128/MarkerAAspect.aj
new file mode 100644 (file)
index 0000000..b2eb632
--- /dev/null
@@ -0,0 +1,23 @@
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+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++) {
+      System.out.println("  >> Outer proceed");
+      result = thisJoinPoint.proceed();
+      System.out.println("  << Outer proceed");
+    }
+    System.out.println("<< Outer intercept");
+    return result;
+  }
+}
diff --git a/tests/bugs198/github_128/MarkerB.java b/tests/bugs198/github_128/MarkerB.java
new file mode 100644 (file)
index 0000000..6f6aa3d
--- /dev/null
@@ -0,0 +1,9 @@
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+@Retention(RUNTIME)
+@Target(METHOD)
+public @interface MarkerB {}
diff --git a/tests/bugs198/github_128/MarkerBAspect.aj b/tests/bugs198/github_128/MarkerBAspect.aj
new file mode 100644 (file)
index 0000000..1381d5f
--- /dev/null
@@ -0,0 +1,30 @@
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+
+@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() {
+      @Override
+      public void run() {
+        try {
+          for (int i = 0; i < proceedTimes; i++) {
+            System.out.println("      >> Inner proceed");
+            thisJoinPoint.proceed();
+            System.out.println("      << Inner proceed");
+          }
+        }
+        catch (Throwable throwable) {
+          throwable.printStackTrace(System.out);
+        }
+      }
+    }).start();
+    System.out.println("    << Inner intercept");
+    return null;
+  }
+}
index 7982ec630c59e97294697bb0c1272ccab8444345..ac151b127c011e43e220cae5ed48d3ed90d1f5c8 100644 (file)
@@ -48,6 +48,10 @@ public class Bugs198Tests extends XMLBasedAjcTestCase {
     }
   }
 
+  public void testAsyncProceedNestedAroundAdvice_gh128() {
+    runTest("asynchronous proceed for nested around-advice chain");
+  }
+
   public static Test suite() {
     return XMLBasedAjcTestCase.loadSuite(Bugs198Tests.class);
   }
index 0eb413baa7ff60371bb7d90bfaca34658b57d8e1..aadf36f9212767a8354d5b3acc2b398cdf128310 100644 (file)
                </run>
        </ajc-test>
 
+       <ajc-test dir="bugs198/github_128" title="asynchronous proceed for nested around-advice chain">
+               <compile files="Application.java MarkerA.java MarkerAAspect.aj MarkerB.java MarkerBAspect.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>
+
 </suite>