Add latency to simulate long database queries.

This commit is contained in:
Florian THIERRY
2025-09-18 17:51:55 +02:00
parent 9dce18d00f
commit 2fe14de357
5 changed files with 27 additions and 0 deletions

View File

@@ -10,6 +10,8 @@ import java.util.List;
import java.util.Optional;
import java.util.UUID;
import static com.zeenea.experiments.virtualthreads.virtualthreadsapp.utils.LatencyUtils.sleepOneSec;
@Component
public class CatalogJpaAdapter implements CatalogPort {
private final CatalogJpaRepository catalogJpaRepository;
@@ -26,6 +28,7 @@ public class CatalogJpaAdapter implements CatalogPort {
@Override
public List<Catalog> getAll() {
sleepOneSec();
return catalogJpaRepository.findAll()
.stream()
.map(CatalogJpaEntity::toDomain)

View File

@@ -8,6 +8,8 @@ import org.springframework.stereotype.Component;
import java.util.List;
import static com.zeenea.experiments.virtualthreads.virtualthreadsapp.utils.LatencyUtils.sleepOneSec;
@Component
public class ItemJpaAdapter implements ItemPort {
private final ItemJpaRepository itemJpaRepository;
@@ -18,6 +20,7 @@ public class ItemJpaAdapter implements ItemPort {
@Override
public List<Item> getAll() {
sleepOneSec();
return itemJpaRepository.findAll()
.stream()
.map(ItemJpaEntity::toDomain)

View File

@@ -0,0 +1,15 @@
package com.zeenea.experiments.virtualthreads.virtualthreadsapp.utils;
public class LatencyUtils {
public static void sleep(int millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
public static void sleepOneSec() {
sleep(1000);
}
}