Skip to content

Commit c8b09dc

Browse files
LeonardoFerreiraaartembilan
authored andcommitted
Add checkConf&Returns into RoutingCF.addTargetCF
When only `AbstractRoutingConnectionFactory.addTargetConnectionFactory()` is used, the `AbstractRoutingConnectionFactory.afterPropertiesSet()` throw an `java.lang.IllegalArgumentException: At least one target factory (or default) is required` because the property `confirms` is `null` (the method `addTargetConnectionFactory` doesn't call `checkConfirmsAndReturns` that fill this field). * add `checkConfirmsAndReturns` into the `AbstractRoutingConnectionFactory .addTargetConnectionFactory()` * using `assertThatNoException()` instead of `catch/fail` **Cherry-pick to `2.4.x` & `2.3.x`**
1 parent c09da5f commit c8b09dc

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/AbstractRoutingConnectionFactory.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-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.
@@ -34,6 +34,7 @@
3434
* @author Artem Bilan
3535
* @author Josh Chappelle
3636
* @author Gary Russell
37+
* @author Leonardo Ferreira
3738
* @since 1.3
3839
*/
3940
public abstract class AbstractRoutingConnectionFactory implements ConnectionFactory, RoutingConnectionFactory,
@@ -238,6 +239,8 @@ protected void addTargetConnectionFactory(Object key, ConnectionFactory connecti
238239
for (ConnectionListener listener : this.connectionListeners) {
239240
connectionFactory.addConnectionListener(listener);
240241
}
242+
243+
checkConfirmsAndReturns(connectionFactory);
241244
}
242245

243246
/**

spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/RoutingConnectionFactoryTests.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-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.
@@ -17,6 +17,7 @@
1717
package org.springframework.amqp.rabbit.connection;
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
20+
import static org.assertj.core.api.Assertions.assertThatNoException;
2021
import static org.mockito.ArgumentMatchers.any;
2122
import static org.mockito.ArgumentMatchers.anyBoolean;
2223
import static org.mockito.BDDMockito.given;
@@ -51,6 +52,7 @@
5152
* @author Artem Bilan
5253
* @author Josh Chappelle
5354
* @author Gary Russell
55+
* @author Leonardo Ferreira
5456
* @since 1.3
5557
*/
5658
public class RoutingConnectionFactoryTests {
@@ -323,4 +325,19 @@ protected synchronized void redeclareElementsIfNecessary() {
323325
assertThat(SimpleResourceHolder.unbind(connectionFactory)).isEqualTo("foo");
324326
}
325327

328+
@Test
329+
void afterPropertiesSetShouldNotThrowAnyExceptionAfterAddTargetConnectionFactory() throws Exception {
330+
AbstractRoutingConnectionFactory routingFactory = new AbstractRoutingConnectionFactory() {
331+
@Override
332+
protected Object determineCurrentLookupKey() {
333+
return null;
334+
}
335+
};
336+
337+
routingFactory.addTargetConnectionFactory("1", Mockito.mock(ConnectionFactory.class));
338+
339+
assertThatNoException()
340+
.isThrownBy(routingFactory::afterPropertiesSet);
341+
}
342+
326343
}

0 commit comments

Comments
 (0)