-
Notifications
You must be signed in to change notification settings - Fork 355
Expand file tree
/
Copy pathSlickUtils.scala
More file actions
67 lines (55 loc) · 1.77 KB
/
Copy pathSlickUtils.scala
File metadata and controls
67 lines (55 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import datadog.trace.agent.test.AgentTestRunner.blockUntilChildSpansFinished
import datadog.trace.api.Trace
import datadog.trace.bootstrap.instrumentation.api.AgentTracer.{setAsyncPropagationEnabled, activeSpan}
import datadog.trace.common.writer.ListWriter
import datadog.trace.core.DDSpan
import slick.jdbc.H2Profile.api._
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, Future}
class SlickUtils(TEST_WRITER: ListWriter) {
import SlickUtils._
val database = Database.forURL(
Url,
user = Username,
driver = "org.h2.Driver",
keepAliveConnection = true,
// Limit number of threads to hit Slick-specific case when we need to avoid re-wrapping
// wrapped runnables.
executor = AsyncExecutor("test", numThreads = 1, queueSize = 1000)
)
TEST_WRITER.waitUntilReported(setup())
TEST_WRITER.clear()
@Trace
def setup(): DDSpan = {
setAsyncPropagationEnabled(true)
Await.result(
database.run(
sqlu"""CREATE ALIAS IF NOT EXISTS SLEEP FOR "java.lang.Thread.sleep(long)""""
),
Duration.Inf
)
activeSpan().asInstanceOf[DDSpan]
}
@Trace
def startQuery(query: String): Future[Vector[Int]] = {
try {
setAsyncPropagationEnabled(true)
database.run(sql"#$query".as[Int])
} finally {
blockUntilChildSpansFinished(activeSpan(), 1)
}
}
def getResults(future: Future[Vector[Int]]): Int = {
Await.result(future, Duration.Inf).head
}
}
object SlickUtils {
val Driver = "h2"
val Db = "test"
val Username = "TESTUSER"
val Url = s"jdbc:${Driver}:mem:${Db}"
val TestValue = 3
val TestQuery = "SELECT 3"
val ObfuscatedTestQuery = "SELECT ?"
val SleepQuery = "CALL SLEEP(3000)"
}