Skip to content

Commit 642ac60

Browse files
committed
Add test "asynchronous proceed for nested around-advice chain"
Relates to eclipse-aspectj#128. Signed-off-by: Alexander Kriegisch <[email protected]>
1 parent 03fc86d commit 642ac60

File tree

7 files changed

+168
-0
lines changed

7 files changed

+168
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class Application {
2+
@MarkerA
3+
@MarkerB
4+
public void doSomething() {
5+
System.out.println(" Doing something");
6+
}
7+
8+
public static void main(String[] args) throws InterruptedException {
9+
MarkerAAspect.proceedTimes = Integer.parseInt(args[0]);
10+
MarkerBAspect.proceedTimes = Integer.parseInt(args[1]);
11+
new Application().doSomething();
12+
Thread.sleep(500);
13+
}
14+
}

tests/bugs198/github_128/MarkerA.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import static java.lang.annotation.ElementType.METHOD;
2+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
3+
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.Target;
6+
7+
@Retention(RUNTIME)
8+
@Target(METHOD)
9+
public @interface MarkerA {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import org.aspectj.lang.ProceedingJoinPoint;
2+
import org.aspectj.lang.annotation.Around;
3+
import org.aspectj.lang.annotation.Aspect;
4+
import org.aspectj.lang.annotation.DeclarePrecedence;
5+
6+
@Aspect
7+
@DeclarePrecedence("MarkerAAspect, MarkerBAspect")
8+
public class MarkerAAspect {
9+
public static int proceedTimes = 1;
10+
11+
@Around("@annotation(MarkerA) && execution(* *(..))")
12+
public Object intercept(ProceedingJoinPoint thisJoinPoint) throws Throwable {
13+
System.out.println(">> Outer intercept");
14+
Object result = null;
15+
for (int i = 0; i < proceedTimes; i++) {
16+
System.out.println(" >> Outer proceed");
17+
result = thisJoinPoint.proceed();
18+
System.out.println(" << Outer proceed");
19+
}
20+
System.out.println("<< Outer intercept");
21+
return result;
22+
}
23+
}

tests/bugs198/github_128/MarkerB.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import static java.lang.annotation.ElementType.METHOD;
2+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
3+
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.Target;
6+
7+
@Retention(RUNTIME)
8+
@Target(METHOD)
9+
public @interface MarkerB {}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import org.aspectj.lang.ProceedingJoinPoint;
2+
import org.aspectj.lang.annotation.Around;
3+
import org.aspectj.lang.annotation.Aspect;
4+
5+
@Aspect
6+
public class MarkerBAspect {
7+
public static int proceedTimes = 1;
8+
9+
@Around("@annotation(MarkerB) && execution(* *(..))")
10+
public Object intercept(ProceedingJoinPoint thisJoinPoint) throws Throwable {
11+
System.out.println(" >> Inner intercept");
12+
new Thread(new Runnable() {
13+
@Override
14+
public void run() {
15+
try {
16+
for (int i = 0; i < proceedTimes; i++) {
17+
System.out.println(" >> Inner proceed");
18+
thisJoinPoint.proceed();
19+
System.out.println(" << Inner proceed");
20+
}
21+
}
22+
catch (Throwable throwable) {
23+
throwable.printStackTrace(System.out);
24+
}
25+
}
26+
}).start();
27+
System.out.println(" << Inner intercept");
28+
return null;
29+
}
30+
}

tests/src/test/java/org/aspectj/systemtest/ajc198/Bugs198Tests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public void testGitHub_125() {
4848
}
4949
}
5050

51+
public void testAsyncProceedNestedAroundAdvice_gh128() {
52+
runTest("asynchronous proceed for nested around-advice chain");
53+
}
54+
5155
public static Test suite() {
5256
return XMLBasedAjcTestCase.loadSuite(Bugs198Tests.class);
5357
}

tests/src/test/resources/org/aspectj/systemtest/ajc198/ajc198.xml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,83 @@
167167
</run>
168168
</ajc-test>
169169

