diff --git a/api/pom.xml b/api/pom.xml index 622aaba..b88d1de 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -49,6 +49,16 @@ true + + jitpack + https://jitpack.io + + true + + + true + + @@ -118,6 +128,11 @@ ktorm-support-mysql ${ktorm_version} + + com.github.hekeki + huckleberry + 0.0.2-beta + org.flywaydb flyway-core diff --git a/api/resources/logback.xml b/api/resources/logback.xml index bdbb64e..e573f7d 100644 --- a/api/resources/logback.xml +++ b/api/resources/logback.xml @@ -4,7 +4,7 @@ %d{YYYY-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - + diff --git a/api/test/NotesRetrievePerformanceTest.kt b/api/test/NotesRetrievePerformanceTest.kt new file mode 100644 index 0000000..6998bee --- /dev/null +++ b/api/test/NotesRetrievePerformanceTest.kt @@ -0,0 +1,50 @@ +import be.vandewalleh.services.NotesService +import be.vandewalleh.services.UserService +import com.hekeki.huckleberry.Benchmark +import com.hekeki.huckleberry.BenchmarkRunner +import com.hekeki.huckleberry.BenchmarkTest +import com.hekeki.huckleberry.TimeUnit +import com.zaxxer.hikari.HikariConfig +import com.zaxxer.hikari.HikariDataSource +import me.liuwj.ktorm.database.* +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Test +import org.kodein.di.Kodein +import org.kodein.di.generic.bind +import org.kodein.di.generic.instance +import org.kodein.di.generic.singleton + + +val hikariConfig = HikariConfig().apply { + jdbcUrl = "jdbc:mariadb://localhost:3306/Notes" + username = "test" + password = "test" +} + +val dataSource = HikariDataSource(hikariConfig) + +val db = Database.Companion.connect(dataSource) + +val kodein = Kodein { + bind() with singleton { db } + bind() with singleton { UserService(this.kodein) } + bind() with singleton { NotesService(this.kodein) } +} + +val notesService by kodein.instance() + +@Benchmark(threads = 1, iterations = 30, warmup = true, warmupIterations = 1000, timeUnit = TimeUnit.MILLIS) +class RetrieveNotesBenchmarkTest : BenchmarkTest { + + override fun execute() { + notesService.getNotes(15) + } + + @Test + fun compute() { + val benchmarkResult = BenchmarkRunner(RetrieveNotesBenchmarkTest::class.java).run() + assertTrue(benchmarkResult.median(2, TimeUnit.MILLIS)) + assertTrue(benchmarkResult.maxTime(4, TimeUnit.MILLIS)) + } + +}