ReplaySubject extends Subject<T> { @CheckReturnValue @NonNull public static <T> ReplaySubject<T> create() { return new ReplaySubject<T>(new UnboundedReplayBuffer<T>(16)); } @SuppressWarnings("unchecked")  ReplaySubject(ReplayBuffer<T> buffer); @CheckReturnValue @NonNull static ReplaySubject<T> create(); @CheckReturnValue @NonNull static ReplaySubject<T> create(int capacityHint); @CheckReturnValue @NonNull static ReplaySubject<T> createWithSize(int maxSize); @CheckReturnValue @NonNull static ReplaySubject<T> createWithTime(long maxAge, TimeUnit unit, Scheduler scheduler); @CheckReturnValue @NonNull static ReplaySubject<T> createWithTimeAndSize(long maxAge, TimeUnit unit, Scheduler scheduler, int maxSize); @Override void onSubscribe(Disposable s); @Override void onNext(T t); @Override void onError(Throwable t); @Override void onComplete(); @Override boolean hasObservers(); @Override @Nullable Throwable getThrowable(); @Nullable T getValue(); @Experimental void cleanupBuffer(); Object[] getValues(); T[] getValues(T[] array); @Override boolean hasComplete(); @Override boolean hasThrowable(); boolean hasValue();  }
@Test public void subscribeCancelRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final TestObserver<Integer> to = new TestObserver<Integer>(); final ReplaySubject<Integer> rp = ReplaySubject.create(); Runnable r1 = new Runnable() { @Override public void run() { rp.subscribe(to); } }; Runnable r2 = new Runnable() { @Override public void run() { to.cancel(); } }; TestHelper.race(r1, r2); } }
@Test public void subscribeRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final ReplaySubject<Integer> rp = ReplaySubject.create(); Runnable r1 = new Runnable() { @Override public void run() { rp.test(); } }; TestHelper.race(r1, r1); } }