From 022922923e7565b700ffa825acb3cc244611ba6c Mon Sep 17 00:00:00 2001 From: Anton Keks Date: Fri, 25 Aug 2023 12:08:18 +0300 Subject: [PATCH] add loom jdbc test --- sample/src/LoomTest.kt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 sample/src/LoomTest.kt diff --git a/sample/src/LoomTest.kt b/sample/src/LoomTest.kt new file mode 100644 index 0000000..952a6cd --- /dev/null +++ b/sample/src/LoomTest.kt @@ -0,0 +1,20 @@ +import com.sun.net.httpserver.HttpServer +import klite.Config +import klite.jdbc.PooledDataSource +import klite.jdbc.query +import java.net.InetSocketAddress +import java.util.concurrent.Executors + +fun main() { + Config.useEnvFile() + val db = PooledDataSource(maxSize = 100) + HttpServer.create(InetSocketAddress(8080), 10).apply { + executor = Executors.newThreadPerTaskExecutor(Thread.ofVirtual().name("req-", 1).factory()) + createContext("/hello") { e -> + val dbTime = db.query("select pg_sleep(1), clock_timestamp()") { getString(2) }.first() + e.sendResponseHeaders(200, 0) + e.responseBody.writer().use { it.write("$dbTime, ${Thread.currentThread().name} ${Thread.currentCarrierThread().name}\n") } + } + start() + } +}