Tidy up SleuthRxJavaPlugins

It doesn't need to extend RxJavaPlugins, and this change makes the
deprecation less of a mess.
This commit is contained in:
Dave Syer
2016-04-25 11:13:10 +01:00
parent c9cdb7e4c3
commit 24f65fd65f
3 changed files with 25 additions and 24 deletions

View File

@@ -5,14 +5,16 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.TraceKeys;
import org.springframework.cloud.sleuth.Tracer;
import rx.functions.Action0;
import rx.plugins.RxJavaErrorHandler;
import rx.plugins.RxJavaObservableExecutionHook;
import rx.plugins.RxJavaPlugins;
import rx.plugins.RxJavaSchedulersHook;
import rx.plugins.SleuthRxJavaPlugins;
/**
* {@link RxJavaSchedulersHook} that wraps a {@link Action0} into its tracing
* {@link RxJavaSchedulersHook} that wraps an {@link Action0} into its tracing
* representation.
*
* @author Shivang Shah
@@ -31,18 +33,18 @@ class SleuthRxJavaSchedulersHook extends RxJavaSchedulersHook {
this.tracer = tracer;
this.traceKeys = traceKeys;
try {
this.delegate = SleuthRxJavaPlugins.getInstance().getSchedulersHook();
this.delegate = RxJavaPlugins.getInstance().getSchedulersHook();
if (this.delegate instanceof SleuthRxJavaSchedulersHook) {
return;
}
RxJavaErrorHandler errorHandler = SleuthRxJavaPlugins.getInstance().getErrorHandler();
RxJavaErrorHandler errorHandler = RxJavaPlugins.getInstance().getErrorHandler();
RxJavaObservableExecutionHook observableExecutionHook
= SleuthRxJavaPlugins.getInstance().getObservableExecutionHook();
= RxJavaPlugins.getInstance().getObservableExecutionHook();
logCurrentStateOfRxJavaPlugins(errorHandler, observableExecutionHook);
SleuthRxJavaPlugins.resetPlugins();
SleuthRxJavaPlugins.getInstance().registerSchedulersHook(this);
SleuthRxJavaPlugins.getInstance().registerErrorHandler(errorHandler);
SleuthRxJavaPlugins.getInstance().registerObservableExecutionHook(observableExecutionHook);
RxJavaPlugins.getInstance().registerSchedulersHook(this);
RxJavaPlugins.getInstance().registerErrorHandler(errorHandler);
RxJavaPlugins.getInstance().registerObservableExecutionHook(observableExecutionHook);
} catch (Exception e) {
log.error("Failed to register Sleuth RxJava SchedulersHook", e);
}

View File

@@ -1,21 +1,19 @@
package rx.plugins;
/**
* {@link RxJavaPlugins} helper class to access the package scope method
* of {@link RxJavaPlugins#reset()}. Will disappear once this gets closed
* {@link RxJavaPlugins} helper class to access the package scope method of
* {@link RxJavaPlugins#reset()}.
*
* @deprecated Will disappear once this gets closed
* https://github.com/ReactiveX/RxJava/issues/2297
*
* @author Shivang Shah
* @since 1.0.0
*/
@Deprecated
public class SleuthRxJavaPlugins extends RxJavaPlugins {
SleuthRxJavaPlugins() {
super();
}
public class SleuthRxJavaPlugins {
public static void resetPlugins() {
getInstance().reset();
RxJavaPlugins.getInstance().reset();
}
}

View File

@@ -1,5 +1,7 @@
package org.springframework.cloud.sleuth.instrument.rxjava;
import static org.assertj.core.api.BDDAssertions.then;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -12,17 +14,16 @@ import org.springframework.cloud.sleuth.Tracer;
import rx.functions.Action0;
import rx.plugins.RxJavaErrorHandler;
import rx.plugins.RxJavaObservableExecutionHook;
import rx.plugins.RxJavaPlugins;
import rx.plugins.RxJavaSchedulersHook;
import rx.plugins.SleuthRxJavaPlugins;
import static org.assertj.core.api.BDDAssertions.then;
/**
*
* @author Shivang Shah
*/
@RunWith(MockitoJUnitRunner.class)
public class SleuthRxJavaSchedulersHookTest {
public class SleuthRxJavaSchedulersHookTests {
@Mock
Tracer tracer;
@@ -39,16 +40,16 @@ public class SleuthRxJavaSchedulersHookTest {
@Test
public void should_not_override_existing_custom_hooks() {
SleuthRxJavaPlugins.getInstance().registerErrorHandler(new MyRxJavaErrorHandler());
SleuthRxJavaPlugins.getInstance().registerObservableExecutionHook(new MyRxJavaObservableExecutionHook());
RxJavaPlugins.getInstance().registerErrorHandler(new MyRxJavaErrorHandler());
RxJavaPlugins.getInstance().registerObservableExecutionHook(new MyRxJavaObservableExecutionHook());
new SleuthRxJavaSchedulersHook(this.tracer, this.traceKeys);
then(SleuthRxJavaPlugins.getInstance().getErrorHandler()).isExactlyInstanceOf(MyRxJavaErrorHandler.class);
then(SleuthRxJavaPlugins.getInstance().getObservableExecutionHook()).isExactlyInstanceOf(MyRxJavaObservableExecutionHook.class);
then(RxJavaPlugins.getInstance().getErrorHandler()).isExactlyInstanceOf(MyRxJavaErrorHandler.class);
then(RxJavaPlugins.getInstance().getObservableExecutionHook()).isExactlyInstanceOf(MyRxJavaObservableExecutionHook.class);
}
@Test
public void should_wrap_delegates_action_in_wrapped_action_when_delegate_is_present_on_schedule() {
SleuthRxJavaPlugins.getInstance().registerSchedulersHook(new MyRxJavaSchedulersHook());
RxJavaPlugins.getInstance().registerSchedulersHook(new MyRxJavaSchedulersHook());
SleuthRxJavaSchedulersHook schedulersHook = new SleuthRxJavaSchedulersHook(
this.tracer, this.traceKeys);
Action0 action = schedulersHook.onSchedule(() -> {