Skip to content

Commit

Permalink
Add test "asynchronous proceed for nested around-advice chain"
Browse files Browse the repository at this point in the history
Relates to #128.

Signed-off-by: Alexander Kriegisch <[email protected]>
  • Loading branch information
kriegaex committed Mar 23, 2022
1 parent af0e70f commit 72e9147
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/bugs198/github_128/Application.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
9 changes: 9 additions & 0 deletions tests/bugs198/github_128/MarkerA.java
Original file line number Diff line number Diff line change
@@ -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 {}
23 changes: 23 additions & 0 deletions tests/bugs198/github_128/MarkerAAspect.aj
Original file line number Diff line number Diff line change
@@ -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;
}
}
9 changes: 9 additions & 0 deletions tests/bugs198/github_128/MarkerB.java
Original file line number Diff line number Diff line change
@@ -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 {}
30 changes: 30 additions & 0 deletions tests/bugs198/github_128/MarkerBAspect.aj
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public void testGitHub_125() {
}
}

public void testAsyncProceedNestedAroundAdvice_gh128() {
runTest("asynchronous proceed for nested around-advice chain");
}

public static Test suite() {
return XMLBasedAjcTestCase.loadSuite(Bugs198Tests.class);
}
Expand Down
79 changes: 79 additions & 0 deletions tests/src/test/resources/org/aspectj/systemtest/ajc198/ajc198.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,83 @@
</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>

0 comments on commit 72e9147

Please sign in to comment.