Skip to content

Commit

Permalink
Merge pull request #32 from Trendyol/jdempotent-deprecated
Browse files Browse the repository at this point in the history
updated deprecated annotations
  • Loading branch information
memojja authored Nov 3, 2021
2 parents 36b836b + e762aa9 commit b468585
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Jdempotent-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.trendyol</groupId>
<artifactId>Jdempotent-core</artifactId>
<version>1.0.9</version>
<version>1.0.10</version>
<name>Jdempotent-core</name>
<packaging>jar</packaging>
<url>https://github.com/Trendyol/Jdempotent/tree/master/Jdempotent-core</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
* That annotation needs to ignore annotation field
*
*/
@Deprecated
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface IdempotentIgnore {
public @interface JdempotentIgnore {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
* Add to the methods arguments that represents the idempotent request payload.
*
*/
@Deprecated
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface IdempotentRequestPayload {
public @interface JdempotentRequestPayload {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
* Add to the methods that need to be idempotent.
*
*/
@Deprecated
@Retention(RetentionPolicy.RUNTIME)
public @interface IdempotentResource {
public @interface JdempotentResource {

/**
* Prefix value to make hash value more collider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ public IdempotentAspect(IdempotentRepository idempotentRepository, ErrorConditio
* @return
* @throws Throwable
*/
@Around("@annotation(com.trendyol.jdempotent.core.annotation.IdempotentResource)")
@Around("@annotation(com.trendyol.jdempotent.core.annotation.JdempotentResource)")
public Object execute(ProceedingJoinPoint pjp) throws Throwable {
String classAndMethodName = generateLogPrefixForIncomingEvent(pjp);
IdempotentRequestWrapper requestObject = findIdempotentRequestArg(pjp);
String listenerName = ((MethodSignature) pjp.getSignature()).getMethod().getAnnotation(IdempotentResource.class).cachePrefix();
String listenerName = ((MethodSignature) pjp.getSignature()).getMethod().getAnnotation(JdempotentResource.class).cachePrefix();
IdempotencyKey idempotencyKey = keyGenerator.generateIdempotentKey(requestObject, listenerName, stringBuilders.get(), messageDigests.get());
Long customTtl = ((MethodSignature) pjp.getSignature()).getMethod().getAnnotation(IdempotentResource.class).ttl();
TimeUnit timeUnit = ((MethodSignature) pjp.getSignature()).getMethod().getAnnotation(IdempotentResource.class).ttlTimeUnit();
Long customTtl = ((MethodSignature) pjp.getSignature()).getMethod().getAnnotation(JdempotentResource.class).ttl();
TimeUnit timeUnit = ((MethodSignature) pjp.getSignature()).getMethod().getAnnotation(JdempotentResource.class).ttlTimeUnit();

logger.debug(classAndMethodName + "starting for {}", requestObject);

Expand Down Expand Up @@ -209,7 +209,7 @@ public IdempotentRequestWrapper findIdempotentRequestArg(ProceedingJoinPoint pjp
Annotation[][] annotations = method.getParameterAnnotations();
for (int i = 0; i < args.length; i++) {
for (Annotation annotation : annotations[i]) {
if (annotation instanceof IdempotentRequestPayload) {
if (annotation instanceof JdempotentRequestPayload) {
return new IdempotentRequestWrapper(getIdempotentNonIgnorableWrapper(args[i]));
}
}
Expand Down Expand Up @@ -259,7 +259,7 @@ public IdempotentIgnorableWrapper getIdempotentNonIgnorableWrapper(Object args)
wrapper.getNonIgnoredFields().put(declaredField.getName(), declaredField.get(args));
} else {
for (Annotation annotation : declaredField.getDeclaredAnnotations()) {
if (!(annotation instanceof IdempotentIgnore)) {
if (!(annotation instanceof JdempotentIgnore)) {
wrapper.getNonIgnoredFields().put(declaredField.getName(), declaredField.get(args));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package aspect.core;

import com.trendyol.jdempotent.core.annotation.IdempotentIgnore;
import com.trendyol.jdempotent.core.annotation.JdempotentIgnore;

public class IdempotentTestPayload {
private String name;
@IdempotentIgnore
@JdempotentIgnore
private Long age;

public IdempotentTestPayload() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
package aspect.core;

import com.trendyol.jdempotent.core.annotation.IdempotentRequestPayload;
import com.trendyol.jdempotent.core.annotation.IdempotentResource;
import com.trendyol.jdempotent.core.annotation.JdempotentRequestPayload;
import com.trendyol.jdempotent.core.annotation.JdempotentResource;
import org.springframework.stereotype.Component;

@Component
public class TestIdempotentResource {
@IdempotentResource
@JdempotentResource
public void idempotentMethod(IdempotentTestPayload testObject) {
}

@IdempotentResource(cachePrefix = "TestIdempotentResource")
@JdempotentResource(cachePrefix = "TestIdempotentResource")
public void idempotentMethodThrowingARuntimeException(IdempotentTestPayload testObject) {
throw new TestException();
}

@IdempotentResource(cachePrefix = "TestIdempotentResource")
public void idempotentMethodWithThreeParameter(@IdempotentRequestPayload IdempotentTestPayload testObject, IdempotentTestPayload anotherObject, IdempotentTestPayload anotherObject2) {
@JdempotentResource(cachePrefix = "TestIdempotentResource")
public void idempotentMethodWithThreeParameter(@JdempotentRequestPayload IdempotentTestPayload testObject, IdempotentTestPayload anotherObject, IdempotentTestPayload anotherObject2) {
}

@IdempotentResource(cachePrefix = "TestIdempotentResource")
public void idempotentMethodWithThreeParamaterAndMultipleIdempotentRequestPayloadAnnotation(IdempotentTestPayload testObject, @IdempotentRequestPayload IdempotentTestPayload anotherObject, @IdempotentRequestPayload Object anotherObject2) {
@JdempotentResource(cachePrefix = "TestIdempotentResource")
public void idempotentMethodWithThreeParamaterAndMultipleJdempotentRequestPayloadAnnotation(IdempotentTestPayload testObject, @JdempotentRequestPayload IdempotentTestPayload anotherObject, @JdempotentRequestPayload Object anotherObject2) {
}

@IdempotentResource(cachePrefix = "TestIdempotentResource")
@JdempotentResource(cachePrefix = "TestIdempotentResource")
public void idempotentMethodWithZeroParamater() {
}

@IdempotentResource(cachePrefix = "TestIdempotentResource")
@JdempotentResource(cachePrefix = "TestIdempotentResource")
public void methodWithTwoParamater(IdempotentTestPayload testObject, IdempotentTestPayload anotherObject) {
}

@IdempotentResource
@JdempotentResource
public IdempotentTestPayload idempotentMethodReturnArg(IdempotentTestPayload testObject) {
return testObject;
}

@IdempotentResource
public String idempotencyKeyAsString(@IdempotentRequestPayload String idempotencyKey) {
@JdempotentResource
public String idempotencyKeyAsString(@JdempotentRequestPayload String idempotencyKey) {
return idempotencyKey;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import aspect.core.IdempotentTestPayload;
import aspect.core.TestException;
import aspect.core.TestIdempotentResource;
import com.trendyol.jdempotent.core.annotation.IdempotentResource;
import com.trendyol.jdempotent.core.annotation.JdempotentResource;
import com.trendyol.jdempotent.core.constant.CryptographyAlgorithm;
import com.trendyol.jdempotent.core.datasource.InMemoryIdempotentRepository;
import com.trendyol.jdempotent.core.generator.DefaultKeyGenerator;
Expand Down Expand Up @@ -40,12 +40,12 @@ public class IdempotentAspectIT {

@Test
public void given_aop_context_then_run_with_aop_context() {
IdempotentResource idempotentResource = TestIdempotentResource.class.getDeclaredMethods()[0].getAnnotation(IdempotentResource.class);
JdempotentResource jdempotentResource = TestIdempotentResource.class.getDeclaredMethods()[0].getAnnotation(JdempotentResource.class);

assertNotEquals(testIdempotentResource.getClass(), TestIdempotentResource.class);
assertTrue(AopUtils.isAopProxy(testIdempotentResource));
assertTrue(AopUtils.isCglibProxy(testIdempotentResource));
assertNotNull(idempotentResource);
assertNotNull(jdempotentResource);

assertEquals(AopProxyUtils.ultimateTargetClass(testIdempotentResource), TestIdempotentResource.class);
assertEquals(AopTestUtils.getTargetObject(testIdempotentResource).getClass(), TestIdempotentResource.class);
Expand Down Expand Up @@ -114,7 +114,7 @@ public void given_new_multiple_payloads_with_multiple_annotations_when_trigger_a
IdempotencyKey idempotencyKey = defaultKeyGenerator.generateIdempotentKey(new IdempotentRequestWrapper(wrapper), "TestIdempotentResource", new StringBuilder(), MessageDigest.getInstance(CryptographyAlgorithm.MD5.value()));

//when
testIdempotentResource.idempotentMethodWithThreeParamaterAndMultipleIdempotentRequestPayloadAnnotation(test, test1, test2);
testIdempotentResource.idempotentMethodWithThreeParamaterAndMultipleJdempotentRequestPayloadAnnotation(test, test1, test2);

//then
assertTrue(idempotentRepository.contains(idempotencyKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import aspect.core.IdempotentTestPayload;
import aspect.core.TestIdempotentResource;
import com.trendyol.jdempotent.core.annotation.IdempotentResource;
import com.trendyol.jdempotent.core.annotation.JdempotentResource;
import com.trendyol.jdempotent.core.aspect.IdempotentAspect;
import com.trendyol.jdempotent.core.callback.ErrorConditionalCallback;
import com.trendyol.jdempotent.core.datasource.IdempotentRepository;
Expand Down Expand Up @@ -73,7 +73,7 @@ public void given_actual_payload_when_key_in_repository_and_method_has_one_arg_t
ProceedingJoinPoint joinPoint = mock(ProceedingJoinPoint.class);
MethodSignature signature = mock(MethodSignature.class);
Method method = TestIdempotentResource.class.getMethod("idempotentMethod", IdempotentTestPayload.class);
IdempotentResource idempotentResource = mock(IdempotentResource.class);
JdempotentResource jdempotentResource = mock(JdempotentResource.class);
IdempotentTestPayload payload = new IdempotentTestPayload("payload");
TestIdempotentResource testIdempotentResource = mock(TestIdempotentResource.class);

Expand Down Expand Up @@ -103,7 +103,7 @@ public void given_actual_payload_when_key_in_repository_and_method_has_one_arg_t
ProceedingJoinPoint joinPoint = mock(ProceedingJoinPoint.class);
MethodSignature signature = mock(MethodSignature.class);
Method method = TestIdempotentResource.class.getMethod("idempotentMethodThrowingARuntimeException", IdempotentTestPayload.class);
IdempotentResource idempotentResource = mock(IdempotentResource.class);
JdempotentResource jdempotentResource = mock(JdempotentResource.class);
IdempotentTestPayload payload = new IdempotentTestPayload("payload");
TestIdempotentResource testIdempotentResource = mock(TestIdempotentResource.class);

Expand Down Expand Up @@ -135,7 +135,7 @@ public void not_given_a_payload_then_return_exception() throws Throwable {
ProceedingJoinPoint joinPoint = mock(ProceedingJoinPoint.class);
MethodSignature signature = mock(MethodSignature.class);
Method method = TestIdempotentResource.class.getMethod("idempotentMethodWithZeroParamater");
IdempotentResource idempotentResource = mock(IdempotentResource.class);
JdempotentResource jdempotentResource = mock(JdempotentResource.class);
IdempotentTestPayload payload = new IdempotentTestPayload("payload");
TestIdempotentResource testIdempotentResource = mock(TestIdempotentResource.class);

Expand Down
4 changes: 2 additions & 2 deletions Jdempotent-spring-boot-couchbase-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.trendyol</groupId>
<artifactId>Jdempotent-spring-boot-couchbase-starter</artifactId>
<version>1.0.9</version>
<version>1.0.10</version>
<name>Jdempotent-spring-boot-couchbase-starter</name>
<packaging>jar</packaging>
<url>https://github.com/Trendyol/Jdempotent/tree/master/Jdempotent-spring-boot-couchbase-starter</url>
Expand Down Expand Up @@ -54,7 +54,7 @@
<dependency>
<groupId>com.trendyol</groupId>
<artifactId>Jdempotent-core</artifactId>
<version>1.0.9</version>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
Expand Down
4 changes: 2 additions & 2 deletions Jdempotent-spring-boot-redis-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.trendyol</groupId>
<artifactId>Jdempotent-spring-boot-redis-starter</artifactId>
<version>1.0.9</version>
<version>1.0.10</version>
<name>Jdempotent-spring-boot-redis-starter</name>
<packaging>jar</packaging>
<url>https://github.com/Trendyol/Jdempotent/tree/master/Jdempotent-spring-boot-redis-starter</url>
Expand Down Expand Up @@ -54,7 +54,7 @@
<dependency>
<groupId>com.trendyol</groupId>
<artifactId>Jdempotent-core</artifactId>
<version>1.0.9</version>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
Expand Down
2 changes: 1 addition & 1 deletion examples/jdempotent-couchbase-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<dependency>
<groupId>com.trendyol</groupId>
<artifactId>Jdempotent-spring-boot-couchbase-starter</artifactId>
<version>1.0.9</version>
<version>1.0.10</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion examples/jdempotent-redis-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<dependency>
<groupId>com.trendyol</groupId>
<artifactId>Jdempotent-spring-boot-redis-starter</artifactId>
<version>1.0.9</version>
<version>1.0.10</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.trendyol.jdempotent.core.annotation.IdempotentRequestPayload;
import com.trendyol.jdempotent.core.annotation.JdempotentRequestPayload;
import javax.mail.MessagingException;
import java.util.concurrent.TimeUnit;
import org.springframework.web.bind.annotation.RequestHeader;
Expand Down Expand Up @@ -47,7 +47,7 @@ public ResponseEntity<SendEmailResponse> sendEmail(@RequestBody SendEmailRequest

@PostMapping("/send-email-header")
@IdempotentResource(cachePrefix = "MailController.sendEmail")
public ResponseEntity<SendEmailResponse> sendEmail(@IdempotentRequestPayload @RequestHeader("x-idempotency-key") String idempotencyKey, @RequestBody SendEmailRequest request) {
public ResponseEntity<SendEmailResponse> sendEmail(@JdempotentRequestPayload @RequestHeader("x-idempotency-key") String idempotencyKey, @RequestBody SendEmailRequest request) {
if (StringUtils.isEmpty(request.getEmail())) {
throw new InvalidEmailAddressException();
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.trendyol</groupId>
<artifactId>jdempotent</artifactId>
<packaging>pom</packaging>
<version>1.0.9</version>
<version>1.0.10</version>
<name>Jdempotent</name>
<url>https://github.com/Trendyol/Jdempotent</url>
<description>Jdempotent</description>
Expand Down

0 comments on commit b468585

Please sign in to comment.