-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds toString to Annotation and BinaryAnnotation (#1652)
If you use Span.toString, embedded annotations and binary annotations look good. However, in tests or debugger they don't. This fixes this. Thx @SirTyro for reporting
- Loading branch information
1 parent
bf5fa50
commit a9c1795
Showing
6 changed files
with
131 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright 2015-2017 The OpenZipkin Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package zipkin; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static zipkin.TestObjects.APP_ENDPOINT; | ||
|
||
public class AnnotationTest { | ||
@Rule public ExpectedException thrown = ExpectedException.none(); | ||
|
||
@Test public void messageWhenMissingValue() { | ||
thrown.expect(NullPointerException.class); | ||
thrown.expectMessage("value"); | ||
|
||
Annotation.create(1L, null, null); | ||
} | ||
|
||
@Test public void toStringIsJson_withEndpoint() { | ||
assertThat(Annotation.create(1L, "foo", APP_ENDPOINT)) | ||
.hasToString( | ||
"{\"timestamp\":1,\"value\":\"foo\",\"endpoint\":{\"serviceName\":\"app\",\"ipv4\":\"172.17.0.2\",\"port\":8080}}"); | ||
} | ||
|
||
// simple spans will not have endpoint defined eventhough normal ones will | ||
@Test public void toStringIsJson_withoutEndpoint() { | ||
assertThat(Annotation.create(1L, "foo", null)) | ||
.hasToString("{\"timestamp\":1,\"value\":\"foo\"}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright 2015-2017 The OpenZipkin Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package zipkin; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static zipkin.TestObjects.APP_ENDPOINT; | ||
|
||
public class BinaryAnnotationTest { | ||
@Rule public ExpectedException thrown = ExpectedException.none(); | ||
|
||
@Test public void messageWhenMissingKey() { | ||
thrown.expect(NullPointerException.class); | ||
thrown.expectMessage("key"); | ||
|
||
BinaryAnnotation.create(null, null, null); | ||
} | ||
|
||
@Test public void messageWhenMissingValue() { | ||
thrown.expect(NullPointerException.class); | ||
thrown.expectMessage("value of foo"); | ||
|
||
BinaryAnnotation.create("foo", null, null); | ||
} | ||
|
||
@Test public void messageWhenMissingType() { | ||
thrown.expect(NullPointerException.class); | ||
thrown.expectMessage("type of foo"); | ||
|
||
BinaryAnnotation.builder().key("foo").value(new byte[0]).build(); | ||
} | ||
|
||
@Test public void toStringIsJson() { | ||
assertThat(BinaryAnnotation.create("foo", "bar", APP_ENDPOINT)) | ||
.hasToString( | ||
"{\"key\":\"foo\",\"value\":\"bar\",\"endpoint\":{\"serviceName\":\"app\",\"ipv4\":\"172.17.0.2\",\"port\":8080}}"); | ||
} | ||
} |