Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
some renames
  • Loading branch information
Staffan Friberg committed Dec 9, 2018
1 parent c49e219 commit c58fd6a
Show file tree
Hide file tree
Showing 25 changed files with 1,230 additions and 250 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Expand Up @@ -2,4 +2,8 @@
/bin/
/build/
*.bak
/.nb-gradle/
/.nb-gradle/
nbproject/
nb-configuration.xml
nbactions.xml
.attach_pid*
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -31,7 +31,7 @@ An example app with OpenTracing enabled, and which is using the JFR tracer, can

## Building
To build the JFR Tracer, and install it into the local maven repo, first ensure that you
have installed an Oracle JDK 7, and an Open JDK 11. These will be required to build the
have installed an Oracle JDK 8, and an Open JDK 11. These will be required to build the
tracer. Once built, the tracer can be used with Oracle JDK 8+ (except Oracle JDK 9 and 10), and OpenJDK 11+.

Ensure that the following two environment variables are set to the JAVA_HOME of the JDKs:
Expand Down
71 changes: 63 additions & 8 deletions build.gradle
Expand Up @@ -12,31 +12,86 @@ sourceSets {
java11 {
java {
srcDirs = ['src/main/java11']
compileClasspath += main.output.classesDirs
runtimeClasspath += main.output.classesDirs
}
}

testJava11 {
java {
srcDirs = ['src/test/java11']
compileClasspath += java11.output.classesDirs + main.output.classesDirs
runtimeClasspath += java11.output.classesDirs + main.output.classesDirs
}
}
}
configurations {
java11Compile {
extendsFrom compile
}

testJava11Compile {
extendsFrom testCompile
}
}

dependencies {
compile group: 'io.opentracing', name: 'opentracing-api', version: '0.32.0-RC2-SNAPSHOT'
compile group: 'io.opentracing', name: 'opentracing-noop', version: '0.32.0-RC2-SNAPSHOT'
java11Compile group: 'io.opentracing', name: 'opentracing-api', version: '0.32.0-RC2-SNAPSHOT'
java11Compile group: 'io.opentracing', name: 'opentracing-noop', version: '0.32.0-RC2-SNAPSHOT'
java11Implementation files(sourceSets.main.output.classesDirs) { builtBy compileJava }
testImplementation 'junit:junit:4.12'
compile 'io.opentracing:opentracing-api:0.32.0-RC1'
testCompile 'io.opentracing:opentracing-mock:0.32.0-RC1'
testCompile 'io.jaegertracing:jaeger-core:0.32.0'
testCompile 'io.opentracing.brave:brave-opentracing:0.31.2'
testCompile 'io.opentracing.contrib:opentracing-concurrent:0.2.0'
testCompile 'org.awaitility:awaitility:3.1.3'
testCompile 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testCompile 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
}

compileJava {
options.compilerArgs.addAll(['-Xlint:all,-deprecation'])
options.compilerArgs.addAll(['-Xlint:all,-deprecation', '-Werror'])
sourceCompatibility = 1.8
targetCompatibility = 1.8
}

compileTestJava {
options.compilerArgs.addAll(['-Xlint:all,-deprecation'])
sourceCompatibility = compileJava.sourceCompatibility
targetCompatibility = compileJava.targetCompatibility
}

test {
useJUnitPlatform()
executable = "${JAVA_8}/bin/java"
forkEvery = 1
testLogging {
events "passed", "skipped", "failed"
}
}

compileJava11Java {
options.compilerArgs.addAll(['--release', '11', '-Xlint:all'])
options.compilerArgs.addAll(['--release', '11', '-Xlint:all', '-Werror'])
sourceCompatibility = 11
targetCompatibility = 11
}

compileTestJava11Java {
options.compilerArgs.addAll(['--release', '11', '-Xlint:all'])
sourceCompatibility = compileJava11Java.sourceCompatibility
targetCompatibility = compileJava11Java.targetCompatibility
}

task testJava11(type: Test) {
dependsOn testJava11Classes
testClassesDirs = sourceSets.testJava11.output.classesDirs
classpath = sourceSets.testJava11.runtimeClasspath
useJUnitPlatform()
executable = "${JAVA_11}/bin/java"
testLogging {
events "passed", "skipped", "failed"
}
}

test.dependsOn testJava11

