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());
}
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());
}
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");
}
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++;
}
}
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;
}
Aggregations