-
Notifications
You must be signed in to change notification settings - Fork 873
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
42 additions
and
33 deletions.
There are no files selected for viewing
39 changes: 22 additions & 17 deletions
39
.../library/src/test/java/io/opentelemetry/instrumentation/grpc/v1_6/MetadataSetterTest.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 |
---|---|---|
@@ -1,27 +1,32 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.grpc.v1_6; | ||
|
||
import io.opentelemetry.context.Context; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import io.grpc.Metadata; | ||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.instrumentation.grpc.v1_6.propagator.GrpcPropagator; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
class MetadataSetterTest { | ||
|
||
@Test | ||
void checkThatIterableSizeEqualsOne() { | ||
GrpcPropagator tested = new GrpcPropagator(); | ||
Metadata metadata = new Metadata(); | ||
tested.inject(Context.current(), metadata, MetadataSetter.INSTANCE); | ||
@Test | ||
void checkThatIterableSizeEqualsOne() { | ||
GrpcPropagator tested = new GrpcPropagator(); | ||
Metadata metadata = new Metadata(); | ||
tested.inject(Context.current(), metadata, MetadataSetter.INSTANCE); | ||
|
||
int size = 0; | ||
for (String s : metadata.getAll( | ||
Metadata.Key.of(GrpcPropagator.FIELD, Metadata.ASCII_STRING_MARSHALLER))) { | ||
if (s != null) { | ||
size++; | ||
} | ||
} | ||
assertTrue(size == 1); | ||
int size = 0; | ||
for (String s : | ||
metadata.getAll(Metadata.Key.of(GrpcPropagator.FIELD, Metadata.ASCII_STRING_MARSHALLER))) { | ||
if (s != null) { | ||
size++; | ||
} | ||
} | ||
} | ||
assertTrue(size == 1); | ||
} | ||
} |
36 changes: 20 additions & 16 deletions
36
...y/src/test/java/io/opentelemetry/instrumentation/grpc/v1_6/propagator/GrpcPropagator.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 |
---|---|---|
@@ -1,32 +1,36 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.grpc.v1_6.propagator; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.propagation.TextMapGetter; | ||
import io.opentelemetry.context.propagation.TextMapPropagator; | ||
import io.opentelemetry.context.propagation.TextMapSetter; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class GrpcPropagator implements TextMapPropagator { | ||
|
||
public static final String FIELD = "X-grpc-field"; | ||
private static final String METADATA = "value"; | ||
public static final String FIELD = "X-grpc-field"; | ||
private static final String METADATA = "value"; | ||
|
||
@Override | ||
public List<String> fields() { | ||
return Collections.singletonList(FIELD); | ||
} | ||
@Override | ||
public List<String> fields() { | ||
return Collections.singletonList(FIELD); | ||
} | ||
|
||
@Override | ||
public <C> void inject(Context context, C carrier, TextMapSetter<C> setter) { | ||
for (int i = 0; i < 2; i++) { | ||
setter.set(carrier, FIELD, METADATA); | ||
} | ||
@Override | ||
public <C> void inject(Context context, C carrier, TextMapSetter<C> setter) { | ||
for (int i = 0; i < 2; i++) { | ||
setter.set(carrier, FIELD, METADATA); | ||
} | ||
} | ||
|
||
@Override | ||
public <C> Context extract(Context context, C carrier, TextMapGetter<C> getter) { | ||
return context; | ||
} | ||
@Override | ||
public <C> Context extract(Context context, C carrier, TextMapGetter<C> getter) { | ||
return context; | ||
} | ||
} |