Search in sources :

Example 61 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project herd by FINRAOS.

the class PublishNotificationMessagesAdviceTest method testPublishNotificationMessagesAmazonServiceException.

@Test
public void testPublishNotificationMessagesAmazonServiceException() throws Throwable {
    // Create a notification message.
    NotificationMessage notificationMessage = new NotificationMessage(MessageTypeEntity.MessageEventTypes.SQS.name(), AWS_SQS_QUEUE_NAME, MESSAGE_TEXT, Collections.singletonList(new MessageHeader(KEY, VALUE)));
    // Mock a join point of the method call.
    ProceedingJoinPoint joinPoint = getMockedProceedingJoinPoint("testPublishNotificationMessages");
    // Mock the external calls.
    doCallRealMethod().when(notificationMessageInMemoryQueue).clear();
    doCallRealMethod().when(notificationMessageInMemoryQueue).add(notificationMessage);
    when(notificationMessageInMemoryQueue.isEmpty()).thenCallRealMethod();
    doCallRealMethod().when(notificationMessageInMemoryQueue).remove();
    doThrow(new AmazonServiceException(ERROR_MESSAGE)).when(notificationMessagePublishingService).publishNotificationMessage(notificationMessage);
    // Clear the queue.
    notificationMessageInMemoryQueue.clear();
    // Add the notification message to the queue.
    notificationMessageInMemoryQueue.add(notificationMessage);
    // Validate that the queue is not empty now.
    assertFalse(notificationMessageInMemoryQueue.isEmpty());
    // Call the method under test.
    publishNotificationMessagesAdvice.publishNotificationMessages(joinPoint);
    // Verify the external calls.
    verify(notificationMessageInMemoryQueue, times(2)).clear();
    verify(notificationMessageInMemoryQueue).add(notificationMessage);
    verify(notificationMessageInMemoryQueue, times(3)).isEmpty();
    verify(notificationMessageInMemoryQueue).remove();
    verify(notificationMessagePublishingService).publishNotificationMessage(notificationMessage);
    verify(notificationMessagePublishingService).addNotificationMessageToDatabaseQueue(notificationMessage);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertTrue(notificationMessageInMemoryQueue.isEmpty());
}
Also used : NotificationMessage(org.finra.herd.model.dto.NotificationMessage) AmazonServiceException(com.amazonaws.AmazonServiceException) MessageHeader(org.finra.herd.model.dto.MessageHeader) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 62 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project herd by FINRAOS.

the class PublishNotificationMessagesAdviceTest method testPublishNotificationMessagesDatabaseException.

@Test
public void testPublishNotificationMessagesDatabaseException() throws Throwable {
    // Create a notification message.
    NotificationMessage notificationMessage = new NotificationMessage(MessageTypeEntity.MessageEventTypes.SQS.name(), AWS_SQS_QUEUE_NAME, MESSAGE_TEXT, Collections.singletonList(new MessageHeader(KEY, VALUE)));
    // Mock a join point of the method call.
    ProceedingJoinPoint joinPoint = getMockedProceedingJoinPoint("testPublishNotificationMessages");
    // Mock the external calls.
    doCallRealMethod().when(notificationMessageInMemoryQueue).clear();
    doCallRealMethod().when(notificationMessageInMemoryQueue).add(notificationMessage);
    when(notificationMessageInMemoryQueue.isEmpty()).thenCallRealMethod();
    doCallRealMethod().when(notificationMessageInMemoryQueue).remove();
    doThrow(new AmazonServiceException(ERROR_MESSAGE)).when(notificationMessagePublishingService).publishNotificationMessage(notificationMessage);
    doThrow(new RuntimeException(ERROR_MESSAGE)).when(notificationMessagePublishingService).addNotificationMessageToDatabaseQueue(notificationMessage);
    // Clear the queue.
    notificationMessageInMemoryQueue.clear();
    // Add the notification message to the queue.
    notificationMessageInMemoryQueue.add(notificationMessage);
    // Validate that the queue is not empty now.
    assertFalse(notificationMessageInMemoryQueue.isEmpty());
    // Call the method under test.
    publishNotificationMessagesAdvice.publishNotificationMessages(joinPoint);
    // Verify the external calls.
    verify(notificationMessageInMemoryQueue, times(2)).clear();
    verify(notificationMessageInMemoryQueue).add(notificationMessage);
    verify(notificationMessageInMemoryQueue, times(3)).isEmpty();
    verify(notificationMessageInMemoryQueue).remove();
    verify(notificationMessagePublishingService).publishNotificationMessage(notificationMessage);
    verify(notificationMessagePublishingService).addNotificationMessageToDatabaseQueue(notificationMessage);
    verifyNoMoreInteractionsHelper();
    // Validate the results.
    assertTrue(notificationMessageInMemoryQueue.isEmpty());
}
Also used : NotificationMessage(org.finra.herd.model.dto.NotificationMessage) AmazonServiceException(com.amazonaws.AmazonServiceException) MessageHeader(org.finra.herd.model.dto.MessageHeader) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 63 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project spring-cloud-sleuth by spring-cloud.

the class TraceAsyncAspectTest method should_work.

