Skip to content
Closed
Show file tree
Hide file tree
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 @@ -35,12 +35,14 @@
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_USER;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DbSystemNameIncubatingValues.HSQLDB;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.context.propagation.TextMapSetter;
import io.opentelemetry.instrumentation.test.utils.PortUtils;
Expand All @@ -59,6 +61,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import java.util.function.Consumer;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -149,7 +152,7 @@ void contextPropagation() {

@SuppressWarnings("deprecation") // uses deprecated db semconv
@Test
void highConcurrency() {
void highConcurrency() throws Exception {
int count = 100;
String baseUrl = "/listProducts";
CountDownLatch latch = new CountDownLatch(1);
Expand All @@ -160,29 +163,37 @@ void highConcurrency() {
TextMapSetter<HttpRequestBuilder> setter =
(carrier, name, value) -> carrier.header(name, value);

List<Future<?>> futures = new ArrayList<>();
for (int i = 0; i < count; i++) {
int index = i;
pool.submit(
() -> {
try {
latch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
testing.runWithSpan(
"client " + index,
() -> {
HttpRequestBuilder builder =
HttpRequest.builder()
.get(baseUrl + "?" + TEST_REQUEST_ID_PARAMETER + "=" + index);
Span.current().setAttribute(TEST_REQUEST_ID_ATTRIBUTE, index);
propagator.inject(Context.current(), builder, setter);
client.execute(builder.build()).aggregate().join();
});
});
futures.add(
pool.submit(
() -> {
try {
assertThat(latch.await(10, SECONDS)).isTrue();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new AssertionError(e);
}
try (Scope ignored = Context.root().makeCurrent()) {
testing.runWithSpan(
"client " + index,
() -> {
HttpRequestBuilder builder =
HttpRequest.builder()
.get(baseUrl + "?" + TEST_REQUEST_ID_PARAMETER + "=" + index);
Span.current().setAttribute(TEST_REQUEST_ID_ATTRIBUTE, index);
propagator.inject(Context.current(), builder, setter);
client.execute(builder.build()).aggregate().join();
});
}
}));
}

latch.countDown();
for (Future<?> future : futures) {
future.get(30, SECONDS);
}

List<Consumer<TraceAssert>> assertions = new ArrayList<>();
for (int i = 0; i < count; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_USER;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DbSystemNameIncubatingValues.HSQLDB;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.context.propagation.TextMapSetter;
import io.opentelemetry.instrumentation.test.utils.PortUtils;
Expand All @@ -59,6 +61,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import java.util.function.Consumer;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -149,7 +152,7 @@ void contextPropagation() {

@SuppressWarnings("deprecation") // uses deprecated db semconv
@Test
void highConcurrency() {
void highConcurrency() throws Exception {
int count = 100;
String baseUrl = "/listProducts";
CountDownLatch latch = new CountDownLatch(1);
Expand All @@ -160,29 +163,37 @@ void highConcurrency() {
TextMapSetter<HttpRequestBuilder> setter =
(carrier, name, value) -> carrier.header(name, value);

List<Future<?>> futures = new ArrayList<>();
for (int i = 0; i < count; i++) {
int index = i;
pool.submit(
() -> {
try {
latch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
testing.runWithSpan(
"client " + index,
() -> {
HttpRequestBuilder builder =
HttpRequest.builder()
.get(baseUrl + "?" + TEST_REQUEST_ID_PARAMETER + "=" + index);
Span.current().setAttribute(TEST_REQUEST_ID_ATTRIBUTE, index);
propagator.inject(Context.current(), builder, setter);
client.execute(builder.build()).aggregate().join();
});
});
futures.add(
pool.submit(
() -> {
try {
assertThat(latch.await(10, SECONDS)).isTrue();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new AssertionError(e);
}
try (Scope ignored = Context.root().makeCurrent()) {
testing.runWithSpan(
"client " + index,
() -> {
HttpRequestBuilder builder =
HttpRequest.builder()
.get(baseUrl + "?" + TEST_REQUEST_ID_PARAMETER + "=" + index);
Span.current().setAttribute(TEST_REQUEST_ID_ATTRIBUTE, index);
propagator.inject(Context.current(), builder, setter);
client.execute(builder.build()).aggregate().join();
});
}
}));
}

latch.countDown();
for (Future<?> future : futures) {
future.get(30, SECONDS);
}

List<Consumer<TraceAssert>> assertions = new ArrayList<>();
for (int i = 0; i < count; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_SYSTEM;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DB_USER;
import static io.opentelemetry.semconv.incubating.DbIncubatingAttributes.DbSystemNameIncubatingValues.HSQLDB;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.context.propagation.TextMapSetter;
import io.opentelemetry.instrumentation.test.utils.PortUtils;
Expand All @@ -59,6 +61,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import java.util.function.Consumer;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -149,7 +152,7 @@ void contextPropagation() {

@SuppressWarnings("deprecation") // uses deprecated db semconv
@Test
void highConcurrency() {
void highConcurrency() throws Exception {
int count = 100;
String baseUrl = "/listProducts";
CountDownLatch latch = new CountDownLatch(1);
Expand All @@ -160,29 +163,37 @@ void highConcurrency() {
TextMapSetter<HttpRequestBuilder> setter =
(carrier, name, value) -> carrier.header(name, value);

List<Future<?>> futures = new ArrayList<>();
for (int i = 0; i < count; i++) {
int index = i;
pool.submit(
() -> {
try {
latch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
testing.runWithSpan(
"client " + index,
() -> {
HttpRequestBuilder builder =
HttpRequest.builder()
.get(baseUrl + "?" + TEST_REQUEST_ID_PARAMETER + "=" + index);
Span.current().setAttribute(TEST_REQUEST_ID_ATTRIBUTE, index);
propagator.inject(Context.current(), builder, setter);
client.execute(builder.build()).aggregate().join();
});
});
futures.add(
pool.submit(
() -> {
try {
assertThat(latch.await(10, SECONDS)).isTrue();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new AssertionError(e);
}
try (Scope ignored = Context.root().makeCurrent()) {
testing.runWithSpan(
"client " + index,
() -> {
HttpRequestBuilder builder =
HttpRequest.builder()
.get(baseUrl + "?" + TEST_REQUEST_ID_PARAMETER + "=" + index);
Span.current().setAttribute(TEST_REQUEST_ID_ATTRIBUTE, index);
propagator.inject(Context.current(), builder, setter);
client.execute(builder.build()).aggregate().join();
});
}
}));
}

latch.countDown();
for (Future<?> future : futures) {
future.get(30, SECONDS);
}

List<Consumer<TraceAssert>> assertions = new ArrayList<>();
for (int i = 0; i < count; i++) {
Expand Down
Loading