#190 - More simplifications for Spring Boot 1.4 M3.
Replaced all occurrences of @SpringApplicationConfiguration with @SpringBootTest. Using SpringRunner instead of @SpringJUnit4ClassRunner now.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,9 +30,10 @@ import org.springframework.util.StopWatch;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Configuration
|
||||
public class RedisSentinelApplicationConfig {
|
||||
public class RedisSentinelApplication {
|
||||
|
||||
static final RedisSentinelConfiguration SENTINEL_CONFIG = new RedisSentinelConfiguration().master("mymaster") //
|
||||
.sentinel("localhost", 26379) //
|
||||
@@ -43,14 +44,9 @@ public class RedisSentinelApplicationConfig {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
ApplicationContext context = SpringApplication.run(RedisSentinelApplicationConfig.class, args);
|
||||
|
||||
RedisConnectionFactory factory = context.getBean(RedisConnectionFactory.class);
|
||||
|
||||
StringRedisTemplate template = new StringRedisTemplate();
|
||||
template.setConnectionFactory(factory);
|
||||
template.afterPropertiesSet();
|
||||
ApplicationContext context = SpringApplication.run(RedisSentinelApplication.class, args);
|
||||
|
||||
StringRedisTemplate template = context.getBean(StringRedisTemplate.class);
|
||||
template.opsForValue().set("loop-forever", "0");
|
||||
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
@@ -58,10 +54,13 @@ public class RedisSentinelApplicationConfig {
|
||||
while (true) {
|
||||
|
||||
try {
|
||||
|
||||
String value = "IT:= " + template.opsForValue().increment("loop-forever", 1);
|
||||
printBackFromErrorStateInfoIfStopWatchIsRunning(stopWatch);
|
||||
System.out.println(value);
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
|
||||
System.err.println(e.getCause().getMessage());
|
||||
startStopWatchIfNotRunning(stopWatch);
|
||||
}
|
||||
@@ -70,21 +69,22 @@ public class RedisSentinelApplicationConfig {
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RedisConnectionFactory connectionFactory() {
|
||||
public @Bean StringRedisTemplate redisTemplate() {
|
||||
return new StringRedisTemplate(connectionFactory());
|
||||
}
|
||||
|
||||
public @Bean RedisConnectionFactory connectionFactory() {
|
||||
return new JedisConnectionFactory(sentinelConfig());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RedisSentinelConfiguration sentinelConfig() {
|
||||
public @Bean RedisSentinelConfiguration sentinelConfig() {
|
||||
return SENTINEL_CONFIG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear database before shut down.
|
||||
*/
|
||||
@PreDestroy
|
||||
public void flushTestDb() {
|
||||
public @PreDestroy void flushTestDb() {
|
||||
factory.getConnection().flushDb();
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
logging.level.root=INFO
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d %5p %40.40c:%4L - %m%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,15 +18,13 @@ package example.springdata.redis;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@Configuration
|
||||
@EnableAutoConfiguration
|
||||
@SpringBootApplication
|
||||
public class RedisTestConfiguration {
|
||||
|
||||
@Autowired RedisConnectionFactory factory;
|
||||
@@ -34,8 +32,7 @@ public class RedisTestConfiguration {
|
||||
/**
|
||||
* Clear database before shut down.
|
||||
*/
|
||||
@PreDestroy
|
||||
public void flushTestDb() {
|
||||
public @PreDestroy void flushTestDb() {
|
||||
factory.getConnection().flushDb();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package example.springdata.redis.commands;
|
||||
|
||||
import example.springdata.redis.test.util.RequiresRedisServer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@@ -24,25 +26,22 @@ import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.data.redis.connection.RedisConnection;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import example.springdata.redis.RedisTestConfiguration;
|
||||
import example.springdata.redis.test.util.RequiresRedisServer;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Show usage of operations on redis keys using low level API provided by {@link RedisConnection}.
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { RedisTestConfiguration.class })
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootApplication
|
||||
public class KeyOperationsTests {
|
||||
|
||||
// we only want to run this tests when redis is up an running
|
||||
|
||||
1
redis/example/src/test/resources/application.properties
Normal file
1
redis/example/src/test/resources/application.properties
Normal file
@@ -0,0 +1 @@
|
||||
logging.level.root=WARN
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d %5p %40.40c:%4L - %m%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="warn">
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
@@ -35,7 +35,7 @@ import org.junit.Test;
|
||||
import org.junit.rules.RuleChain;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -49,7 +49,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = ApplicationConfiguration.class)
|
||||
@SpringBootTest(classes = ApplicationConfiguration.class)
|
||||
public class PersonRepositoryTests<K, V> {
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user