|
|
@ -78,9 +78,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}.
|
|
|
@ -90,6 +90,7 @@ import static org.mockito.Mockito.verify;
|
|
|
|
* @author Gary Russell
|
|
|
|
* @author Gary Russell
|
|
|
|
* @author HaiTao Zhang
|
|
|
|
* @author HaiTao Zhang
|
|
|
|
* @author Franjo Zilic
|
|
|
|
* @author Franjo Zilic
|
|
|
|
|
|
|
|
* @author Yanming Zhou
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ExtendWith(OutputCaptureExtension.class)
|
|
|
|
@ExtendWith(OutputCaptureExtension.class)
|
|
|
|
class RabbitAutoConfigurationTests {
|
|
|
|
class RabbitAutoConfigurationTests {
|
|
|
@ -173,10 +174,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"));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -354,10 +355,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");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -428,7 +430,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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -548,9 +550,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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -562,7 +564,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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -577,9 +579,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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -602,7 +604,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");
|
|
|
@ -843,8 +845,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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|