diff options
author | Alexander Kriegisch <Alexander@Kriegisch.name> | 2022-02-28 18:44:07 +0700 |
---|---|---|
committer | Alexander Kriegisch <Alexander@Kriegisch.name> | 2022-03-23 15:39:14 +0700 |
commit | 9d35aceab5f642c8d8eaa59ddae4ed2c66a081ed (patch) | |
tree | d00ef3fbc92cf19261b45727a9f6419c54e65aed | |
parent | 72e91478f44129d92716807742cd7474265ff5da (diff) | |
download | aspectj-9d35aceab5f642c8d8eaa59ddae4ed2c66a081ed.tar.gz aspectj-9d35aceab5f642c8d8eaa59ddae4ed2c66a081ed.zip |
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 <Alexander@Kriegisch.name>
-rw-r--r-- | tests/bugs198/github_128/Application.java | 34 | ||||
-rw-r--r-- | tests/bugs198/github_128/MarkerAAspect.aj | 4 | ||||
-rw-r--r-- | tests/bugs198/github_128/MarkerANativeAspect.aj | 16 | ||||
-rw-r--r-- | tests/bugs198/github_128/MarkerBAspect.aj | 19 | ||||
-rw-r--r-- | tests/bugs198/github_128/MarkerBNativeAspect.aj | 31 | ||||
-rw-r--r-- | tests/src/test/java/org/aspectj/systemtest/ajc198/Bugs198Tests.java | 14 | ||||
-rw-r--r-- | tests/src/test/resources/org/aspectj/systemtest/ajc198/ajc198.xml | 239 |
7 files changed, 343 insertions, 14 deletions
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 @@ </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"> @@ -246,4 +246,241 @@ </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=" << Inner intercept"/> + <line text=" << Outer proceed"/> + <line text="<< Outer intercept"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << 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=" << Inner intercept"/> + <line text=" << Outer proceed"/> + <line text=" >> Outer proceed"/> + <line text=" >> Inner intercept"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text=" << Inner intercept"/> + <line text=" << Outer proceed"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text="<< 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=" << Inner intercept"/> + <line text=" << Outer proceed"/> + <line text="<< Outer intercept"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << 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=" << Inner intercept"/> + <line text=" << Outer proceed"/> + <line text=" >> Outer proceed"/> + <line text=" >> Inner intercept"/> + <line text=" >> Inner proceed"/> + <line text=" << Inner intercept"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text=" << Outer proceed"/> + <line text=" >> Inner proceed"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text="<< 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=" << Inner intercept"/> + <line text=" << Outer proceed"/> + <line text="<< Outer intercept"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << 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=" << Inner intercept"/> + <line text=" << Outer proceed"/> + <line text=" >> Outer proceed"/> + <line text=" >> Inner intercept"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text=" << Inner intercept"/> + <line text=" << Outer proceed"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text="<< 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=" << Inner intercept"/> + <line text=" << Outer proceed"/> + <line text="<< Outer intercept"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << 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=" << Inner intercept"/> + <line text=" << Outer proceed"/> + <line text=" >> Outer proceed"/> + <line text=" >> Inner intercept"/> + <line text=" >> Inner proceed"/> + <line text=" << Inner intercept"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text=" << Outer proceed"/> + <line text=" >> Inner proceed"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text="<< 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=" << Inner intercept"/> + <line text=" << Outer proceed"/> + <line text="<< Outer intercept"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << 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=" << Inner intercept"/> + <line text=" << Outer proceed"/> + <line text=" >> Outer proceed"/> + <line text=" >> Inner intercept"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text=" << Inner intercept"/> + <line text=" << Outer proceed"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text="<< 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=" << Inner intercept"/> + <line text=" << Outer proceed"/> + <line text="<< Outer intercept"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << 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=" << Inner intercept"/> + <line text=" << Outer proceed"/> + <line text=" >> Outer proceed"/> + <line text=" >> Inner intercept"/> + <line text=" >> Inner proceed"/> + <line text=" << Inner intercept"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text=" << Outer proceed"/> + <line text=" >> Inner proceed"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text=" >> Inner proceed"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text=" Doing something"/> + <line text=" << Inner proceed"/> + <line text="<< Outer intercept"/> + </stdout> + </run> + </ajc-test> + </suite> |