Skip to content

Commit

Permalink
backfills tests for traceparent
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Cole committed Mar 12, 2020
1 parent 94aca21 commit b7ea224
Show file tree
Hide file tree
Showing 10 changed files with 412 additions and 81 deletions.
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
#
# Copyright 2013-2020 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.
#

blank_issues_enabled: false
contact_links:
- name: Question
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 The OpenZipkin Authors
* Copyright 2013-2020 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
Expand Down
16 changes: 16 additions & 0 deletions propagation/w3c/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@
<main.signature.artifact>java16</main.signature.artifact>
</properties>

<dependencies>
<!-- to mock Platform calls -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
import java.util.Collections;
import java.util.List;

import static brave.propagation.w3c.TraceparentFormat.FORMAT_LENGTH;
import static brave.propagation.w3c.TraceparentFormat.maybeExtractParent;
import static brave.propagation.w3c.TraceparentFormat.validateFormat;
import static brave.propagation.w3c.TraceparentFormat.parseTraceparentFormat;

final class TraceContextExtractor<C, K> implements Extractor<C> {
final Getter<C, K> getter;
Expand Down Expand Up @@ -57,22 +55,20 @@ final class TraceContextExtractor<C, K> implements Extractor<C> {
if (handler.context == null) {
if (extra == DEFAULT_EXTRA) return EMPTY;
return TraceContextOrSamplingFlags.newBuilder()
.extra(extra)
.samplingFlags(SamplingFlags.EMPTY)
.build();
.extra(extra)
.samplingFlags(SamplingFlags.EMPTY)
.build();
}
return TraceContextOrSamplingFlags.newBuilder().context(handler.context).extra(extra).build();
}

static final class TraceparentFormatHandler implements TracestateFormat.Handler {
TraceContext context;

@Override public boolean onThisState(CharSequence tracestateString, int pos) {
if (validateFormat(tracestateString, pos) < FORMAT_LENGTH) {
return false;
}
context = maybeExtractParent(tracestateString, pos);
return true;
@Override
public boolean onThisState(CharSequence tracestateString, int beginIndex, int endIndex) {
context = parseTraceparentFormat(tracestateString, beginIndex, endIndex);
return context != null;
}
}

Expand All @@ -81,5 +77,5 @@ static final class TraceparentFormatHandler implements TracestateFormat.Handler

static final List<Object> DEFAULT_EXTRA = Collections.singletonList(MARKER);
static final TraceContextOrSamplingFlags EMPTY =
TraceContextOrSamplingFlags.EMPTY.toBuilder().extra(DEFAULT_EXTRA).build();
TraceContextOrSamplingFlags.EMPTY.toBuilder().extra(DEFAULT_EXTRA).build();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 The OpenZipkin Authors
* Copyright 2013-2018 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 The OpenZipkin Authors
* Copyright 2013-2018 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
Expand Down
Loading

0 comments on commit b7ea224

Please sign in to comment.