Skip to content
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

RxJavaPlugins.reset() does not reset Observable.hook #4006

Closed
DariusL opened this issue Jun 14, 2016 · 6 comments
Closed

RxJavaPlugins.reset() does not reset Observable.hook #4006

DariusL opened this issue Jun 14, 2016 · 6 comments

Comments

@DariusL
Copy link

DariusL commented Jun 14, 2016

I tried using the RxJavaObservableExecutionHook and noticed that once used, it cannot be changed. It seems that Observable holds a static reference to this hook and uses whatever was set when the class was created. Calling reset() has no effect on Observable.

import org.junit.Test;

import rx.Observable;
import rx.plugins.RxJavaObservableExecutionHook;
import rx.plugins.RxJavaPlugins;

import static org.junit.Assert.assertTrue;

public class HookTest {

    @Test
    public void testChangeHooks() {
        Hook first = new Hook();
        RxJavaPlugins.getInstance().registerObservableExecutionHook(first);

        Observable.just(null).subscribe();

        assertTrue(first.invoked);

        RxJavaPlugins.getInstance().reset();
        Hook second = new Hook();
        RxJavaPlugins.getInstance().registerObservableExecutionHook(second);

        Observable.just(null).subscribe();

        assertTrue(second.invoked);
    }

    static class Hook extends RxJavaObservableExecutionHook {
        boolean invoked = false;

        @Override
        public <T> Observable.OnSubscribe<T> onSubscribeStart(Observable<? extends T> observableInstance, Observable.OnSubscribe<T> onSubscribe) {
            invoked = true;
            return super.onSubscribeStart(observableInstance, onSubscribe);
        }
    }
}

The second assert fails. I'm using 1.1.5.

@akarnokd
Copy link
Member

Yes, you can't override that once the Observable class has been loaded. Single and Completable allow it to be replaced manually, but only from unit tests of the same package. The whole RxJavaPlugins has to be redesigned.

@artem-zinnatullin
Copy link
Contributor

For now you can register kind of super execution hook and add/remove
listeners to it.

On Tue, 14 Jun 2016, 11:07 David Karnok, [email protected] wrote:

Yes, you can't override that once the Observable class has been loaded.
Single and Completable allow it to be replaced manually, but only from
unit tests of the same package. The whole RxJavaPlugins has to be
redesigned.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#4006 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AA7B3Lr-vPkH8XyxnQ3BkSxokIBjMFVaks5qLmElgaJpZM4I1C3I
.

@DariusL
Copy link
Author

DariusL commented Jun 14, 2016

Yeah, I figured I needed some sort of composite hook.

@DariusL
Copy link
Author

DariusL commented Jun 14, 2016

An easy fix would be to remove the hook field from Observable. I assume it is there for performance.

@akarnokd
Copy link
Member

I'm working on a PR to solve problems like this. Stay tuned.

@akarnokd
Copy link
Member

Closing via #4007.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants