brave.propagation.Propagation.Getter Java Examples

The following examples show how to use brave.propagation.Propagation.Getter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ZipkinProviderDelegateTest.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetterOnGetSpanId() {
  Getter<Invocation, String> getter = Deencapsulation
      .getField(ZipkinProviderDelegate.class, "INVOCATION_STRING_GETTER");

  Invocation invocation = Mockito.mock(Invocation.class);
  Map<String, String> context = new HashMap<>();

  Mockito.when(invocation.getContext()).thenReturn(context);

  // if there is no spanId or traceId, then result is null
  String spanId = getter.get(invocation, ZipkinProviderDelegate.SPAN_ID_HEADER_NAME);
  Assert.assertNull(spanId);

  // if there is no spanId but traceId, then traceId will be returned as result
  final String testTraceId = "testTraceId";
  context.put(ZipkinProviderDelegate.TRACE_ID_HEADER_NAME, testTraceId);
  spanId = getter.get(invocation, ZipkinProviderDelegate.SPAN_ID_HEADER_NAME);
  Assert.assertEquals(testTraceId, spanId);

  // if there is spanId, then spanId will be returned
  final String testSpanId = "testSpanId";
  context.put(ZipkinProviderDelegate.SPAN_ID_HEADER_NAME, testSpanId);
  spanId = getter.get(invocation, ZipkinProviderDelegate.SPAN_ID_HEADER_NAME);
  Assert.assertEquals(testSpanId, spanId);
}
 
Example #2
Source File: ZipkinProviderDelegateTest.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetterOnGetOtherContent() {
  Getter<Invocation, String> getter = Deencapsulation
      .getField(ZipkinProviderDelegate.class, "INVOCATION_STRING_GETTER");

  Invocation invocation = Mockito.mock(Invocation.class);
  Map<String, String> context = new HashMap<>();

  Mockito.when(invocation.getContext()).thenReturn(context);

  final String key = "key";
  String value = getter.get(invocation, key);
  Assert.assertNull(value);

  final String expectedValue = "value";
  context.put(key, expectedValue);
  value = getter.get(invocation, key);
  Assert.assertEquals(expectedValue, value);
}
 
Example #3
Source File: TextMapPropagation.java    From brave-opentracing with Apache License 2.0 5 votes vote down vote up
TextMapExtractor(
    Propagation<String> propagation,
    Set<String> allNames,
    Getter<Map<String, String>, String> getter) {
  this.allNames = allNames;
  this.delegate = propagation.extractor(getter);
}
 
Example #4
Source File: TracingMethodMessageHandlerAdapter.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
TracingMethodMessageHandlerAdapter(MessagingTracing messagingTracing,
		Getter<MessageHeaderAccessor, String> getter) {
	this.tracing = messagingTracing.tracing();
	this.tracer = tracing.tracer();
	this.extractor = tracing.propagation().extractor(MessageConsumerRequest.GETTER);
	this.getter = getter;
}
 
Example #5
Source File: TextMapPropagation.java    From brave with Apache License 2.0 5 votes vote down vote up
TextMapExtractor(
    Propagation<String> propagation,
    Set<String> allNames,
    Getter<Map<String, String>, String> getter) {
  this.allNames = allNames;
  this.delegate = propagation.extractor(getter);
}
 
Example #6
Source File: StringPropagationAdapterTest.java    From brave with Apache License 2.0 5 votes vote down vote up
@Test public void getterAdapter() {
  Map<String, Integer> map = new LinkedHashMap<>();
  map.put("1", 1);
  map.put("2", 2);

  Getter<Map<Integer, String>, String> wrappedGetter = new GetterAdapter<>(getter, map);

  Map<Integer, String> request = new LinkedHashMap<>();
  request.put(1, "one");
  request.put(2, "two");

  assertThat(wrappedGetter.get(request, "1")).isEqualTo("one");
  assertThat(wrappedGetter.get(request, "2")).isEqualTo("two");
  assertThat(wrappedGetter.get(request, "3")).isNull();
}
 
Example #7
Source File: ZipkinProviderDelegate.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
private Getter<Invocation, String> extractor() {
  return INVOCATION_STRING_GETTER;
}
 
Example #8
Source File: AWSExtractor.java    From zipkin-aws with Apache License 2.0 4 votes vote down vote up
AWSExtractor(AWSPropagation propagation, Getter<R, String> getter) {
  this.propagation = propagation;
  this.getter = getter;
}
 
Example #9
Source File: XCloudTraceContextExtractor.java    From zipkin-gcp with Apache License 2.0 4 votes vote down vote up
XCloudTraceContextExtractor(Propagation<String> primary, Getter<R, String> getter) {
  this.primary = primary.extractor(getter);
  this.getter = getter;
}
 
Example #10
Source File: TracingMethodMessageHandlerAdapter.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
MessageConsumerRequest(Message delegate,
		Getter<MessageHeaderAccessor, String> getter) {
	this.delegate = delegate;
	this.mutableHeaders = MessageHeaderAccessor.getMutableAccessor(delegate);
	this.getter = getter;
}
 
Example #11
Source File: StringPropagationAdapterTest.java    From brave with Apache License 2.0 4 votes vote down vote up
@Test public void getter_equalsHashCodeString() {
  assertDelegates(
      () -> mock(Getter.class),
      g -> new StringPropagationAdapter.GetterAdapter<>(g, Collections.emptyMap())
  );
}