Skip to content

Commit 392c3e4

Browse files
Arooba-gitmp911de
authored andcommitted
Move blocking random key generation to executor thread.
Closes #666
1 parent eb48ae4 commit 392c3e4

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.time.Duration;
2020
import java.util.Collections;
2121
import java.util.UUID;
22+
import java.util.concurrent.ExecutorService;
23+
import java.util.concurrent.Executors;
2224

2325
import example.springdata.redis.RedisTestConfiguration;
2426
import org.junit.jupiter.api.BeforeEach;
@@ -39,12 +41,14 @@
3941
* {@link ReactiveRedisConnectionFactory}.
4042
*
4143
* @author Mark Paluch
44+
* @author Arooba Shahoor
4245
*/
4346
@SpringBootTest(classes = RedisTestConfiguration.class)
4447
class KeyCommandsTests {
4548

4649
private static final String PREFIX = KeyCommandsTests.class.getSimpleName();
4750
private static final String KEY_PATTERN = PREFIX + "*";
51+
private final ExecutorService executor = Executors.newSingleThreadExecutor();
4852

4953
@Autowired ReactiveRedisConnectionFactory connectionFactory;
5054

@@ -99,15 +103,16 @@ void storeToListAndPop() {
99103

100104
private void generateRandomKeys(int nrKeys) {
101105

102-
var keyFlux = Flux.range(0, nrKeys).map(i -> (PREFIX + "-" + i));
106+
executor.execute(() -> {
107+
var keyFlux = Flux.range(0, nrKeys).map(i -> (PREFIX + "-" + i));
103108

104-
var generator = keyFlux.map(String::getBytes).map(ByteBuffer::wrap) //
105-
.map(key -> SetCommand.set(key) //
106-
.value(ByteBuffer.wrap(UUID.randomUUID().toString().getBytes())));
109+
var generator = keyFlux.map(String::getBytes).map(ByteBuffer::wrap) //
110+
.map(key -> SetCommand.set(key) //
111+
.value(ByteBuffer.wrap(UUID.randomUUID().toString().getBytes())));
107112

108-
connection.stringCommands().set(generator).as(StepVerifier::create) //
113+
connection.stringCommands().set(generator).as(StepVerifier::create) //
109114
.expectNextCount(nrKeys) //
110-
.verifyComplete();
115+
.verifyComplete();});
111116

112117
}
113118

0 commit comments

Comments
 (0)