From 9d35aceab5f642c8d8eaa59ddae4ed2c66a081ed Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Mon, 28 Feb 2022 18:44:07 +0700 Subject: [PATCH] Expand "asynchronous proceed for nested around-advice" to 4 scenarios: 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 --- tests/bugs198/github_128/Application.java | 34 ++- tests/bugs198/github_128/MarkerAAspect.aj | 4 +- .../bugs198/github_128/MarkerANativeAspect.aj | 16 ++ tests/bugs198/github_128/MarkerBAspect.aj | 19 +- .../bugs198/github_128/MarkerBNativeAspect.aj | 31 +++ .../systemtest/ajc198/Bugs198Tests.java | 14 +- .../org/aspectj/systemtest/ajc198/ajc198.xml | 239 +++++++++++++++++- 7 files changed, 343 insertions(+), 14 deletions(-) create mode 100644 tests/bugs198/github_128/MarkerANativeAspect.aj create mode 100644 tests/bugs198/github_128/MarkerBNativeAspect.aj diff --git a/tests/bugs198/github_128/Application.java b/tests/bugs198/github_128/Application.java index d42b0fee4..9a4a7312f 100644 --- a/tests/bugs198/github_128/Application.java +++ b/tests/bugs198/github_128/Application.java @@ -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(); + } + } diff --git a/tests/bugs198/github_128/MarkerAAspect.aj b/tests/bugs198/github_128/MarkerAAspect.aj index b2eb63211..d090ed9ea 100644 --- a/tests/bugs198/github_128/MarkerAAspect.aj +++ b/tests/bugs198/github_128/MarkerAAspect.aj @@ -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 index 000000000..37d9f2fee --- /dev/null +++ b/tests/bugs198/github_128/MarkerANativeAspect.aj @@ -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; + } +} diff --git a/tests/bugs198/github_128/MarkerBAspect.aj b/tests/bugs198/github_128/MarkerBAspect.aj index 1381d5f77..d5548f9da 100644 --- a/tests/bugs198/github_128/MarkerBAspect.aj +++ b/tests/bugs198/github_128/MarkerBAspect.aj @@ -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 index 000000000..6bd4b8683 --- /dev/null +++ b/tests/bugs198/github_128/MarkerBNativeAspect.aj @@ -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; + } +} 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 ac151b127..9421f4aee 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc198/Bugs198Tests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc198/Bugs198Tests.java @@ -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() { 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 aadf36f92..0e1132782 100644 --- a/tests/src/test/resources/org/aspectj/systemtest/ajc198/ajc198.xml +++ b/tests/src/test/resources/org/aspectj/systemtest/ajc198/ajc198.xml @@ -167,7 +167,7 @@ - + @@ -246,4 +246,241 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.39.5