Skip to content

Commit

Permalink
2.x: Improve coverage & related cleanup 03/05 (#5891)
Browse files Browse the repository at this point in the history
* 2.x: Improve coverage & related cleanup 03/05

* Fix camelCase local variable naming errors in tests.
  • Loading branch information
akarnokd authored Mar 5, 2018
1 parent 51dd03b commit cb05a26
Show file tree
Hide file tree
Showing 93 changed files with 2,523 additions and 433 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ public T next() {

@Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.setOnce(this, s)) {
s.request(batchSize);
}
SubscriptionHelper.setOnce(this, s, batchSize);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,7 @@ static final class BufferOpenSubscriber<Open>

@Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.setOnce(this, s)) {
s.request(Long.MAX_VALUE);
}
SubscriptionHelper.setOnce(this, s, Long.MAX_VALUE);
}

@Override
Expand Down Expand Up @@ -378,9 +376,7 @@ static final class BufferCloseSubscriber<T, C extends Collection<? super T>>

@Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.setOnce(this, s)) {
s.request(Long.MAX_VALUE);
}
SubscriptionHelper.setOnce(this, s, Long.MAX_VALUE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ public void removeChild(ReplaySubscription<T> p) {

@Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.setOnce(connection, s)) {
s.request(Long.MAX_VALUE);
}
SubscriptionHelper.setOnce(connection, s, Long.MAX_VALUE);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,7 @@ static final class CombineLatestInnerSubscriber<T>

@Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.setOnce(this, s)) {
s.request(prefetch);
}
SubscriptionHelper.setOnce(this, s, prefetch);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,7 @@ public boolean isDisposed() {

@Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.setOnce(this, s)) {
s.request(Long.MAX_VALUE);
}
SubscriptionHelper.setOnce(this, s, Long.MAX_VALUE);
}

@Override
Expand Down Expand Up @@ -470,9 +468,7 @@ public boolean isDisposed() {

@Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.setOnce(this, s)) {
s.request(Long.MAX_VALUE);
}
SubscriptionHelper.setOnce(this, s, Long.MAX_VALUE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,8 @@ static final class MergeWithObserver<T> extends AtomicInteger
}

