-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates an OpenTracing integration test
- Loading branch information
1 parent
c80e65e
commit 2e0d93c
Showing
17 changed files
with
664 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/ExporterResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.quarkus.it.opentracing; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import io.opentracing.mock.MockSpan; | ||
import io.opentracing.mock.MockTracer; | ||
|
||
@Path("/export") | ||
public class ExporterResource { | ||
@Inject | ||
MockTracer mockTracer; | ||
|
||
@GET | ||
@Path("/clear") | ||
public void clearExporter() { | ||
mockTracer.reset(); | ||
} | ||
|
||
@GET | ||
public List<MockSpan> retrieve() { | ||
return mockTracer.finishedSpans().stream() | ||
.filter(span -> !span.operationName().equals("GET:io.quarkus.it.opentracing.ExporterResource.clearExporter") && | ||
!span.operationName().equals("GET:io.quarkus.it.opentracing.ExporterResource.retrieve")) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...tion-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/JdbcResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.quarkus.it.opentracing; | ||
|
||
import java.sql.Connection; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
|
||
import javax.inject.Inject; | ||
import javax.sql.DataSource; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
@Path("/jdbc") | ||
public class JdbcResource { | ||
@Inject | ||
DataSource defaultDataSource; | ||
|
||
@GET | ||
public TraceData jdbc() throws SQLException { | ||
Connection con = defaultDataSource.getConnection(); | ||
try (Statement stmt = con.createStatement()) { | ||
ResultSet resultSet = stmt.executeQuery("select 1"); | ||
resultSet.next(); | ||
String result = resultSet.getString(1); | ||
TraceData data = new TraceData(); | ||
data.message = result; | ||
return data; | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/MockTracerProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.quarkus.it.opentracing; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Singleton; | ||
|
||
import io.opentracing.mock.MockTracer; | ||
import io.opentracing.util.GlobalTracer; | ||
import io.quarkus.arc.AlternativePriority; | ||
|
||
@ApplicationScoped | ||
public class MockTracerProvider { | ||
|
||
@Produces | ||
@Singleton | ||
@AlternativePriority(1) | ||
public MockTracer createInMemoryExporter() { | ||
MockTracer tracer = new MockTracer(); | ||
GlobalTracer.registerIfAbsent(tracer); | ||
return tracer; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/PingPongResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.quarkus.it.opentracing; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
|
||
import io.smallrye.common.annotation.Blocking; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
@Singleton | ||
@Path("/client") | ||
public class PingPongResource { | ||
@RegisterRestClient(configKey = "pingpong") | ||
public interface PingPongRestClient { | ||
|
||
@Path("/client/pong/{message}") | ||
@GET | ||
String pingpong(@PathParam("message") String message); | ||
|
||
@GET | ||
@Path("/client/pong/{message}") | ||
Uni<String> asyncPingpong(@PathParam("message") String message); | ||
} | ||
|
||
@Inject | ||
@RestClient | ||
PingPongRestClient pingRestClient; | ||
|
||
@GET | ||
@Path("pong/{message}") | ||
public String pong(@PathParam("message") String message) { | ||
return message; | ||
} | ||
|
||
@GET | ||
@Blocking | ||
@Path("ping/{message}") | ||
public String ping(@PathParam("message") String message) { | ||
return pingRestClient.pingpong(message); | ||
} | ||
|
||
@GET | ||
@Path("async-ping/{message}") | ||
public Uni<String> asyncPing(@PathParam("message") String message) { | ||
return pingRestClient.asyncPingpong(message); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...on-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/SimpleResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.quarkus.it.opentracing; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
@Path("/") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public class SimpleResource { | ||
|
||
@Inject | ||
TracedService tracedService; | ||
|
||
@GET | ||
@Path("/direct") | ||
public TraceData directTrace() { | ||
TraceData data = new TraceData(); | ||
data.message = "Direct trace"; | ||
|
||
return data; | ||
} | ||
|
||
@GET | ||
@Path("/chained") | ||
public TraceData chainedTrace() { | ||
TraceData data = new TraceData(); | ||
data.message = tracedService.call(); | ||
|
||
return data; | ||
} | ||
|
||
@GET | ||
@Path("/deep/path") | ||
public TraceData deepUrlPathTrace() { | ||
TraceData data = new TraceData(); | ||
data.message = "Deep url path"; | ||
|
||
return data; | ||
} | ||
|
||
@GET | ||
@Path("/param/{paramId}") | ||
public TraceData pathParameters(@PathParam("paramId") String paramId) { | ||
TraceData data = new TraceData(); | ||
data.message = "ParameterId: " + paramId; | ||
|
||
return data; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...gration-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/TraceData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.quarkus.it.opentracing; | ||
|
||
public class TraceData { | ||
public String message; | ||
public String tracer; | ||
public String span; | ||
} |
10 changes: 10 additions & 0 deletions
10
...ion-tests/smallrye-opentracing/src/main/java/io/quarkus/it/opentracing/TracedService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.quarkus.it.opentracing; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class TracedService { | ||
public String call() { | ||
return "Chained trace"; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ye-opentracing/src/main/java/io/quarkus/it/opentracing/json/MockSpanModuleSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.quarkus.it.opentracing.json; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
|
||
import io.opentracing.mock.MockSpan; | ||
import io.quarkus.jackson.ObjectMapperCustomizer; | ||
|
||
@Singleton | ||
public class MockSpanModuleSerializer implements ObjectMapperCustomizer { | ||
@Override | ||
public void customize(ObjectMapper objectMapper) { | ||
SimpleModule simpleModule = new SimpleModule(); | ||
simpleModule.addSerializer(MockSpan.class, new MockSpanSerializer()); | ||
objectMapper.registerModule(simpleModule); | ||
} | ||
} |
Oops, something went wrong.