Search in sources :

Example 61 with DirectFieldAccessor

use of org.springframework.beans.DirectFieldAccessor in project spring-boot by spring-projects.

the class RabbitAutoConfigurationTests method testRabbitTemplateMessageConverters.

@Test
public void testRabbitTemplateMessageConverters() {
    load(MessageConvertersConfiguration.class);
    RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
    assertThat(rabbitTemplate.getMessageConverter()).isSameAs(this.context.getBean("myMessageConverter"));
    DirectFieldAccessor dfa = new DirectFieldAccessor(rabbitTemplate);
    assertThat(dfa.getPropertyValue("retryTemplate")).isNull();
}
Also used : RabbitTemplate(org.springframework.amqp.rabbit.core.RabbitTemplate) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 62 with DirectFieldAccessor

use of org.springframework.beans.DirectFieldAccessor in project spring-boot by spring-projects.

the class RabbitAutoConfigurationTests method testDefaultRabbitConfiguration.

@Test
public void testDefaultRabbitConfiguration() {
    load(TestConfiguration.class);
    RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
    RabbitMessagingTemplate messagingTemplate = this.context.getBean(RabbitMessagingTemplate.class);
    CachingConnectionFactory connectionFactory = this.context.getBean(CachingConnectionFactory.class);
    DirectFieldAccessor dfa = new DirectFieldAccessor(connectionFactory);
    RabbitAdmin amqpAdmin = this.context.getBean(RabbitAdmin.class);
    assertThat(rabbitTemplate.getConnectionFactory()).isEqualTo(connectionFactory);
    assertThat(getMandatory(rabbitTemplate)).isFalse();
    assertThat(messagingTemplate.getRabbitTemplate()).isEqualTo(rabbitTemplate);
    assertThat(amqpAdmin).isNotNull();
    assertThat(connectionFactory.getHost()).isEqualTo("localhost");
    assertThat(dfa.getPropertyValue("publisherConfirms")).isEqualTo(false);
    assertThat(dfa.getPropertyValue("publisherReturns")).isEqualTo(false);
    assertThat(this.context.containsBean("rabbitListenerContainerFactory")).as("Listener container factory should be created by default").isTrue();
}
Also used : RabbitTemplate(org.springframework.amqp.rabbit.core.RabbitTemplate) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RabbitMessagingTemplate(org.springframework.amqp.rabbit.core.RabbitMessagingTemplate) CachingConnectionFactory(org.springframework.amqp.rabbit.connection.CachingConnectionFactory) RabbitAdmin(org.springframework.amqp.rabbit.core.RabbitAdmin) Test(org.junit.Test)

Example 63 with DirectFieldAccessor

use of org.springframework.beans.DirectFieldAccessor in project spring-boot by spring-projects.

the class RabbitAutoConfigurationTests method testRabbitListenerContainerFactoryBackOff.