jar {
into('META-INF/versions/11') {
from sourceSets.java11.output
Expand Down
Expand Up @@ -16,28 +16,38 @@
package io.opentracing.contrib.jfrtracer;

import io.opentracing.Tracer;
import io.opentracing.contrib.jfrtracer.impl.wrapper.DelegatingJfrTracer;
import io.opentracing.contrib.jfrtracer.impl.wrapper.TracerWrapper;

import java.util.logging.Logger;

/**
* Factory responsible for creating the wrapper tracer used to emit the flight
* recorder events.
* Factory responsible for creating the wrapper tracer used to emit the flight recorder events.
* <p>
* Note that this is only supported API.
*/
public final class WrapperFactory {
public final class JfrTracerFactory {

private static final Logger LOG = Logger.getLogger(JfrTracerFactory.class.getName());

private JfrTracerFactory() {
}

/**
* Wraps a tracer in a tracer which will provide contextual JFR events The
* tracer will be small and the overhead small.
*
* @param delegate the tracer responsible for the normal open tracing work. This
* can, for example, be your usual Jaeger or Zipkin tracer.
* @return the wrapped tracer to use. You would normally register this tracer as
* your global tracer.
* Wraps a tracer in a tracer which will provide contextual JFR events The tracer will be small and the overhead
* small.
*
* @param delegate the tracer responsible for the normal open tracing work. This can, for example, be your usual
* Jaeger or Zipkin tracer.
* @return the wrapped tracer to use. You would normally register this tracer as your global tracer.
*/
public static Tracer wrap(Tracer delegate) {
if (delegate instanceof DelegatingJfrTracer) {
public static Tracer create(Tracer delegate) {

LOG.info("Using DelegatingJfrTracer to capture contextual information into JFR.");

if (delegate instanceof TracerWrapper) {
throw new IllegalArgumentException("You may not wrap a jfr tracer!");
}
return new DelegatingJfrTracer(delegate);

return new TracerWrapper(delegate);
}
}
Expand Up @@ -18,16 +18,15 @@
import java.util.logging.Logger;

import io.opentracing.Span;
import io.opentracing.contrib.jfrtracer.impl.jfr.JfrScopeEmitterImpl;

/**
* Abstract super class for emitters.
*/
abstract class AbstractJfrEmitterImpl implements JfrEmitter {
abstract class AbstractJfrEmitter implements JfrEmitter {
static final Logger LOGGER = Logger.getLogger(JfrScopeEmitterImpl.class.getName());
protected Span span;

AbstractJfrEmitterImpl(Span span) {
AbstractJfrEmitter(Span span) {
this.span = span;
}
}
Expand Up @@ -16,8 +16,6 @@
package io.opentracing.contrib.jfrtracer.impl.jfr;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

Expand All @@ -26,24 +24,21 @@
/**
* Abstract super class for span emitters.
*/
abstract class AbstractJfrSpanEmitterImpl extends AbstractJfrEmitterImpl {
protected final static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(1, 1, 2, TimeUnit.SECONDS,
new ArrayBlockingQueue<Runnable>(50), new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(r, "JfrTracer Span Events");
thread.setDaemon(true);
return thread;
}
}, new RejectedExecutionHandler() {
@Override
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
// Seems very unlikely to happen, but just to be sure...
LOGGER.warning("Span Event queue full - dropped span event");
}
abstract class AbstractJfrSpanEmitter extends AbstractJfrEmitter {

protected final static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(1, 1, Long.MAX_VALUE, TimeUnit.NANOSECONDS,
new ArrayBlockingQueue<Runnable>(50),
(r) -> {
Thread thread = new Thread(r, "JfrTracer Span Events");
thread.setDaemon(true);
return thread;
},
(r, e) -> {
// Seems very unlikely to happen, but just to be sure...
LOGGER.warning("Span Event queue full - dropped span event");
});

AbstractJfrSpanEmitterImpl(Span span) {
AbstractJfrSpanEmitter(Span span) {
super(span);
}
}
Expand Up @@ -16,8 +16,6 @@
package io.opentracing.contrib.jfrtracer.impl.jfr;

import io.opentracing.Span;
import io.opentracing.contrib.jfrtracer.impl.jfr.JfrScopeEmitterImpl;
import io.opentracing.contrib.jfrtracer.impl.jfr.JfrSpanEmitterImpl;

/**
* For creating JfrEmitters.
Expand Down

0 comments on commit c58fd6a

Please sign in to comment.