170+
<ajc-test dir="bugs198/github_128" title="asynchronous proceed for nested around-advice chain">
171+
<compile files="Application.java MarkerA.java MarkerAAspect.aj MarkerB.java MarkerBAspect.aj" options="-1.8" />
172+
<run class="Application" options="1,1">
173+
<stdout ordered="no">
174+
<line text=">> Outer intercept"/>
175+
<line text=" >> Outer proceed"/>
176+
<line text=" >> Inner intercept"/>
177+
<line text=" &lt;&lt; Inner intercept"/>
178+
<line text=" &lt;&lt; Outer proceed"/>
179+
<line text="&lt;&lt; Outer intercept"/>
180+
<line text=" >> Inner proceed"/>
181+
<line text=" Doing something"/>
182+
<line text=" &lt;&lt; Inner proceed"/>
183+
</stdout>
184+
</run>
185+
<run class="Application" options="2,1">
186+
<stdout ordered="no">
187+
<line text=">> Outer intercept"/>
188+
<line text=" >> Outer proceed"/>
189+
<line text=" >> Inner intercept"/>
190+
<line text=" &lt;&lt; Inner intercept"/>
191+
<line text=" &lt;&lt; Outer proceed"/>
192+
<line text=" >> Outer proceed"/>
193+
<line text=" >> Inner intercept"/>
194+
<line text=" >> Inner proceed"/>
195+
<line text=" Doing something"/>
196+
<line text=" &lt;&lt; Inner proceed"/>
197+
<line text=" &lt;&lt; Inner intercept"/>
198+
<line text=" &lt;&lt; Outer proceed"/>
199+
<line text=" >> Inner proceed"/>
200+
<line text=" Doing something"/>
201+
<line text=" &lt;&lt; Inner proceed"/>
202+
<line text="&lt;&lt; Outer intercept"/>
203+
</stdout>
204+
</run>
205+
<run class="Application" options="1,2">
206+
<stdout ordered="no">
207+
<line text=">> Outer intercept"/>
208+
<line text=" >> Outer proceed"/>
209+
<line text=" >> Inner intercept"/>
210+
<line text=" &lt;&lt; Inner intercept"/>
211+
<line text=" &lt;&lt; Outer proceed"/>
212+
<line text="&lt;&lt; Outer intercept"/>
213+
<line text=" >> Inner proceed"/>
214+
<line text=" Doing something"/>
215+
<line text=" &lt;&lt; Inner proceed"/>
216+
<line text=" >> Inner proceed"/>
217+
<line text=" Doing something"/>
218+
<line text=" &lt;&lt; Inner proceed"/>
219+
</stdout>
220+
</run>
221+
<run class="Application" options="2,2">
222+
<stdout ordered="no">
223+
<line text=">> Outer intercept"/>
224+
<line text=" >> Outer proceed"/>
225+
<line text=" >> Inner intercept"/>
226+
<line text=" &lt;&lt; Inner intercept"/>
227+
<line text=" &lt;&lt; Outer proceed"/>
228+
<line text=" >> Outer proceed"/>
229+
<line text=" >> Inner intercept"/>
230+
<line text=" >> Inner proceed"/>
231+
<line text=" &lt;&lt; Inner intercept"/>
232+
<line text=" Doing something"/>
233+
<line text=" &lt;&lt; Inner proceed"/>
234+
<line text=" &lt;&lt; Outer proceed"/>
235+
<line text=" >> Inner proceed"/>
236+
<line text=" >> Inner proceed"/>
237+
<line text=" Doing something"/>
238+
<line text=" &lt;&lt; Inner proceed"/>
239+
<line text=" >> Inner proceed"/>
240+
<line text=" Doing something"/>
241+
<line text=" &lt;&lt; Inner proceed"/>
242+
<line text=" Doing something"/>
243+
<line text=" &lt;&lt; Inner proceed"/>
244+
<line text="&lt;&lt; Outer intercept"/>
245+
</stdout>
246+
</run>
247+
</ajc-test>
248+
170249
</suite>

0 commit comments

Comments
 (0)