From 72e91478f44129d92716807742cd7474265ff5da Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Mon, 28 Feb 2022 09:25:46 +0700 Subject: Add test "asynchronous proceed for nested around-advice chain" Relates to #128. Signed-off-by: Alexander Kriegisch --- tests/bugs198/github_128/Application.java | 14 ++++ tests/bugs198/github_128/MarkerA.java | 9 +++ tests/bugs198/github_128/MarkerAAspect.aj | 23 +++++++ tests/bugs198/github_128/MarkerB.java | 9 +++ tests/bugs198/github_128/MarkerBAspect.aj | 30 ++++++++ .../aspectj/systemtest/ajc198/Bugs198Tests.java | 4 ++ .../org/aspectj/systemtest/ajc198/ajc198.xml | 79 ++++++++++++++++++++++ 7 files changed, 168 insertions(+) create mode 100644 tests/bugs198/github_128/Application.java create mode 100644 tests/bugs198/github_128/MarkerA.java create mode 100644 tests/bugs198/github_128/MarkerAAspect.aj create mode 100644 tests/bugs198/github_128/MarkerB.java create mode 100644 tests/bugs198/github_128/MarkerBAspect.aj (limited to 'tests') diff --git a/tests/bugs198/github_128/Application.java b/tests/bugs198/github_128/Application.java new file mode 100644 index 000000000..d42b0fee4 --- /dev/null +++ b/tests/bugs198/github_128/Application.java @@ -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 index 000000000..89e60978c --- /dev/null +++ b/tests/bugs198/github_128/MarkerA.java @@ -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 index 000000000..b2eb63211 --- /dev/null +++ b/tests/bugs198/github_128/MarkerAAspect.aj @@ -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 index 000000000..6f6aa3dd0 --- /dev/null +++ b/tests/bugs198/github_128/MarkerB.java @@ -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 index 000000000..1381d5f77 --- /dev/null +++ b/tests/bugs198/github_128/MarkerBAspect.aj @@ -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; + } +} diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc198/Bugs198Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc198/Bugs198Tests.java index 7982ec630..ac151b127 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc198/Bugs198Tests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc198/Bugs198Tests.java @@ -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); } diff --git a/tests/src/test/resources/org/aspectj/systemtest/ajc198/ajc198.xml b/tests/src/test/resources/org/aspectj/systemtest/ajc198/ajc198.xml index 0eb413baa..aadf36f92 100644 --- a/tests/src/test/resources/org/aspectj/systemtest/ajc198/ajc198.xml +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc198/ajc198.xml @@ -167,4 +167,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3