Add cache-redis smoke test

See gh-40
This commit is contained in:
Moritz Halbritter
2022-08-09 14:51:38 +02:00
parent 451eaf2e2e
commit e13d64e71f
12 changed files with 132 additions and 0 deletions

1
cache-redis/README.adoc Normal file
View File

@@ -0,0 +1 @@
Tests if caching with Redis works

18
cache-redis/build.gradle Normal file
View File

@@ -0,0 +1,18 @@
plugins {
id 'java'
id 'org.springframework.boot'
id 'org.springframework.aot.smoke-test'
id 'org.graalvm.buildtools.native'
}
dependencies {
implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
implementation("org.springframework.boot:spring-boot-starter-cache")
implementation("org.springframework.boot:spring-boot-starter-data-redis")
implementation(project(":aot-smoke-test-third-party-hints"))
testImplementation("org.springframework.boot:spring-boot-starter-test")
aotTestImplementation(project(":aot-smoke-test-support"))
aotTestImplementation("org.awaitility:awaitility:4.2.0")
}

View File

@@ -0,0 +1,6 @@
version: '3.1'
services:
redis:
image: 'redis:7'
ports:
- 6379

View File

@@ -0,0 +1,23 @@
package com.example.cache.redis;
import java.time.Duration;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;
import org.springframework.aot.smoketest.support.assertj.AssertableOutput;
import org.springframework.aot.smoketest.support.junit.AotSmokeTest;
import static org.assertj.core.api.Assertions.assertThat;
@AotSmokeTest
class CacheRedisApplicationAotTests {
@Test
void methodIsCached(AssertableOutput output) {
Awaitility.await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> {
assertThat(output).hasSingleLineContaining("invoke: 1").hasNoLinesContaining("invoke: 2");
});
}
}

View File

@@ -0,0 +1,21 @@
package com.example.cache.redis;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Component
class CLR implements CommandLineRunner {
private final TestService testService;
public CLR(TestService testService) {
this.testService = testService;
}
@Override
public void run(String... args) {
this.testService.invoke();
this.testService.invoke();
}
}

View File

@@ -0,0 +1,10 @@
package com.example.cache.redis;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
@EnableCaching
class CacheConfiguration {
}

View File

@@ -0,0 +1,17 @@
package com.example.cache.redis;
import org.springframework.aot.smoketest.thirdpartyhints.NettyRuntimeHints;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportRuntimeHints;
@SpringBootApplication
@ImportRuntimeHints(NettyRuntimeHints.class)
public class CacheRedisApplication {
public static void main(String[] args) throws InterruptedException {
SpringApplication.run(CacheRedisApplication.class, args);
Thread.currentThread().join(); // To be able to measure memory consumption
}
}

View File

@@ -0,0 +1,17 @@
package com.example.cache.redis;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
@Service
class TestService {
private int counter = 1;
@Cacheable(cacheNames = "invoke")
public void invoke() {
System.out.printf("invoke: %d%n", this.counter);
this.counter++;
}
}

View File

@@ -0,0 +1,3 @@
spring.cache.type=redis
spring.data.redis.host=${REDIS_HOST:localhost}
spring.data.redis.port=${REDIS_PORT_6379:6379}

View File

@@ -0,0 +1,14 @@
package com.example.cache.redis;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class CacheRedisApplicationTests {
@Test
void contextLoads() {
}
}

View File

@@ -9,6 +9,7 @@ smoke_tests:
- cache-cache2k
- cache-caffeine
- cache-hazelcast
- cache-redis
- cache-simple
- cloud-function-web
- cloud-function-webflux

View File

@@ -37,6 +37,7 @@ include "batch"
include "cache-cache2k"
include "cache-caffeine"
include "cache-hazelcast"
include "cache-redis"
include "cache-simple"
include "cloud-function-web"
include "cloud-function-webflux"