Skip to content

Commit 7f8eedf

Browse files
committed
Convert mock-server to wiremock
mock-server uses older LMAX disruptor which requires Unsafe
1 parent e1ba289 commit 7f8eedf

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

dependencyManagement/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ val DEPENDENCIES = listOf(
8383
"org.codehaus.mojo:animal-sniffer-annotations:1.24",
8484
"org.jctools:jctools-core:4.0.5",
8585
"org.junit-pioneer:junit-pioneer:1.9.1",
86-
"org.mock-server:mockserver-netty:5.15.0:shaded",
86+
"com.github.tomakehurst:wiremock-jre8:2.35.2",
8787
"org.skyscreamer:jsonassert:1.5.3",
8888
"com.android.tools:desugar_jdk_libs:2.1.3",
8989
)

exporters/otlp/testing-internal/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dependencies {
3131
implementation("com.linecorp.armeria:armeria-junit5")
3232
implementation("io.github.netmikey.logunit:logunit-jul")
3333
implementation("org.assertj:assertj-core")
34-
implementation("org.mock-server:mockserver-netty")
34+
implementation("com.github.tomakehurst:wiremock-jre8")
3535
}
3636

3737
// Skip OWASP dependencyCheck task on test module

exporters/otlp/testing-internal/src/main/java/io/opentelemetry/exporter/otlp/testing/internal/AbstractHttpTelemetryExporterTest.java

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import static org.junit.jupiter.api.Named.named;
1313
import static org.junit.jupiter.params.provider.Arguments.arguments;
1414

15+
import com.github.tomakehurst.wiremock.WireMockServer;
16+
import com.github.tomakehurst.wiremock.client.WireMock;
1517
import com.google.protobuf.InvalidProtocolBufferException;
1618
import com.google.protobuf.Message;
1719
import com.linecorp.armeria.common.HttpRequest;
@@ -695,6 +697,7 @@ void nonRetryableError(int code) {
695697

696698
@Test
697699
void proxy() {
700+
<<<<<<< HEAD
698701
// configure mockserver to proxy to the local OTLP server
699702
InetSocketAddress serverSocketAddress = server.httpSocketAddress();
700703
try (ClientAndServer clientAndServer =
@@ -709,10 +712,31 @@ void proxy() {
709712
ProxyOptions.create(
710713
InetSocketAddress.createUnresolved("localhost", clientAndServer.getPort())))
711714
.build();
715+
=======
716+
// configure wiremock to proxy to the local OTLP server
717+
WireMockServer wireMockServer = new WireMockServer(0);
718+
wireMockServer.start();
719+
720+
// Configure WireMock to proxy all requests to the actual server
721+
wireMockServer.stubFor(
722+
WireMock.any(WireMock.anyUrl())
723+
.willReturn(WireMock.aResponse().proxiedFrom(server.httpUri().toString())));
724+
725+
try (TelemetryExporter<T> exporter =
726+
exporterBuilder()
727+
// Configure exporter with server endpoint, and proxy options to route through
728+
// wiremock proxy
729+
.setEndpoint(server.httpUri() + path)
730+
.setProxyOptions(
731+
ProxyOptions.create(
732+
InetSocketAddress.createUnresolved("localhost", wireMockServer.port())))
733+
.build()) {
734+
>>>>>>> 7ba6108a4 (Convert mock-server to wiremock)
712735

713736
try {
714737
List<T> telemetry = Collections.singletonList(generateFakeTelemetry());
715738

739+
<<<<<<< HEAD
716740
assertThat(exporter.export(telemetry).join(10, TimeUnit.SECONDS).isSuccess()).isTrue();
717741
// assert that mock server received request
718742
assertThat(clientAndServer.retrieveRecordedRequests(new org.mockserver.model.HttpRequest()))
@@ -723,6 +747,38 @@ void proxy() {
723747
} finally {
724748
exporter.shutdown();
725749
}
750+
=======
751+
assertThat(exporter.export(telemetry).join(10, TimeUnit.SECONDS).isSuccess()).isTrue();
752+
// assert that wiremock server received request
753+
wireMockServer.verify(1, WireMock.anyRequestedFor(WireMock.anyUrl()));
754+
// assert that server received telemetry from proxy, and is as expected
755+
List<U> expectedResourceTelemetry = toProto(telemetry);
756+
assertThat(exportedResourceTelemetry).containsExactlyElementsOf(expectedResourceTelemetry);
757+
} finally {
758+
wireMockServer.stop();
759+
}
760+
}
761+
762+
@Test
763+
void executorService() {
764+
ExecutorServiceSpy executorService =
765+
new ExecutorServiceSpy(Executors.newSingleThreadExecutor());
766+
767+
try (TelemetryExporter<T> exporter =
768+
exporterBuilder()
769+
.setEndpoint(server.httpUri() + path)
770+
.setExecutorService(executorService)
771+
.build()) {
772+
CompletableResultCode result =
773+
exporter.export(Collections.singletonList(generateFakeTelemetry()));
774+
775+
assertThat(result.join(10, TimeUnit.SECONDS).isSuccess()).isTrue();
776+
assertThat(executorService.getTaskCount()).isPositive();
777+
} finally {
778+
// If setting executor, the user is responsible for calling shutdown
779+
assertThat(executorService.isShutdown()).isFalse();
780+
executorService.shutdown();
781+
>>>>>>> 7ba6108a4 (Convert mock-server to wiremock)
726782
}
727783
}
728784

0 commit comments

Comments
 (0)