Add data-redis-reactive smoke test

Closes gh-62
This commit is contained in:
Moritz Halbritter
2022-08-10 10:04:10 +02:00
parent 6a456b979a
commit dfda0a30be
12 changed files with 210 additions and 1 deletions

View File

@@ -25,6 +25,7 @@ smoke_tests:
- data-mongodb-reactive
- data-r2dbc
- data-redis
- data-redis-reactive
- data-rest-mongodb
- event-listener
- flyway

View File

@@ -0,0 +1 @@
Tests if Spring Data Redis Reactive works

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-data-redis-reactive")
implementation("org.springframework.boot:spring-boot-starter-json")
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,25 @@
package com.example.data.redis.reactive;
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 DataRedisReactiveApplicationAotTests {
@Test
void findAll(AssertableOutput output) {
Awaitility.await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> {
assertThat(output).hasSingleLineContaining("1: Person{firstname='first-1', lastname='last-1'}")
.hasSingleLineContaining("2: Person{firstname='first-2', lastname='last-2'}")
.hasSingleLineContaining("3: Person{firstname='first-3', lastname='last-3'}");
});
}
}

View File

@@ -0,0 +1,32 @@
package com.example.data.redis.reactive;
import reactor.core.publisher.Flux;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.ReactiveRedisOperations;
import org.springframework.stereotype.Component;
@Component
class CLR implements CommandLineRunner {
private final ReactiveRedisOperations<String, Person> redisOperations;
CLR(ReactiveRedisOperations<String, Person> redisOperations) {
this.redisOperations = redisOperations;
}
@Override
public void run(String... args) throws Exception {
Flux.just(new Person("1", "first-1", "last-1"), new Person("2", "first-2", "last-2"),
new Person("3", "first-3", "last-3"))
.flatMap((person) -> this.redisOperations.opsForValue().set(person.getId(), person)).collectList()
.block();
for (int i = 1; i <= 3; i++) {
String id = Integer.toString(i);
this.redisOperations.opsForValue().get(id).subscribe((person) -> System.out.printf("%s: %s%n", id, person),
(ex) -> ex.printStackTrace(System.out));
}
}
}

View File

@@ -0,0 +1,33 @@
package com.example.data.redis.reactive;
import com.example.data.redis.reactive.DataRedisReactiveApplication.PersonRuntimeHints;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.smoketest.thirdpartyhints.NettyRuntimeHints;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportRuntimeHints;
import org.springframework.context.aot.BindingReflectionHintsRegistrar;
@SpringBootApplication
@ImportRuntimeHints({ NettyRuntimeHints.class, PersonRuntimeHints.class })
public class DataRedisReactiveApplication {
public static void main(String[] args) throws InterruptedException {
SpringApplication.run(DataRedisReactiveApplication.class, args);
Thread.currentThread().join(); // To be able to measure memory consumption
}
static class PersonRuntimeHints implements RuntimeHintsRegistrar {
private final BindingReflectionHintsRegistrar bindingReflectionHintsRegistrar = new BindingReflectionHintsRegistrar();
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
this.bindingReflectionHintsRegistrar.registerReflectionHints(hints.reflection(), Person.class);
}
}
}

View File

@@ -0,0 +1,64 @@
/*
* Copyright 2020 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 com.example.data.redis.reactive;
public class Person {
private String id;
private String firstname;
private String lastname;
public Person() {
}
public Person(String id, String firstname, String lastname) {
this.id = id;
this.firstname = firstname;
this.lastname = lastname;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
@Override
public String toString() {
return "Person{" + "firstname='" + firstname + '\'' + ", lastname='" + lastname + '\'' + '}';
}
}

View File

@@ -0,0 +1,26 @@
package com.example.data.redis.reactive;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration(proxyBeanMethods = false)
class RedisConfiguration {
@Bean
ReactiveRedisTemplate<String, Person> redisOperations(ObjectMapper objectMapper,
ReactiveRedisConnectionFactory connectionFactory) {
Jackson2JsonRedisSerializer<Person> serializer = new Jackson2JsonRedisSerializer<>(objectMapper, Person.class);
RedisSerializationContext.RedisSerializationContextBuilder<String, Person> builder = RedisSerializationContext
.newSerializationContext(new StringRedisSerializer());
RedisSerializationContext<String, Person> context = builder.value(serializer).build();
return new ReactiveRedisTemplate<>(connectionFactory, context);
}
}

View File

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

View File

@@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class DataR2DbcApplicationTests {
class DataRedisReactiveApplicationTests {
@Test
void contextLoads() {

View File

@@ -53,6 +53,7 @@ include "data-mongodb"
include "data-mongodb-reactive"
include "data-r2dbc"
include "data-redis"
include "data-redis-reactive"
include "data-rest-mongodb"
include "event-listener"
include "flyway"