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

H2 #12

Merged
merged 14 commits into from
Jun 16, 2024
Merged

H2 #12

7 changes: 1 addition & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,18 @@ bootRun { jvmArgs(["-Xms2g", "-Xmx2g", "-XX:+ExitOnOutOfMemoryError", "-Djdk.tra

dependencies {
implementation 'com.github.ben-manes.caffeine:caffeine'
implementation 'org.postgresql:postgresql:42.+'
implementation 'org.springframework.data:spring-data-jpa:3.3.1'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.hibernate.orm:hibernate-jcache'
implementation 'org.hibernate:hibernate-ehcache:5.6.15.Final'
implementation 'org.ehcache:ehcache:3.10.8'
runtimeOnly 'com.h2database:h2'
testImplementation 'io.github.hakky54:logcaptor:2.9.2'
testImplementation 'io.github.oshai:kotlin-logging-jvm:6.0.9'
testImplementation 'org.apache.commons:commons-compress:1.26.2'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.junit-pioneer:junit-pioneer:2.2.0'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation "org.testcontainers:postgresql:1.19.8"
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions results/ci/scenarios-smoketest/Ubuntu-22.04/java-22/results.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
scenario,approach,requests_ok,requests_error,requests_per_second_p50,requests_per_second_p90,requests_per_second_max,latency_millis_min,latency_millis_p50,latency_millis_p90,latency_millis_p99,latency_millis_max,cpu_use_percent_avg,cpu_use_percent_max,ram_use_percent_avg,ram_use_percent_max,heap_use_percent_avg,heap_use_percent_max,garbage_collection_count,garbage_collection_time_millis,platform_threads_avg,platform_threads_max,sockets_avg,sockets_max,network_kib_per_req_avg,network_kib_per_req_max,network_packets_per_req_avg,network_packets_per_req_max
smoketest,platform-tomcat,1301,0,200,200,201,0.35,0.43,0.56,0.84,7.75,5.22,12.6,18.2,18.2,4.16,4.83,119,504,64,65,288,305,0.88,1.05,8.61,10
smoketest,loom-tomcat,1300,0,200,200,201,0.36,0.47,0.61,0.87,1.66,4.48,5.82,21.9,22.0,4.57,6.15,119,497,23,24,288,305,0.87,1.04,8.58,10
smoketest,loom-netty,1300,0,200,200,201,0.41,0.51,0.67,1.04,2.29,4.40,6.33,22.1,22.1,4.11,5.76,105,476,19,20,288,305,0.62,0.73,5.36,6
smoketest,webflux-netty,1301,0,200,200,201,0.38,0.48,0.67,1.30,19.9,4.35,5.83,22.3,22.3,3.06,4.00,117,548,23,24,288,305,0.63,0.74,5.40,6
smoketest2,platform-tomcat,56,0,10,10,10,1004,1004,1009,1352,1406,3.92,7.70,22.4,22.5,10.7,10.8,98,364,38,40,213,215,2.12,3.29,20.9,29.8
smoketest2,loom-tomcat,56,0,10,10,10,1004,1005,1007,1392,1448,3.69,6.09,22.7,22.7,10.2,10.7,112,440,23,24,213,215,2.54,5.60,24.6,49.8
smoketest2,loom-netty,58,0,10,10,10,1004,1005,1008,1118,1176,4.61,10.8,22.6,22.7,8.94,9.29,112,464,20,20,213,215,2.52,8.60,22.5,76.2
smoketest2,webflux-netty,59,0,10,10,10,1003,1004,1008,1110,1167,4.28,11.1,22.7,22.8,8.93,9.22,96,352,24,24,213,215,2.60,9.01,23.1,79.8
smoketest,platform-tomcat,1300,0,200,200,201,0.31,0.38,0.49,0.80,1.67,3.71,5.28,18.0,18.1,3.70,4.23,119,504,61,62,87,104,0.88,1.06,8.59,10.1
smoketest,loom-tomcat,1300,0,200,200,201,0.33,0.42,0.53,0.86,6.05,4.63,7.82,22,22.1,5.05,6.52,119,476,21,21,87,104,0.87,1.04,8.58,10
smoketest,loom-netty,1300,0,200,200,201,0.41,0.50,0.68,1.07,2.06,4.14,6.05,22.2,22.2,4.74,6.33,119,539,17,17,87,104,0.62,0.73,5.35,6
smoketest,webflux-netty,1300,0,200,200,201,0.39,0.48,0.67,1.01,1.85,4.14,5.82,22.4,22.5,3.57,4.62,136,616,21,22,87,104,0.62,0.74,5.35,6
smoketest2,platform-tomcat,56,0,10,10,10,1003,1005,1007,1341,1397,3.36,4.79,22.4,22.5,12.5,12.9,112,408,36,39,12,14,1.87,2.31,18.7,22.8
smoketest2,loom-tomcat,56,0,10,10,10,1003,1005,1007,1384,1439,2.81,3.75,22.5,22.6,12.3,12.7,112,416,21,22,12,14,1.87,2.24,18.8,22.4
smoketest2,loom-netty,59,0,10,10,10,1003,1005,1007,1113,1172,3.80,5.20,22.5,22.5,11.1,11.4,112,472,17,18,12,14,1.36,1.64,12.1,14
smoketest2,webflux-netty,59,0,10,10,10,1003,1004,1006,1112,1170,3.38,4.23,22.6,22.6,11.0,11.2,112,480,21,22,12,14,1.36,1.64,12.1,14
Binary file modified results/ci/scenarios-smoketest/Ubuntu-22.04/java-22/results.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions results/ci/scenarios-smoketest/ubuntu-24.04/java-21/results.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
scenario,approach,requests_ok,requests_error,requests_per_second_p50,requests_per_second_p90,requests_per_second_max,latency_millis_min,latency_millis_p50,latency_millis_p90,latency_millis_p99,latency_millis_max,cpu_use_percent_avg,cpu_use_percent_max,ram_use_percent_avg,ram_use_percent_max,heap_use_percent_avg,heap_use_percent_max,garbage_collection_count,garbage_collection_time_millis,platform_threads_avg,platform_threads_max,sockets_avg,sockets_max,network_kib_per_req_avg,network_kib_per_req_max,network_packets_per_req_avg,network_packets_per_req_max
smoketest,platform-tomcat,1300,0,200,200,201,0.29,0.39,0.51,0.98,3.31,5.10,7.36,18.1,18.2,4.13,4.66,126,644,73,74,270,304,0.88,1.05,8.60,11.5
smoketest,loom-tomcat,1300,0,200,200,201,0.32,0.41,0.54,0.76,1.85,4.31,5.33,22.2,22.3,5.09,6.64,119,546,26,27,270,304,0.87,1.05,8.59,11.6
smoketest,loom-netty,1300,0,200,200,201,0.40,0.53,0.71,1.15,6.12,4.65,6.33,22.3,22.5,4.74,6.38,119,630,22,23,270,304,0.62,0.78,5.38,8.14
smoketest,webflux-netty,1300,0,200,200,201,0.38,0.50,0.67,1.11,3.72,4.59,6.76,22.5,22.6,3.84,4.79,119,630,26,27,270,304,0.62,0.79,5.36,8.17
smoketest2,platform-tomcat,56,0,10,10,10,1004,1005,1008,1385,1440,4.48,6.34,22.7,22.8,4.56,10.2,119,566,38,40,212,214,2.55,5.59,24.6,49.6
smoketest2,loom-tomcat,56,0,10,10,10,1004,1005,1008,1396,1452,4.47,8.27,22.9,22.9,4.41,10.7,104,501,26,27,212,214,2.71,6.59,26.2,59.2
smoketest2,loom-netty,58,0,10,10,10,1004,1006,1008,1122,1180,4.07,6.30,22.5,22.6,5.42,6.89,110,520,22,23,212,214,1.55,2.81,14.0,25
smoketest2,webflux-netty,59,0,10,10,10,1003,1005,1008,1110,1169,3.94,5.53,22.5,22.5,6.07,6.99,107,501,26,27,212,214,1.56,2.81,14.0,25
smoketest,platform-tomcat,1300,0,200,200,201,0.31,0.38,0.50,0.83,4.43,4.10,5.86,16.1,16.3,3.61,4.18,119,525,64,65,69,103,0.87,1.05,8.58,11.5
smoketest,loom-tomcat,1300,0,200,200,201,0.32,0.40,0.54,0.80,2.41,5.68,9.23,20.1,20.2,4.62,6.11,119,511,21,22,69,103,0.87,1.04,8.58,11.5
smoketest,loom-netty,1300,0,200,200,201,0.42,0.52,0.67,1.06,5.68,4.66,7.91,20.0,20.2,4.30,5.95,119,539,17,18,69,103,0.62,0.79,5.36,8.20
smoketest,webflux-netty,1300,0,200,200,201,0.38,0.51,0.68,1.13,2.52,5.53,9.62,20.3,20.4,3.35,4.28,119,567,21,22,69,103,0.63,0.80,5.36,8.21
smoketest2,platform-tomcat,56,0,10,10,10,1003,1004,1007,1342,1398,3.92,5.01,20.5,20.7,11.9,12.0,98,364,37,39,11,13,1.86,2.31,18.7,22.8
smoketest2,loom-tomcat,56,0,10,10,10,1004,1005,1024,1385,1440,4.44,8.10,20.6,20.8,9.02,11.8,117,462,21,22,11,13,1.87,2.20,18.8,22
smoketest2,loom-netty,59,0,10,10,10,1003,1005,1006,1111,1170,3.22,3.98,20.5,20.6,10.2,10.5,98,399,17,18,11,13,1.36,1.64,12.1,14
smoketest2,webflux-netty,59,0,10,10,10,1003,1004,1006,1102,1161,3.10,3.99,20.7,20.8,10.2,10.4,98,413,21,22,11,13,1.36,1.62,12.1,14
Binary file modified results/ci/scenarios-smoketest/ubuntu-24.04/java-21/results.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 0 additions & 6 deletions src/main/bash/benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ echo
log "Contents of $scenariosFile:"
cat "$scenariosFile"

log "Starting DB"
docker compose up -d

first_line=true
while IFS=',' read -r scenario k6Config delayCallDepth delayInMillis connections requestsPerSecond warmupDurationInSeconds testDurationInSeconds; do
if [[ -z "$scenario" || $scenario == "#"* || $first_line == true ]]; then
Expand All @@ -82,9 +79,6 @@ done < "$scenariosFile"
./src/main/python/results_chart.py -i "$resultsCsvFile" -o "$resultsPngFile"
./src/main/python/results_chart.py -i "$resultsCsvFile" -o "$resultsNettyPngFile" -a "loom-netty,webflux-netty" || true

log "Stopping DB"
docker compose down

endSeconds=$( date +%s )
testDurationInSeconds=$(( endSeconds - startSeconds ))

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/uk/gleissner/loomwebflux/LoomWebfluxApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;
import uk.gleissner.loomwebflux.config.AppProperties;

Expand All @@ -13,9 +12,8 @@
@EnableScheduling
@EnableCaching
public class LoomWebfluxApp {
static ConfigurableApplicationContext ctx;

public static void main(String[] args) {
ctx = SpringApplication.run(LoomWebfluxApp.class, args);
SpringApplication.run(LoomWebfluxApp.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import reactor.core.publisher.Mono;
import uk.gleissner.loomwebflux.controller.LoomWebFluxController;
import uk.gleissner.loomwebflux.movie.domain.Movie;
import uk.gleissner.loomwebflux.movie.repo.AppPropertiesAwareMovieRepo;
import uk.gleissner.loomwebflux.movie.repo.CachedMovieRepo;

import java.util.List;
import java.util.Set;
Expand All @@ -28,9 +28,9 @@
public class MovieController extends LoomWebFluxController {

private static final String API_PATH = "/movies";
private final AppPropertiesAwareMovieRepo movieRepo;
private final CachedMovieRepo movieRepo;

MovieController(WebClient webClient, AppPropertiesAwareMovieRepo movieRepo) {
MovieController(WebClient webClient, CachedMovieRepo movieRepo) {
super(webClient);
this.movieRepo = movieRepo;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package uk.gleissner.loomwebflux.movie.domain;

import jakarta.persistence.Cacheable;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
Expand All @@ -13,7 +12,6 @@
import static jakarta.persistence.GenerationType.IDENTITY;

@Entity
@Cacheable
@Data
@Builder(toBuilder = true)
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package uk.gleissner.loomwebflux.movie.domain;

import jakarta.persistence.Cacheable;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
Expand All @@ -15,7 +14,6 @@
import static jakarta.persistence.GenerationType.IDENTITY;

@Entity
@Cacheable
@Data
@Builder(toBuilder = true)
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package uk.gleissner.loomwebflux.movie.domain;

import jakarta.persistence.Cacheable;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
Expand All @@ -22,7 +21,6 @@
import static jakarta.persistence.GenerationType.IDENTITY;

@Entity
@Cacheable
@Data
@Builder(toBuilder = true)
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package uk.gleissner.loomwebflux.movie.domain;

import jakarta.annotation.Nullable;
import jakarta.persistence.Cacheable;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
Expand All @@ -17,7 +16,6 @@
import static jakarta.persistence.GenerationType.IDENTITY;

@Entity
@Cacheable
@Data
@Builder(toBuilder = true)
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
import java.util.Set;

@Component
public class AppPropertiesAwareMovieRepo {
public class CachedMovieRepo {

private static final String MOVIES_BY_DIRECTOR_NAME_CACHE_NAME = "moviesByDirectorName";

private final AppProperties appProperties;
private final MovieRepo underlying;
private final Cache moviesByDirectorNameCache;

AppPropertiesAwareMovieRepo(AppProperties appProperties, MovieRepo underlying, CacheManager cacheManager) {
CachedMovieRepo(AppProperties appProperties, MovieRepo underlying, CacheManager cacheManager) {
this.appProperties = appProperties;
this.underlying = underlying;
this.moviesByDirectorNameCache = cacheManager.getCache(MOVIES_BY_DIRECTOR_NAME_CACHE_NAME);
}

@Cacheable("moviesByDirectorName")
@Cacheable(MOVIES_BY_DIRECTOR_NAME_CACHE_NAME)
public Set<Movie> findByDirectorName(String directorName) {
return underlying.findByDirectorName(directorName);
}
Expand All @@ -33,17 +33,19 @@ public Movie save(Movie movie) {
if (appProperties.repoReadOnly()) {
return movie;
} else {
// TODO cg Save new movie to cache
moviesByDirectorNameCache.invalidate();
evictMovieFromCache(movie);
return underlying.save(movie);
}
}

public void deleteById(Long id) {
if (!appProperties.repoReadOnly()) {
underlying.findById(id).ifPresent(this::evictMovieFromCache);
underlying.deleteById(id);
// TODO cg Expire deleted movie from cache
moviesByDirectorNameCache.invalidate();
}
}

private void evictMovieFromCache(Movie movie) {
movie.getDirectors().forEach(director -> moviesByDirectorNameCache.evict(director.getLastName()));
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package uk.gleissner.loomwebflux.movie.repo;

import jakarta.persistence.QueryHint;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.QueryHints;
import org.springframework.data.repository.ListCrudRepository;
import uk.gleissner.loomwebflux.movie.domain.Movie;

import java.util.Set;

import static org.hibernate.jpa.HibernateHints.HINT_CACHEABLE;

public interface MovieRepo extends ListCrudRepository<Movie, Long> {

@QueryHints(@QueryHint(name = HINT_CACHEABLE, value = "true"))
@Query("SELECT m FROM Movie m JOIN m.directors d WHERE d.lastName = :directorName")
Set<Movie> findByDirectorName(String directorName);
}
16 changes: 1 addition & 15 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,14 @@ spring:
threads:
virtual:
enabled: true
cache:
# TODO cg Examine why this Hibernate query cache is not used. Instead, only the Spring Boot cache (Caffeine) is used.
jcache:
provider: org.ehcache.jsr107.EhcacheCachingProvider
cache-names: moviesByDirectorName
jpa:
open-in-view: false
properties:
hibernate:
javax.cache.missing_cache_strategy: create
cache:
region:
factory_class: jcache
# TODO cg Examine why the Hibernate query cache is not used. Instead, only the Spring Boot cache (Caffeine) is used.
use_query_cache: true
use_second_level_cache: true
globally_quoted_identifiers: true
hibernate:
ddl-auto: update
datasource:
url: jdbc:postgresql://localhost:5432/postgres
username: postgres
password: password
hikari:
connectionTimeout: 60000
maximumPoolSize: 100
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/scenarios/scenarios-get-post-movies.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
scenario,k6Config,delayCallDepth,delayInMillis,connections,requestsPerSecond,warmupDurationInSeconds,testDurationInSeconds
10k-vus-smooth-spike-get-post-movies-call-depth-1,get-post-movies-smooth-vus-spike.js,1,100,10000,,0,300
25k-vus-smooth-spike-get-post-movies-call-depth-1,get-post-movies-smooth-vus-spike.js,1,100,25000,,0,300
10k-vus-smooth-spike-get-post-movies-call-depth-1,get-post-movies-smooth-vus-spike.js,1,100,10000,,0,60
25k-vus-smooth-spike-get-post-movies-call-depth-1,get-post-movies-smooth-vus-spike.js,1,100,25000,,0,60
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package uk.gleissner.loomwebflux.fixture

import io.github.oshai.kotlinlogging.KotlinLogging
import nl.altindag.log.LogCaptor
import org.junit.jupiter.api.BeforeEach
import org.junitpioneer.jupiter.cartesian.ArgumentSets
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT
import org.springframework.test.context.ActiveProfiles
import org.springframework.test.context.DynamicPropertyRegistry
import org.springframework.test.context.DynamicPropertySource
import org.springframework.test.web.reactive.server.WebTestClient
import org.testcontainers.containers.PostgreSQLContainer
import uk.gleissner.loomwebflux.Approaches.*
import uk.gleissner.loomwebflux.controller.LoomWebFluxController

Expand All @@ -30,22 +28,7 @@ abstract class AbstractIntegrationTest {
}

companion object {

const val SPRING_DATASOURCE_URL = "spring.datasource.url"

val postgres: PostgreSQLContainer<*> = PostgreSQLContainer("postgres:16-alpine")
.withUsername("postgres")
.withPassword("password")

init {
postgres.start()
}

@JvmStatic
@DynamicPropertySource
fun configureProperties(registry: DynamicPropertyRegistry) {
registry.add(SPRING_DATASOURCE_URL, postgres::getJdbcUrl)
}
val log = KotlinLogging.logger { }

@JvmStatic
fun approaches(): List<String> = listOf(PLATFORM_TOMCAT, LOOM_TOMCAT, LOOM_NETTY, WEBFLUX_NETTY)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.gleissner.loomwebflux.movie

import nl.altindag.log.LogCaptor
import org.assertj.core.api.Assertions.assertThat
import org.junitpioneer.jupiter.cartesian.CartesianTest
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -16,6 +17,8 @@ import uk.gleissner.loomwebflux.movie.repo.MovieRepo
import java.time.Duration
import java.time.Instant.now

private const val SQL_LOG_NAME = "org.hibernate.SQL"

internal class MovieControllerIntegrationTest : AbstractIntegrationTest() {

@Autowired
Expand All @@ -35,23 +38,36 @@ internal class MovieControllerIntegrationTest : AbstractIntegrationTest() {
@CartesianTestApproachesAndDelayCallDepths
fun `save and delete movies`(approach: String, delayCallDepth: Int) {
val movies = listOf(mulhollandDrive, theStraightStory)
assertThat(getMovies(approach, directorLastName = davidLynch.lastName, delayCallDepth = delayCallDepth)).isEmpty()
fun getMovies() = getMovies(approach, directorLastName = davidLynch.lastName, delayCallDepth = delayCallDepth)
assertThat(getMovies()).isEmpty()

val savedMovies = saveMovies(approach, movies, delayCallDepth = delayCallDepth)
assertThat(savedMovies).hasSize(movies.size)
savedMovies.forEach {
assertThat(it.id).isNotNull()
}
savedMovies.forEach { assertThat(it.id).isNotNull() }
assertThat(savedMovies).usingRecursiveComparison().ignoringFieldsMatchingRegexes(".*id").isEqualTo(movies)
assertThatSqlQueryIssued(true) { assertThat(getMovies()).containsExactlyElementsOf(savedMovies) }
assertThatSqlQueryIssued(false) { assertThat(getMovies()).containsExactlyElementsOf(savedMovies) }

assertThat(getMovies(approach, directorLastName = davidLynch.lastName, delayCallDepth = delayCallDepth)).containsExactlyElementsOf(savedMovies)
savedMovies.forEach { savedMovie -> deleteMovie(approach, movieId = savedMovie.id, delayCallDepth = delayCallDepth) }
assertThatSqlQueryIssued(true) { assertThat(getMovies()).isEmpty() }
logCaptor.assertCorrectThreadType(approach, expectedLogCount = (delayCallDepth + 1) * 7)
}

savedMovies.forEach {
deleteMovie(approach, movieId = it.id, delayCallDepth = delayCallDepth)
private fun assertThatSqlQueryIssued(queryIssued: Boolean, repoCall: Runnable) {
val logCaptor = LogCaptor.forName(SQL_LOG_NAME)
try {
logCaptor.setLogLevelToDebug()
repoCall.run()
val selectCount = logCaptor.debugLogs.filter { it.startsWith("select") }.size
if (queryIssued) {
assertThat(selectCount).isPositive()
} else {
assertThat(selectCount).isZero()
}
} finally {
logCaptor.setLogLevelToInfo()
logCaptor.close()
}

assertThat(getMovies(approach, directorLastName = davidLynch.lastName, delayCallDepth = delayCallDepth)).isEmpty()
logCaptor.assertCorrectThreadType(approach, expectedLogCount = (delayCallDepth + 1) * 6)
}

private fun getMovies(
Expand Down
Loading
Loading