Skip to content

Commit

Permalink
Merge pull request #960 from benjchristensen/issue-879-unit-test
Browse files Browse the repository at this point in the history
Retry Unit Test from #879
  • Loading branch information
benjchristensen committed Mar 13, 2014
2 parents 84bf7c8 + 4feddf8 commit fc2e45f
Showing 1 changed file with 38 additions and 4 deletions.
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());
}
}

0 comments on commit fc2e45f

Please sign in to comment.