protected Long nullSafeLong(String lowerHexStr, int index) { if (lowerHexStr == null) return null; return TraceAndSpanIdGenerator.unsignedLowerHexStringToLong(lowerHexStr, index); } }
protected Long nullSafeLong(String lowerHexStr) { if (lowerHexStr == null) return null; return TraceAndSpanIdGenerator.unsignedLowerHexStringToLong(lowerHexStr); }
protected Long nullSafeLong(String lowerHexStr, int index) { if (lowerHexStr == null) return null; return TraceAndSpanIdGenerator.unsignedLowerHexStringToLong(lowerHexStr, index); } }
protected Long nullSafeLong(String lowerHexStr) { if (lowerHexStr == null) return null; return TraceAndSpanIdGenerator.unsignedLowerHexStringToLong(lowerHexStr); }
@Override public void call() throws Throwable { TraceAndSpanIdGenerator.unsignedLowerHexStringToLong(badHexString); } });
@Override public void call() throws Throwable { TraceAndSpanIdGenerator.unsignedLowerHexStringToLong(badHexString, 0); } });
@DataProvider(value = { "0000000000000000 | 0", "0000000000000001 | 1", "ffffffffffffffff | 18446744073709551615", "fffffffffffffffe | 18446744073709551614", "7fae59489091369a | 9200389256962455194", "eb5e7aaefeb92b4f | 16960128138740312911", "d2153abe4c047408 | 15138070311469347848", "9041ee0d07d6c72c | 10394851154681317164", "6470a5ce0e9262f4 | 7237466905610707700", "000003c8a251fb93 | 4160251624339", }, splitBy = "\\|") @Test public void longToUnsignedLowerHexString_and_unsignedLowerHexStringToLong_work_as_expected_for_known_values(String actualHexValue, String actualUnsignedDecimalValue) { // given long actualSignedPrimitive = new BigInteger(actualUnsignedDecimalValue).longValue(); // when String calculatedHexValue = TraceAndSpanIdGenerator.longToUnsignedLowerHexString(actualSignedPrimitive); long calculatedPrimitiveValue = TraceAndSpanIdGenerator.unsignedLowerHexStringToLong(actualHexValue); // then assertThat(calculatedHexValue).isEqualTo(actualHexValue); assertThat(calculatedPrimitiveValue).isEqualTo(actualSignedPrimitive); }
@Test public void convertWingtipsSpanToZipkinSpan_works_as_expected_for_128_bit_trace_id() { // given String high64Bits = "463ac35c9f6413ad"; String low64Bits = "48485a3953bb6124"; String hex128Bits = high64Bits + low64Bits; String spanName = UUID.randomUUID().toString(); String traceId = hex128Bits; String spanId = low64Bits; long startTimeEpochMicros = Math.abs(random.nextLong()); long durationNanos = Math.abs(random.nextLong()); Endpoint zipkinEndpoint = Endpoint.create(UUID.randomUUID().toString(), 42); String localComponentNamespace = UUID.randomUUID().toString(); Map<String,String> tags = createSingleTagMap(); List<TimestampedAnnotation> annotations = createSingleTimestampedAnnotationList(); Span wingtipsSpan = new Span( traceId, null, spanId, spanName, true, null, Span.SpanPurpose.CLIENT, startTimeEpochMicros, null, durationNanos, tags, annotations ); // when zipkin.Span zipkinSpan = impl.convertWingtipsSpanToZipkinSpan(wingtipsSpan, zipkinEndpoint, localComponentNamespace); // then assertThat(zipkinSpan.traceIdHigh).isEqualTo(unsignedLowerHexStringToLong(high64Bits)); assertThat(zipkinSpan.traceId).isEqualTo(unsignedLowerHexStringToLong(low64Bits)); }
assertThat(zipkinSpan.id).isEqualTo(unsignedLowerHexStringToLong(wingtipsSpan.getSpanId())); assertThat(zipkinSpan.name).isEqualTo(wingtipsSpan.getSpanName()); assertThat(zipkinSpan.parentId).isNull(); assertThat(zipkinSpan.timestamp).isEqualTo(wingtipsSpan.getSpanStartTimeEpochMicros()); assertThat(zipkinSpan.traceId).isEqualTo(unsignedLowerHexStringToLong(wingtipsSpan.getTraceId())); assertThat(zipkinSpan.duration).isEqualTo(durationMicros); assertThat(zipkinSpan.binaryAnnotations).doesNotContain(tagOneAsAnnotation, tagTwoAsAnnotation);
assertThat(zipkinSpan.id).isEqualTo(unsignedLowerHexStringToLong(wingtipsSpan.getSpanId())); assertThat(zipkinSpan.name).isEqualTo(wingtipsSpan.getSpanName()); assertThat(zipkinSpan.parentId).isEqualTo(unsignedLowerHexStringToLong(wingtipsSpan.getParentSpanId())); assertThat(zipkinSpan.timestamp).isEqualTo(wingtipsSpan.getSpanStartTimeEpochMicros()); assertThat(zipkinSpan.traceId).isEqualTo(unsignedLowerHexStringToLong(wingtipsSpan.getTraceId())); assertThat(zipkinSpan.duration).isEqualTo(durationMicros); assertThat(zipkinSpan.binaryAnnotations).contains(tagOneAsAnnotation, tagTwoAsAnnotation);