Fix file formatting (#256)
This commit is contained in:
parent
d70f4ded94
commit
bdf2b8eafd
|
@ -18,23 +18,6 @@ package io.opentelemetry.auto.bootstrap.instrumentation.decorator
|
||||||
import io.opentelemetry.auto.config.Config
|
import io.opentelemetry.auto.config.Config
|
||||||
import io.opentelemetry.auto.instrumentation.api.MoreTags
|
import io.opentelemetry.auto.instrumentation.api.MoreTags
|
||||||
import io.opentelemetry.auto.instrumentation.api.Tags
|
import io.opentelemetry.auto.instrumentation.api.Tags
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright 2020, OpenTelemetry Authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import io.opentelemetry.trace.Span
|
import io.opentelemetry.trace.Span
|
||||||
|
|
||||||
import static io.opentelemetry.auto.test.utils.ConfigUtils.withConfigOverride
|
import static io.opentelemetry.auto.test.utils.ConfigUtils.withConfigOverride
|
||||||
|
|
|
@ -18,7 +18,7 @@ class RangeQueryTest extends Specification {
|
||||||
final VersionRangeRequest rangeRequest = new VersionRangeRequest()
|
final VersionRangeRequest rangeRequest = new VersionRangeRequest()
|
||||||
rangeRequest.setRepositories(MuzzlePlugin.MUZZLE_REPOS)
|
rangeRequest.setRepositories(MuzzlePlugin.MUZZLE_REPOS)
|
||||||
rangeRequest.setArtifact(directiveArtifact)
|
rangeRequest.setArtifact(directiveArtifact)
|
||||||
|
|
||||||
// This call makes an actual network request, which may fail if network access is limited.
|
// This call makes an actual network request, which may fail if network access is limited.
|
||||||
final VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest)
|
final VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest)
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ class ExporterAdaptersTest extends Specification {
|
||||||
|
|
||||||
then:
|
then:
|
||||||
file != null
|
file != null
|
||||||
|
|
||||||
where:
|
where:
|
||||||
exporter << [loggingExporterJar, jaegerExporterJar]
|
exporter << [loggingExporterJar, jaegerExporterJar]
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import io.opentelemetry.auto.bootstrap.AgentClassLoader
|
import io.opentelemetry.auto.bootstrap.AgentClassLoader
|
||||||
import io.opentelemetry.auto.config.Config
|
|
||||||
import io.opentelemetry.auto.bootstrap.instrumentation.decorator.HttpClientDecorator
|
import io.opentelemetry.auto.bootstrap.instrumentation.decorator.HttpClientDecorator
|
||||||
|
import io.opentelemetry.auto.config.Config
|
||||||
import io.opentelemetry.auto.instrumentation.api.MoreTags
|
import io.opentelemetry.auto.instrumentation.api.MoreTags
|
||||||
import io.opentelemetry.auto.instrumentation.api.SpanTypes
|
import io.opentelemetry.auto.instrumentation.api.SpanTypes
|
||||||
import io.opentelemetry.auto.instrumentation.api.Tags
|
import io.opentelemetry.auto.instrumentation.api.Tags
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
<Configuration status="WARN">
|
<Configuration status="WARN">
|
||||||
<Appenders>
|
<Appenders>
|
||||||
<Console name="Console" target="SYSTEM_OUT">
|
<Console name="Console" target="SYSTEM_OUT">
|
||||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
|
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
||||||
</Console>
|
</Console>
|
||||||
</Appenders>
|
</Appenders>
|
||||||
<Loggers>
|
<Loggers>
|
||||||
<Root level="warn">
|
<Root level="warn">
|
||||||
<AppenderRef ref="Console" />
|
<AppenderRef ref="Console"/>
|
||||||
</Root>
|
</Root>
|
||||||
</Loggers>
|
</Loggers>
|
||||||
</Configuration>
|
</Configuration>
|
||||||
|
|
|
@ -24,26 +24,26 @@ import okhttp3.internal.http.HttpMethod
|
||||||
|
|
||||||
class OkHttp3Test extends HttpClientTest {
|
class OkHttp3Test extends HttpClientTest {
|
||||||
|
|
||||||
def client = new OkHttpClient()
|
def client = new OkHttpClient()
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
int doRequest(String method, URI uri, Map<String, String> headers, Closure callback) {
|
int doRequest(String method, URI uri, Map<String, String> headers, Closure callback) {
|
||||||
def body = HttpMethod.requiresRequestBody(method) ? RequestBody.create(MediaType.parse("text/plain"), "") : null
|
def body = HttpMethod.requiresRequestBody(method) ? RequestBody.create(MediaType.parse("text/plain"), "") : null
|
||||||
def request = new Request.Builder()
|
def request = new Request.Builder()
|
||||||
.url(uri.toURL())
|
.url(uri.toURL())
|
||||||
.method(method, body)
|
.method(method, body)
|
||||||
.headers(Headers.of(headers)).build()
|
.headers(Headers.of(headers)).build()
|
||||||
def response = client.newCall(request).execute()
|
def response = client.newCall(request).execute()
|
||||||
callback?.call()
|
callback?.call()
|
||||||
return response.code()
|
return response.code()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
String component() {
|
String component() {
|
||||||
return OkHttpClientDecorator.DECORATE.getComponentName()
|
return OkHttpClientDecorator.DECORATE.getComponentName()
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean testRedirects() {
|
boolean testRedirects() {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,80 +37,80 @@ import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.SUCC
|
||||||
import static io.opentelemetry.trace.Span.Kind.INTERNAL
|
import static io.opentelemetry.trace.Span.Kind.INTERNAL
|
||||||
|
|
||||||
class PlayServerTest extends HttpServerTest<Server> {
|
class PlayServerTest extends HttpServerTest<Server> {
|
||||||
@Override
|
@Override
|
||||||
Server startServer(int port) {
|
Server startServer(int port) {
|
||||||
def router =
|
def router =
|
||||||
new RoutingDsl()
|
new RoutingDsl()
|
||||||
.GET(SUCCESS.getPath()).routeTo({
|
.GET(SUCCESS.getPath()).routeTo({
|
||||||
controller(SUCCESS) {
|
controller(SUCCESS) {
|
||||||
Results.status(SUCCESS.getStatus(), SUCCESS.getBody())
|
Results.status(SUCCESS.getStatus(), SUCCESS.getBody())
|
||||||
}
|
|
||||||
} as Supplier)
|
|
||||||
.GET(QUERY_PARAM.getPath()).routeTo({
|
|
||||||
controller(QUERY_PARAM) {
|
|
||||||
Results.status(QUERY_PARAM.getStatus(), QUERY_PARAM.getBody())
|
|
||||||
}
|
|
||||||
} as Supplier)
|
|
||||||
.GET(REDIRECT.getPath()).routeTo({
|
|
||||||
controller(REDIRECT) {
|
|
||||||
Results.found(REDIRECT.getBody())
|
|
||||||
}
|
|
||||||
} as Supplier)
|
|
||||||
.GET(ERROR.getPath()).routeTo({
|
|
||||||
controller(ERROR) {
|
|
||||||
Results.status(ERROR.getStatus(), ERROR.getBody())
|
|
||||||
}
|
|
||||||
} as Supplier)
|
|
||||||
.GET(EXCEPTION.getPath()).routeTo({
|
|
||||||
controller(EXCEPTION) {
|
|
||||||
throw new Exception(EXCEPTION.getBody())
|
|
||||||
}
|
|
||||||
} as Supplier)
|
|
||||||
|
|
||||||
return Server.forRouter(router.build(), port)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void stopServer(Server server) {
|
|
||||||
server.stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String component() {
|
|
||||||
return NettyHttpServerDecorator.DECORATE.getComponentName()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
boolean hasHandlerSpan() {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean testExceptionBody() {
|
|
||||||
// I can't figure out how to set a proper exception handler to customize the response body.
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void handlerSpan(TraceAssert trace, int index, Object parent, String method = "GET", ServerEndpoint endpoint = SUCCESS) {
|
|
||||||
trace.span(index) {
|
|
||||||
operationName "play.request"
|
|
||||||
spanKind INTERNAL
|
|
||||||
errored endpoint == ERROR || endpoint == EXCEPTION
|
|
||||||
childOf((SpanData) parent)
|
|
||||||
tags {
|
|
||||||
"$MoreTags.SPAN_TYPE" SpanTypes.HTTP_SERVER
|
|
||||||
"$Tags.COMPONENT" PlayHttpServerDecorator.DECORATE.getComponentName()
|
|
||||||
"$MoreTags.NET_PEER_IP" { it == null || it == "127.0.0.1" } // Optional
|
|
||||||
"$Tags.HTTP_URL" String
|
|
||||||
"$Tags.HTTP_METHOD" String
|
|
||||||
"$Tags.HTTP_STATUS" Long
|
|
||||||
if (endpoint == EXCEPTION) {
|
|
||||||
errorTags(Exception, EXCEPTION.body)
|
|
||||||
}
|
|
||||||
if (endpoint.query) {
|
|
||||||
"$MoreTags.HTTP_QUERY" endpoint.query
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} as Supplier)
|
||||||
|
.GET(QUERY_PARAM.getPath()).routeTo({
|
||||||
|
controller(QUERY_PARAM) {
|
||||||
|
Results.status(QUERY_PARAM.getStatus(), QUERY_PARAM.getBody())
|
||||||
|
}
|
||||||
|
} as Supplier)
|
||||||
|
.GET(REDIRECT.getPath()).routeTo({
|
||||||
|
controller(REDIRECT) {
|
||||||
|
Results.found(REDIRECT.getBody())
|
||||||
|
}
|
||||||
|
} as Supplier)
|
||||||
|
.GET(ERROR.getPath()).routeTo({
|
||||||
|
controller(ERROR) {
|
||||||
|
Results.status(ERROR.getStatus(), ERROR.getBody())
|
||||||
|
}
|
||||||
|
} as Supplier)
|
||||||
|
.GET(EXCEPTION.getPath()).routeTo({
|
||||||
|
controller(EXCEPTION) {
|
||||||
|
throw new Exception(EXCEPTION.getBody())
|
||||||
|
}
|
||||||
|
} as Supplier)
|
||||||
|
|
||||||
|
return Server.forRouter(router.build(), port)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void stopServer(Server server) {
|
||||||
|
server.stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
String component() {
|
||||||
|
return NettyHttpServerDecorator.DECORATE.getComponentName()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean hasHandlerSpan() {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean testExceptionBody() {
|
||||||
|
// I can't figure out how to set a proper exception handler to customize the response body.
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void handlerSpan(TraceAssert trace, int index, Object parent, String method = "GET", ServerEndpoint endpoint = SUCCESS) {
|
||||||
|
trace.span(index) {
|
||||||
|
operationName "play.request"
|
||||||
|
spanKind INTERNAL
|
||||||
|
errored endpoint == ERROR || endpoint == EXCEPTION
|
||||||
|
childOf((SpanData) parent)
|
||||||
|
tags {
|
||||||
|
"$MoreTags.SPAN_TYPE" SpanTypes.HTTP_SERVER
|
||||||
|
"$Tags.COMPONENT" PlayHttpServerDecorator.DECORATE.getComponentName()
|
||||||
|
"$MoreTags.NET_PEER_IP" { it == null || it == "127.0.0.1" } // Optional
|
||||||
|
"$Tags.HTTP_URL" String
|
||||||
|
"$Tags.HTTP_METHOD" String
|
||||||
|
"$Tags.HTTP_STATUS" Long
|
||||||
|
if (endpoint == EXCEPTION) {
|
||||||
|
errorTags(Exception, EXCEPTION.body)
|
||||||
|
}
|
||||||
|
if (endpoint.query) {
|
||||||
|
"$MoreTags.HTTP_QUERY" endpoint.query
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,10 +46,7 @@ public class TracingClientResponseSubscriber implements CoreSubscriber<ClientRes
|
||||||
this.clientRequest = clientRequest;
|
this.clientRequest = clientRequest;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
spanRef = new AtomicReference<>(span);
|
spanRef = new AtomicReference<>(span);
|
||||||
this.parentSpan =
|
this.parentSpan = parentSpan == null ? DefaultSpan.getInvalid() : parentSpan;
|
||||||
parentSpan == null
|
|
||||||
? DefaultSpan.getInvalid()
|
|
||||||
: parentSpan;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -30,37 +30,37 @@ import java.util.concurrent.CompletableFuture
|
||||||
@Timeout(10)
|
@Timeout(10)
|
||||||
class VertxHttpClientTest extends HttpClientTest {
|
class VertxHttpClientTest extends HttpClientTest {
|
||||||
|
|
||||||
@Shared
|
@Shared
|
||||||
Vertx vertx = Vertx.vertx(new VertxOptions())
|
Vertx vertx = Vertx.vertx(new VertxOptions())
|
||||||
@Shared
|
@Shared
|
||||||
HttpClient httpClient = vertx.createHttpClient()
|
HttpClient httpClient = vertx.createHttpClient()
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
int doRequest(String method, URI uri, Map<String, String> headers, Closure callback) {
|
int doRequest(String method, URI uri, Map<String, String> headers, Closure callback) {
|
||||||
CompletableFuture<HttpClientResponse> future = new CompletableFuture<>()
|
CompletableFuture<HttpClientResponse> future = new CompletableFuture<>()
|
||||||
def request = httpClient.request(HttpMethod.valueOf(method), uri.port, uri.host, "$uri")
|
def request = httpClient.request(HttpMethod.valueOf(method), uri.port, uri.host, "$uri")
|
||||||
headers.each { request.putHeader(it.key, it.value) }
|
headers.each { request.putHeader(it.key, it.value) }
|
||||||
request.handler { response ->
|
request.handler { response ->
|
||||||
callback?.call()
|
callback?.call()
|
||||||
future.complete(response)
|
future.complete(response)
|
||||||
}
|
|
||||||
request.end()
|
|
||||||
|
|
||||||
return future.get().statusCode()
|
|
||||||
}
|
}
|
||||||
|
request.end()
|
||||||
|
|
||||||
@Override
|
return future.get().statusCode()
|
||||||
String component() {
|
}
|
||||||
return NettyHttpClientDecorator.DECORATE.getComponentName()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean testRedirects() {
|
String component() {
|
||||||
false
|
return NettyHttpClientDecorator.DECORATE.getComponentName()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean testConnectionFailure() {
|
boolean testRedirects() {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean testConnectionFailure() {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,52 +31,52 @@ import java.util.concurrent.CompletableFuture
|
||||||
@Timeout(10)
|
@Timeout(10)
|
||||||
class VertxRxCircuitBreakerWebClientTest extends HttpClientTest {
|
class VertxRxCircuitBreakerWebClientTest extends HttpClientTest {
|
||||||
|
|
||||||
@Shared
|
@Shared
|
||||||
Vertx vertx = Vertx.vertx(new VertxOptions())
|
Vertx vertx = Vertx.vertx(new VertxOptions())
|
||||||
@Shared
|
@Shared
|
||||||
WebClient client = WebClient.create(vertx)
|
WebClient client = WebClient.create(vertx)
|
||||||
@Shared
|
@Shared
|
||||||
CircuitBreaker breaker = CircuitBreaker.create("my-circuit-breaker", vertx,
|
CircuitBreaker breaker = CircuitBreaker.create("my-circuit-breaker", vertx,
|
||||||
new CircuitBreakerOptions()
|
new CircuitBreakerOptions()
|
||||||
.setTimeout(-1) // Disable the timeout otherwise it makes each test take this long.
|
.setTimeout(-1) // Disable the timeout otherwise it makes each test take this long.
|
||||||
)
|
)
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
int doRequest(String method, URI uri, Map<String, String> headers, Closure callback) {
|
int doRequest(String method, URI uri, Map<String, String> headers, Closure callback) {
|
||||||
def request = client.request(HttpMethod.valueOf(method), uri.port, uri.host, "$uri")
|
def request = client.request(HttpMethod.valueOf(method), uri.port, uri.host, "$uri")
|
||||||
headers.each { request.putHeader(it.key, it.value) }
|
headers.each { request.putHeader(it.key, it.value) }
|
||||||
|
|
||||||
def future = new CompletableFuture<Integer>()
|
def future = new CompletableFuture<Integer>()
|
||||||
|
|
||||||
breaker.executeCommand({ command ->
|
breaker.executeCommand({ command ->
|
||||||
request.rxSend().doOnSuccess {
|
request.rxSend().doOnSuccess {
|
||||||
command.complete(it)
|
command.complete(it)
|
||||||
}.doOnError {
|
}.doOnError {
|
||||||
command.fail(it)
|
command.fail(it)
|
||||||
}.subscribe()
|
}.subscribe()
|
||||||
}, {
|
}, {
|
||||||
callback?.call()
|
callback?.call()
|
||||||
if (it.succeeded()) {
|
if (it.succeeded()) {
|
||||||
future.complete(it.result().statusCode())
|
future.complete(it.result().statusCode())
|
||||||
} else {
|
} else {
|
||||||
future.completeExceptionally(it.cause())
|
future.completeExceptionally(it.cause())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return future.get()
|
return future.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
String component() {
|
String component() {
|
||||||
return NettyHttpClientDecorator.DECORATE.getComponentName()
|
return NettyHttpClientDecorator.DECORATE.getComponentName()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean testRedirects() {
|
boolean testRedirects() {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean testConnectionFailure() {
|
boolean testConnectionFailure() {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,35 +27,35 @@ import spock.lang.Timeout
|
||||||
@Timeout(10)
|
@Timeout(10)
|
||||||
class VertxRxWebClientTest extends HttpClientTest {
|
class VertxRxWebClientTest extends HttpClientTest {
|
||||||
|
|
||||||
@Shared
|
@Shared
|
||||||
Vertx vertx = Vertx.vertx(new VertxOptions())
|
Vertx vertx = Vertx.vertx(new VertxOptions())
|
||||||
@Shared
|
@Shared
|
||||||
WebClient client = WebClient.create(vertx)
|
WebClient client = WebClient.create(vertx)
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
int doRequest(String method, URI uri, Map<String, String> headers, Closure callback) {
|
int doRequest(String method, URI uri, Map<String, String> headers, Closure callback) {
|
||||||
def request = client.request(HttpMethod.valueOf(method), uri.port, uri.host, "$uri")
|
def request = client.request(HttpMethod.valueOf(method), uri.port, uri.host, "$uri")
|
||||||
headers.each { request.putHeader(it.key, it.value) }
|
headers.each { request.putHeader(it.key, it.value) }
|
||||||
return request
|
return request
|
||||||
.rxSend()
|
.rxSend()
|
||||||
.doOnSuccess { response -> callback?.call() }
|
.doOnSuccess { response -> callback?.call() }
|
||||||
.map { it.statusCode() }
|
.map { it.statusCode() }
|
||||||
.toObservable()
|
.toObservable()
|
||||||
.blockingFirst()
|
.blockingFirst()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
String component() {
|
String component() {
|
||||||
return NettyHttpClientDecorator.DECORATE.getComponentName()
|
return NettyHttpClientDecorator.DECORATE.getComponentName()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean testRedirects() {
|
boolean testRedirects() {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean testConnectionFailure() {
|
boolean testConnectionFailure() {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,84 +34,84 @@ import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.REDI
|
||||||
import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
import static io.opentelemetry.auto.test.base.HttpServerTest.ServerEndpoint.SUCCESS
|
||||||
|
|
||||||
class VertxHttpServerTest extends HttpServerTest<Vertx> {
|
class VertxHttpServerTest extends HttpServerTest<Vertx> {
|
||||||
public static final String CONFIG_HTTP_SERVER_PORT = "http.server.port"
|
public static final String CONFIG_HTTP_SERVER_PORT = "http.server.port"
|
||||||
|
|
||||||
|
@Override
|
||||||
|
Vertx startServer(int port) {
|
||||||
|
def server = Vertx.vertx(new VertxOptions()
|
||||||
|
// Useful for debugging:
|
||||||
|
// .setBlockedThreadCheckInterval(Integer.MAX_VALUE)
|
||||||
|
.setClusterPort(port))
|
||||||
|
final CompletableFuture<Void> future = new CompletableFuture<>()
|
||||||
|
server.deployVerticle(verticle().name,
|
||||||
|
new DeploymentOptions()
|
||||||
|
.setConfig(new JsonObject().put(CONFIG_HTTP_SERVER_PORT, port))
|
||||||
|
.setInstances(3)) { res ->
|
||||||
|
if (!res.succeeded()) {
|
||||||
|
throw new RuntimeException("Cannot deploy server Verticle", res.cause())
|
||||||
|
}
|
||||||
|
future.complete(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
future.get()
|
||||||
|
return server
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Class<io.vertx.reactivex.core.AbstractVerticle> verticle() {
|
||||||
|
return VertxWebTestServer
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void stopServer(Vertx server) {
|
||||||
|
server.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
String component() {
|
||||||
|
return NettyHttpServerDecorator.DECORATE.getComponentName()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean testExceptionBody() {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
static class VertxWebTestServer extends AbstractVerticle {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Vertx startServer(int port) {
|
void start(final Future<Void> startFuture) {
|
||||||
def server = Vertx.vertx(new VertxOptions()
|
final int port = config().getInteger(CONFIG_HTTP_SERVER_PORT)
|
||||||
// Useful for debugging:
|
final Router router = Router.router(vertx)
|
||||||
// .setBlockedThreadCheckInterval(Integer.MAX_VALUE)
|
|
||||||
.setClusterPort(port))
|
router.route(SUCCESS.path).handler { ctx ->
|
||||||
final CompletableFuture<Void> future = new CompletableFuture<>()
|
controller(SUCCESS) {
|
||||||
server.deployVerticle(verticle().name,
|
ctx.response().setStatusCode(SUCCESS.status).end(SUCCESS.body)
|
||||||
new DeploymentOptions()
|
|
||||||
.setConfig(new JsonObject().put(CONFIG_HTTP_SERVER_PORT, port))
|
|
||||||
.setInstances(3)) { res ->
|
|
||||||
if (!res.succeeded()) {
|
|
||||||
throw new RuntimeException("Cannot deploy server Verticle", res.cause())
|
|
||||||
}
|
|
||||||
future.complete(null)
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
future.get()
|
router.route(QUERY_PARAM.path).handler { ctx ->
|
||||||
return server
|
controller(QUERY_PARAM) {
|
||||||
}
|
ctx.response().setStatusCode(QUERY_PARAM.status).end(ctx.request().query())
|
||||||
|
|
||||||
protected Class<io.vertx.reactivex.core.AbstractVerticle> verticle() {
|
|
||||||
return VertxWebTestServer
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void stopServer(Vertx server) {
|
|
||||||
server.close()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String component() {
|
|
||||||
return NettyHttpServerDecorator.DECORATE.getComponentName()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
boolean testExceptionBody() {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
static class VertxWebTestServer extends AbstractVerticle {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void start(final Future<Void> startFuture) {
|
|
||||||
final int port = config().getInteger(CONFIG_HTTP_SERVER_PORT)
|
|
||||||
final Router router = Router.router(vertx)
|
|
||||||
|
|
||||||
router.route(SUCCESS.path).handler { ctx ->
|
|
||||||
controller(SUCCESS) {
|
|
||||||
ctx.response().setStatusCode(SUCCESS.status).end(SUCCESS.body)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
router.route(QUERY_PARAM.path).handler { ctx ->
|
|
||||||
controller(QUERY_PARAM) {
|
|
||||||
ctx.response().setStatusCode(QUERY_PARAM.status).end(ctx.request().query())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
router.route(REDIRECT.path).handler { ctx ->
|
|
||||||
controller(REDIRECT) {
|
|
||||||
ctx.response().setStatusCode(REDIRECT.status).putHeader("location", REDIRECT.body).end()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
router.route(ERROR.path).handler { ctx ->
|
|
||||||
controller(ERROR) {
|
|
||||||
ctx.response().setStatusCode(ERROR.status).end(ERROR.body)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
router.route(EXCEPTION.path).handler { ctx ->
|
|
||||||
controller(EXCEPTION) {
|
|
||||||
throw new Exception(EXCEPTION.body)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vertx.createHttpServer()
|
|
||||||
.requestHandler { router.accept(it) }
|
|
||||||
.listen(port) { startFuture.complete() }
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
router.route(REDIRECT.path).handler { ctx ->
|
||||||
|
controller(REDIRECT) {
|
||||||
|
ctx.response().setStatusCode(REDIRECT.status).putHeader("location", REDIRECT.body).end()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
router.route(ERROR.path).handler { ctx ->
|
||||||
|
controller(ERROR) {
|
||||||
|
ctx.response().setStatusCode(ERROR.status).end(ERROR.body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
router.route(EXCEPTION.path).handler { ctx ->
|
||||||
|
controller(EXCEPTION) {
|
||||||
|
throw new Exception(EXCEPTION.body)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vertx.createHttpServer()
|
||||||
|
.requestHandler { router.accept(it) }
|
||||||
|
.listen(port) { startFuture.complete() }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue