|
|
@ -17,6 +17,7 @@
|
|
|
|
package org.springframework.boot.autoconfigure.amqp;
|
|
|
|
package org.springframework.boot.autoconfigure.amqp;
|
|
|
|
|
|
|
|
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.net.ssl.SSLContext;
|
|
|
|
import javax.net.ssl.SSLContext;
|
|
|
@ -125,6 +126,7 @@ class RabbitAutoConfigurationTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
void testConnectionFactoryWithOverrides() {
|
|
|
|
void testConnectionFactoryWithOverrides() {
|
|
|
|
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
|
|
|
.withPropertyValues("spring.rabbitmq.host:remote-server", "spring.rabbitmq.port:9000",
|
|
|
|
.withPropertyValues("spring.rabbitmq.host:remote-server", "spring.rabbitmq.port:9000",
|
|
|
@ -137,15 +139,16 @@ class RabbitAutoConfigurationTests {
|
|
|
|
assertThat(connectionFactory.getVirtualHost()).isEqualTo("/vhost");
|
|
|
|
assertThat(connectionFactory.getVirtualHost()).isEqualTo("/vhost");
|
|
|
|
com.rabbitmq.client.ConnectionFactory rcf = connectionFactory.getRabbitConnectionFactory();
|
|
|
|
com.rabbitmq.client.ConnectionFactory rcf = connectionFactory.getRabbitConnectionFactory();
|
|
|
|
assertThat(rcf.getConnectionTimeout()).isEqualTo(123);
|
|
|
|
assertThat(rcf.getConnectionTimeout()).isEqualTo(123);
|
|
|
|
assertThat((Address[]) ReflectionTestUtils.getField(connectionFactory, "addresses")).hasSize(1);
|
|
|
|
assertThat((List<Address>) ReflectionTestUtils.getField(connectionFactory, "addresses")).hasSize(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
void testConnectionFactoryWithCustomConnectionNameStrategy() {
|
|
|
|
void testConnectionFactoryWithCustomConnectionNameStrategy() {
|
|
|
|
this.contextRunner.withUserConfiguration(ConnectionNameStrategyConfiguration.class).run((context) -> {
|
|
|
|
this.contextRunner.withUserConfiguration(ConnectionNameStrategyConfiguration.class).run((context) -> {
|
|
|
|
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
|
|
|
|
CachingConnectionFactory connectionFactory = context.getBean(CachingConnectionFactory.class);
|
|
|
|
Address[] addresses = (Address[]) ReflectionTestUtils.getField(connectionFactory, "addresses");
|
|
|
|
List<Address> addresses = (List<Address>) ReflectionTestUtils.getField(connectionFactory, "addresses");
|
|
|
|
assertThat(addresses).hasSize(1);
|
|
|
|
assertThat(addresses).hasSize(1);
|
|
|
|
com.rabbitmq.client.ConnectionFactory rcf = mock(com.rabbitmq.client.ConnectionFactory.class);
|
|
|
|
com.rabbitmq.client.ConnectionFactory rcf = mock(com.rabbitmq.client.ConnectionFactory.class);
|
|
|
|
given(rcf.newConnection(isNull(), eq(addresses), anyString())).willReturn(mock(Connection.class));
|
|
|
|
given(rcf.newConnection(isNull(), eq(addresses), anyString())).willReturn(mock(Connection.class));
|
|
|
@ -363,8 +366,8 @@ class RabbitAutoConfigurationTests {
|
|
|
|
this.contextRunner.withUserConfiguration(TestConfiguration5.class).run((context) -> {
|
|
|
|
this.contextRunner.withUserConfiguration(TestConfiguration5.class).run((context) -> {
|
|
|
|
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = context
|
|
|
|
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = context
|
|
|
|
.getBean("rabbitListenerContainerFactory", SimpleRabbitListenerContainerFactory.class);
|
|
|
|
.getBean("rabbitListenerContainerFactory", SimpleRabbitListenerContainerFactory.class);
|
|
|
|
rabbitListenerContainerFactory.setTxSize(10);
|
|
|
|
rabbitListenerContainerFactory.setBatchSize(10);
|
|
|
|
verify(rabbitListenerContainerFactory).setTxSize(10);
|
|
|
|
verify(rabbitListenerContainerFactory).setBatchSize(10);
|
|
|
|
assertThat(rabbitListenerContainerFactory.getAdviceChain()).isNull();
|
|
|
|
assertThat(rabbitListenerContainerFactory.getAdviceChain()).isNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -385,7 +388,7 @@ class RabbitAutoConfigurationTests {
|
|
|
|
"spring.rabbitmq.listener.simple.prefetch:40",
|
|
|
|
"spring.rabbitmq.listener.simple.prefetch:40",
|
|
|
|
"spring.rabbitmq.listener.simple.defaultRequeueRejected:false",
|
|
|
|
"spring.rabbitmq.listener.simple.defaultRequeueRejected:false",
|
|
|
|
"spring.rabbitmq.listener.simple.idleEventInterval:5",
|
|
|
|
"spring.rabbitmq.listener.simple.idleEventInterval:5",
|
|
|
|
"spring.rabbitmq.listener.simple.transactionSize:20",
|
|
|
|
"spring.rabbitmq.listener.simple.batchSize:20",
|
|
|
|
"spring.rabbitmq.listener.simple.missingQueuesFatal:false")
|
|
|
|
"spring.rabbitmq.listener.simple.missingQueuesFatal:false")
|
|
|
|
.run((context) -> {
|
|
|
|
.run((context) -> {
|
|
|
|
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = context
|
|
|
|
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = context
|
|
|
@ -393,12 +396,23 @@ class RabbitAutoConfigurationTests {
|
|
|
|
assertThat(rabbitListenerContainerFactory).hasFieldOrPropertyWithValue("concurrentConsumers", 5);
|
|
|
|
assertThat(rabbitListenerContainerFactory).hasFieldOrPropertyWithValue("concurrentConsumers", 5);
|
|
|
|
assertThat(rabbitListenerContainerFactory).hasFieldOrPropertyWithValue("maxConcurrentConsumers",
|
|
|
|
assertThat(rabbitListenerContainerFactory).hasFieldOrPropertyWithValue("maxConcurrentConsumers",
|
|
|
|
10);
|
|
|
|
10);
|
|
|
|
assertThat(rabbitListenerContainerFactory).hasFieldOrPropertyWithValue("txSize", 20);
|
|
|
|
assertThat(rabbitListenerContainerFactory).hasFieldOrPropertyWithValue("batchSize", 20);
|
|
|
|
assertThat(rabbitListenerContainerFactory).hasFieldOrPropertyWithValue("missingQueuesFatal", false);
|
|
|
|
assertThat(rabbitListenerContainerFactory).hasFieldOrPropertyWithValue("missingQueuesFatal", false);
|
|
|
|
checkCommonProps(context, rabbitListenerContainerFactory);
|
|
|
|
checkCommonProps(context, rabbitListenerContainerFactory);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void testRabbitListenerContainerFactoryWithDeprecatedTransactionSizeStillWorks() {
|
|
|
|
|
|
|
|
this.contextRunner
|
|
|
|
|
|
|
|
.withUserConfiguration(MessageConvertersConfiguration.class, MessageRecoverersConfiguration.class)
|
|
|
|
|
|
|
|
.withPropertyValues("spring.rabbitmq.listener.simple.transactionSize:20").run((context) -> {
|
|
|
|
|
|
|
|
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = context
|
|
|
|
|
|
|
|
.getBean("rabbitListenerContainerFactory", SimpleRabbitListenerContainerFactory.class);
|
|
|
|
|
|
|
|
assertThat(rabbitListenerContainerFactory).hasFieldOrPropertyWithValue("batchSize", 20);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void testDirectRabbitListenerContainerFactoryWithCustomSettings() {
|
|
|
|
void testDirectRabbitListenerContainerFactoryWithCustomSettings() {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner
|
|
|
|