Skip to content

Commit ab3eb36

Browse files
garyrussellartembilan
authored andcommitted
GH-1494: Fix Test Harness with @repeatable
Resolves #1494 Capture mode failed to capture arguments/result/exception if multiple `@RabbitListener` annotations present. **cherry-pick to 2.4.x**
1 parent 97644e9 commit ab3eb36

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

spring-rabbit-test/src/main/java/org/springframework/amqp/rabbit/test/RabbitListenerTestHarness.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,7 +41,7 @@
4141
import org.springframework.amqp.rabbit.test.mockito.LatchCountDownAndCallRealMethodAnswer;
4242
import org.springframework.aop.framework.ProxyFactoryBean;
4343
import org.springframework.core.annotation.AnnotationAttributes;
44-
import org.springframework.core.annotation.AnnotationUtils;
44+
import org.springframework.core.annotation.MergedAnnotations;
4545
import org.springframework.core.type.AnnotationMetadata;
4646
import org.springframework.test.util.AopTestUtils;
4747
import org.springframework.util.Assert;
@@ -172,9 +172,9 @@ private static final class CaptureAdvice implements MethodInterceptor {
172172

173173
@Override
174174
public Object invoke(MethodInvocation invocation) throws Throwable {
175-
boolean isListenerMethod =
176-
AnnotationUtils.findAnnotation(invocation.getMethod(), RabbitListener.class) != null
177-
|| AnnotationUtils.findAnnotation(invocation.getMethod(), RabbitHandler.class) != null;
175+
MergedAnnotations annotations = MergedAnnotations.from(invocation.getMethod());
176+
boolean isListenerMethod = annotations.isPresent(RabbitListener.class)
177+
|| annotations.isPresent(RabbitHandler.class);
178178
try {
179179
Object result = invocation.proceed();
180180
if (isListenerMethod) {

spring-rabbit-test/src/test/java/org/springframework/amqp/rabbit/test/examples/ExampleRabbitListenerCaptureTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -139,6 +139,11 @@ public Queue queue2() {
139139
return new AnonymousQueue();
140140
}
141141

142+
@Bean
143+
public Queue queue3() {
144+
return new AnonymousQueue();
145+
}
146+
142147
@Bean
143148
public RabbitAdmin admin(ConnectionFactory cf) {
144149
return new RabbitAdmin(cf);
@@ -168,6 +173,7 @@ public String foo(String foo) {
168173
}
169174

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

0 commit comments

Comments
 (0)