@Test
public void testRabbitListenerContainerFactoryBackOff() {
    load(TestConfiguration5.class);
    SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = this.context.getBean("rabbitListenerContainerFactory", SimpleRabbitListenerContainerFactory.class);
    rabbitListenerContainerFactory.setTxSize(10);
    verify(rabbitListenerContainerFactory).setTxSize(10);
    DirectFieldAccessor dfa = new DirectFieldAccessor(rabbitListenerContainerFactory);
    Advice[] adviceChain = (Advice[]) dfa.getPropertyValue("adviceChain");
    assertThat(adviceChain).isNull();
}
Also used : SimpleRabbitListenerContainerFactory(org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Advice(org.aopalliance.aop.Advice) Test(org.junit.Test)

Example 64 with DirectFieldAccessor

use of org.springframework.beans.DirectFieldAccessor in project spring-boot by spring-projects.

the class RabbitAutoConfigurationTests method testRabbitListenerContainerFactoryWithCustomSettings.

@Test
public void testRabbitListenerContainerFactoryWithCustomSettings() {
    load(new Class<?>[] { MessageConvertersConfiguration.class, MessageRecoverersConfiguration.class }, "spring.rabbitmq.listener.retry.enabled:true", "spring.rabbitmq.listener.retry.maxAttempts:4", "spring.rabbitmq.listener.retry.initialInterval:2000", "spring.rabbitmq.listener.retry.multiplier:1.5", "spring.rabbitmq.listener.retry.maxInterval:5000", "spring.rabbitmq.listener.autoStartup:false", "spring.rabbitmq.listener.acknowledgeMode:manual", "spring.rabbitmq.listener.concurrency:5", "spring.rabbitmq.listener.maxConcurrency:10", "spring.rabbitmq.listener.prefetch:40", "spring.rabbitmq.listener.defaultRequeueRejected:false", "spring.rabbitmq.listener.idleEventInterval:5", "spring.rabbitmq.listener.transactionSize:20");
    SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory = this.context.getBean("rabbitListenerContainerFactory", SimpleRabbitListenerContainerFactory.class);
    DirectFieldAccessor dfa = new DirectFieldAccessor(rabbitListenerContainerFactory);
    assertThat(dfa.getPropertyValue("autoStartup")).isEqualTo(Boolean.FALSE);
    assertThat(dfa.getPropertyValue("acknowledgeMode")).isEqualTo(AcknowledgeMode.MANUAL);
    assertThat(dfa.getPropertyValue("concurrentConsumers")).isEqualTo(5);
    assertThat(dfa.getPropertyValue("maxConcurrentConsumers")).isEqualTo(10);
    assertThat(dfa.getPropertyValue("prefetchCount")).isEqualTo(40);
    assertThat(dfa.getPropertyValue("txSize")).isEqualTo(20);
    assertThat(dfa.getPropertyValue("messageConverter")).isSameAs(this.context.getBean("myMessageConverter"));
    assertThat(dfa.getPropertyValue("defaultRequeueRejected")).isEqualTo(Boolean.FALSE);
    assertThat(dfa.getPropertyValue("idleEventInterval")).isEqualTo(5L);
    Advice[] adviceChain = (Advice[]) dfa.getPropertyValue("adviceChain");
    assertThat(adviceChain).isNotNull();
    assertThat(adviceChain.length).isEqualTo(1);
    dfa = new DirectFieldAccessor(adviceChain[0]);
    MessageRecoverer messageRecoverer = this.context.getBean("myMessageRecoverer", MessageRecoverer.class);
    MethodInvocationRecoverer<?> mir = (MethodInvocationRecoverer<?>) dfa.getPropertyValue("recoverer");
    Message message = mock(Message.class);
    Exception ex = new Exception("test");
    mir.recover(new Object[] { "foo", message }, ex);
    verify(messageRecoverer).recover(message, ex);
    RetryTemplate retryTemplate = (RetryTemplate) dfa.getPropertyValue("retryOperations");
    assertThat(retryTemplate).isNotNull();
    dfa = new DirectFieldAccessor(retryTemplate);
    SimpleRetryPolicy retryPolicy = (SimpleRetryPolicy) dfa.getPropertyValue("retryPolicy");
    ExponentialBackOffPolicy backOffPolicy = (ExponentialBackOffPolicy) dfa.getPropertyValue("backOffPolicy");
    assertThat(retryPolicy.getMaxAttempts()).isEqualTo(4);
    assertThat(backOffPolicy.getInitialInterval()).isEqualTo(2000);
    assertThat(backOffPolicy.getMultiplier()).isEqualTo(1.5);
    assertThat(backOffPolicy.getMaxInterval()).isEqualTo(5000);
}
Also used : RetryTemplate(org.springframework.retry.support.RetryTemplate) MessageRecoverer(org.springframework.amqp.rabbit.retry.MessageRecoverer) Message(org.springframework.amqp.core.Message) ExponentialBackOffPolicy(org.springframework.retry.backoff.ExponentialBackOffPolicy) SimpleRabbitListenerContainerFactory(org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MethodInvocationRecoverer(org.springframework.retry.interceptor.MethodInvocationRecoverer) SimpleRetryPolicy(org.springframework.retry.policy.SimpleRetryPolicy) Advice(org.aopalliance.aop.Advice) ExpectedException(org.junit.rules.ExpectedException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Test(org.junit.Test)

Example 65 with DirectFieldAccessor

use of org.springframework.beans.DirectFieldAccessor in project spring-boot by spring-projects.

the class CacheAutoConfigurationTests method redisCacheExplicit.

@Test
public void redisCacheExplicit() {
    load(RedisCacheConfiguration.class, "spring.cache.type=redis");
    RedisCacheManager cacheManager = validateCacheManager(RedisCacheManager.class);
    assertThat(cacheManager.getCacheNames()).isEmpty();
    assertThat((Boolean) new DirectFieldAccessor(cacheManager).getPropertyValue("usePrefix")).isTrue();
}
Also used : RedisCacheManager(org.springframework.data.redis.cache.RedisCacheManager) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Aggregations

DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)95 Test (org.junit.Test)79 List (java.util.List)25 Method (java.lang.reflect.Method)16 ScheduledMethodRunnable (org.springframework.scheduling.support.ScheduledMethodRunnable)16 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)15 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)15 ScheduledTaskRegistrar (org.springframework.scheduling.config.ScheduledTaskRegistrar)15 IntervalTask (org.springframework.scheduling.config.IntervalTask)8 CronTask (org.springframework.scheduling.config.CronTask)7 DefaultMessageListenerContainer (org.springframework.jms.listener.DefaultMessageListenerContainer)5 CachingConnectionFactory (org.springframework.amqp.rabbit.connection.CachingConnectionFactory)4 DataSourceTransactionManagerAutoConfiguration (org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration)4 EmbeddedDataSourceConfiguration (org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration)4 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)4 JdbcOperations (org.springframework.jdbc.core.JdbcOperations)4 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)4 JdbcOperationsSessionRepository (org.springframework.session.jdbc.JdbcOperationsSessionRepository)4 ViewResolver (org.springframework.web.servlet.ViewResolver)4