Skip to content

Commit

Permalink
chore: refactor load test
Browse files Browse the repository at this point in the history
  • Loading branch information
querwurzel committed Dec 15, 2024
1 parent 667a4d7 commit 73dcd9e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;

import static java.time.Duration.ofMillis;
import static java.time.LocalDateTime.parse;
Expand Down Expand Up @@ -89,9 +90,10 @@ void viewOneTimePasteConcurrently() {
}
};

Flux.range(1, 50)
Flux.fromStream(Stream.generate(() -> request))
.take(50)
.parallel()
.doOnNext(unused -> request.run())
.doOnNext(Runnable::run)
.runOn(Schedulers.boundedElastic())
.subscribe();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,15 @@ void trackConcurrentPasteViews() {

Flux.fromStream(Stream.generate(intialPaste::getId))
.take(concurrency)
.parallel()
.doOnNext(trackingService::trackView)
.doOnNext(id -> pasteRepository.findById(id)
.doOnNext(paste -> setField(paste, "remoteAddress", String.valueOf(random.nextInt())))
.flatMap(paste -> pasteRepository.save(paste)) // simulate a concurrent update
.retry()
.subscribe()
)
.subscribeOn(Schedulers.parallel())
.runOn(Schedulers.parallel())
.subscribe();

waitAtMost(Duration.ofMinutes(1)).pollInterval(Duration.ofSeconds(1)).until(
Expand Down

0 comments on commit 73dcd9e

Please sign in to comment.