-
Notifications
You must be signed in to change notification settings - Fork 12
Adds java-concurrent #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
objectiser
merged 3 commits into
opentracing-contrib:master
from
jam01:feat/java-concurrent
Sep 17, 2018
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <artifactId>opentracing-agent-rules-parent</artifactId> | ||
| <groupId>io.opentracing.contrib</groupId> | ||
| <version>0.3.1-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>opentracing-agent-rules-java-concurrent</artifactId> | ||
|
|
||
| <properties> | ||
| <opentracing-agent.lib>${project.build.directory}/lib</opentracing-agent.lib> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>io.opentracing.contrib</groupId> | ||
| <artifactId>opentracing-agent</artifactId> | ||
| <version>${project.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>io.opentracing.contrib</groupId> | ||
| <artifactId>opentracing-agent-itests</artifactId> | ||
| <scope>test</scope> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>io.opentracing</groupId> | ||
| <artifactId>opentracing-mock</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>io.opentracing.contrib</groupId> | ||
| <artifactId>opentracing-concurrent</artifactId> | ||
jam01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <version>${version.junit}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <configuration> | ||
| <skip>true</skip> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-dependency-plugin</artifactId> | ||
| <executions> | ||
| <execution> | ||
| <id>get-agent</id> | ||
| <phase>pre-integration-test</phase> | ||
| <goals> | ||
| <goal>copy</goal> | ||
| </goals> | ||
| <configuration> | ||
| <artifactItems> | ||
| <artifactItem> | ||
| <groupId>io.opentracing.contrib</groupId> | ||
| <artifactId>opentracing-agent</artifactId> | ||
| <overWrite>true</overWrite> | ||
| <outputDirectory>${opentracing-agent.lib}</outputDirectory> | ||
| <destFileName>opentracing-agent.jar</destFileName> | ||
| </artifactItem> | ||
| </artifactItems> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-failsafe-plugin</artifactId> | ||
| <configuration> | ||
| <argLine> | ||
| -javaagent:${opentracing-agent.lib}/opentracing-agent.jar | ||
| -Dorg.jboss.byteman.verbose | ||
| </argLine> | ||
| </configuration> | ||
| <executions> | ||
| <execution> | ||
| <id>run-integration-tests</id> | ||
| <goals> | ||
| <goal>integration-test</goal> | ||
| </goals> | ||
| <configuration> | ||
| <includes> | ||
| <include>**/*ITest.java</include> | ||
| </includes> | ||
| </configuration> | ||
| </execution> | ||
| <execution> | ||
| <id>final-verify</id> | ||
| <goals> | ||
| <goal>verify</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
| </project> | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| ################################################################################## | ||
| # java-concurrent Rule Set | ||
| # | ||
| # This rule set will intercept calls to all methods specified by | ||
| # java.util.concurrent.Executor and subinterfaces in java.util.concurrent. | ||
| # | ||
| # The rule set assumes that all calls to ExecutorService's methods eventually | ||
| # call Executor.execute(Runnable) | ||
| # | ||
| # TODO: Consider generating rule set from script. | ||
| # See: https://stackoverflow.com/a/32763032/4814697 | ||
|
|
||
| HELPER io.opentracing.contrib.agent.OpenTracingHelper | ||
|
|
||
| RULE Executor.execute | ||
| INTERFACE ^java.util.concurrent.Executor | ||
| METHOD execute | ||
| AT ENTRY | ||
| IF getTracer().activeSpan() != null | ||
| DO | ||
| $1 = new io.opentracing.contrib.concurrent.TracedRunnable($1, getTracer()); | ||
| ENDRULE | ||
|
|
||
| RULE ScheduledExecutorService.schedule(Runnable) | ||
| INTERFACE ^java.util.concurrent.ScheduledExecutorService | ||
| METHOD schedule(java.lang.Runnable,long,java.util.concurrent.TimeUnit) | ||
| AT ENTRY | ||
| IF getTracer().activeSpan() != null | ||
| DO | ||
| $1 = new io.opentracing.contrib.concurrent.TracedRunnable($1, getTracer()); | ||
| ENDRULE | ||
|
|
||
| RULE ScheduledExecutorService.schedule(Callable) | ||
| INTERFACE ^java.util.concurrent.ScheduledExecutorService | ||
| METHOD schedule(java.util.concurrent.Callable,long,java.util.concurrent.TimeUnit) | ||
| AT ENTRY | ||
| IF getTracer().activeSpan() != null | ||
| DO | ||
| $1 = new io.opentracing.contrib.concurrent.TracedCallable($1, getTracer()); | ||
| ENDRULE | ||
|
|
||
| RULE ScheduledExecutorService.scheduleAtFixedRate | ||
| INTERFACE ^java.util.concurrent.ScheduledExecutorService | ||
| METHOD scheduleAtFixedRate | ||
| AT ENTRY | ||
| IF getTracer().activeSpan() != null | ||
| DO | ||
| $1 = new io.opentracing.contrib.concurrent.TracedRunnable($1, getTracer()); | ||
| ENDRULE | ||
|
|
||
| RULE ScheduledExecutorService.scheduleWithFixedDelay | ||
| INTERFACE ^java.util.concurrent.ScheduledExecutorService | ||
| METHOD scheduleWithFixedDelay | ||
| AT ENTRY | ||
| IF getTracer().activeSpan() != null | ||
| DO | ||
| $1 = new io.opentracing.contrib.concurrent.TracedRunnable($1, getTracer()); | ||
| ENDRULE |
79 changes: 79 additions & 0 deletions
79
...current/src/test/java/io/opentracing/contrib/agent/concurrent/AbstractConcurrentTest.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package io.opentracing.contrib.agent.concurrent; | ||
|
|
||
| import io.opentracing.contrib.agent.common.OTAgentTestBase; | ||
| import io.opentracing.mock.MockSpan; | ||
| import org.junit.Before; | ||
|
|
||
| import java.util.concurrent.Callable; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.FutureTask; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| /** | ||
| * @author Pavol Loffay | ||
| * @author Jose Montoya | ||
| */ | ||
| public abstract class AbstractConcurrentTest extends OTAgentTestBase { | ||
|
|
||
| protected CountDownLatch countDownLatch = new CountDownLatch(0); | ||
|
|
||
| @Before | ||
| @Override | ||
| public void init() { | ||
| super.init(); | ||
| countDownLatch = new CountDownLatch(1); | ||
| } | ||
|
|
||
| protected void assertParentSpan(MockSpan parent) { | ||
| for (MockSpan child : getTracer().finishedSpans()) { | ||
| if (child == parent) { | ||
| continue; | ||
| } | ||
|
|
||
| if (parent == null) { | ||
| assertEquals(0, child.parentId()); | ||
| } else { | ||
| assertEquals(parent.context().traceId(), child.context().traceId()); | ||
| assertEquals(parent.context().spanId(), child.parentId()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected Thread createThread(Runnable runnable) { | ||
| Thread thread = new Thread(runnable); | ||
| return thread; | ||
| } | ||
|
|
||
| protected <V> Thread createThread(FutureTask<V> futureTask) { | ||
| Thread thread = new Thread(futureTask); | ||
| return thread; | ||
| } | ||
|
|
||
| class TestRunnable implements Runnable { | ||
| @Override | ||
| public void run() { | ||
| try { | ||
| getTracer().buildSpan("childRunnable") | ||
| .startActive(true) | ||
| .close(); | ||
| } finally { | ||
| countDownLatch.countDown(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class TestCallable implements Callable<Void> { | ||
| @Override | ||
| public Void call() throws Exception { | ||
| try { | ||
| getTracer().buildSpan("childCallable") | ||
| .startActive(true) | ||
| .close(); | ||
| } finally { | ||
| countDownLatch.countDown(); | ||
| } | ||
| return null; | ||
| } | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
.../java-concurrent/src/test/java/io/opentracing/contrib/agent/concurrent/ExecutorITest.java
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package io.opentracing.contrib.agent.concurrent; | ||
|
|
||
| import io.opentracing.mock.MockSpan; | ||
| import org.junit.Test; | ||
|
|
||
| import java.util.concurrent.Executor; | ||
| import java.util.concurrent.Executors; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| /** | ||
| * @author Pavol Loffay | ||
| * @author Jose Montoya | ||
| */ | ||
| public class ExecutorITest extends AbstractConcurrentTest { | ||
|
|
||
| @Test | ||
| public void testExecute() throws InterruptedException { | ||
| Executor executor = Executors.newFixedThreadPool(10); | ||
|
|
||
| MockSpan parentSpan = getTracer().buildSpan("foo").startManual(); | ||
| getTracer().scopeManager().activate(parentSpan, true); | ||
| executor.execute(new TestRunnable()); | ||
|
|
||
| countDownLatch.await(); | ||
| assertParentSpan(parentSpan); | ||
| assertEquals(1, getTracer().finishedSpans().size()); | ||
|
|
||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.