From 00489c74eab8532d2d83b618ddc40a86bcb27fa7 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 2 Feb 2018 09:51:49 +0000 Subject: [PATCH] Start building against Spring Data Kay SR4 snapshots The fix in Spring Data Redis for sentinel configuration means that two Jedis sentinel tests now attempt to connect to a Sentinel. As a result the tests fail. Running a Redis Sentinel in a Docker container appears to be non-trivial. As an alternative, this commit updates the tests to capture the JedisConnectionFactory prior to its initialization (which is the failure trigger) and then assert that its configuration is as expected. See gh-11884 Closes gh-11855 --- .../RedisAutoConfigurationJedisTests.java | 47 +++++++++++++++++-- .../spring-boot-dependencies/pom.xml | 2 +- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java index 9b007db40c..f00579a4cc 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java @@ -19,6 +19,8 @@ package org.springframework.boot.autoconfigure.data.redis; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions; @@ -160,8 +162,12 @@ public class RedisAutoConfigurationJedisTests { this.runner .withPropertyValues("spring.redis.sentinel.master:mymaster", "spring.redis.sentinel.nodes:127.0.0.1:26379,127.0.0.1:26380") - .run((context) -> assertThat(context.getBean(JedisConnectionFactory.class) - .isRedisSentinelAware()).isTrue()); + .withUserConfiguration(JedisConnectionFactoryCaptorConfiguration.class) + .run((context) -> { + assertThat(context).hasFailed(); + assertThat(JedisConnectionFactoryCaptor.connectionFactory + .isRedisSentinelAware()).isTrue(); + }); } @Test @@ -170,9 +176,15 @@ public class RedisAutoConfigurationJedisTests { .withPropertyValues("spring.redis.password=password", "spring.redis.sentinel.master:mymaster", "spring.redis.sentinel.nodes:127.0.0.1:26379,127.0.0.1:26380") - .run((context) -> assertThat( - context.getBean(JedisConnectionFactory.class).getPassword()) - .isEqualTo("password")); + .withUserConfiguration(JedisConnectionFactoryCaptorConfiguration.class) + .run((context) -> { + assertThat(context).hasFailed(); + assertThat(JedisConnectionFactoryCaptor.connectionFactory + .isRedisSentinelAware()).isTrue(); + assertThat( + JedisConnectionFactoryCaptor.connectionFactory.getPassword()) + .isEqualTo("password"); + }); } @Test @@ -194,4 +206,29 @@ public class RedisAutoConfigurationJedisTests { } + @Configuration + static class JedisConnectionFactoryCaptorConfiguration { + + @Bean + JedisConnectionFactoryCaptor jedisConnectionFactoryCaptor() { + return new JedisConnectionFactoryCaptor(); + } + + } + + static class JedisConnectionFactoryCaptor implements BeanPostProcessor { + + static JedisConnectionFactory connectionFactory; + + @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) + throws BeansException { + if (bean instanceof JedisConnectionFactory) { + connectionFactory = (JedisConnectionFactory) bean; + } + return bean; + } + + } + } diff --git a/spring-boot-project/spring-boot-dependencies/pom.xml b/spring-boot-project/spring-boot-dependencies/pom.xml index 6a077c764a..1e7dd646d3 100644 --- a/spring-boot-project/spring-boot-dependencies/pom.xml +++ b/spring-boot-project/spring-boot-dependencies/pom.xml @@ -144,7 +144,7 @@ 2.0.2.RELEASE 4.0.0.RELEASE 2.0.1.RELEASE - Kay-SR3 + Kay-BUILD-SNAPSHOT 0.24.0.RELEASE 5.0.1.RELEASE 2.1.2.RELEASE