Modified usage of Redis containers for tests (#1971)

Changed CircleCI configuration to machine.  Added new build profile to skip Docker tests.
This commit is contained in:
Robert McNees
2021-11-15 14:49:16 -05:00
committed by GitHub
parent 0bf16eb12b
commit ae72a5b62b
4 changed files with 57 additions and 37 deletions

View File

@@ -1,9 +1,11 @@
version: 2
jobs:
build:
docker:
- image: springcloud/pipeline-base
user: appuser
machine:
image: ubuntu-2004:202107-02
# docker:
# - image: springcloud/pipeline-base
# user: appuser
environment:
_JAVA_OPTIONS: "-Xms1024m -Xmx2048m"
TERM: dumb
@@ -12,18 +14,18 @@ jobs:
- gh-pages # list of branches to ignore
steps:
- checkout
- restore_cache:
key: sc-config-{{ .Branch }}
# - restore_cache:
# key: sc-config-{{ .Branch }}
- run:
name: "Download dependencies"
command: ./mvnw -s .settings.xml -U --fail-never dependency:go-offline || true
- save_cache:
key: sc-config-{{ .Branch }}
paths:
- ~/.m2
# - save_cache:
# key: sc-config-{{ .Branch }}
# paths:
# - ~/.m2
- run:
name: "Running build"
command: ./mvnw -s .settings.xml clean org.jacoco:jacoco-maven-plugin:prepare-agent install -U -P sonar -nsu --batch-mode -Dmaven.test.redirectTestOutputToFile=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
command: ./mvnw -s .settings.xml clean org.jacoco:jacoco-maven-plugin:prepare-agent install -U -P sonar,withoutDockerTests -nsu --batch-mode -Dmaven.test.redirectTestOutputToFile=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
- run:
name: "Aggregate test results"
when: always

21
pom.xml
View File

@@ -30,6 +30,7 @@
<spring-cloud-commons.version>3.1.0-SNAPSHOT</spring-cloud-commons.version>
<aws-java-sdk.version>1.11.911</aws-java-sdk.version>
<google-api-services-iam.version>v1-rev20201112-1.30.10</google-api-services-iam.version>
<testcontainers.version>1.15.1</testcontainers.version>
<wiremock.version>2.31.0</wiremock.version>
<maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError>
<maven-checkstyle-plugin.failsOnViolation>true
@@ -110,6 +111,13 @@
<version>v1-rev20200210-1.30.9</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-bom</artifactId>
<version>${testcontainers.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<version>${wiremock.version}</version>
@@ -222,6 +230,19 @@
</plugins>
</build>
</profile>
<profile>
<id>withoutDockerTests</id>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludedGroups>DockerRequired</excludedGroups>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>

View File

@@ -164,9 +164,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>it.ozimov</groupId>
<artifactId>embedded-redis</artifactId>
<version>0.7.3</version>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>

View File

@@ -16,44 +16,42 @@
package org.springframework.cloud.config.server.environment;
import java.io.IOException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import redis.embedded.RedisServer;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.config.environment.Environment;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class)
@DataRedisTest(properties = "spring.redis.port=6378")
@SpringBootTest
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@ActiveProfiles("redis")
@Testcontainers
@Tag("DockerRequired")
public class RedisEnvironmentRepositoryIntegrationTests {
private RedisServer redisServer;
@Before
public void startRedis() throws IOException {
redisServer = new RedisServer(6378);
redisServer.start();
}
@After
public void stopRedis() {
redisServer.stop();
}
@Container
public static GenericContainer redisContainer = new GenericContainer<>("redis:5.0.9-alpine").withExposedPorts(6379);
@Autowired
StringRedisTemplate redis;
private StringRedisTemplate redis;
@DynamicPropertySource
static void containerProperties(DynamicPropertyRegistry registry) {
registry.add("spring.redis.host", redisContainer::getContainerIpAddress);
registry.add("spring.redis.port", redisContainer::getFirstMappedPort);
}
@Test
public void test() {