Skip to content

Commit 9f2261a

Browse files
committed
Move blocking random key generation to executor thread
1 parent 321e3e9 commit 9f2261a

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

redis/reactive/src/test/java/example/springdata/redis/commands/KeyCommandsTests.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.time.Duration;
2525
import java.util.Collections;
2626
import java.util.UUID;
27+
import java.util.concurrent.ExecutorService;
28+
import java.util.concurrent.Executors;
2729

2830
import org.junit.jupiter.api.BeforeEach;
2931
import org.junit.jupiter.api.Test;
@@ -42,13 +44,15 @@
4244
* {@link ReactiveRedisConnectionFactory}.
4345
*
4446
* @author Mark Paluch
47+
* @author Arooba Shahoor
4548
*/
4649
@SpringBootTest(classes = RedisTestConfiguration.class)
4750
@EnabledOnRedisAvailable
4851
class KeyCommandsTests {
4952

5053
private static final String PREFIX = KeyCommandsTests.class.getSimpleName();
5154
private static final String KEY_PATTERN = PREFIX + "*";
55+
private final ExecutorService executor = Executors.newSingleThreadExecutor();
5256

5357
@Autowired ReactiveRedisConnectionFactory connectionFactory;
5458

@@ -103,13 +107,15 @@ void storeToListAndPop() {
103107

104108
private void generateRandomKeys(int nrKeys) {
105109

106-
var keyFlux = Flux.range(0, nrKeys).map(i -> (PREFIX + "-" + i));
110+
executor.execute(() -> {
111+
var keyFlux = Flux.range(0, nrKeys).map(i -> (PREFIX + "-" + i));
107112

108-
var generator = keyFlux.map(String::getBytes).map(ByteBuffer::wrap) //
109-
.map(key -> SetCommand.set(key) //
110-
.value(ByteBuffer.wrap(UUID.randomUUID().toString().getBytes())));
113+
var generator = keyFlux.map(String::getBytes).map(ByteBuffer::wrap) //
114+
.map(key -> SetCommand.set(key) //
115+
.value(ByteBuffer.wrap(UUID.randomUUID().toString().getBytes())));
111116

112-
StepVerifier.create(connection.stringCommands().set(generator)).expectNextCount(nrKeys).verifyComplete();
117+
StepVerifier.create(connection.stringCommands().set(generator)).expectNextCount(nrKeys).verifyComplete();
118+
});
113119

114120
}
115121

0 commit comments

Comments
 (0)