Skip to content

Commit

Permalink
Merge branch '2.6.x' into 2.7.x
Browse files Browse the repository at this point in the history
Closes gh-31989
  • Loading branch information
wilkinsona committed Aug 4, 2022
2 parents a69cf00 + 329fa8d commit d8e6d9b
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 32 deletions.
Expand Up @@ -5,32 +5,21 @@ plugins {

description = "Spring Boot cache smoke test"

def caches = [
"caffeine": [
"com.github.ben-manes.caffeine:caffeine"
],
"couchbase": [
project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-couchbase")
],
"ehcache": [
"javax.cache:cache-api",
"org.ehcache:ehcache"
],
"ehcache2": [
"net.sf.ehcache:ehcache"
],
"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")
]
]
sourceSets {
redisTest {
compileClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.main.output
}
}

configurations {
caffeine
couchbase
ehcache
ehcache2
hazelcast
infinispan
}

dependencies {
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator"))
Expand All @@ -39,7 +28,73 @@ dependencies {

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

if (project.hasProperty("cache")) {
caches[project.getProperty("cache")].each { runtimeOnly it }
}
}
caffeine(enforcedPlatform(project(":spring-boot-project:spring-boot-dependencies")))
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=*

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>

0 comments on commit d8e6d9b

Please sign in to comment.