Skip to content

Commit

Permalink
apply spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
wgy035 committed May 24, 2024
1 parent 4e54e1e commit 035dad3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 33 deletions.
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);
}
}
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;
}
}

0 comments on commit 035dad3

Please sign in to comment.