// Issue#926
@Test
public void should_work() throws Throwable {
    TraceAsyncAspect asyncAspect = new TraceAsyncAspect(this.tracing.tracer(), new DefaultSpanNamer(), new TraceKeys()) {

        @Override
        String name(ProceedingJoinPoint pjp) {
            return "foo-bar";
        }
    };
    asyncAspect.traceBackgroundThread(this.point);
    BDDAssertions.then(this.reporter.getSpans()).hasSize(1);
    BDDAssertions.then(this.reporter.getSpans().get(0).name()).isEqualTo("foo-bar");
}
Also used : TraceKeys(org.springframework.cloud.sleuth.TraceKeys) DefaultSpanNamer(org.springframework.cloud.sleuth.DefaultSpanNamer) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Test(org.junit.Test)

Example 64 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project Saturn by vipshop.

the class AuditLogAspect method addAuditParamsIfPossible.

private void addAuditParamsIfPossible(ProceedingJoinPoint joinPoint) {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Annotation[][] annotations = signature.getMethod().getParameterAnnotations();
    int i = 0;
    for (Object arg : joinPoint.getArgs()) {
        for (Annotation annotation : annotations[i]) {
            if (annotation.annotationType() == AuditParam.class) {
                AuditParam auditParamAnno = (AuditParam) annotation;
                String value = auditParamAnno.value();
                if (value != null) {
                    AuditInfoContext.put(value, arg == null ? null : arg.toString());
                }
            }
        }
        i++;
    }
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) AuditParam(com.vip.saturn.job.console.aop.annotation.AuditParam) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Annotation(java.lang.annotation.Annotation)

Example 65 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project paascloud-master by paascloud.

the class MqProducerStoreAspect method processMqProducerStoreJoinPoint.

/**
 * Add exe time method object.
 *
 * @param joinPoint the join point
 *
 * @return the object
 */
@Around(value = "mqProducerStoreAnnotationPointcut()")
public Object processMqProducerStoreJoinPoint(ProceedingJoinPoint joinPoint) throws Throwable {
    log.info("processMqProducerStoreJoinPoint - 线程id={}", Thread.currentThread().getId());
    Object result;
    Object[] args = joinPoint.getArgs();
    MqProducerStore annotation = getAnnotation(joinPoint);
    MqSendTypeEnum type = annotation.sendType();
    int orderType = annotation.orderType().orderType();
    DelayLevelEnum delayLevelEnum = annotation.delayLevel();
    if (args.length == 0) {
        throw new TpcBizException(ErrorCodeEnum.TPC10050005);
    }
    MqMessageData domain = null;
    for (Object object : args) {
        if (object instanceof MqMessageData) {
            domain = (MqMessageData) object;
            break;
        }
    }
    if (domain == null) {
        throw new TpcBizException(ErrorCodeEnum.TPC10050005);
    }
    domain.setOrderType(orderType);
    domain.setProducerGroup(producerGroup);
    if (type == MqSendTypeEnum.WAIT_CONFIRM) {
        if (delayLevelEnum != DelayLevelEnum.ZERO) {
            domain.setDelayLevel(delayLevelEnum.delayLevel());
        }
        mqMessageService.saveWaitConfirmMessage(domain);
    }
    result = joinPoint.proceed();
    if (type == MqSendTypeEnum.SAVE_AND_SEND) {
        mqMessageService.saveAndSendMessage(domain);
    } else if (type == MqSendTypeEnum.DIRECT_SEND) {
        mqMessageService.directSendMessage(domain);
    } else {
        final MqMessageData finalDomain = domain;
        taskExecutor.execute(() -> mqMessageService.confirmAndSendMessage(finalDomain.getMessageKey()));
    }
    return result;
}
Also used : MqProducerStore(com.paascloud.provider.annotation.MqProducerStore) MqMessageData(com.paascloud.provider.model.domain.MqMessageData) MqSendTypeEnum(com.paascloud.provider.model.enums.MqSendTypeEnum) DelayLevelEnum(com.paascloud.provider.model.enums.DelayLevelEnum) TpcBizException(com.paascloud.provider.exceptions.TpcBizException) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Around(org.aspectj.lang.annotation.Around)

Aggregations

ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)77 Around (org.aspectj.lang.annotation.Around)32 MethodSignature (org.aspectj.lang.reflect.MethodSignature)16 Method (java.lang.reflect.Method)14 Test (org.junit.Test)14 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)10 SimpleDateFormat (java.text.SimpleDateFormat)8 ArrayList (java.util.ArrayList)8 JoinPoint (org.aspectj.lang.JoinPoint)8 FaseDTO (com.tomasio.projects.trainning.dto.FaseDTO)7 OrganizacaoDTO (com.tomasio.projects.trainning.dto.OrganizacaoDTO)7 PessoaDTO (com.tomasio.projects.trainning.dto.PessoaDTO)7 MockProceedingJoinPoint (org.finra.herd.core.MockProceedingJoinPoint)7 Annotation (java.lang.annotation.Annotation)5 CancelamentoMatriculaDTO (com.tomasio.projects.trainning.dto.CancelamentoMatriculaDTO)4 MatriculaDTO (com.tomasio.projects.trainning.dto.MatriculaDTO)4 Date (java.util.Date)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Action (org.apache.nifi.action.Action)4 MessageHeader (org.finra.herd.model.dto.MessageHeader)4