Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempted fix for intermittent issue #4532

Merged
merged 1 commit into from
Jul 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import io.helidon.tracing.Span;
import io.helidon.tracing.jersey.client.ClientTracingFilter;
Expand All @@ -42,11 +40,13 @@
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.core.Response;
import org.glassfish.jersey.client.ClientConfig;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.fail;
Expand All @@ -63,11 +63,29 @@ class OpentraceableClientE2ETest {
private static Client client;

@BeforeAll
static void startServerInitClient() throws Exception {
static void startServerInitClient() {
server = startWebServer();
client = ClientBuilder.newClient(new ClientConfig(ClientTracingFilter.class));
}

@AfterAll
static void stopAndClose() throws Exception {
if (server != null) {
server.shutdown()
.toCompletableFuture()
.get(10, TimeUnit.SECONDS);
}

if (client != null) {
client.close();
}
}

@BeforeEach
void resetTraces() {
EVENTS_MAP.clear();
}

@Test
void e2e() throws Exception {
io.helidon.tracing.Tracer tracer = tracer("test-client");
Expand All @@ -89,29 +107,21 @@ void e2e() throws Exception {

TraceContext traceContext = ((BraveSpanContext) start.unwrap(io.opentracing.Span.class).context()).unwrap();

assertSpanChain(EVENTS_MAP.remove(traceContext.traceIdString()), EVENTS_MAP);
zipkin2.Span reportedSpan = EVENTS_MAP.remove(traceContext.traceIdString());
assertThat("Span with id " + reportedSpan.traceId() + " was not found in "
+ printSpans(EVENTS_MAP), reportedSpan, notNullValue());
assertSpanChain(reportedSpan, EVENTS_MAP);
assertThat(EVENTS_MAP.entrySet(), hasSize(0));
}

@AfterEach
public void stopAndClose() throws Exception {
if (server != null) {
server.shutdown()
.toCompletableFuture()
.get(10, TimeUnit.SECONDS);
}

client.close();
}

/**
* Use custom {@link Tracer} that adds events to {@link #EVENTS_MAP} map.
*/
private static io.helidon.tracing.Tracer tracer(String serviceName) {
Tracing braveTracing = Tracing.newBuilder()
.localServiceName(serviceName)
.spanReporter(span -> {
EVENTS_MAP.put(span.id(), span);
EVENTS_MAP.put(span.traceId(), span);
EVENTS_LATCH.countDown();
})
.build();
Expand All @@ -120,7 +130,7 @@ private static io.helidon.tracing.Tracer tracer(String serviceName) {
return OpenTracing.create(new ZipkinTracer(BraveTracer.create(braveTracing), List.of()));
}

private static WebServer startWebServer() throws InterruptedException, ExecutionException, TimeoutException {
private static WebServer startWebServer() {
return WebServer.builder()
.host("localhost")
.routing(Routing.builder()
Expand Down