-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: add annotation @ExecutorSince #4
- Loading branch information
1 parent
e8d8b73
commit 23d95a2
Showing
5 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
plugin/src/main/groovy/org/clarify4j/config/annotation/ExecutorSince.java
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 @@ | ||
package org.clarify4j.config.annotation; | ||
|
||
import java.lang.annotation.*; | ||
|
||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.METHOD, ElementType.TYPE}) | ||
public @interface ExecutorSince { | ||
} |
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 |
---|---|---|
|
@@ -9,6 +9,4 @@ | |
String expression(); | ||
|
||
boolean disable() default false; | ||
|
||
Class<?> clazz() default Saga.class; | ||
} |
30 changes: 30 additions & 0 deletions
30
plugin/src/main/groovy/org/clarify4j/config/handler/ExecutorSinceHandler.java
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 @@ | ||
package org.clarify4j.config.handler; | ||
|
||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.Signature; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Component; | ||
import org.unify4j.common.Time4j; | ||
|
||
import java.util.Date; | ||
|
||
@Aspect | ||
@Component | ||
public class ExecutorSinceHandler { | ||
protected static final Logger logger = LoggerFactory.getLogger(ExecutorSinceHandler.class); | ||
|
||
@Around(value = "@annotation(org.clarify4j.config.annotation.ExecutorSince)") | ||
public Object execute(ProceedingJoinPoint joinPoint) throws Throwable { | ||
Date start = new Date(); | ||
Object proceed = joinPoint.proceed(); | ||
String since = Time4j.sinceSmallRecently(start, new Date()); | ||
Signature signature = joinPoint.getSignature(); | ||
String clazz = joinPoint.getTarget().getClass().getSimpleName(); | ||
String method = signature.getName(); | ||
logger.info("Execution of method '{}' in class '{}' completed in {}", method, clazz, since); | ||
return proceed; | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
plugin/src/test/groovy/org/clarify4j/ExecutorSinceTest.java
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,47 @@ | ||
package org.clarify4j; | ||
|
||
import org.clarify4j.config.annotation.ExecutorSince; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.reflect.Method; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class ExecutorSinceTest { | ||
@ExecutorSince | ||
private static class TestClass { | ||
@ExecutorSince | ||
public void testMethod() { | ||
} | ||
} | ||
|
||
@Test | ||
void annotationTypeShouldBeAvailableOnClass() { | ||
ExecutorSince annotation = TestClass.class.getAnnotation(ExecutorSince.class); | ||
assertNotNull(annotation, "Annotation should be present on the class."); | ||
} | ||
|
||
@Test | ||
void annotationTypeShouldBeAvailableOnMethod() throws NoSuchMethodException { | ||
Method method = TestClass.class.getMethod("testMethod"); | ||
ExecutorSince annotation = method.getAnnotation(ExecutorSince.class); | ||
assertNotNull(annotation, "Annotation should be present on the method."); | ||
} | ||
|
||
@Test | ||
void shouldHaveRuntimeRetention() { | ||
RetentionPolicy retentionPolicy = ExecutorSince.class.getAnnotation(Retention.class).value(); | ||
assertEquals(RetentionPolicy.RUNTIME, retentionPolicy, "Retention policy should be RUNTIME."); | ||
} | ||
|
||
@Test | ||
void shouldBeDocumented() { | ||
Annotation documented = ExecutorSince.class.getAnnotation(Documented.class); | ||
assertNotNull(documented, "Annotation should be documented."); | ||
} | ||
} |