-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AbstractInMemorySpanBuilder to respect FOLLOWS_FROM (#1063)
Motivation: OpenTracing semantics defines a FOLLOWS_FROM relationship which is an alternative means of representing a parent relationship. However AbstractInMemorySpanBuilder doesn't respect this Reference type and only recognizes CHILD_OF. Modifications: - AbstractInMemorySpanBuilder#parent() should also match References against FOLLOWS_FROM Result: AbstractInMemorySpanBuilder#parent() respects the FOLLOWS_FROM relationship.
- Loading branch information
1 parent
97f0d60
commit 5c38aaa
Showing
3 changed files
with
65 additions
and
5 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
56 changes: 56 additions & 0 deletions
56
...inmemory/src/test/java/io/servicetalk/opentracing/inmemory/DefaultInMemoryTracerTest.java
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,56 @@ | ||
/* | ||
* Copyright © 2020 Apple Inc. and the ServiceTalk project 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 io.servicetalk.opentracing.inmemory; | ||
|
||
import io.servicetalk.opentracing.inmemory.api.InMemoryScopeManager; | ||
import io.servicetalk.opentracing.inmemory.api.InMemorySpan; | ||
import io.servicetalk.opentracing.inmemory.api.InMemorySpanBuilder; | ||
import io.servicetalk.opentracing.inmemory.api.InMemorySpanContext; | ||
import io.servicetalk.opentracing.inmemory.api.InMemoryTraceState; | ||
import io.servicetalk.opentracing.inmemory.api.InMemoryTracer; | ||
|
||
import org.junit.Test; | ||
|
||
import static io.opentracing.References.CHILD_OF; | ||
import static io.opentracing.References.FOLLOWS_FROM; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class DefaultInMemoryTracerTest { | ||
@Test | ||
public void childOfReferenceRespected() { | ||
verifyParentReference("childOfReferenceRespected", true); | ||
} | ||
|
||
@Test | ||
public void followsFromReferenceRespected() { | ||
verifyParentReference("followsFromReferenceRespected", false); | ||
} | ||
|
||
private static void verifyParentReference(final String parentTraceIdHex, boolean childOf) { | ||
InMemoryScopeManager mockScopeManager = mock(InMemoryScopeManager.class); | ||
InMemorySpanContext mockParentContext = mock(InMemorySpanContext.class); | ||
InMemoryTraceState mockParentTraceState = mock(InMemoryTraceState.class); | ||
when(mockParentContext.traceState()).thenReturn(mockParentTraceState); | ||
when(mockParentTraceState.traceIdHex()).thenReturn(parentTraceIdHex); | ||
InMemoryTracer tracer = new DefaultInMemoryTracer.Builder(mockScopeManager).build(); | ||
InMemorySpanBuilder spanBuilder = tracer.buildSpan("foo"); | ||
spanBuilder.addReference(childOf ? CHILD_OF : FOLLOWS_FROM, mockParentContext); | ||
InMemorySpan span = spanBuilder.start(); | ||
assertEquals(parentTraceIdHex, span.context().traceState().traceIdHex()); | ||
} | ||
} |