Skip to content

Commit

Permalink
Use a static method to access EMPTY InstrumentationLibraryInfo. (#897)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Cristian Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Feb 20, 2020
1 parent 986a22e commit aadea3d
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@AutoValue
@Immutable
public abstract class InstrumentationLibraryInfo {
public static final InstrumentationLibraryInfo EMPTY = create("", null);
private static final InstrumentationLibraryInfo EMPTY = create("", null);

/**
* Creates a new instance of {@link InstrumentationLibraryInfo}.
Expand All @@ -43,8 +43,27 @@ public static InstrumentationLibraryInfo create(String name, @Nullable String ve
return new AutoValue_InstrumentationLibraryInfo(name, version);
}

/**
* Returns an "empty" {@code InstrumentationLibraryInfo}.
*
* @return an "empty" {@code InstrumentationLibraryInfo}.
*/
public static InstrumentationLibraryInfo getEmpty() {
return EMPTY;
}

/**
* Returns the name of the instrumentation library.
*
* @return the name of the instrumentation library.
*/
public abstract String getName();

/**
* Returns the version of the instrumentation library, or {@code null} if not available.
*
* @return the version of the instrumentation library, or {@code null} if not available.
*/
@Nullable
public abstract String getVersion();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public static TimedEvent create(
public static Builder newBuilder() {
return new AutoValue_SpanData.Builder()
.setParentSpanId(SpanId.getInvalid())
.setInstrumentationLibraryInfo(InstrumentationLibraryInfo.EMPTY)
.setInstrumentationLibraryInfo(InstrumentationLibraryInfo.getEmpty())
.setLinks(Collections.<io.opentelemetry.trace.Link>emptyList())
.setTotalRecordedLinks(0)
.setAttributes(Collections.<String, AttributeValue>emptyMap())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public class InstrumentationLibraryInfoTest {

@Test
public void emptyLibraryInfo() {
assertThat(InstrumentationLibraryInfo.EMPTY.getName()).isEmpty();
assertThat(InstrumentationLibraryInfo.EMPTY.getVersion()).isNull();
assertThat(InstrumentationLibraryInfo.getEmpty().getName()).isEmpty();
assertThat(InstrumentationLibraryInfo.getEmpty().getVersion()).isNull();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class AbstractCounterBuilderTest {
private static final MeterProviderSharedState METER_SHARED_STATE =
MeterProviderSharedState.create(TestClock.create(), Resource.getEmpty());
private static final InstrumentationLibraryInfo INSTRUMENTATION_LIBRARY_INFO =
InstrumentationLibraryInfo.EMPTY;
InstrumentationLibraryInfo.getEmpty();

@Test
public void defaultValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class AbstractInstrumentBuilderTest {
private static final MeterProviderSharedState METER_SHARED_STATE =
MeterProviderSharedState.create(TestClock.create(), Resource.getEmpty());
private static final InstrumentationLibraryInfo INSTRUMENTATION_LIBRARY_INFO =
InstrumentationLibraryInfo.EMPTY;
InstrumentationLibraryInfo.getEmpty();

@Test
public void preventNull_Name() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class AbstractMeasureBuilderTest {
private static final MeterProviderSharedState METER_SHARED_STATE =
MeterProviderSharedState.create(TestClock.create(), Resource.getEmpty());
private static final InstrumentationLibraryInfo INSTRUMENTATION_LIBRARY_INFO =
InstrumentationLibraryInfo.EMPTY;
InstrumentationLibraryInfo.getEmpty();

@Test
public void defaultValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class AbstractObserverBuilderTest {
private static final MeterProviderSharedState METER_SHARED_STATE =
MeterProviderSharedState.create(TestClock.create(), Resource.getEmpty());
private static final InstrumentationLibraryInfo INSTRUMENTATION_LIBRARY_INFO =
InstrumentationLibraryInfo.EMPTY;
InstrumentationLibraryInfo.getEmpty();

@Test
public void defaultValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void metricData_NullDescriptor() {
MetricData.create(
null,
Resource.getEmpty(),
InstrumentationLibraryInfo.EMPTY,
InstrumentationLibraryInfo.getEmpty(),
Collections.<Point>singletonList(DOUBLE_POINT));
}

Expand All @@ -80,7 +80,7 @@ public void metricData_NullResource() {
MetricData.create(
LONG_METRIC_DESCRIPTOR,
null,
InstrumentationLibraryInfo.EMPTY,
InstrumentationLibraryInfo.getEmpty(),
Collections.<Point>singletonList(DOUBLE_POINT));
}

Expand All @@ -100,7 +100,7 @@ public void metricData_NullPoints() {
thrown.expect(NullPointerException.class);
thrown.expectMessage("points");
MetricData.create(
LONG_METRIC_DESCRIPTOR, Resource.getEmpty(), InstrumentationLibraryInfo.EMPTY, null);
LONG_METRIC_DESCRIPTOR, Resource.getEmpty(), InstrumentationLibraryInfo.getEmpty(), null);
}

@Test
Expand All @@ -109,12 +109,12 @@ public void metricData_Getters() {
MetricData.create(
LONG_METRIC_DESCRIPTOR,
Resource.getEmpty(),
InstrumentationLibraryInfo.EMPTY,
InstrumentationLibraryInfo.getEmpty(),
Collections.<Point>emptyList());
assertThat(metricData.getDescriptor()).isEqualTo(LONG_METRIC_DESCRIPTOR);
assertThat(metricData.getResource()).isEqualTo(Resource.getEmpty());
assertThat(metricData.getInstrumentationLibraryInfo())
.isEqualTo(InstrumentationLibraryInfo.EMPTY);
.isEqualTo(InstrumentationLibraryInfo.getEmpty());
assertThat(metricData.getPoints()).isEmpty();
}

Expand All @@ -128,7 +128,7 @@ public void metricData_LongPoints() {
MetricData.create(
LONG_METRIC_DESCRIPTOR,
Resource.getEmpty(),
InstrumentationLibraryInfo.EMPTY,
InstrumentationLibraryInfo.getEmpty(),
Collections.<Point>singletonList(LONG_POINT));
assertThat(metricData.getPoints()).containsExactly(LONG_POINT);
}
Expand All @@ -143,7 +143,7 @@ public void metricData_DoublePoints() {
MetricData.create(
DOUBLE_METRIC_DESCRIPTOR,
Resource.getEmpty(),
InstrumentationLibraryInfo.EMPTY,
InstrumentationLibraryInfo.getEmpty(),
Collections.<Point>singletonList(DOUBLE_POINT));
assertThat(metricData.getPoints()).containsExactly(DOUBLE_POINT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void defaultValues() {
assertThat(spanData.getTimedEvents()).isEqualTo(emptyList());
assertThat(spanData.getLinks()).isEqualTo(emptyList());
assertThat(spanData.getInstrumentationLibraryInfo())
.isSameInstanceAs(InstrumentationLibraryInfo.EMPTY);
.isSameInstanceAs(InstrumentationLibraryInfo.getEmpty());
assertThat(spanData.getHasRemoteParent()).isFalse();
}

Expand Down

0 comments on commit aadea3d

Please sign in to comment.