Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move blocking random key generation to executor thread #666

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -42,13 +44,15 @@
* {@link ReactiveRedisConnectionFactory}.
*
* @author Mark Paluch
* @author Arooba Shahoor
*/
@SpringBootTest(classes = RedisTestConfiguration.class)
@EnabledOnRedisAvailable
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 +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();
});

}

Expand Down