Java Code Examples for io.reactivex.rxjava3.subjects.PublishSubject#compose()

The following examples show how to use io.reactivex.rxjava3.subjects.PublishSubject#compose() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReplayingShareObservableTest.java    From RxReplayingShare with Apache License 2.0 6 votes vote down vote up
@Test public void initialValueToNewSubscriberAfterUnsubscribe() {
  PublishSubject<String> subject = PublishSubject.create();
  Observable<String> observable = subject.compose(ReplayingShare.<String>instance());

  TestObserver<String> observer1 = new TestObserver<>();
  observable.subscribe(observer1);
  observer1.assertNoValues();

  subject.onNext("Foo");
  observer1.assertValues("Foo");
  observer1.dispose();

  TestObserver<String> observer2 = new TestObserver<>();
  observable.subscribe(observer2);
  observer2.assertValues("Foo");
}
 
Example 2
Source File: ReplayingShareObservableTest.java    From RxReplayingShare with Apache License 2.0 6 votes vote down vote up
@Test public void valueMissedWhenNoSubscribers() {
  PublishSubject<String> subject = PublishSubject.create();
  Observable<String> observable = subject.compose(ReplayingShare.<String>instance());

  TestObserver<String> observer1 = new TestObserver<>();
  observable.subscribe(observer1);
  observer1.assertNoValues();
  observer1.dispose();

  subject.onNext("Foo");
  observer1.assertNoValues();

  TestObserver<String> observer2 = new TestObserver<>();
  observable.subscribe(observer2);
  observer2.assertNoValues();
}
 
Example 3
Source File: ReplayingShareObservableTest.java    From RxReplayingShare with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("CheckReturnValue")
@Test public void fatalExceptionDuringReplayThrown() {
  PublishSubject<String> subject = PublishSubject.create();
  Observable<String> observable = subject.compose(ReplayingShare.<String>instance());

  observable.subscribe();
  subject.onNext("Foo");

  Consumer<String> brokenAction = new Consumer<String>() {
    @Override public void accept(String s) {
      throw new OutOfMemoryError("broken!");
    }
  };
  try {
    observable.subscribe(brokenAction);
    fail();
  } catch (OutOfMemoryError e) {
    assertEquals("broken!", e.getMessage());
  }
}
 
Example 4
Source File: ReplayingShareObservableTest.java    From RxReplayingShare with Apache License 2.0 6 votes vote down vote up
@Ignore("No backpressure in Observable")
@Test public void backpressureHonoredWhenCached() {
  PublishSubject<String> subject = PublishSubject.create();
  Observable<String> observable = subject.compose(ReplayingShare.<String>instance());

  TestObserver<String> observer1 = new TestObserver<>();
  observable.subscribe(observer1);
  observer1.assertNoValues();

  subject.onNext("Foo");
  observer1.assertValues("Foo");

  TestObserver<String> observer2 = new TestObserver<>(/*0*/);
  observable.subscribe(observer2);
  observer2.assertNoValues();

  subject.onNext("Bar"); // Replace the cached value...
  observer1.assertValues("Foo", "Bar");

  //observer2.requestMore(1); // ...and ensure new requests see it.
  observer2.assertValues("Bar");
}
 
Example 5
Source File: ReplayingShareObservableTest.java    From RxReplayingShare with Apache License 2.0 6 votes vote down vote up
@Test public void streamsDoNotShareInstances() {
  PublishSubject<String> subjectA = PublishSubject.create();
  Observable<String> observableA = subjectA.compose(ReplayingShare.<String>instance());
  TestObserver<String> observerA1 = new TestObserver<>();
  observableA.subscribe(observerA1);

  PublishSubject<String> subjectB = PublishSubject.create();
  Observable<String> observableB = subjectB.compose(ReplayingShare.<String>instance());
  TestObserver<String> observerB1 = new TestObserver<>();
  observableB.subscribe(observerB1);

  subjectA.onNext("Foo");
  observerA1.assertValues("Foo");
  subjectB.onNext("Bar");
  observerB1.assertValues("Bar");

  TestObserver<String> observerA2 = new TestObserver<>();
  observableA.subscribe(observerA2);
  observerA2.assertValues("Foo");

  TestObserver<String> observerB2 = new TestObserver<>();
  observableB.subscribe(observerB2);
  observerB2.assertValues("Bar");
}
 
Example 6
Source File: ReplayingShareObservableTest.java    From RxReplayingShare with Apache License 2.0 5 votes vote down vote up
@Test public void noInitialValue() {
  PublishSubject<String> subject = PublishSubject.create();
  Observable<String> observable = subject.compose(ReplayingShare.<String>instance());

  TestObserver<String> observer = new TestObserver<>();
  observable.subscribe(observer);
  observer.assertNoValues();
}
 
Example 7
Source File: ReplayingShareObservableTest.java    From RxReplayingShare with Apache License 2.0 5 votes vote down vote up
@Test public void initialValueToNewSubscriber() {
  PublishSubject<String> subject = PublishSubject.create();
  Observable<String> observable = subject.compose(ReplayingShare.<String>instance());

  TestObserver<String> observer1 = new TestObserver<>();
  observable.subscribe(observer1);
  observer1.assertNoValues();

  subject.onNext("Foo");
  observer1.assertValues("Foo");

  TestObserver<String> observer2 = new TestObserver<>();
  observable.subscribe(observer2);
  observer2.assertValues("Foo");
}
 
Example 8
Source File: ReplayingShareObservableTest.java    From RxReplayingShare with Apache License 2.0 5 votes vote down vote up
@Test public void unsubscribeBeforeSubscribePreventsCacheEmission() {
  PublishSubject<String> upstream = PublishSubject.create();
  Observable<String> replayed = upstream.compose(ReplayingShare.<String>instance());
  replayed.subscribe();
  upstream.onNext("something to cache");

  TestObserver<String> testObserver = new TestObserver<>();
  testObserver.dispose();
  replayed.subscribe(testObserver);
  testObserver.assertNoValues();
}
 
Example 9
Source File: ReplayingShareObservableTest.java    From RxReplayingShare with Apache License 2.0 5 votes vote down vote up
@Test public void defaultValueOnSubscribe() {
  PublishSubject<String> subject = PublishSubject.create();
  Observable<String> observable = subject.compose(ReplayingShare.createWithDefault("default"));

  TestObserver<String> observer1 = new TestObserver<>();
  observable.subscribe(observer1);
  observer1.assertValues("default");

  subject.onNext("Foo");
  observer1.assertValues("default", "Foo");
}
 
Example 10
Source File: ReplayingShareObservableTest.java    From RxReplayingShare with Apache License 2.0 5 votes vote down vote up
@Test public void defaultValueIsOverriddenByLatestEmissionForNewSubscriber() {
  PublishSubject<String> subject = PublishSubject.create();
  Observable<String> observable = subject.compose(ReplayingShare.createWithDefault("default"));

  TestObserver<String> observer1 = new TestObserver<>();
  observable.subscribe(observer1);
  observer1.assertValues("default");

  subject.onNext("Foo");
  observer1.assertValues("default", "Foo");

  TestObserver<String> observer2 = new TestObserver<>();
  observable.subscribe(observer2);
  observer2.assertValues("Foo");
}