@Override
public void onSubscribe(Subscription d) {
if (SubscriptionHelper.setOnce(mainSubscription, d)) {
d.request(prefetch);
}
public void onSubscribe(Subscription s) {
SubscriptionHelper.setOnce(mainSubscription, s, prefetch);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,8 @@ static final class MergeWithObserver<T> extends AtomicInteger
}

@Override
public void onSubscribe(Subscription d) {
if (SubscriptionHelper.setOnce(mainSubscription, d)) {
d.request(prefetch);
}
public void onSubscribe(Subscription s) {
SubscriptionHelper.setOnce(mainSubscription, s, prefetch);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,36 +526,16 @@ static final class InnerSubscription<T> extends AtomicLong implements Subscripti
public void request(long n) {
// ignore negative requests
if (SubscriptionHelper.validate(n)) {
// In general, RxJava doesn't prevent concurrent requests (with each other or with
// a cancel) so we need a CAS-loop, but we need to handle
// request overflow and cancelled/not requested state as well.
for (;;) {
// get the current request amount
long r = get();
// if child called cancel() do nothing
if (r == CANCELLED) {
return;
}
// ignore zero requests except any first that sets in zero
if (r >= 0L && n == 0) {
return;
}
// otherwise, increase the request count
long u = BackpressureHelper.addCap(r, n);

// try setting the new request value
if (compareAndSet(r, u)) {
// increment the total request counter
BackpressureHelper.add(totalRequested, n);
// if successful, notify the parent dispatcher this child can receive more
// elements
parent.manageRequests();

parent.buffer.replay(this);
return;
}
// otherwise, someone else changed the state (perhaps a concurrent
// request or cancellation) so retry
// add to the current requested and cap it at MAX_VALUE
// except when there was a concurrent cancellation
if (BackpressureHelper.addCancel(this, n) != CANCELLED) {
// increment the total request counter
BackpressureHelper.add(totalRequested, n);
// if successful, notify the parent dispatcher this child can receive more
// elements
parent.manageRequests();
// try replaying any cached content
parent.buffer.replay(this);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public void onComplete() {
completeMain();
}

boolean setOther(Subscription o) {
return SubscriptionHelper.setOnce(other, o);
void setOther(Subscription o) {
SubscriptionHelper.setOnce(other, o, Long.MAX_VALUE);
}

@Override
Expand Down Expand Up @@ -150,9 +150,7 @@ static final class SamplerSubscriber<T> implements FlowableSubscriber<Object> {

@Override
public void onSubscribe(Subscription s) {
if (parent.setOther(s)) {
s.request(Long.MAX_VALUE);
}
parent.setOther(s);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ final class OtherSubscriber extends AtomicReference<Subscription>

@Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.setOnce(this, s)) {
s.request(Long.MAX_VALUE);
}
SubscriptionHelper.setOnce(this, s, Long.MAX_VALUE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ final class OtherSubscriber extends AtomicReference<Subscription> implements Flo

@Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.setOnce(this, s)) {
s.request(Long.MAX_VALUE);
}
SubscriptionHelper.setOnce(this, s, Long.MAX_VALUE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,7 @@ static final class TimeoutConsumer extends AtomicReference<Subscription>

@Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.setOnce(this, s)) {
s.request(Long.MAX_VALUE);
}
SubscriptionHelper.setOnce(this, s, Long.MAX_VALUE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ static final class WindowBoundaryMainSubscriber<T, B>

@Override
public void onSubscribe(Subscription d) {
if (SubscriptionHelper.setOnce(upstream, d)) {
d.request(Long.MAX_VALUE);
}
SubscriptionHelper.setOnce(upstream, d, Long.MAX_VALUE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,7 @@ static final class WithLatestInnerSubscriber

@Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.setOnce(this, s)) {
s.request(Long.MAX_VALUE);
}
SubscriptionHelper.setOnce(this, s, Long.MAX_VALUE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ static final class OtherSubscriber<T> extends

@Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.setOnce(this, s)) {
s.request(Long.MAX_VALUE);
}
SubscriptionHelper.setOnce(this, s, Long.MAX_VALUE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.reactivex.*;
import io.reactivex.disposables.*;
import io.reactivex.exceptions.Exceptions;

/**
* Waits until the source Future completes or the wait times out; treats a {@code null}
Expand Down Expand Up @@ -50,17 +51,11 @@ protected void subscribeActual(MaybeObserver<? super T> observer) {
} else {
v = future.get(timeout, unit);
}
} catch (InterruptedException ex) {
if (!d.isDisposed()) {
observer.onError(ex);
}
return;
} catch (ExecutionException ex) {
if (!d.isDisposed()) {
observer.onError(ex.getCause());
} catch (Throwable ex) {
if (ex instanceof ExecutionException) {
ex = ex.getCause();
}
return;
} catch (TimeoutException ex) {
Exceptions.throwIfFatal(ex);
if (!d.isDisposed()) {
observer.onError(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ static final class TakeUntilOtherMaybeObserver<U>

@Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.setOnce(this, s)) {
s.request(Long.MAX_VALUE);
}
SubscriptionHelper.setOnce(this, s, Long.MAX_VALUE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ static final class TimeoutOtherMaybeObserver<T, U>

@Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.setOnce(this, s)) {
s.request(Long.MAX_VALUE);
}
SubscriptionHelper.setOnce(this, s, Long.MAX_VALUE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import io.reactivex.*;
import io.reactivex.disposables.Disposable;
import io.reactivex.internal.disposables.DisposableHelper;

public final class ObservableSkip<T> extends AbstractObservableWithUpstream<T, T> {
final long n;
Expand All @@ -40,9 +41,11 @@ static final class SkipObserver<T> implements Observer<T>, Disposable {
}

@Override
public void onSubscribe(Disposable s) {
this.d = s;
actual.onSubscribe(this);
public void onSubscribe(Disposable d) {
if (DisposableHelper.validate(this.d, d)) {
this.d = d;
actual.onSubscribe(this);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,7 @@ static final class JoinInnerSubscriber<T>

@Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.setOnce(this, s)) {
s.request(prefetch);
}
SubscriptionHelper.setOnce(this, s, prefetch);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ static final class ParallelReduceFullInnerSubscriber<T>

@Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.setOnce(this, s)) {
s.request(Long.MAX_VALUE);
}
SubscriptionHelper.setOnce(this, s, Long.MAX_VALUE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,7 @@ static final class SortedJoinInnerSubscriber<T>

@Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.setOnce(this, s)) {
s.request(Long.MAX_VALUE);
}
SubscriptionHelper.setOnce(this, s, Long.MAX_VALUE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static final class OtherObserver<T, U>

@Override
public void onSubscribe(Disposable d) {
if (DisposableHelper.set(this, d)) {
if (DisposableHelper.setOnce(this, d)) {

actual.onSubscribe(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ static final class TakeUntilOtherSubscriber

@Override
public void onSubscribe(Subscription s) {
if (SubscriptionHelper.setOnce(this, s)) {
s.request(Long.MAX_VALUE);
}
SubscriptionHelper.setOnce(this, s, Long.MAX_VALUE);
}

@Override
Expand Down
Loading

0 comments on commit cb05a26

Please sign in to comment.