Skip to content

Commit c481299

Browse files
committed
Merge branch '2.7.x'
Closes gh-31990
2 parents 05877dc + d8e6d9b commit c481299

File tree

5 files changed

+142
-29
lines changed

5 files changed

+142
-29
lines changed

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-cache/build.gradle

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,19 @@ plugins {
55

66
description = "Spring Boot cache smoke test"
77

8-
def caches = [
9-
"caffeine": [
10-
"com.github.ben-manes.caffeine:caffeine"
11-
],
12-
"couchbase": [
13-
project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-couchbase")
14-
],
15-
"ehcache": [
16-
"javax.cache:cache-api",
17-
dependencies.create("org.ehcache:ehcache") {
18-
artifact {
19-
classifier = 'jakarta'
20-
}
21-
}
22-
],
23-
"hazelcast": [
24-
"com.hazelcast:hazelcast",
25-
"com.hazelcast:hazelcast-spring"
26-
],
27-
"redis": [
28-
project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-redis")
29-
]
30-
]
8+
sourceSets {
9+
redisTest {
10+
compileClasspath += sourceSets.main.output
11+
runtimeClasspath += sourceSets.main.output
12+
}
13+
}
14+
15+
configurations {
16+
caffeine
17+
couchbase
18+
ehcache
19+
hazelcast
20+
}
3121

3222
dependencies {
3323
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator"))
@@ -36,7 +26,55 @@ dependencies {
3626

3727
testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
3828

39-
if (project.hasProperty("cache")) {
40-
caches[project.getProperty("cache")].each { runtimeOnly it }
41-
}
42-
}
29+
caffeine(enforcedPlatform(project(":spring-boot-project:spring-boot-dependencies")))
30+
caffeine("com.github.ben-manes.caffeine:caffeine")
31+
32+
couchbase(enforcedPlatform(project(":spring-boot-project:spring-boot-dependencies")))
33+
couchbase(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-couchbase"))
34+
35+
ehcache(enforcedPlatform(project(":spring-boot-project:spring-boot-dependencies")))
36+
ehcache("javax.cache:cache-api")
37+
ehcache("org.ehcache:ehcache::jakarta")
38+
39+
hazelcast(enforcedPlatform(project(":spring-boot-project:spring-boot-dependencies")))
40+
hazelcast("com.hazelcast:hazelcast")
41+
hazelcast("com.hazelcast:hazelcast-spring")
42+
43+
redisTestImplementation(enforcedPlatform(project(":spring-boot-project:spring-boot-parent")))
44+
redisTestImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-redis"))
45+
redisTestImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test"))
46+
redisTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
47+
redisTestImplementation("org.testcontainers:testcontainers")
48+
redisTestImplementation("org.testcontainers:junit-jupiter")
49+
}
50+
51+
def testCaffeine = tasks.register("testCaffeine", Test) {
52+
description = "Runs the tests against Caffeine"
53+
classpath = sourceSets.test.runtimeClasspath + configurations.caffeine
54+
}
55+
56+
def testCouchbase = tasks.register("testCouchbase", Test) {
57+
description = "Runs the tests against Couchbase"
58+
classpath = sourceSets.test.runtimeClasspath + configurations.couchbase
59+
}
60+
61+
def testEhcache = tasks.register("testEhcache", Test) {
62+
description = "Runs the tests against Ehcache"
63+
classpath = sourceSets.test.runtimeClasspath + configurations.ehcache
64+
systemProperties = ["spring.cache.jcache.config" : "classpath:ehcache3.xml"]
65+
}
66+
67+
def testHazelcast = tasks.register("testHazelcast", Test) {
68+
description = "Runs the tests against Hazelcast"
69+
classpath = sourceSets.test.runtimeClasspath + configurations.hazelcast
70+
}
71+
72+
def testRedis = tasks.register("testRedis", Test) {
73+
description = "Runs the tests against Redis"
74+
classpath = sourceSets.redisTest.runtimeClasspath
75+
testClassesDirs = sourceSets.redisTest.output.classesDirs
76+
}
77+
78+
tasks.named("check").configure {
79+
dependsOn testCaffeine, testCouchbase, testEhcache, testHazelcast, testRedis
80+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
management.endpoints.web.exposure.include=*
2-
3-
spring.cache.jcache.config=classpath:ehcache3.xml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<infinispan>
3+
4+
<!-- ************************************** -->
5+
<!-- Corresponds to @Cacheable("cache-name") -->
6+
<!-- ************************************** -->
7+
<cache-container default-cache="countries">
8+
<local-cache name="countries"/>
9+
</cache-container>
10+
11+
</infinispan>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2012-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.cache;
18+
19+
import org.junit.jupiter.api.Test;
20+
import org.testcontainers.junit.jupiter.Container;
21+
import org.testcontainers.junit.jupiter.Testcontainers;
22+
23+
import org.springframework.beans.factory.annotation.Autowired;
24+
import org.springframework.boot.test.context.SpringBootTest;
25+
import org.springframework.boot.testsupport.testcontainers.RedisContainer;
26+
import org.springframework.cache.Cache;
27+
import org.springframework.cache.CacheManager;
28+
import org.springframework.test.context.DynamicPropertyRegistry;
29+
import org.springframework.test.context.DynamicPropertySource;
30+
31+
import static org.assertj.core.api.Assertions.assertThat;
32+
33+
@SpringBootTest
34+
@Testcontainers(disabledWithoutDocker = true)
35+
class SampleCacheApplicationRedisTests {
36+
37+
@Container
38+
private static final RedisContainer redis = new RedisContainer();
39+
40+
@Autowired
41+
private CacheManager cacheManager;
42+
43+
@Autowired
44+
private CountryRepository countryRepository;
45+
46+
@DynamicPropertySource
47+
static void redisProperties(DynamicPropertyRegistry properties) {
48+
properties.add("spring.redis.url",
49+
() -> "redis://" + redis.getContainerIpAddress() + ":" + redis.getFirstMappedPort());
50+
}
51+
52+
@Test
53+
void validateCache() {
54+
Cache countries = this.cacheManager.getCache("countries");
55+
assertThat(countries).isNotNull();
56+
countries.clear(); // Simple test assuming the cache is empty
57+
assertThat(countries.get("BE")).isNull();
58+
Country be = this.countryRepository.findByCode("BE");
59+
assertThat((Country) countries.get("BE").get()).isEqualTo(be);
60+
}
61+
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<include resource="org/springframework/boot/logging/logback/base.xml"/>
4+
</configuration>

0 commit comments

Comments
 (0)