Skip to content

Commit

Permalink
Move blocking random key generation to executor thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Arooba-git committed Jul 22, 2023
1 parent 321e3e9 commit fb2f40f
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,6 +51,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;

Expand Down Expand Up @@ -103,13 +106,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();
});

}

Expand Down

0 comments on commit fb2f40f

Please sign in to comment.