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

Retry Unit Test from #879 #960

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions rxjava-core/src/test/java/rx/operators/OperatorRetryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
import static rx.operators.OperatorRetry.*;

import java.util.concurrent.atomic.AtomicInteger;

import org.junit.Test;
import org.mockito.InOrder;

import rx.Observable;
import rx.Observable.OnSubscribeFunc;
import rx.Observer;
import rx.Subscription;
import rx.functions.Action1;
Expand Down Expand Up @@ -130,7 +130,7 @@ public Subscription onSubscribe(Observer<? super String> o) {
return Subscriptions.empty();
}
}

@Test
public void testUnsubscribeFromRetry() {
PublishSubject<Integer> subject = PublishSubject.create();
Expand All @@ -139,10 +139,44 @@ public void testUnsubscribeFromRetry() {
@Override
public void call(Integer n) {
count.incrementAndGet();
}});
}
});
subject.onNext(1);
sub.unsubscribe();
subject.onNext(2);
assertEquals(1,count.get());
assertEquals(1, count.get());
}

@Test
public void testRetryAllowsSubscriptionAfterAllSubscriptionsUnsubsribed() throws InterruptedException {
final AtomicInteger subsCount = new AtomicInteger(0);
OnSubscribeFunc<String> onSubscribe = new OnSubscribeFunc<String>() {
@Override
public Subscription onSubscribe(Observer<? super String> observer) {
subsCount.incrementAndGet();
return new Subscription() {
boolean unsubscribed = false;

@Override
public void unsubscribe() {
subsCount.decrementAndGet();
unsubscribed = true;
}

@Override
public boolean isUnsubscribed() {
return unsubscribed;
}
};
}
};
Observable<String> stream = Observable.create(onSubscribe);
Observable<String> streamWithRetry = stream.retry();
Subscription sub = streamWithRetry.subscribe();
assertEquals(1, subsCount.get());
sub.unsubscribe();
assertEquals(0, subsCount.get());
streamWithRetry.subscribe();
assertEquals(1, subsCount.get());
}
}