Skip to content

Commit

Permalink
GH-1494: Fix Test Harness with @repeatable
Browse files Browse the repository at this point in the history
Resolves #1494

Capture mode failed to capture arguments/result/exception if multiple
`@RabbitListener` annotations present.

**cherry-pick to 2.4.x**
  • Loading branch information
garyrussell authored and artembilan committed Aug 29, 2022
1 parent 97644e9 commit ab3eb36
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 the original author or authors.
* Copyright 2016-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,7 +41,7 @@
import org.springframework.amqp.rabbit.test.mockito.LatchCountDownAndCallRealMethodAnswer;
import org.springframework.aop.framework.ProxyFactoryBean;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.annotation.MergedAnnotations;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.test.util.AopTestUtils;
import org.springframework.util.Assert;
Expand Down Expand Up @@ -172,9 +172,9 @@ private static final class CaptureAdvice implements MethodInterceptor {

@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
boolean isListenerMethod =
AnnotationUtils.findAnnotation(invocation.getMethod(), RabbitListener.class) != null
|| AnnotationUtils.findAnnotation(invocation.getMethod(), RabbitHandler.class) != null;
MergedAnnotations annotations = MergedAnnotations.from(invocation.getMethod());
boolean isListenerMethod = annotations.isPresent(RabbitListener.class)
|| annotations.isPresent(RabbitHandler.class);
try {
Object result = invocation.proceed();
if (isListenerMethod) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 the original author or authors.
* Copyright 2016-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -139,6 +139,11 @@ public Queue queue2() {
return new AnonymousQueue();
}

@Bean
public Queue queue3() {
return new AnonymousQueue();
}

@Bean
public RabbitAdmin admin(ConnectionFactory cf) {
return new RabbitAdmin(cf);
Expand Down Expand Up @@ -168,6 +173,7 @@ public String foo(String foo) {
}

@RabbitListener(id = "bar", queues = "#{queue2.name}")
@RabbitListener(id = "bar2", queues = "#{queue3.name}")
public void foo(@Payload String foo, @Header("amqp_receivedRoutingKey") String rk) {
if (!failed && foo.equals("ex")) {
failed = true;
Expand Down

0 comments on commit ab3eb36

Please sign in to comment.