|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2021 the original author or authors.
|
|
|
|
* Copyright 2012-2022 the original author or authors.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
@ -84,9 +84,9 @@ import static org.mockito.ArgumentMatchers.anyString;
|
|
|
|
import static org.mockito.ArgumentMatchers.eq;
|
|
|
|
import static org.mockito.ArgumentMatchers.eq;
|
|
|
|
import static org.mockito.ArgumentMatchers.isNull;
|
|
|
|
import static org.mockito.ArgumentMatchers.isNull;
|
|
|
|
import static org.mockito.BDDMockito.given;
|
|
|
|
import static org.mockito.BDDMockito.given;
|
|
|
|
|
|
|
|
import static org.mockito.BDDMockito.then;
|
|
|
|
import static org.mockito.Mockito.inOrder;
|
|
|
|
import static org.mockito.Mockito.inOrder;
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
import static org.mockito.Mockito.verify;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Tests for {@link RabbitAutoConfiguration}.
|
|
|
|
* Tests for {@link RabbitAutoConfiguration}.
|
|
|
@ -179,10 +179,10 @@ class RabbitAutoConfigurationTests {
|
|
|
|
given(rcf.newConnection(isNull(), eq(addresses), anyString())).willReturn(mock(Connection.class));
|
|
|
|
given(rcf.newConnection(isNull(), eq(addresses), anyString())).willReturn(mock(Connection.class));
|
|
|
|
ReflectionTestUtils.setField(connectionFactory, "rabbitConnectionFactory", rcf);
|
|
|
|
ReflectionTestUtils.setField(connectionFactory, "rabbitConnectionFactory", rcf);
|
|
|
|
connectionFactory.createConnection();
|
|
|
|
connectionFactory.createConnection();
|
|
|
|
verify(rcf).newConnection(isNull(), eq(addresses), eq("test#0"));
|
|
|
|
then(rcf).should().newConnection(isNull(), eq(addresses), eq("test#0"));
|
|
|
|
connectionFactory.resetConnection();
|
|
|
|
connectionFactory.resetConnection();
|
|
|
|
connectionFactory.createConnection();
|
|
|
|
connectionFactory.createConnection();
|
|
|
|
verify(rcf).newConnection(isNull(), eq(addresses), eq("test#1"));
|
|
|
|
then(rcf).should().newConnection(isNull(), eq(addresses), eq("test#1"));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -360,10 +360,11 @@ class RabbitAutoConfigurationTests {
|
|
|
|
RabbitTemplate template = mock(RabbitTemplate.class);
|
|
|
|
RabbitTemplate template = mock(RabbitTemplate.class);
|
|
|
|
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
|
|
|
ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
|
|
|
|
configurer.configure(template, connectionFactory);
|
|
|
|
configurer.configure(template, connectionFactory);
|
|
|
|
verify(template).setMessageConverter(context.getBean("myMessageConverter", MessageConverter.class));
|
|
|
|
then(template).should()
|
|
|
|
verify(template).setExchange("my-exchange");
|
|
|
|
.setMessageConverter(context.getBean("myMessageConverter", MessageConverter.class));
|
|
|
|
verify(template).setRoutingKey("my-routing-key");
|
|
|
|
then(template).should().setExchange("my-exchange");
|
|
|
|
verify(template).setDefaultReceiveQueue("default-queue");
|
|
|
|
then(template).should().setRoutingKey("my-routing-key");
|
|
|
|
|
|
|
|
then(template).should().setDefaultReceiveQueue("default-queue");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -434,7 +435,7 @@ class RabbitAutoConfigurationTests {
|
|
|
|
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = context
|
|
|
|
SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = context
|
|
|
|
.getBean("rabbitListenerContainerFactory", SimpleRabbitListenerContainerFactory.class);
|
|
|
|
.getBean("rabbitListenerContainerFactory", SimpleRabbitListenerContainerFactory.class);
|
|
|
|
rabbitListenerContainerFactory.setBatchSize(10);
|
|
|
|
rabbitListenerContainerFactory.setBatchSize(10);
|
|
|
|
verify(rabbitListenerContainerFactory).setBatchSize(10);
|
|
|
|
then(rabbitListenerContainerFactory).should().setBatchSize(10);
|
|
|
|
assertThat(rabbitListenerContainerFactory.getAdviceChain()).isNull();
|
|
|
|
assertThat(rabbitListenerContainerFactory.getAdviceChain()).isNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -554,9 +555,9 @@ class RabbitAutoConfigurationTests {
|
|
|
|
.getBean(SimpleRabbitListenerContainerFactoryConfigurer.class);
|
|
|
|
.getBean(SimpleRabbitListenerContainerFactoryConfigurer.class);
|
|
|
|
SimpleRabbitListenerContainerFactory factory = mock(SimpleRabbitListenerContainerFactory.class);
|
|
|
|
SimpleRabbitListenerContainerFactory factory = mock(SimpleRabbitListenerContainerFactory.class);
|
|
|
|
configurer.configure(factory, mock(ConnectionFactory.class));
|
|
|
|
configurer.configure(factory, mock(ConnectionFactory.class));
|
|
|
|
verify(factory).setConcurrentConsumers(5);
|
|
|
|
then(factory).should().setConcurrentConsumers(5);
|
|
|
|
verify(factory).setMaxConcurrentConsumers(10);
|
|
|
|
then(factory).should().setMaxConcurrentConsumers(10);
|
|
|
|
verify(factory).setPrefetchCount(40);
|
|
|
|
then(factory).should().setPrefetchCount(40);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -568,7 +569,7 @@ class RabbitAutoConfigurationTests {
|
|
|
|
.getBean(SimpleRabbitListenerContainerFactoryConfigurer.class);
|
|
|
|
.getBean(SimpleRabbitListenerContainerFactoryConfigurer.class);
|
|
|
|
SimpleRabbitListenerContainerFactory factory = mock(SimpleRabbitListenerContainerFactory.class);
|
|
|
|
SimpleRabbitListenerContainerFactory factory = mock(SimpleRabbitListenerContainerFactory.class);
|
|
|
|
configurer.configure(factory, mock(ConnectionFactory.class));
|
|
|
|
configurer.configure(factory, mock(ConnectionFactory.class));
|
|
|
|
verify(factory).setConsumerBatchEnabled(true);
|
|
|
|
then(factory).should().setConsumerBatchEnabled(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -583,9 +584,9 @@ class RabbitAutoConfigurationTests {
|
|
|
|
.getBean(DirectRabbitListenerContainerFactoryConfigurer.class);
|
|
|
|
.getBean(DirectRabbitListenerContainerFactoryConfigurer.class);
|
|
|
|
DirectRabbitListenerContainerFactory factory = mock(DirectRabbitListenerContainerFactory.class);
|
|
|
|
DirectRabbitListenerContainerFactory factory = mock(DirectRabbitListenerContainerFactory.class);
|
|
|
|
configurer.configure(factory, mock(ConnectionFactory.class));
|
|
|
|
configurer.configure(factory, mock(ConnectionFactory.class));
|
|
|
|
verify(factory).setConsumersPerQueue(5);
|
|
|
|
then(factory).should().setConsumersPerQueue(5);
|
|
|
|
verify(factory).setPrefetchCount(40);
|
|
|
|
then(factory).should().setPrefetchCount(40);
|
|
|
|
verify(factory).setDeBatchingEnabled(false);
|
|
|
|
then(factory).should().setDeBatchingEnabled(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -608,7 +609,7 @@ class RabbitAutoConfigurationTests {
|
|
|
|
Message message = mock(Message.class);
|
|
|
|
Message message = mock(Message.class);
|
|
|
|
Exception ex = new Exception("test");
|
|
|
|
Exception ex = new Exception("test");
|
|
|
|
mir.recover(new Object[] { "foo", message }, ex);
|
|
|
|
mir.recover(new Object[] { "foo", message }, ex);
|
|
|
|
verify(messageRecoverer).recover(message, ex);
|
|
|
|
then(messageRecoverer).should().recover(message, ex);
|
|
|
|
RetryTemplate retryTemplate = (RetryTemplate) ReflectionTestUtils.getField(advice, "retryOperations");
|
|
|
|
RetryTemplate retryTemplate = (RetryTemplate) ReflectionTestUtils.getField(advice, "retryOperations");
|
|
|
|
assertThat(retryTemplate).isNotNull();
|
|
|
|
assertThat(retryTemplate).isNotNull();
|
|
|
|
SimpleRetryPolicy retryPolicy = (SimpleRetryPolicy) ReflectionTestUtils.getField(retryTemplate, "retryPolicy");
|
|
|
|
SimpleRetryPolicy retryPolicy = (SimpleRetryPolicy) ReflectionTestUtils.getField(retryTemplate, "retryPolicy");
|
|
|
@ -849,8 +850,8 @@ class RabbitAutoConfigurationTests {
|
|
|
|
ConnectionFactoryCustomizer.class);
|
|
|
|
ConnectionFactoryCustomizer.class);
|
|
|
|
InOrder inOrder = inOrder(firstCustomizer, secondCustomizer);
|
|
|
|
InOrder inOrder = inOrder(firstCustomizer, secondCustomizer);
|
|
|
|
com.rabbitmq.client.ConnectionFactory targetConnectionFactory = getTargetConnectionFactory(context);
|
|
|
|
com.rabbitmq.client.ConnectionFactory targetConnectionFactory = getTargetConnectionFactory(context);
|
|
|
|
inOrder.verify(firstCustomizer).customize(targetConnectionFactory);
|
|
|
|
then(firstCustomizer).should(inOrder).customize(targetConnectionFactory);
|
|
|
|
inOrder.verify(secondCustomizer).customize(targetConnectionFactory);
|
|
|
|
then(secondCustomizer).should(inOrder).customize(targetConnectionFactory);
|
|
|
|
inOrder.verifyNoMoreInteractions();
|
|
|
|
inOrder.verifyNoMoreInteractions();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -859,7 +860,7 @@ class RabbitAutoConfigurationTests {
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
void whenASimpleContainerCustomizerIsDefinedThenItIsCalledToConfigureTheContainer() {
|
|
|
|
void whenASimpleContainerCustomizerIsDefinedThenItIsCalledToConfigureTheContainer() {
|
|
|
|
this.contextRunner.withUserConfiguration(SimpleContainerCustomizerConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(SimpleContainerCustomizerConfiguration.class)
|
|
|
|
.run((context) -> verify(context.getBean(ContainerCustomizer.class))
|
|
|
|
.run((context) -> then(context.getBean(ContainerCustomizer.class)).should()
|
|
|
|
.configure(any(SimpleMessageListenerContainer.class)));
|
|
|
|
.configure(any(SimpleMessageListenerContainer.class)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -868,7 +869,7 @@ class RabbitAutoConfigurationTests {
|
|
|
|
void whenADirectContainerCustomizerIsDefinedThenItIsCalledToConfigureTheContainer() {
|
|
|
|
void whenADirectContainerCustomizerIsDefinedThenItIsCalledToConfigureTheContainer() {
|
|
|
|
this.contextRunner.withUserConfiguration(DirectContainerCustomizerConfiguration.class)
|
|
|
|
this.contextRunner.withUserConfiguration(DirectContainerCustomizerConfiguration.class)
|
|
|
|
.withPropertyValues("spring.rabbitmq.listener.type:direct")
|
|
|
|
.withPropertyValues("spring.rabbitmq.listener.type:direct")
|
|
|
|
.run((context) -> verify(context.getBean(ContainerCustomizer.class))
|
|
|
|
.run((context) -> then(context.getBean(ContainerCustomizer.class)).should()
|
|
|
|
.configure(any(DirectMessageListenerContainer.class)));
|
|
|
|
.configure(any(DirectMessageListenerContainer.class)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|