Skip to content

Commit

Permalink
Merge branch '2.7.x'
Browse files Browse the repository at this point in the history
Closes gh-31990
  • Loading branch information
wilkinsona committed Aug 4, 2022
2 parents 05877dc + d8e6d9b commit c481299
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,19 @@ 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",
dependencies.create("org.ehcache:ehcache") {
artifact {
classifier = 'jakarta'
}
}
],
"hazelcast": [
"com.hazelcast:hazelcast",
"com.hazelcast:hazelcast-spring"
],
"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
hazelcast
}

dependencies {
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-actuator"))
Expand All @@ -36,7 +26,55 @@ 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::jakarta")

hazelcast(enforcedPlatform(project(":spring-boot-project:spring-boot-dependencies")))
hazelcast("com.hazelcast:hazelcast")
hazelcast("com.hazelcast:hazelcast-spring")

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 testHazelcast = tasks.register("testHazelcast", Test) {
description = "Runs the tests against Hazelcast"
classpath = sourceSets.test.runtimeClasspath + configurations.hazelcast
}

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, testHazelcast, testRedis
}
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
management.endpoints.web.exposure.include=*

spring.cache.jcache.config=classpath:ehcache3.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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 c481299

Please sign in to comment.