@@ -16,9 +16,8 @@
|
||||
package example.springdata.redis.commands;
|
||||
|
||||
import example.springdata.redis.RedisTestConfiguration;
|
||||
import example.springdata.redis.test.util.RequiresRedisServer;
|
||||
import example.springdata.redis.test.condition.EnabledOnRedisAvailable;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -26,20 +25,17 @@ import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.redis.connection.ReactiveListCommands.PopResult;
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnection;
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.ReactiveStringCommands.SetCommand;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.data.redis.util.ByteUtils;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Show usage of reactive operations on Redis keys using low level API provided by
|
||||
@@ -47,12 +43,9 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = RedisTestConfiguration.class)
|
||||
public class KeyCommandsTests {
|
||||
|
||||
// we only want to run this tests when redis is up an running
|
||||
public static @ClassRule RequiresRedisServer requiresServer = RequiresRedisServer.onLocalhost();
|
||||
@EnabledOnRedisAvailable
|
||||
class KeyCommandsTests {
|
||||
|
||||
private static final String PREFIX = KeyCommandsTests.class.getSimpleName();
|
||||
private static final String KEY_PATTERN = PREFIX + "*";
|
||||
@@ -62,8 +55,8 @@ public class KeyCommandsTests {
|
||||
private ReactiveRedisConnection connection;
|
||||
private RedisSerializer<String> serializer = new StringRedisSerializer();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
this.connection = connectionFactory.getReactiveConnection();
|
||||
}
|
||||
|
||||
@@ -73,7 +66,7 @@ public class KeyCommandsTests {
|
||||
* All keys will be loaded within <strong>one single</strong> operation.
|
||||
*/
|
||||
@Test
|
||||
public void iterateOverKeysMatchingPrefixUsingKeysCommand() {
|
||||
void iterateOverKeysMatchingPrefixUsingKeysCommand() {
|
||||
|
||||
generateRandomKeys(50);
|
||||
|
||||
@@ -91,7 +84,7 @@ public class KeyCommandsTests {
|
||||
* Uses {@code RPUSH} to store an item inside a list and {@code BRPOP} <br />
|
||||
*/
|
||||
@Test
|
||||
public void storeToListAndPop() {
|
||||
void storeToListAndPop() {
|
||||
|
||||
var popResult = connection.listCommands()
|
||||
.brPop(Collections.singletonList(ByteBuffer.wrap("list".getBytes())), Duration.ofSeconds(5));
|
||||
|
||||
@@ -18,22 +18,19 @@ package example.springdata.redis.operations;
|
||||
import example.springdata.redis.EmailAddress;
|
||||
import example.springdata.redis.Person;
|
||||
import example.springdata.redis.RedisTestConfiguration;
|
||||
import example.springdata.redis.test.util.RequiresRedisServer;
|
||||
import example.springdata.redis.test.condition.EnabledOnRedisAvailable;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.ReactiveRedisOperations;
|
||||
import org.springframework.data.redis.util.ByteUtils;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Show usage of reactive Template API on Redis lists using {@link ReactiveRedisOperations} with Jackson serialization.
|
||||
@@ -41,12 +38,9 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Slf4j
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = RedisTestConfiguration.class)
|
||||
public class JacksonJsonTests {
|
||||
|
||||
// we only want to run this tests when redis is up an running
|
||||
public static @ClassRule RequiresRedisServer requiresServer = RequiresRedisServer.onLocalhost();
|
||||
@EnabledOnRedisAvailable
|
||||
class JacksonJsonTests {
|
||||
|
||||
@Autowired ReactiveRedisOperations<String, Person> typedOperations;
|
||||
|
||||
@@ -60,7 +54,7 @@ public class JacksonJsonTests {
|
||||
* @see RedisTestConfiguration#reactiveJsonPersonRedisTemplate(ReactiveRedisConnectionFactory)
|
||||
*/
|
||||
@Test
|
||||
public void shouldWriteAndReadPerson() {
|
||||
void shouldWriteAndReadPerson() {
|
||||
|
||||
StepVerifier.create(typedOperations.opsForValue().set("homer", new Person("Homer", "Simpson"))) //
|
||||
.expectNext(true) //
|
||||
@@ -70,11 +64,11 @@ public class JacksonJsonTests {
|
||||
.map(ByteUtils::getBytes) //
|
||||
.map(String::new);
|
||||
|
||||
StepVerifier.create(get) //
|
||||
get.as(StepVerifier::create) //
|
||||
.expectNext("{\"firstname\":\"Homer\",\"lastname\":\"Simpson\"}") //
|
||||
.verifyComplete();
|
||||
|
||||
StepVerifier.create(typedOperations.opsForValue().get("homer")) //
|
||||
typedOperations.opsForValue().get("homer").as(StepVerifier::create) //
|
||||
.expectNext(new Person("Homer", "Simpson")) //
|
||||
.verifyComplete();
|
||||
}
|
||||
@@ -87,9 +81,10 @@ public class JacksonJsonTests {
|
||||
* @see RedisTestConfiguration#reactiveJsonObjectRedisTemplate(ReactiveRedisConnectionFactory)
|
||||
*/
|
||||
@Test
|
||||
public void shouldWriteAndReadPersonObject() {
|
||||
void shouldWriteAndReadPersonObject() {
|
||||
|
||||
StepVerifier.create(genericOperations.opsForValue().set("homer", new Person("Homer", "Simpson"))) //
|
||||
genericOperations.opsForValue().set("homer", new Person("Homer", "Simpson")) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(true) //
|
||||
.verifyComplete();
|
||||
|
||||
@@ -97,11 +92,11 @@ public class JacksonJsonTests {
|
||||
.map(ByteUtils::getBytes) //
|
||||
.map(String::new);
|
||||
|
||||
StepVerifier.create(get) //
|
||||
get.as(StepVerifier::create) //
|
||||
.expectNext("{\"_type\":\"example.springdata.redis.Person\",\"firstname\":\"Homer\",\"lastname\":\"Simpson\"}") //
|
||||
.verifyComplete();
|
||||
|
||||
StepVerifier.create(genericOperations.opsForValue().get("homer")) //
|
||||
genericOperations.opsForValue().get("homer").as(StepVerifier::create) //
|
||||
.expectNext(new Person("Homer", "Simpson")) //
|
||||
.verifyComplete();
|
||||
}
|
||||
@@ -115,9 +110,10 @@ public class JacksonJsonTests {
|
||||
* @see RedisTestConfiguration#reactiveJsonObjectRedisTemplate(ReactiveRedisConnectionFactory)
|
||||
*/
|
||||
@Test
|
||||
public void shouldWriteAndReadEmailObject() {
|
||||
void shouldWriteAndReadEmailObject() {
|
||||
|
||||
StepVerifier.create(genericOperations.opsForValue().set("mail", new EmailAddress("homer@the-simpsons.com"))) //
|
||||
genericOperations.opsForValue().set("mail", new EmailAddress("homer@the-simpsons.com")) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(true) //
|
||||
.verifyComplete();
|
||||
|
||||
@@ -125,11 +121,12 @@ public class JacksonJsonTests {
|
||||
.map(ByteUtils::getBytes) //
|
||||
.map(String::new);
|
||||
|
||||
StepVerifier.create(get) //
|
||||
get.as(StepVerifier::create) //
|
||||
.expectNext("{\"_type\":\"example.springdata.redis.EmailAddress\",\"address\":\"homer@the-simpsons.com\"}") //
|
||||
.verifyComplete();
|
||||
|
||||
StepVerifier.create(genericOperations.opsForValue().get("mail")) //
|
||||
genericOperations.opsForValue().get("mail") //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(new EmailAddress("homer@the-simpsons.com")) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
package example.springdata.redis.operations;
|
||||
|
||||
import example.springdata.redis.RedisTestConfiguration;
|
||||
import example.springdata.redis.test.util.RequiresRedisServer;
|
||||
import example.springdata.redis.test.condition.EnabledOnRedisAvailable;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
@@ -24,15 +24,12 @@ import reactor.test.StepVerifier;
|
||||
import java.time.Duration;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.redis.core.ReactiveListOperations;
|
||||
import org.springframework.data.redis.core.ReactiveRedisOperations;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Show usage of reactive Template API on Redis lists using {@link ReactiveRedisOperations}.
|
||||
@@ -40,17 +37,14 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Slf4j
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = RedisTestConfiguration.class)
|
||||
public class ListOperationsTests {
|
||||
|
||||
// we only want to run this tests when redis is up an running
|
||||
public static @ClassRule RequiresRedisServer requiresServer = RequiresRedisServer.onLocalhost();
|
||||
@EnabledOnRedisAvailable
|
||||
class ListOperationsTests {
|
||||
|
||||
@Autowired ReactiveRedisOperations<String, String> operations;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@BeforeEach
|
||||
void before() {
|
||||
StepVerifier.create(operations.execute(it -> it.serverCommands().flushDb())).expectNext("OK").verifyComplete();
|
||||
}
|
||||
|
||||
@@ -58,7 +52,7 @@ public class ListOperationsTests {
|
||||
* A simple queue using Redis blocking list commands {@code BLPOP} and {@code LPUSH} to produce the queue message.
|
||||
*/
|
||||
@Test
|
||||
public void shouldPollAndPopulateQueue() {
|
||||
void shouldPollAndPopulateQueue() {
|
||||
|
||||
var queue = "foo";
|
||||
|
||||
|
||||
@@ -18,22 +18,19 @@ package example.springdata.redis.operations;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import example.springdata.redis.RedisTestConfiguration;
|
||||
import example.springdata.redis.test.util.RequiresRedisServer;
|
||||
import example.springdata.redis.test.condition.EnabledOnRedisAvailable;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.redis.core.ReactiveRedisOperations;
|
||||
import org.springframework.data.redis.core.ReactiveValueOperations;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* Show usage of reactive Template API on Redis strings using {@link ReactiveRedisOperations}.
|
||||
@@ -41,17 +38,14 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Slf4j
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = RedisTestConfiguration.class)
|
||||
public class ValueOperationsTests {
|
||||
|
||||
// we only want to run this tests when redis is up an running
|
||||
public static @ClassRule RequiresRedisServer requiresServer = RequiresRedisServer.onLocalhost();
|
||||
@EnabledOnRedisAvailable
|
||||
class ValueOperationsTests {
|
||||
|
||||
@Autowired ReactiveRedisOperations<String, String> operations;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
@BeforeEach
|
||||
void before() {
|
||||
StepVerifier.create(operations.execute(it -> it.serverCommands().flushDb())).expectNext("OK").verifyComplete();
|
||||
}
|
||||
|
||||
@@ -59,7 +53,7 @@ public class ValueOperationsTests {
|
||||
* Implement a simple caching sequence using {@code GET} and {@code SETEX} commands.
|
||||
*/
|
||||
@Test
|
||||
public void shouldCacheValue() {
|
||||
void shouldCacheValue() {
|
||||
|
||||
var cacheKey = "foo";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user