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

OperatorGroupBy does not accept multiple subscriptions when source async #900

Closed
davidmoten opened this issue Feb 19, 2014 · 2 comments
Closed

Comments

@davidmoten
Copy link
Collaborator

The test below fails in 0.16.1. I have not tested against new versions but I suggest we should if the test is valid. Please have a look, thanks.

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.mockito.Matchers;

import rx.Observable;
import rx.Observer;
import rx.observables.GroupedObservable;
import rx.util.functions.Func1;

public class OperatorGroupByTest2 {

    @Test
    public void testGroupByOnAsynchronousSourceAcceptsMultipleSubscriptions()
            throws InterruptedException {

        // choose an asynchronous source
        Observable<Long> source = Observable
                .interval(10, TimeUnit.MILLISECONDS).take(1);

        // apply groupBy to the source
        Observable<GroupedObservable<Boolean, Long>> stream = source
                .groupBy(IS_EVEN);

        // create two observers
        Observer<GroupedObservable<Boolean, Long>> o1 = mock(Observer.class);
        Observer<GroupedObservable<Boolean, Long>> o2 = mock(Observer.class);

        // subscribe with the observers
        stream.subscribe(o1);
        stream.subscribe(o2);

        // check that subscriptions were successful
        verify(o1, never()).onError(Matchers.<Throwable> any());
        verify(o2, never()).onError(Matchers.<Throwable> any());
    }

    private static Func1<Long, Boolean> IS_EVEN = new Func1<Long, Boolean>() {

        @Override
        public Boolean call(Long n) {
            return n % 2 == 0;
        }
    };

}
benjchristensen added a commit to benjchristensen/RxJava that referenced this issue Feb 19, 2014
benjchristensen added a commit that referenced this issue Feb 19, 2014
@benjchristensen
Copy link
Member

I merged the unit test into master branch and it is passing.

@benjchristensen
Copy link
Member

Thank you by the way for submitting a unit test along with the report. That makes it far easier.

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

No branches or pull requests

2 participants