From 9f2261a3e3cb84b5697cc22e2cf459cf2c7e6310 Mon Sep 17 00:00:00 2001 From: Aroooba Date: Sun, 23 Jul 2023 04:34:27 +0900 Subject: [PATCH] Move blocking random key generation to executor thread --- .../redis/commands/KeyCommandsTests.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/redis/reactive/src/test/java/example/springdata/redis/commands/KeyCommandsTests.java b/redis/reactive/src/test/java/example/springdata/redis/commands/KeyCommandsTests.java index 1ff35d61f..78d8c3ddf 100644 --- a/redis/reactive/src/test/java/example/springdata/redis/commands/KeyCommandsTests.java +++ b/redis/reactive/src/test/java/example/springdata/redis/commands/KeyCommandsTests.java @@ -24,6 +24,8 @@ import java.time.Duration; import java.util.Collections; import java.util.UUID; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -42,6 +44,7 @@ * {@link ReactiveRedisConnectionFactory}. * * @author Mark Paluch + * @author Arooba Shahoor */ @SpringBootTest(classes = RedisTestConfiguration.class) @EnabledOnRedisAvailable @@ -49,6 +52,7 @@ class KeyCommandsTests { private static final String PREFIX = KeyCommandsTests.class.getSimpleName(); private static final String KEY_PATTERN = PREFIX + "*"; + private final ExecutorService executor = Executors.newSingleThreadExecutor(); @Autowired ReactiveRedisConnectionFactory connectionFactory; @@ -103,13 +107,15 @@ void storeToListAndPop() { private void generateRandomKeys(int nrKeys) { - var keyFlux = Flux.range(0, nrKeys).map(i -> (PREFIX + "-" + i)); + executor.execute(() -> { + var keyFlux = Flux.range(0, nrKeys).map(i -> (PREFIX + "-" + i)); - var generator = keyFlux.map(String::getBytes).map(ByteBuffer::wrap) // - .map(key -> SetCommand.set(key) // - .value(ByteBuffer.wrap(UUID.randomUUID().toString().getBytes()))); + var generator = keyFlux.map(String::getBytes).map(ByteBuffer::wrap) // + .map(key -> SetCommand.set(key) // + .value(ByteBuffer.wrap(UUID.randomUUID().toString().getBytes()))); - StepVerifier.create(connection.stringCommands().set(generator)).expectNextCount(nrKeys).verifyComplete(); + StepVerifier.create(connection.stringCommands().set(generator)).expectNextCount(nrKeys).verifyComplete(); + }); }