mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Run cache smoke tests against all cache providers
Closes gh-31137
This commit is contained in:
parent
6efa77f3f5
commit
329fa8d37d
@ -5,32 +5,21 @@ plugins {
|
|||||||
|
|
||||||
description = "Spring Boot cache smoke test"
|
description = "Spring Boot cache smoke test"
|
||||||
|
|
||||||
def caches = [
|
sourceSets {
|
||||||
"caffeine": [
|
redisTest {
|
||||||
"com.github.ben-manes.caffeine:caffeine"
|
compileClasspath += sourceSets.main.output
|
||||||
],
|
runtimeClasspath += sourceSets.main.output
|
||||||
"couchbase": [
|
}
|
||||||
project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-couchbase")
|
}
|
||||||
],
|
|
||||||
"ehcache": [
|
configurations {
|
||||||
"javax.cache:cache-api",
|
caffeine
|
||||||
"org.ehcache:ehcache"
|
couchbase
|
||||||
],
|
ehcache
|
||||||
"ehcache2": [
|
ehcache2
|
||||||
"net.sf.ehcache:ehcache"
|
hazelcast
|
||||||
],
|
infinispan
|
||||||
"hazelcast": [
|
}
|
||||||
"com.hazelcast:hazelcast",
|
|
||||||
"com.hazelcast:hazelcast-spring"
|
|
||||||
],
|
|
||||||
"infinispan": [
|
|
||||||
"org.infinispan:infinispan-jcache",
|
|
||||||
"org.infinispan:infinispan-spring5-embedded"
|
|
||||||
],
|
|
||||||
"redis": [
|
|
||||||
project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-redis")
|
|
||||||
]
|
|
||||||
]
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator"))
|
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator"))
|
||||||
@ -39,7 +28,73 @@ dependencies {
|
|||||||
|
|
||||||
testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
|
testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
|
||||||
|
|
||||||
if (project.hasProperty("cache")) {
|
caffeine(enforcedPlatform(project(":spring-boot-project:spring-boot-dependencies")))
|
||||||
caches[project.getProperty("cache")].each { runtimeOnly it }
|
caffeine("com.github.ben-manes.caffeine:caffeine")
|
||||||
|
|
||||||
|
couchbase(enforcedPlatform(project(":spring-boot-project:spring-boot-dependencies")))
|
||||||
|
couchbase(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-couchbase"))
|
||||||
|
|
||||||
|
ehcache(enforcedPlatform(project(":spring-boot-project:spring-boot-dependencies")))
|
||||||
|
ehcache("javax.cache:cache-api")
|
||||||
|
ehcache("org.ehcache:ehcache")
|
||||||
|
ehcache2(enforcedPlatform(project(":spring-boot-project:spring-boot-dependencies")))
|
||||||
|
ehcache2("net.sf.ehcache:ehcache")
|
||||||
|
|
||||||
|
hazelcast(enforcedPlatform(project(":spring-boot-project:spring-boot-dependencies")))
|
||||||
|
hazelcast("com.hazelcast:hazelcast")
|
||||||
|
hazelcast("com.hazelcast:hazelcast-spring")
|
||||||
|
|
||||||
|
infinispan(enforcedPlatform(project(":spring-boot-project:spring-boot-dependencies")))
|
||||||
|
infinispan("javax.cache:cache-api")
|
||||||
|
infinispan("org.infinispan:infinispan-jcache")
|
||||||
|
infinispan("org.infinispan:infinispan-spring5-embedded")
|
||||||
|
|
||||||
|
redisTestImplementation(enforcedPlatform(project(":spring-boot-project:spring-boot-parent")))
|
||||||
|
redisTestImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-redis"))
|
||||||
|
redisTestImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
|
||||||
|
redisTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
|
||||||
|
redisTestImplementation("org.testcontainers:testcontainers")
|
||||||
|
redisTestImplementation("org.testcontainers:junit-jupiter")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def testCaffeine = tasks.register("testCaffeine", Test) {
|
||||||
|
description = "Runs the tests against Caffeine"
|
||||||
|
classpath = sourceSets.test.runtimeClasspath + configurations.caffeine
|
||||||
|
}
|
||||||
|
|
||||||
|
def testCouchbase = tasks.register("testCouchbase", Test) {
|
||||||
|
description = "Runs the tests against Couchbase"
|
||||||
|
classpath = sourceSets.test.runtimeClasspath + configurations.couchbase
|
||||||
|
}
|
||||||
|
|
||||||
|
def testEhcache = tasks.register("testEhcache", Test) {
|
||||||
|
description = "Runs the tests against Ehcache"
|
||||||
|
classpath = sourceSets.test.runtimeClasspath + configurations.ehcache
|
||||||
|
systemProperties = ["spring.cache.jcache.config" : "classpath:ehcache3.xml"]
|
||||||
|
}
|
||||||
|
|
||||||
|
def testEhcache2 = tasks.register("testEhcache2", Test) {
|
||||||
|
description = "Runs the tests against Ehcache2"
|
||||||
|
classpath = sourceSets.test.runtimeClasspath + configurations.ehcache2
|
||||||
|
}
|
||||||
|
|
||||||
|
def testHazelcast = tasks.register("testHazelcast", Test) {
|
||||||
|
description = "Runs the tests against Hazelcast"
|
||||||
|
classpath = sourceSets.test.runtimeClasspath + configurations.hazelcast
|
||||||
|
}
|
||||||
|
|
||||||
|
def testInfinispan = tasks.register("testInfinispan", Test) {
|
||||||
|
description = "Runs the tests against Infinispan"
|
||||||
|
classpath = sourceSets.test.runtimeClasspath + configurations.infinispan
|
||||||
|
systemProperties = ["spring.cache.jcache.config" : "classpath:infinispan.xml"]
|
||||||
|
}
|
||||||
|
|
||||||
|
def testRedis = tasks.register("testRedis", Test) {
|
||||||
|
description = "Runs the tests against Redis"
|
||||||
|
classpath = sourceSets.redisTest.runtimeClasspath
|
||||||
|
testClassesDirs = sourceSets.redisTest.output.classesDirs
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named("check").configure {
|
||||||
|
dependsOn testCaffeine, testCouchbase, testEhcache, testEhcache2, testHazelcast, testInfinispan, testRedis
|
||||||
}
|
}
|
@ -1,3 +1 @@
|
|||||||
management.endpoints.web.exposure.include=*
|
management.endpoints.web.exposure.include=*
|
||||||
|
|
||||||
spring.cache.jcache.config=classpath:ehcache3.xml
|
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<infinispan>
|
||||||
|
|
||||||
|
<!-- ************************************** -->
|
||||||
|
<!-- Corresponds to @Cacheable("cache-name") -->
|
||||||
|
<!-- ************************************** -->
|
||||||
|
<cache-container default-cache="countries">
|
||||||
|
<local-cache name="countries"/>
|
||||||
|
</cache-container>
|
||||||
|
|
||||||
|
</infinispan>
|
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2022 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.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package smoketest.cache;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.testcontainers.junit.jupiter.Container;
|
||||||
|
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.boot.testsupport.testcontainers.RedisContainer;
|
||||||
|
import org.springframework.cache.Cache;
|
||||||
|
import org.springframework.cache.CacheManager;
|
||||||
|
import org.springframework.test.context.DynamicPropertyRegistry;
|
||||||
|
import org.springframework.test.context.DynamicPropertySource;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@Testcontainers(disabledWithoutDocker = true)
|
||||||
|
class SampleCacheApplicationRedisTests {
|
||||||
|
|
||||||
|
@Container
|
||||||
|
private static final RedisContainer redis = new RedisContainer();
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CacheManager cacheManager;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CountryRepository countryRepository;
|
||||||
|
|
||||||
|
@DynamicPropertySource
|
||||||
|
static void redisProperties(DynamicPropertyRegistry properties) {
|
||||||
|
properties.add("spring.redis.url",
|
||||||
|
() -> "redis://" + redis.getContainerIpAddress() + ":" + redis.getFirstMappedPort());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void validateCache() {
|
||||||
|
Cache countries = this.cacheManager.getCache("countries");
|
||||||
|
assertThat(countries).isNotNull();
|
||||||
|
countries.clear(); // Simple test assuming the cache is empty
|
||||||
|
assertThat(countries.get("BE")).isNull();
|
||||||
|
Country be = this.countryRepository.findByCode("BE");
|
||||||
|
assertThat((Country) countries.get("BE").get()).isEqualTo(be);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration>
|
||||||
|
<include resource="org/springframework/boot/logging/logback/base.xml"/>
|
||||||
|
</configuration>
|
Loading…
Reference in New Issue
Block a user