Search in sources :

Example 1 with ReplaySubject

use of io.reactivex.rxjava3.subjects.ReplaySubject in project RxJava by ReactiveX.

the class ReplayProcessorTest method subscriptionLeak.

@Test
public void subscriptionLeak() {
    ReplayProcessor<Object> replaySubject = ReplayProcessor.create();
    Disposable connection = replaySubject.subscribe();
    assertEquals(1, replaySubject.subscriberCount());
    connection.dispose();
    assertEquals(0, replaySubject.subscriberCount());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable)

Example 2 with ReplaySubject

use of io.reactivex.rxjava3.subjects.ReplaySubject in project RxJava by ReactiveX.

the class ReplaySubjectTest method sizeboundReplayError.

@Test
public void sizeboundReplayError() {
    ReplaySubject<Integer> rp = ReplaySubject.createWithSize(2);
    rp.onNext(1);
    rp.onNext(2);
    rp.onNext(3);
    rp.onNext(4);
    rp.onError(new TestException());
    rp.test().assertFailure(TestException.class, 3, 4);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 3 with ReplaySubject

use of io.reactivex.rxjava3.subjects.ReplaySubject in project RxJava by ReactiveX.

the class ReplaySubjectTest method sizeAndTimeBoundReplayError.

@Test
public void sizeAndTimeBoundReplayError() {
    ReplaySubject<Integer> rp = ReplaySubject.createWithTimeAndSize(1, TimeUnit.DAYS, Schedulers.single(), 2);
    rp.onNext(1);
    rp.onNext(2);
    rp.onNext(3);
    rp.onNext(4);
    rp.onError(new TestException());
    rp.test().assertFailure(TestException.class, 3, 4);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 4 with ReplaySubject

use of io.reactivex.rxjava3.subjects.ReplaySubject in project RxJava by ReactiveX.

the class ReplaySubjectTest method currentStateMethodsError.

@Test
public void currentStateMethodsError() {
    ReplaySubject<Object> as = ReplaySubject.create();
    assertFalse(as.hasThrowable());
    assertFalse(as.hasComplete());
    assertNull(as.getThrowable());
    as.onError(new TestException());
    assertTrue(as.hasThrowable());
    assertFalse(as.hasComplete());
    assertTrue(as.getThrowable() instanceof TestException);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Example 5 with ReplaySubject

use of io.reactivex.rxjava3.subjects.ReplaySubject in project RxJava by ReactiveX.

the class ReplaySubjectTest method peekStateTimeAndSizeValue.

@Test
public void peekStateTimeAndSizeValue() {
    ReplaySubject<Integer> rp = ReplaySubject.createWithTimeAndSize(1, TimeUnit.DAYS, Schedulers.computation(), 1);
    assertNull(rp.getValue());
    assertEquals(0, rp.getValues().length);
    assertNull(rp.getValues(new Integer[2])[0]);
    rp.onComplete();
    assertNull(rp.getValue());
    assertEquals(0, rp.getValues().length);
    assertNull(rp.getValues(new Integer[2])[0]);
    rp = ReplaySubject.createWithTimeAndSize(1, TimeUnit.DAYS, Schedulers.computation(), 1);
    rp.onError(new TestException());
    assertNull(rp.getValue());
    assertEquals(0, rp.getValues().length);
    assertNull(rp.getValues(new Integer[2])[0]);
}
Also used : TestException(io.reactivex.rxjava3.exceptions.TestException)

Aggregations

TestException (io.reactivex.rxjava3.exceptions.TestException)20 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)4 Test (org.junit.Test)4 Disposable (io.reactivex.rxjava3.disposables.Disposable)2