Skip to content

Commit bfe7195

Browse files
committed
Update to Reactive Streams 1.0.0.M1
1 parent 6cf69b8 commit bfe7195

File tree

5 files changed

+31
-30
lines changed

5 files changed

+31
-30
lines changed

rxjava-reactive-streams/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ description = "Adapter between RxJava and ReactiveStreams"
22

33
dependencies {
44
compile 'io.reactivex:rxjava:1.0.+'
5-
compile 'org.reactivestreams:reactive-streams:0.4.0'
6-
testCompile 'org.reactivestreams:reactive-streams-tck:0.4.0'
5+
compile 'org.reactivestreams:reactive-streams:1.0.0.M1'
6+
testCompile 'org.reactivestreams:reactive-streams-tck:1.0.0.M1'
77
}
88

99
test {

rxjava-reactive-streams/src/main/java/rx/internal/reactivestreams/PublisherAdapter.java

+24-8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.HashSet;
2424
import java.util.Set;
2525
import java.util.concurrent.atomic.AtomicBoolean;
26+
import java.util.concurrent.atomic.AtomicLong;
2627

2728
public class PublisherAdapter<T> implements Publisher<T> {
2829

@@ -39,9 +40,17 @@ public void subscribe(final Subscriber<? super T> s) {
3940
if (subscribers.add(s)) {
4041
observable.subscribe(new rx.Subscriber<T>() {
4142
private final AtomicBoolean done = new AtomicBoolean();
43+
private final AtomicLong pending = new AtomicLong(Long.MIN_VALUE);
4244

4345
private void doRequest(long n) {
44-
request(n);
46+
if (!done.get()) {
47+
if (pending.addAndGet(n) >= 0) {
48+
unsubscribe();
49+
onError(new IllegalStateException("Violation of rule 3.17 - more than Long.MAX_VALUE elements requested"));
50+
} else {
51+
request(n);
52+
}
53+
}
4554
}
4655

4756
@Override
@@ -70,27 +79,34 @@ public void cancel() {
7079
}
7180
}
7281

73-
private void fireDone() {
74-
if (done.compareAndSet(false, true)) {
82+
private boolean fireDone() {
83+
boolean first = done.compareAndSet(false, true);
84+
if (first) {
7585
subscribers.remove(s);
7686
}
87+
return first;
7788
}
7889

7990
@Override
8091
public void onCompleted() {
81-
s.onComplete();
92+
if (fireDone()) {
93+
s.onComplete();
94+
}
8295
}
8396

8497
@Override
8598
public void onError(Throwable e) {
86-
s.onError(e);
87-
fireDone();
99+
if (fireDone()) {
100+
s.onError(e);
101+
}
88102
}
89103

90104
@Override
91105
public void onNext(T t) {
92-
s.onNext(t);
93-
fireDone();
106+
if (!done.get()) {
107+
pending.decrementAndGet();
108+
s.onNext(t);
109+
}
94110
}
95111
});
96112
} else {

rxjava-reactive-streams/src/test/java/rx/reactivestreams/TckPublisherTest.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import rx.Observable;
2424
import rx.RxReactiveStreams;
2525
import rx.reactivestreams.test.CountdownIterable;
26+
import rx.schedulers.Schedulers;
2627

2728
@Test
2829
public class TckPublisherTest extends PublisherVerification<Long> {
@@ -34,14 +35,12 @@ public TckPublisherTest() {
3435
super(new TestEnvironment(DEFAULT_TIMEOUT_MILLIS), PUBLISHER_REFERENCE_CLEANUP_TIMEOUT_MILLIS);
3536
}
3637

37-
@Override
38-
public long maxElementsFromPublisher() {
39-
return Long.MAX_VALUE;
40-
}
41-
4238
@Override
4339
public Publisher<Long> createPublisher(long elements) {
44-
return RxReactiveStreams.toPublisher(Observable.from(new CountdownIterable(elements)));
40+
return RxReactiveStreams.toPublisher(
41+
Observable.from(new CountdownIterable(elements))
42+
.observeOn(Schedulers.computation())
43+
);
4544
}
4645

4746
@Override

rxjava-reactive-streams/src/test/java/rx/reactivestreams/TckSubscriberBlackboxTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,4 @@ public Publisher<Long> createHelperPublisher(long elements) {
6666
return RxReactiveStreams.toPublisher(Observable.from(new CountdownIterable(elements)));
6767
}
6868

69-
7069
}

rxjava-reactive-streams/src/test/java/rx/reactivestreams/TckSubscriberWhiteboxTest.java

-13
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,4 @@ public Publisher<Long> createHelperPublisher(long elements) {
113113
return RxReactiveStreams.toPublisher(Observable.from(new CountdownIterable(elements)));
114114
}
115115

116-
public void spec309_callingRequestWithNegativeNumberMustThrow() throws Throwable {
117-
notVerified(); // nonsense test, subscriber doesn't create any Subscription implementations
118-
}
119-
120-
@Override
121-
public void spec309_callingRequestZeroMustThrow() throws Throwable {
122-
notVerified(); // nonsense test, subscriber doesn't create any Subscription implementations
123-
}
124-
125-
@Override
126-
public void spec317_mustSignalOnErrorWhenPendingAboveLongMaxValue() throws Throwable {
127-
notVerified(); // nonsense test, the publisher should implement this
128-
}
129116
}

0 commit comments

Comments
 (0)