Skip to content

Commit fb2f40f

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

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

+10-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;
@@ -49,6 +51,7 @@ class KeyCommandsTests {
4951

5052
private static final String PREFIX = KeyCommandsTests.class.getSimpleName();
5153
private static final String KEY_PATTERN = PREFIX + "*";
54+
private final ExecutorService executor = Executors.newSingleThreadExecutor();
5255

5356
@Autowired ReactiveRedisConnectionFactory connectionFactory;
5457

@@ -103,13 +106,15 @@ void storeToListAndPop() {
103106

104107
private void generateRandomKeys(int nrKeys) {
105108

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

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

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

114119
}
115120

0 commit comments

Comments
 (0)