-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test "asynchronous proceed for nested around-advice chain"
Relates to #128. Signed-off-by: Alexander Kriegisch <[email protected]>
- Loading branch information
Showing
7 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters