Skip to content

Commit

Permalink
test component loader is used
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger committed Feb 19, 2024
1 parent 14b7ddf commit d0c8aba
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,44 @@ void builder_addSpanProcessorCustomizer() {
verifyNoInteractions(spanExporter1);
}

@Test
void builder_addSpanProcessorUsingComponentLoader() {
SpanProcessor spanProcessor = Mockito.mock(SpanProcessor.class);
doReturn(true).when(spanProcessor).isStartRequired();
doReturn(true).when(spanProcessor).isEndRequired();
Mockito.lenient().doReturn(CompletableResultCode.ofSuccess()).when(spanProcessor).shutdown();
Mockito.lenient().when(spanExporter1.shutdown()).thenReturn(CompletableResultCode.ofSuccess());

SpiHelper spiHelper =
SpiHelper.create(AutoConfiguredOpenTelemetrySdkBuilder.class.getClassLoader());

SdkTracerProvider sdkTracerProvider =
builder
.setComponentLoader(
new ComponentLoader() {
@SuppressWarnings("unchecked")
@Override
public <T> Iterable<T> load(Class<T> spiClass) {
if (spiClass.equals(SpanProcessor.class)) {
return Collections.singletonList((T) spanProcessor);
}
return spiHelper.load(spiClass);
}
})
.build()
.getOpenTelemetrySdk()
.getSdkTracerProvider();

Span span = sdkTracerProvider.get("dummy-scope").spanBuilder("dummy-span").startSpan();

verify(spanProcessor).onStart(any(), same((ReadWriteSpan) span));

span.end();
verify(spanProcessor).onEnd(same((ReadableSpan) span));

verifyNoInteractions(spanExporter1);
}

@Test
void builder_addPropertiesSupplier() {
AutoConfiguredOpenTelemetrySdk autoConfigured =
Expand Down

0 comments on commit d0c8aba

Please sign in to comment.