java - How to simulate slow SQL database in test? -


i have bug manifest himself when database slow. applies simplest database operations (select, etc).

i create test, force database slow. how that?
use spring boot, spring data, hibernate, mariadb.

ideally, want 'slow database' part contained in test code, in java application. way, test automated , self-contained.

i want slow down database access 1 test (not globally, access).

i proposed introduce database trigger (before select) sleep

but not flexible, because slows down every access, not access 1 test.

i see 4 possible solutions problem.

  1. you don't have create slow database, can create slow connection database. if run database on different (virtual) machine, there systems simulating shitty internet connections delaying network responses randomly.

  2. you can use sleep(10) function provided database, require "injecting" sql query or override method purpose of test , replace select select sleep(10).

  3. simulate stress-test on database mysqlslap if use mysql.

  4. another solution, a bit stupid tho, can use spring-aop , attach delay aspect before , after dao method execution random small sleep. way have control on it, don't have modify existing code , let spring make job of doing delay without integration real-system. not stupid after all. 1 quite flexible , think go it. easiest setup.

if it's stupid, works, it's not stupid.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -