Skip to content

Commit

Permalink
Update to OpenTracing API 0.31.0 (#28)
Browse files Browse the repository at this point in the history
* Update to OpenTracing API 0.31.0

* Remove some unnecessary throws declarations from tests.
  • Loading branch information
sjoerdtalsma authored Jan 16, 2018
1 parent 8a0ccf5 commit db3be86
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 33 deletions.
7 changes: 1 addition & 6 deletions opentracing-tracerresolver-itest/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2017 The OpenTracing Authors
Copyright 2017-2018 The OpenTracing Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,11 +41,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-mock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 The OpenTracing Authors
* Copyright 2017-2018 The OpenTracing Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,19 +15,22 @@
*/
package io.opentracing.contrib.tracerresolver;

import io.opentracing.ScopeManager;
import io.opentracing.Span;
import io.opentracing.SpanContext;
import io.opentracing.Tracer;
import io.opentracing.mock.MockTracer;
import io.opentracing.propagation.Format;

import java.util.ArrayList;
import java.util.List;

public final class Mocks {
static final List<Class<?>> calledConverterTypes = new ArrayList<Class<?>>();

public static class FallbackTracer extends MockTracer {
public static class FallbackTracer extends UnimplementedTracer {
}

public static class ResolvedTracer extends MockTracer {
public static class ResolvedTracer extends UnimplementedTracer {
}

public static class MockTracerResolver extends TracerResolver {
Expand Down Expand Up @@ -75,4 +78,33 @@ public Tracer convert(Tracer existingTracer) {
}
}

/**
* Unimplemented tracer because we don't actually use these mock tracers.
* Their purpose is merely verifying what is being resolved.
*/
private static abstract class UnimplementedTracer implements Tracer {
@Override
public ScopeManager scopeManager() {
return null;
}

@Override
public Span activeSpan() {
return null;
}

@Override
public SpanBuilder buildSpan(String operationName) {
return null;
}

@Override
public <C> void inject(SpanContext spanContext, Format<C> format, C carrier) {
}

@Override
public <C> SpanContext extract(Format<C> format, C carrier) {
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 The OpenTracing Authors
* Copyright 2017-2018 The OpenTracing Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,7 +39,7 @@ public class TracerResolverTest {
private static final File SERVICES_DIR = new File("target/test-classes/META-INF/services/");

@After
public void cleanServiceFiles() throws IOException {
public void cleanServiceFiles() {
new File(SERVICES_DIR, TracerResolver.class.getName()).delete();
new File(SERVICES_DIR, Tracer.class.getName()).delete();
}
Expand All @@ -57,7 +57,7 @@ public void verifyGlobalTracerAbsence() throws ClassNotFoundException {
}

@Test
public void testNothingRegistered() throws IOException {
public void testNothingRegistered() {
assertThat(TracerResolver.resolveTracer(), is(nullValue()));
}

Expand Down
8 changes: 7 additions & 1 deletion opentracing-tracerresolver/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2017 The OpenTracing Authors
Copyright 2017-2018 The OpenTracing Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -58,6 +58,12 @@
<artifactId>opentracing-mock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-util</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 The OpenTracing Authors
* Copyright 2017-2018 The OpenTracing Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,16 +15,15 @@
*/
package io.opentracing.contrib.tracerresolver;

import io.opentracing.NoopTracerFactory;
import io.opentracing.mock.MockTracer;
import io.opentracing.util.GlobalTracer;
import io.opentracing.util.GlobalTracerTestUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;

import static io.opentracing.contrib.tracerresolver.TracerResolverTest.writeServiceFile;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -37,7 +36,7 @@ public class TracerConverterTest {
* Clean up any service files we may have created during our tests.
*/
@After
public void cleanServiceFiles() throws IOException {
public void cleanServiceFiles() {
new File(SERVICES_DIR, TracerResolver.class.getName()).delete();
new File(SERVICES_DIR, TracerConverter.class.getName()).delete();
}
Expand All @@ -55,10 +54,8 @@ public void resetTracerResolver() {
*/
@Before
@After
public void clearGlobalTracer() throws NoSuchFieldException, IllegalAccessException {
Field globalTracer = GlobalTracer.class.getDeclaredField("tracer");
globalTracer.setAccessible(true);
globalTracer.set(null, NoopTracerFactory.create());
public void clearGlobalTracer() {
GlobalTracerTestUtil.resetGlobalTracer();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017 The OpenTracing Authors
* Copyright 2017-2018 The OpenTracing Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,10 +15,10 @@
*/
package io.opentracing.contrib.tracerresolver;

import io.opentracing.NoopTracerFactory;
import io.opentracing.Tracer;
import io.opentracing.mock.MockTracer;
import io.opentracing.util.GlobalTracer;
import io.opentracing.util.GlobalTracerTestUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -27,7 +27,6 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Field;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
Expand All @@ -36,7 +35,7 @@ public class TracerResolverTest {
private static final File SERVICES_DIR = new File("target/test-classes/META-INF/services/");

@After
public void cleanServiceFiles() throws IOException {
public void cleanServiceFiles() {
new File(SERVICES_DIR, TracerResolver.class.getName()).delete();
new File(SERVICES_DIR, Tracer.class.getName()).delete();
}
Expand All @@ -49,14 +48,12 @@ public void resetTracerResolver() {

@Before
@After
public void clearGlobalTracer() throws NoSuchFieldException, IllegalAccessException {
Field globalTracer = GlobalTracer.class.getDeclaredField("tracer");
globalTracer.setAccessible(true);
globalTracer.set(null, NoopTracerFactory.create());
public void clearGlobalTracer() {
GlobalTracerTestUtil.resetGlobalTracer();
}

@Test
public void testNothingRegistered() throws IOException {
public void testNothingRegistered() {
assertThat(TracerResolver.resolveTracer(), is(nullValue()));
}

Expand Down
11 changes: 9 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2017 The OpenTracing Authors
Copyright 2017-2018 The OpenTracing Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -51,7 +51,7 @@
<build.java.version>1.6</build.java.version>
<main.basedir>${project.basedir}</main.basedir>

<opentracing-api.version>0.30.0</opentracing-api.version>
<opentracing-api.version>0.31.0</opentracing-api.version>
<javax.annotation-api.version>1.3</javax.annotation-api.version>
<junit.version>4.12</junit.version>
<hamcrest.version>1.3</hamcrest.version>
Expand Down Expand Up @@ -111,6 +111,13 @@
<artifactId>opentracing-util</artifactId>
<version>${opentracing-api.version}</version>
</dependency>
<dependency>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-util</artifactId>
<version>${opentracing-api.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
Expand Down

0 comments on commit db3be86

Please sign in to comment.