Skip to content

Commit e3967c9

Browse files
committed
Add kotlin and scala formatter
1 parent ccc5af0 commit e3967c9

13 files changed

Lines changed: 240 additions & 101 deletions

File tree

dd-java-agent/instrumentation/akka-http-10.0/src/test/scala/AkkaHttpTestAsyncWebServer.scala

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,27 @@ object AkkaHttpTestAsyncWebServer {
1818
val asyncHandler: HttpRequest => Future[HttpResponse] = {
1919
case HttpRequest(GET, uri: Uri, _, _, _) =>
2020
Future {
21-
val endpoint = HttpServerTest.ServerEndpoint.forPath(uri.path.toString())
22-
HttpServerTest.controller(endpoint, new Closure[HttpResponse](()) {
23-
def doCall(): HttpResponse = {
24-
val resp = HttpResponse(status = endpoint.getStatus) //.withHeaders(headers.Type)resp.contentType = "text/plain"
25-
endpoint match {
26-
case SUCCESS => resp.withEntity(endpoint.getBody)
27-
case QUERY_PARAM => resp.withEntity(uri.queryString().orNull)
28-
case REDIRECT => resp.withHeaders(headers.Location(endpoint.getBody))
29-
case ERROR => resp.withEntity(endpoint.getBody)
30-
case EXCEPTION => throw new Exception(endpoint.getBody)
31-
case _ => HttpResponse(status = NOT_FOUND.getStatus).withEntity(NOT_FOUND.getBody)
21+
val endpoint =
22+
HttpServerTest.ServerEndpoint.forPath(uri.path.toString())
23+
HttpServerTest.controller(
24+
endpoint,
25+
new Closure[HttpResponse](()) {
26+
def doCall(): HttpResponse = {
27+
val resp = HttpResponse(status = endpoint.getStatus) //.withHeaders(headers.Type)resp.contentType = "text/plain"
28+
endpoint match {
29+
case SUCCESS => resp.withEntity(endpoint.getBody)
30+
case QUERY_PARAM => resp.withEntity(uri.queryString().orNull)
31+
case REDIRECT =>
32+
resp.withHeaders(headers.Location(endpoint.getBody))
33+
case ERROR => resp.withEntity(endpoint.getBody)
34+
case EXCEPTION => throw new Exception(endpoint.getBody)
35+
case _ =>
36+
HttpResponse(status = NOT_FOUND.getStatus)
37+
.withEntity(NOT_FOUND.getBody)
38+
}
3239
}
3340
}
34-
})
41+
)
3542
}
3643
}
3744

@@ -40,7 +47,10 @@ object AkkaHttpTestAsyncWebServer {
4047
def start(port: Int): Unit = synchronized {
4148
if (null == binding) {
4249
import scala.concurrent.duration._
43-
binding = Await.result(Http().bindAndHandleAsync(asyncHandler, "localhost", port), 10 seconds)
50+
binding = Await.result(
51+
Http().bindAndHandleAsync(asyncHandler, "localhost", port),
52+
10 seconds
53+
)
4454
}
4555
}
4656

dd-java-agent/instrumentation/akka-http-10.0/src/test/scala/AkkaHttpTestSyncWebServer.scala

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,25 @@ object AkkaHttpTestSyncWebServer {
1818
val syncHandler: HttpRequest => HttpResponse = {
1919
case HttpRequest(GET, uri: Uri, _, _, _) => {
2020
val endpoint = HttpServerTest.ServerEndpoint.forPath(uri.path.toString())
21-
HttpServerTest.controller(endpoint, new Closure[HttpResponse](()) {
22-
def doCall(): HttpResponse = {
23-
val resp = HttpResponse(status = endpoint.getStatus)
24-
endpoint match {
25-
case SUCCESS => resp.withEntity(endpoint.getBody)
26-
case QUERY_PARAM => resp.withEntity(uri.queryString().orNull)
27-
case REDIRECT => resp.withHeaders(headers.Location(endpoint.getBody))
28-
case ERROR => resp.withEntity(endpoint.getBody)
29-
case EXCEPTION => throw new Exception(endpoint.getBody)
30-
case _ => HttpResponse(status = NOT_FOUND.getStatus).withEntity(NOT_FOUND.getBody)
21+
HttpServerTest.controller(
22+
endpoint,
23+
new Closure[HttpResponse](()) {
24+
def doCall(): HttpResponse = {
25+
val resp = HttpResponse(status = endpoint.getStatus)
26+
endpoint match {
27+
case SUCCESS => resp.withEntity(endpoint.getBody)
28+
case QUERY_PARAM => resp.withEntity(uri.queryString().orNull)
29+
case REDIRECT =>
30+
resp.withHeaders(headers.Location(endpoint.getBody))
31+
case ERROR => resp.withEntity(endpoint.getBody)
32+
case EXCEPTION => throw new Exception(endpoint.getBody)
33+
case _ =>
34+
HttpResponse(status = NOT_FOUND.getStatus)
35+
.withEntity(NOT_FOUND.getBody)
36+
}
3137
}
3238
}
33-
})
39+
)
3440
}
3541
}
3642

@@ -39,7 +45,10 @@ object AkkaHttpTestSyncWebServer {
3945
def start(port: Int): Unit = synchronized {
4046
if (null == binding) {
4147
import scala.concurrent.duration._
42-
binding = Await.result(Http().bindAndHandleSync(syncHandler, "localhost", port), 10 seconds)
48+
binding = Await.result(
49+
Http().bindAndHandleSync(syncHandler, "localhost", port),
50+
10 seconds
51+
)
4352
}
4453
}
4554

dd-java-agent/instrumentation/akka-http-10.0/src/test/scala/AkkaHttpTestWebServer.scala

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@ object AkkaHttpTestWebServer {
1717
implicit val executionContext = system.dispatcher
1818

1919
val exceptionHandler = ExceptionHandler {
20-
case ex: Exception => complete(HttpResponse(status = EXCEPTION.getStatus).withEntity(ex.getMessage))
20+
case ex: Exception =>
21+
complete(
22+
HttpResponse(status = EXCEPTION.getStatus).withEntity(ex.getMessage)
23+
)
2124
}
2225

2326
val route = { //handleExceptions(exceptionHandler) {
2427
path(SUCCESS.rawPath) {
25-
complete(HttpResponse(status = SUCCESS.getStatus).withEntity(SUCCESS.getBody))
28+
complete(
29+
HttpResponse(status = SUCCESS.getStatus).withEntity(SUCCESS.getBody)
30+
)
2631
} ~ path(QUERY_PARAM.rawPath) {
27-
complete(HttpResponse(status = QUERY_PARAM.getStatus).withEntity(SUCCESS.getBody))
32+
complete(
33+
HttpResponse(status = QUERY_PARAM.getStatus).withEntity(SUCCESS.getBody)
34+
)
2835
} ~ path(REDIRECT.rawPath) {
2936
redirect(Uri(REDIRECT.getBody), StatusCodes.Found)
3037
} ~ path(ERROR.rawPath) {
@@ -39,7 +46,8 @@ object AkkaHttpTestWebServer {
3946
def start(port: Int): Unit = synchronized {
4047
if (null == binding) {
4148
import scala.concurrent.duration._
42-
binding = Await.result(Http().bindAndHandle(route, "localhost", port), 10 seconds)
49+
binding =
50+
Await.result(Http().bindAndHandle(route, "localhost", port), 10 seconds)
4351
}
4452
}
4553

dd-java-agent/instrumentation/finatra-2.9/src/test/scala/ResponseSettingExceptionMapper.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
2-
31
import com.twitter.finagle.http.{Request, Response}
42
import com.twitter.finatra.http.exceptions.ExceptionMapper
53
import com.twitter.finatra.http.response.ResponseBuilder
64
import javax.inject.{Inject, Singleton}
75

86
@Singleton
97
class ResponseSettingExceptionMapper @Inject()(response: ResponseBuilder)
10-
extends ExceptionMapper[Exception] {
8+
extends ExceptionMapper[Exception] {
119

1210
override def toResponse(request: Request, exception: Exception): Response = {
1311
response.internalServerError(exception.getMessage)

dd-java-agent/instrumentation/java-concurrent/akka-testing/src/test/scala/AkkaActors.scala

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import akka.pattern.ask
33
import akka.util.Timeout
44
import datadog.trace.agent.test.AgentTestRunner.blockUntilChildSpansFinished
55
import datadog.trace.api.Trace
6-
import datadog.trace.bootstrap.instrumentation.api.AgentTracer.{activeScope, activeSpan}
6+
import datadog.trace.bootstrap.instrumentation.api.AgentTracer.{
7+
activeScope,
8+
activeSpan
9+
}
710

811
import scala.concurrent.duration._
912

@@ -16,8 +19,10 @@ object AkkaActors {
1619
val howdyGreeter: ActorRef =
1720
system.actorOf(Greeter.props("Howdy", printer), "howdyGreeter")
1821

19-
val forwarder: ActorRef = system.actorOf(Forwarder.props(printer), "forwarderActor")
20-
val helloGreeter: ActorRef = system.actorOf(Greeter.props("Hello", forwarder), "helloGreeter")
22+
val forwarder: ActorRef =
23+
system.actorOf(Forwarder.props(printer), "forwarderActor")
24+
val helloGreeter: ActorRef =
25+
system.actorOf(Greeter.props("Hello", forwarder), "helloGreeter")
2126

2227
@Trace
2328
def tracedChild(opName: String): Unit = {
@@ -67,7 +72,8 @@ class AkkaActors {
6772
}
6873

6974
object Greeter {
70-
def props(message: String, receiverActor: ActorRef): Props = Props(new Greeter(message, receiverActor))
75+
def props(message: String, receiverActor: ActorRef): Props =
76+
Props(new Greeter(message, receiverActor))
7177

7278
final case class WhoToGreet(who: String)
7379

@@ -110,7 +116,8 @@ class Receiver extends Actor with ActorLogging {
110116
}
111117

112118
object Forwarder {
113-
def props(receiverActor: ActorRef): Props = Props(new Forwarder(receiverActor))
119+
def props(receiverActor: ActorRef): Props =
120+
Props(new Forwarder(receiverActor))
114121
}
115122

116123
class Forwarder(receiverActor: ActorRef) extends Actor with ActorLogging {

dd-java-agent/instrumentation/java-concurrent/kotlin-testing/src/test/kotlin/KotlinCoroutineTests.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import datadog.trace.api.Trace
22
import datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeScope
33
import datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeSpan
4-
import kotlinx.coroutines.*
4+
import java.util.concurrent.TimeUnit
5+
import kotlinx.coroutines.CompletableDeferred
6+
import kotlinx.coroutines.CoroutineDispatcher
7+
import kotlinx.coroutines.CoroutineScope
8+
import kotlinx.coroutines.CoroutineStart
9+
import kotlinx.coroutines.async
10+
import kotlinx.coroutines.awaitAll
511
import kotlinx.coroutines.channels.actor
612
import kotlinx.coroutines.channels.consumeEach
713
import kotlinx.coroutines.channels.produce
814
import kotlinx.coroutines.channels.toChannel
15+
import kotlinx.coroutines.launch
16+
import kotlinx.coroutines.runBlocking
917
import kotlinx.coroutines.selects.select
10-
import java.util.concurrent.TimeUnit
18+
import kotlinx.coroutines.withTimeout
19+
import kotlinx.coroutines.yield
1120

1221
class KotlinCoroutineTests(private val dispatcher: CoroutineDispatcher) {
1322

@@ -136,4 +145,3 @@ class KotlinCoroutineTests(private val dispatcher: CoroutineDispatcher) {
136145
return runBlocking(dispatcher, block = block)
137146
}
138147
}
139-

dd-java-agent/instrumentation/java-concurrent/scala-testing/src/test/scala/ScalaConcurrentTests.scala

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import datadog.trace.agent.test.AgentTestRunner.blockUntilChildSpansFinished
22
import datadog.trace.api.Trace
3-
import datadog.trace.bootstrap.instrumentation.api.AgentTracer.{activeScope, activeSpan}
3+
import datadog.trace.bootstrap.instrumentation.api.AgentTracer.{
4+
activeScope,
5+
activeSpan
6+
}
47

58
import scala.concurrent.ExecutionContext.Implicits.global
69
import scala.concurrent.duration._
@@ -9,8 +12,8 @@ import scala.concurrent.{Await, Future, Promise}
912
class ScalaConcurrentTests {
1013

1114
/**
12-
* @return Number of expected spans in the trace
13-
*/
15+
* @return Number of expected spans in the trace
16+
*/
1417
@Trace
1518
def traceWithFutureAndCallbacks(): Integer = {
1619
activeScope().setAsyncPropagation(true)
@@ -40,20 +43,21 @@ class ScalaConcurrentTests {
4043
1
4144
}
4245
goodFuture onSuccess {
43-
case _ => Future {
44-
2
45-
} onSuccess {
46-
case _ => tracedChild("callback")
47-
}
46+
case _ =>
47+
Future {
48+
2
49+
} onSuccess {
50+
case _ => tracedChild("callback")
51+
}
4852
}
4953

5054
blockUntilChildSpansFinished(1)
5155
return 2
5256
}
5357

5458
/**
55-
* @return Number of expected spans in the trace
56-
*/
59+
* @return Number of expected spans in the trace
60+
*/
5761
@Trace
5862
def traceWithPromises(): Integer = {
5963
activeScope().setAsyncPropagation(true)
@@ -86,34 +90,30 @@ class ScalaConcurrentTests {
8690
}
8791

8892
/**
89-
* @return Number of expected spans in the trace
90-
*/
93+
* @return Number of expected spans in the trace
94+
*/
9195
@Trace
9296
def tracedWithFutureFirstCompletions(): Integer = {
9397
activeScope().setAsyncPropagation(true)
94-
val completedVal = Future.firstCompletedOf(
95-
List(
96-
Future {
97-
tracedChild("timeout1")
98-
false
99-
},
100-
Future {
101-
tracedChild("timeout2")
102-
false
103-
},
104-
Future {
105-
tracedChild("timeout3")
106-
true
107-
}))
98+
val completedVal = Future.firstCompletedOf(List(Future {
99+
tracedChild("timeout1")
100+
false
101+
}, Future {
102+
tracedChild("timeout2")
103+
false
104+
}, Future {
105+
tracedChild("timeout3")
106+
true
107+
}))
108108
Await.result(completedVal, 30 seconds)
109109

110110
blockUntilChildSpansFinished(3)
111111
return 4
112112
}
113113

114114
/**
115-
* @return Number of expected spans in the trace
116-
*/
115+
* @return Number of expected spans in the trace
116+
*/
117117
@Trace
118118
def tracedTimeout(): Integer = {
119119
activeScope().setAsyncPropagation(true)

dd-java-agent/instrumentation/java-concurrent/src/slickTest/scala/SlickUtils.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@ class SlickUtils {
1010

1111
import SlickUtils._
1212

13-
val database = Database.forURL(Url,
13+
val database = Database.forURL(
14+
Url,
1415
user = Username,
1516
driver = "org.h2.Driver",
1617
keepAliveConnection = true,
1718
// Limit number of threads to hit Slick-specific case when we need to avoid re-wrapping
1819
// wrapped runnables.
1920
executor = AsyncExecutor("test", numThreads = 1, queueSize = 1000)
2021
)
21-
Await.result(database.run(sqlu"""CREATE ALIAS IF NOT EXISTS SLEEP FOR "java.lang.Thread.sleep(long)""""), Duration.Inf)
22+
Await.result(
23+
database.run(
24+
sqlu"""CREATE ALIAS IF NOT EXISTS SLEEP FOR "java.lang.Thread.sleep(long)""""
25+
),
26+
Duration.Inf
27+
)
2228

2329
@Trace
2430
def startQuery(query: String): Future[Vector[Int]] = {

0 commit comments

Comments
 (0)