Refactor BackpressureTest
This commit is contained in:
parent
5b79f605a4
commit
4e91a6388c
|
@ -10,6 +10,7 @@ import rx.subjects.PublishSubject;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
@ -21,13 +22,16 @@ public class RxJavaBackpressureTest {
|
|||
TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
|
||||
|
||||
//when
|
||||
Observable.range(1, 1_000_000)
|
||||
Observable
|
||||
.range(1, 1_000_000)
|
||||
.observeOn(Schedulers.computation())
|
||||
.subscribe(testSubscriber);
|
||||
|
||||
//then
|
||||
testSubscriber.awaitTerminalEvent();
|
||||
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
||||
assertTrue(testSubscriber
|
||||
.getOnErrorEvents()
|
||||
.size() == 0);
|
||||
|
||||
}
|
||||
|
||||
|
@ -37,14 +41,14 @@ public class RxJavaBackpressureTest {
|
|||
TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
|
||||
PublishSubject<Integer> source = PublishSubject.<Integer> create();
|
||||
|
||||
source.observeOn(Schedulers.computation())
|
||||
source
|
||||
.observeOn(Schedulers.computation())
|
||||
.subscribe(testSubscriber);
|
||||
|
||||
//when
|
||||
for (int i = 0; i < 1_000_000; i++) {
|
||||
source.onNext(i);
|
||||
|
||||
}
|
||||
IntStream
|
||||
.range(0, 1_000_000)
|
||||
.forEach(source::onNext);
|
||||
|
||||
//then
|
||||
testSubscriber.awaitTerminalEvent();
|
||||
|
@ -58,17 +62,20 @@ public class RxJavaBackpressureTest {
|
|||
PublishSubject<Integer> source = PublishSubject.<Integer> create();
|
||||
|
||||
//when
|
||||
source.window(500)
|
||||
source
|
||||
.window(500)
|
||||
.observeOn(Schedulers.computation())
|
||||
.subscribe(testSubscriber);
|
||||
|
||||
for (int i = 0; i < 1_000; i++) {
|
||||
source.onNext(i);
|
||||
}
|
||||
IntStream
|
||||
.range(0, 1_000)
|
||||
.forEach(source::onNext);
|
||||
|
||||
//then
|
||||
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
||||
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
||||
assertTrue(testSubscriber
|
||||
.getOnErrorEvents()
|
||||
.size() == 0);
|
||||
|
||||
}
|
||||
|
||||
|
@ -79,21 +86,24 @@ public class RxJavaBackpressureTest {
|
|||
PublishSubject<Integer> source = PublishSubject.<Integer> create();
|
||||
|
||||
//when
|
||||
source.buffer(1024)
|
||||
source
|
||||
.buffer(1024)
|
||||
.observeOn(Schedulers.computation())
|
||||
.subscribe(testSubscriber);
|
||||
|
||||
for (int i = 0; i < 1_000; i++) {
|
||||
source.onNext(i);
|
||||
}
|
||||
IntStream
|
||||
.range(0, 1_000)
|
||||
.forEach(source::onNext);
|
||||
|
||||
|
||||
//then
|
||||
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
||||
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
||||
assertTrue(testSubscriber
|
||||
.getOnErrorEvents()
|
||||
.size() == 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenHotObservable_whenSkippingOperationIsDefined_shouldNotThrowException() {
|
||||
//given
|
||||
|
@ -106,13 +116,16 @@ public class RxJavaBackpressureTest {
|
|||
.observeOn(Schedulers.computation())
|
||||
.subscribe(testSubscriber);
|
||||
|
||||
for (int i = 0; i < 1_000; i++) {
|
||||
source.onNext(i);
|
||||
}
|
||||
IntStream
|
||||
.range(0, 1_000)
|
||||
.forEach(source::onNext);
|
||||
|
||||
|
||||
//then
|
||||
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
||||
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
||||
assertTrue(testSubscriber
|
||||
.getOnErrorEvents()
|
||||
.size() == 0);
|
||||
|
||||
}
|
||||
|
||||
|
@ -122,34 +135,37 @@ public class RxJavaBackpressureTest {
|
|||
TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
|
||||
|
||||
//when
|
||||
Observable.range(1, 1_000_000)
|
||||
.onBackpressureBuffer(16, () -> {
|
||||
},
|
||||
BackpressureOverflow.ON_OVERFLOW_DROP_OLDEST)
|
||||
Observable
|
||||
.range(1, 1_000_000)
|
||||
.onBackpressureBuffer(16, () -> {}, BackpressureOverflow.ON_OVERFLOW_DROP_OLDEST)
|
||||
.observeOn(Schedulers.computation())
|
||||
.subscribe(testSubscriber);
|
||||
|
||||
//then
|
||||
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
||||
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
||||
assertTrue(testSubscriber
|
||||
.getOnErrorEvents()
|
||||
.size() == 0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenHotObservable_whenOnBackpressureDropDefined_shouldNotThrowException() {
|
||||
//given
|
||||
TestSubscriber<Integer> testSubscriber = new TestSubscriber<>();
|
||||
|
||||
//when
|
||||
Observable.range(1, 1_000_000)
|
||||
Observable
|
||||
.range(1, 1_000_000)
|
||||
.onBackpressureDrop()
|
||||
.observeOn(Schedulers.computation())
|
||||
.subscribe(testSubscriber);
|
||||
|
||||
//then
|
||||
testSubscriber.awaitTerminalEvent(2, TimeUnit.SECONDS);
|
||||
assertTrue(testSubscriber.getOnErrorEvents().size() == 0);
|
||||
assertTrue(testSubscriber
|
||||
.getOnErrorEvents()
|
||||
.size() == 0);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue