Skip to content

Commit

Permalink
Start building against Spring Data Kay SR4 snapshots
Browse files Browse the repository at this point in the history
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 spring-projectsgh-11884
Closes spring-projectsgh-11855
  • Loading branch information
wilkinsona committed Feb 2, 2018
1 parent 9a87424 commit 00489c7
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
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;
Expand Down Expand Up @@ -160,8 +162,12 @@ public void testRedisConfigurationWithSentinel() {
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
Expand All @@ -170,9 +176,15 @@ public void testRedisConfigurationWithSentinelAndPassword() {
.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
Expand All @@ -194,4 +206,29 @@ JedisClientConfigurationBuilderCustomizer customizer() {

}

@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;
}

}

}
2 changes: 1 addition & 1 deletion spring-boot-project/spring-boot-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
<spring-amqp.version>2.0.2.RELEASE</spring-amqp.version>
<spring-batch.version>4.0.0.RELEASE</spring-batch.version>
<spring-cloud-connectors.version>2.0.1.RELEASE</spring-cloud-connectors.version>
<spring-data-releasetrain.version>Kay-SR3</spring-data-releasetrain.version>
<spring-data-releasetrain.version>Kay-BUILD-SNAPSHOT</spring-data-releasetrain.version>
<spring-hateoas.version>0.24.0.RELEASE</spring-hateoas.version>
<spring-integration.version>5.0.1.RELEASE</spring-integration.version>
<spring-kafka.version>2.1.2.RELEASE</spring-kafka.version>
Expand Down

0 comments on commit 00489c7

Please sign in to comment.