generated from newrelic-experimental/java-instrumentation-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
195 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -1,13 +1,28 @@ | ||
package io.reactivex; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.NewField; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
|
||
import io.reactivex.disposables.Disposable; | ||
import io.reactivex.functions.Action; | ||
import io.reactivex.functions.Consumer; | ||
|
||
@Weave(type=MatchType.BaseClass) | ||
public abstract class Observable<T> { | ||
|
||
@NewField | ||
public String observableName = null; | ||
|
||
// Included in order to run tests | ||
public static <T> Observable<T> fromCallable(Callable<? extends T> supplier) { | ||
return Weaver.callOriginal(); | ||
} | ||
|
||
|
||
public abstract Disposable subscribe(Consumer<? super T> onNext, Consumer<? super Throwable> onError, | ||
Action onComplete); | ||
} |
This file contains 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
17 changes: 17 additions & 0 deletions
17
rxjava2-2.0/src/test/java/com/newrelic/instrumentation/labs/test/rxjava2/MyCallable.java
This file contains 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,17 @@ | ||
package com.newrelic.instrumentation.labs.test.rxjava2; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
import com.newrelic.api.agent.Trace; | ||
|
||
public class MyCallable implements Callable<String> { | ||
|
||
private String retValue = "Blue"; | ||
|
||
@Override | ||
@Trace | ||
public String call() throws Exception { | ||
return retValue; | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...2-2.0/src/test/java/com/newrelic/instrumentation/labs/test/rxjava2/MyCompletedAction.java
This file contains 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,36 @@ | ||
package com.newrelic.instrumentation.labs.test.rxjava2; | ||
|
||
import java.util.Random; | ||
|
||
import com.newrelic.api.agent.Trace; | ||
|
||
import io.reactivex.functions.Action; | ||
|
||
public class MyCompletedAction implements Action { | ||
private static Random random = new Random(); | ||
private static int MAXUNITS = 15; | ||
|
||
@Override | ||
@Trace(dispatcher=true) | ||
public void run() throws Exception { | ||
pauseRandomUnits(); | ||
System.out.println("Object has completed"); | ||
} | ||
|
||
private void pauseRandomUnits() { | ||
int n = random.nextInt(MAXUNITS); | ||
pause(n*100L); | ||
} | ||
|
||
private void pause(long ms) { | ||
if(ms > 0) { | ||
try { | ||
Thread.sleep(ms); | ||
} catch (InterruptedException e) { | ||
//e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...va2-2.0/src/test/java/com/newrelic/instrumentation/labs/test/rxjava2/MyErrorConsumer.java
This file contains 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,36 @@ | ||
package com.newrelic.instrumentation.labs.test.rxjava2; | ||
|
||
import java.util.Random; | ||
|
||
import com.newrelic.api.agent.Trace; | ||
|
||
import io.reactivex.functions.Consumer; | ||
|
||
public class MyErrorConsumer implements Consumer<Throwable> { | ||
|
||
private static Random random = new Random(); | ||
private static int MAXUNITS = 15; | ||
|
||
@Override | ||
@Trace(dispatcher=true) | ||
public void accept(Throwable t) throws Exception { | ||
System.out.println("MyErrorConsumer received error: "+t); | ||
t.printStackTrace(); | ||
pauseRandomUnits(); | ||
} | ||
|
||
private void pauseRandomUnits() { | ||
int n = random.nextInt(MAXUNITS); | ||
pause(n*100L); | ||
} | ||
|
||
private void pause(long ms) { | ||
if(ms > 0) { | ||
try { | ||
Thread.sleep(ms); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...a2-2.0/src/test/java/com/newrelic/instrumentation/labs/test/rxjava2/MyStringConsumer.java
This file contains 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,35 @@ | ||
package com.newrelic.instrumentation.labs.test.rxjava2; | ||
|
||
import java.util.Random; | ||
|
||
import com.newrelic.api.agent.Trace; | ||
|
||
import io.reactivex.functions.Consumer; | ||
|
||
public class MyStringConsumer implements Consumer<String> { | ||
|
||
private static Random random = new Random(); | ||
private static int MAXUNITS = 15; | ||
|
||
@Override | ||
@Trace(dispatcher=true) | ||
public void accept(String t) throws Exception { | ||
System.out.println("MyStringConsumer received: "+t); | ||
pauseRandomUnits(); | ||
} | ||
|
||
private void pauseRandomUnits() { | ||
int n = random.nextInt(MAXUNITS); | ||
pause(n*100L); | ||
} | ||
|
||
private void pause(long ms) { | ||
if(ms > 0) { | ||
try { | ||
Thread.sleep(ms); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
rxjava2-2.0/src/test/java/com/newrelic/instrumentation/labs/test/rxjava2/RxJava2Tests.java
This file contains 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,31 @@ | ||
package com.newrelic.instrumentation.labs.test.rxjava2; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import com.newrelic.agent.introspec.InstrumentationTestConfig; | ||
import com.newrelic.agent.introspec.InstrumentationTestRunner; | ||
import com.newrelic.agent.introspec.Introspector; | ||
|
||
import io.reactivex.Observable; | ||
|
||
@RunWith(InstrumentationTestRunner.class) | ||
//Tell the test harness which classes are part of the instrumentation module | ||
@InstrumentationTestConfig(includePrefixes = { "io.reactivex" }) | ||
public class RxJava2Tests { | ||
|
||
@Test | ||
public void testObservable() { | ||
System.out.println("Call to testObservable"); | ||
Introspector introspector = InstrumentationTestRunner.getIntrospector(); | ||
Observable<String> observable = Observable.fromCallable(new MyCallable()); | ||
observable.subscribe(new MyStringConsumer(), new MyErrorConsumer(), new MyCompletedAction()); | ||
|
||
|
||
|
||
} | ||
|
||
public void doObservable() { | ||
|
||
} | ||
} |