Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Reduce visibility of TextMapCodec.contextFromString to package scope #519

Merged

Conversation

isaachier
Copy link
Contributor

@isaachier isaachier commented Aug 17, 2018

Which problem is this PR solving?

Short description of the changes

  • Change visibility.
  • Move all tests that rely on this method's functionality into the TextMapCodecTest class.

Signed-off-by: Isaac Hier <ihier@uber.com>
assertEquals(traceId, contextFromStr.getTraceId());
assertEquals(spanId, contextFromStr.getSpanId());
assertEquals(parentId, contextFromStr.getParentId());
assertEquals(flags, contextFromStr.getFlags());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't see how removing this makes the test equivalent. But this whole test can move to text codec test, since it's not really testing the context toString

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right let me fix that.

assertEquals(expectedContext.getTraceId(), actualContext.getTraceId());
assertEquals(expectedContext.getSpanId(), actualContext.getSpanId());
assertEquals(expectedContext.getParentId(), actualContext.getParentId());
assertEquals(expectedContext.getFlags(), actualContext.getFlags());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing it is not equivalent. But you can change L215 to use TextMapCodec's extract method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this still applies. See testSpanToString in TextMapCodec.

Copy link
Member

@yurishkuro yurishkuro Aug 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's what I am thinking. The method is called testSpanToString. Such method should belong in SpanTest class, not the codecs. But it's not actually testing span.toString(), only spanContext.contextAsString(). So let's separate these.

  • to test span.toString(), we can simply compare with an exact literal string (including the operation name).
  • what is the contract of contextAsString()? Do we, strictly speaking, care if the output matches the output of the codec? What if we use a different codec in the future? I think it mattered more when span context had the opposite fromString() method, but now contextAsString() seems merely a dependency of span.toString(), nothing more. Or is it used elsewhere? If not, we can not test it at all (since it's covered by span.toString() test), and we can consider making it package viz.

Counter-proposal: keep the test here (since it's testing Span's behavior, not the codec), but

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But what? :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, a left over

@codecov
Copy link

codecov bot commented Aug 17, 2018

Codecov Report

Merging #519 into master will increase coverage by 0.1%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master     #519     +/-   ##
===========================================
+ Coverage     88.26%   88.37%   +0.1%     
  Complexity      500      500             
===========================================
  Files            65       65             
  Lines          1849     1849             
  Branches        239      239             
===========================================
+ Hits           1632     1634      +2     
+ Misses          141      138      -3     
- Partials         76       77      +1
Impacted Files Coverage Δ Complexity Δ
...egertracing/internal/propagation/TextMapCodec.java 90.58% <100%> (+0.84%) 22 <3> (+1) ⬆️
...ain/java/io/jaegertracing/internal/JaegerSpan.java 93.45% <100%> (ø) 47 <0> (ø) ⬇️
...a/io/jaegertracing/internal/JaegerSpanContext.java 90.62% <100%> (+0.88%) 22 <1> (ø) ⬇️
...ing/internal/samplers/RemoteControlledSampler.java 89.53% <0%> (-1.17%) 17% <0%> (-1%)
...egertracing/internal/reporters/RemoteReporter.java 85.71% <0%> (+2.38%) 7% <0%> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b6a824d...900524b. Read the comment docs.

Signed-off-by: Isaac Hier <ihier@uber.com>
byte flags = (byte) 129;

// I use MIN_VALUE because the most significant bit, and thats when
// we want to make sure the hex number is positive.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment looks like some old left-over. Doesn't seem to make any sense now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

Isaac Hier added 3 commits August 17, 2018 13:54
Signed-off-by: Isaac Hier <ihier@uber.com>
Signed-off-by: Isaac Hier <ihier@uber.com>
Signed-off-by: Isaac Hier <ihier@uber.com>
@@ -78,7 +78,7 @@ public static JaegerSpanContext contextFromString(String value)

@Override
public void inject(JaegerSpanContext spanContext, TextMap carrier) {
carrier.put(contextKey, encodedValue(spanContext.contextAsString()));
carrier.put(contextKey, encodedValue(spanContext.toString()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a good idea to rely on toString() for marshaling purposes.

Maybe do the same thing as with fromString, move contextAsString() from SpanContext to TextMapCodec, but keep it public so that SpanContext.toString() can call it.

Signed-off-by: Isaac Hier <ihier@uber.com>
assertEquals(expectedContext.getFlags(), actualContext.getFlags());
String operation = "test-operation";
JaegerSpan span = tracer.buildSpan(operation).start();
String expectedString = span.context().toString() + " - " + operation;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prod == prod. Please test for exact string.

Copy link
Contributor Author

@isaachier isaachier Aug 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean I should use a string literal instead of expectedString? Not sure what the suggestion is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, expectedString = "some literal value". Otherwise you are just comparing outputs of two prod functions. If we change the representation used by the codec, technically this test should fail since span.toString() would change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Will do.

Isaac Hier added 2 commits August 20, 2018 16:32
Signed-off-by: Isaac Hier <ihier@uber.com>
Signed-off-by: Isaac Hier <ihier@uber.com>
Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@yurishkuro yurishkuro merged commit 27bd0e0 into jaegertracing:master Aug 20, 2018
@isaachier isaachier deleted the refactor-context-from-string branch August 20, 2018 20:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants