@Test public void equals_returns_true_and_hashCode_same_if_all_fields_are_equal() { // given Span fullSpan1 = createFilledOutSpan(true); Span fullSpan2 = createFilledOutSpan(true); // expect assertThat(fullSpan1.equals(fullSpan2)).isTrue(); assertThat(fullSpan1.hashCode()).isEqualTo(fullSpan2.hashCode()); }
@Test public void equals_returns_false_and_hashCode_different_if_tags_are_different() { // given Span fullSpan1 = createFilledOutSpan(true); Span fullSpan2 = createFilledOutSpan(true); fullSpan1.putTag("key-" + UUID.randomUUID().toString(), UUID.randomUUID().toString()); // expect assertThat(fullSpan1.equals(fullSpan2)).isFalse(); assertThat(fullSpan1.hashCode()).isNotEqualTo(fullSpan2.hashCode()); }
@Test public void equals_returns_false_and_hashCode_different_if_other_is_not_a_Span() { // given Span span = createFilledOutSpan(true); String notASpan = "notASpan"; // expect //noinspection EqualsBetweenInconvertibleTypes assertThat(span.equals(notASpan)).isFalse(); assertThat(span.hashCode()).isNotEqualTo(notASpan.hashCode()); }
@Test public void toString_delegates_to_toJSON() { // given: span with all values filled in Span span = createFilledOutSpan(true); // when: toString is called on that span String toStringVal = span.toString(); // then: it has the same value as toJSON() assertThat(toStringVal).isEqualTo(span.toJSON()); }
@Test public void equals_returns_true_and_hashCode_same_if_same_instance() { // given Span fullSpan = createFilledOutSpan(true); // expect //noinspection EqualsWithItself assertThat(fullSpan.equals(fullSpan)).isTrue(); assertThat(fullSpan.hashCode()).isEqualTo(fullSpan.hashCode()); }
@Test public void equals_returns_false_and_hashCode_different_if_spanName_is_different() { // given Span fullSpan1 = createFilledOutSpan(true); Span fullSpan2 = createFilledOutSpan(true); Whitebox.setInternalState(fullSpan2, "spanName", fullSpan1.getSpanName() + "_nope"); // expect assertThat(fullSpan1.equals(fullSpan2)).isFalse(); assertThat(fullSpan1.hashCode()).isNotEqualTo(fullSpan2.hashCode()); }
@Test public void equals_returns_false_and_hashCode_different_if_parentSpanId_is_different() { // given Span fullSpan1 = createFilledOutSpan(true); Span fullSpan2 = createFilledOutSpan(true); List<String> badDataList = Arrays.asList(fullSpan1.getParentSpanId() + "_nope", null); for (String badData : badDataList) { Whitebox.setInternalState(fullSpan2, "parentSpanId", badData); // expect assertThat(fullSpan1.equals(fullSpan2)).isFalse(); assertThat(fullSpan2.equals(fullSpan1)).isFalse(); assertThat(fullSpan1.hashCode()).isNotEqualTo(fullSpan2.hashCode()); } }
@Test public void equals_returns_false_and_hashCode_different_if_spanId_is_different() { // given Span fullSpan1 = createFilledOutSpan(true); Span fullSpan2 = createFilledOutSpan(true); Whitebox.setInternalState(fullSpan2, "spanId", fullSpan1.getSpanId() + "_nope"); // expect assertThat(fullSpan1.equals(fullSpan2)).isFalse(); assertThat(fullSpan1.hashCode()).isNotEqualTo(fullSpan2.hashCode()); }
@Test public void equals_returns_false_and_hashCode_different_if_traceId_is_different() { // given Span fullSpan1 = createFilledOutSpan(true); Span fullSpan2 = createFilledOutSpan(true); Whitebox.setInternalState(fullSpan2, "traceId", fullSpan1.getTraceId() + "_nope"); // expect assertThat(fullSpan1.equals(fullSpan2)).isFalse(); assertThat(fullSpan1.hashCode()).isNotEqualTo(fullSpan2.hashCode()); }
@Test public void equals_returns_false_and_hashCode_different_if_userId_is_different() { // given Span fullSpan1 = createFilledOutSpan(true); Span fullSpan2 = createFilledOutSpan(true); List<String> badDataList = Arrays.asList(fullSpan1.getUserId() + "_nope", null); for (String badData : badDataList) { Whitebox.setInternalState(fullSpan2, "userId", badData); // expect assertThat(fullSpan1.equals(fullSpan2)).isFalse(); assertThat(fullSpan2.equals(fullSpan1)).isFalse(); assertThat(fullSpan1.hashCode()).isNotEqualTo(fullSpan2.hashCode()); } }
@Test public void equals_returns_false_and_hashCode_different_if_spanStartTimeEpochMicros_is_different() { // given Span fullSpan1 = createFilledOutSpan(true); Span fullSpan2 = createFilledOutSpan(true); Whitebox.setInternalState(fullSpan2, "spanStartTimeEpochMicros", fullSpan1.getSpanStartTimeEpochMicros() + 1); // expect assertThat(fullSpan1.equals(fullSpan2)).isFalse(); assertThat(fullSpan1.hashCode()).isNotEqualTo(fullSpan2.hashCode()); }
@Test public void equals_returns_false_and_hashCode_different_if_annotations_are_different() { // given Span fullSpan1 = createFilledOutSpan(true); Span fullSpan2 = createFilledOutSpan(true); fullSpan1.addTimestampedAnnotation(TimestampedAnnotation.forCurrentTime("foo")); // expect assertThat(fullSpan1.equals(fullSpan2)).isFalse(); assertThat(fullSpan1.hashCode()).isNotEqualTo(fullSpan2.hashCode()); }
@Test public void equals_returns_false_and_hashCode_different_if_sampleable_is_different() { // given Span fullSpan1 = createFilledOutSpan(true); Span fullSpan2 = createFilledOutSpan(true); Whitebox.setInternalState(fullSpan2, "sampleable", !fullSpan1.isSampleable()); // expect assertThat(fullSpan1.equals(fullSpan2)).isFalse(); assertThat(fullSpan1.hashCode()).isNotEqualTo(fullSpan2.hashCode()); }
@Test public void equals_returns_false_and_hashCode_different_if_durationNanos_is_different() { // given Span fullSpan1 = createFilledOutSpan(true); Span fullSpan2 = createFilledOutSpan(true); List<Long> badDataList = Arrays.asList(fullSpan1.getDurationNanos() + 1, null); for (Long badData : badDataList) { Whitebox.setInternalState(fullSpan2, "durationNanos", badData); // expect assertThat(fullSpan1.equals(fullSpan2)).isFalse(); assertThat(fullSpan2.equals(fullSpan1)).isFalse(); assertThat(fullSpan1.hashCode()).isNotEqualTo(fullSpan2.hashCode()); } }
@Test public void equals_returns_false_and_hashCode_different_if_spanPurpose_is_different() { // given Span fullSpan1 = createFilledOutSpan(true); Span fullSpan2 = createFilledOutSpan(true); List<SpanPurpose> badDataList = Arrays.asList(SpanPurpose.CLIENT, SpanPurpose.UNKNOWN, null); for (SpanPurpose badData : badDataList) { assertThat(fullSpan1.getSpanPurpose()).isNotEqualTo(badData); Whitebox.setInternalState(fullSpan2, "spanPurpose", badData); // expect assertThat(fullSpan1.equals(fullSpan2)).isFalse(); assertThat(fullSpan2.equals(fullSpan1)).isFalse(); assertThat(fullSpan1.hashCode()).isNotEqualTo(fullSpan2.hashCode()); } }
public void generateChildSpan_works_as_expected_for_incomplete_parent_span(SpanPurpose childSpanPurpose) { Span parentSpan = createFilledOutSpan(false); String childSpanName = UUID.randomUUID().toString(); assertThat(parentSpan.isCompleted()).isFalse();
public void generateChildSpan_works_as_expected_for_completed_parent_span(SpanPurpose childSpanPurpose) { Span parentSpan = createFilledOutSpan(true); String childSpanName = UUID.randomUUID().toString(); assertThat(parentSpan.isCompleted()).isTrue();
@DataProvider(value = { "SERVER", "CLIENT", "LOCAL_ONLY", "UNKNOWN" }, splitBy = "\\|") @Test public void newBuilder_with_copy_arg_returns_exact_copy(SpanPurpose spanPurpose) { // given Span origSpan = createFilledOutSpan(true); Whitebox.setInternalState(origSpan, "spanPurpose", spanPurpose); assertThat(origSpan.getSpanPurpose()).isEqualTo(spanPurpose); // when Span copySpan = Span.newBuilder(origSpan).build(); // then verifySpanDeepEquals(copySpan, origSpan, false); }