Java Code Examples for io.reactivex.subjects.Subject#onNext()
The following examples show how to use
io.reactivex.subjects.Subject#onNext() .
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: JobsDAOTest.java From jobson with Apache License 2.0 | 6 votes |
@Test public void testPersistStdoutReturnsADisposableThatStopsFurtherReads() { final JobDAO dao = getInstance(); final JobId jobId = dao.persist(STANDARD_VALID_REQUEST).getId(); final Subject<byte[]> stdoutSubject = PublishSubject.create(); final AtomicBoolean stdoutObsWasRead = new AtomicBoolean(false); final Observable<byte[]> stdoutObs = stdoutSubject.map(data -> { stdoutObsWasRead.set(true); return data; }); final Disposable disposable = dao.appendStdout(jobId, stdoutObs); disposable.dispose(); stdoutSubject.onNext(TestHelpers.generateRandomBytes()); assertThat(stdoutObsWasRead.get()); }
Example 2
Source File: JobsDAOTest.java From jobson with Apache License 2.0 | 6 votes |
@Test public void testPersistStderrReturnsADisposableThatStopsFurtherReads() { final JobDAO dao = getInstance(); final JobId jobId = dao.persist(STANDARD_VALID_REQUEST).getId(); final Subject<byte[]> stderrSubject = PublishSubject.create(); final AtomicBoolean stderrObsWasRead = new AtomicBoolean(false); final Observable<byte[]> stderrObs = stderrSubject.map(data -> { stderrObsWasRead.set(true); return data; }); final Disposable disposable = dao.appendStderr(jobId, stderrObs); disposable.dispose(); stderrSubject.onNext(TestHelpers.generateRandomBytes()); assertThat(stderrObsWasRead.get()); }
Example 3
Source File: JobManagerTest.java From jobson with Apache License 2.0 | 6 votes |
@Test public void testGetStdoutUpdatesEchoesUpdatesFromExecutorObservers() throws InterruptedException, ExecutionException, TimeoutException { final CancelablePromise<JobExecutionResult> executorPromise = new SimpleCancelablePromise<>(); final Subject<byte[]> stdoutSubject = PublishSubject.create(); final JobExecutor executor = MockJobExecutor.thatUses(executorPromise, stdoutSubject, Observable.just(TestHelpers.generateRandomBytes())); final JobManager jobManager = createManagerWith(executor); final Pair<JobId, CancelablePromise<FinalizedJob>> ret = jobManager.submit(STANDARD_VALID_REQUEST); final Observable<byte[]> stdoutObservable = jobManager.stdoutUpdates(ret.getLeft()).get(); final AtomicReference<byte[]> bytesFromObservable = new AtomicReference<>(); stdoutObservable.subscribe(bytesFromObservable::set); final byte[] bytesExpected = TestHelpers.generateRandomBytes(); stdoutSubject.onNext(bytesExpected); executorPromise.complete(new JobExecutionResult(FINISHED)); ret.getRight().get(DEFAULT_TIMEOUT, MILLISECONDS); assertThat(bytesFromObservable.get()).isEqualTo(bytesExpected); }
Example 4
Source File: JobManagerTest.java From jobson with Apache License 2.0 | 6 votes |
@Test public void testGetStderrUpdatesEchoesUpdatesFromExecutorObservers() throws InterruptedException, ExecutionException, TimeoutException { final CancelablePromise<JobExecutionResult> executorPromise = new SimpleCancelablePromise<>(); final Subject<byte[]> stderrSubject = PublishSubject.create(); final JobExecutor executor = MockJobExecutor.thatUses(executorPromise, Observable.just(TestHelpers.generateRandomBytes()), stderrSubject); final JobManager jobManager = createManagerWith(executor); final Pair<JobId, CancelablePromise<FinalizedJob>> ret = jobManager.submit(STANDARD_VALID_REQUEST); final Observable<byte[]> stderrObservable = jobManager.stderrUpdates(ret.getLeft()).get(); final AtomicReference<byte[]> bytesFromObservable = new AtomicReference<>(); stderrObservable.subscribe(bytesFromObservable::set); final byte[] bytesExpected = TestHelpers.generateRandomBytes(); stderrSubject.onNext(bytesExpected); executorPromise.complete(new JobExecutionResult(FINISHED)); ret.getRight().get(DEFAULT_TIMEOUT, MILLISECONDS); assertThat(bytesFromObservable.get()).isEqualTo(bytesExpected); }
Example 5
Source File: WsClientAioHander.java From t-io with Apache License 2.0 | 5 votes |
@Override public void handler(Packet packet, ChannelContext ctx) throws Exception { if (packet instanceof WsPacket) { WsPacket wsPacket = (WsPacket) packet; if (!wsPacket.isWsEof()) { return; } } Subject<Packet> packetPublisher = (Subject<Packet>) ctx.getAttribute(WebSocketImpl.packetPublisherKey); packetPublisher.onNext(packet); }
Example 6
Source File: JobManagerTest.java From jobson with Apache License 2.0 | 5 votes |
@Test public void testSubmitJobEventListenersEchoStdoutWhenExecutorEchoesStdout() throws InterruptedException { final Subject<byte[]> stdoutSubject = ReplaySubject.create(); final byte[] expectedStdoutBytes = generateRandomBytes(); stdoutSubject.onNext(expectedStdoutBytes); final JobExecutor jobExecutor = MockJobExecutor.thatUses(stdoutSubject, Observable.never()); final JobManager jobManager = createManagerWith(jobExecutor); final Semaphore s = new Semaphore(1); s.acquire(); final JobEventListeners listeners = JobEventListeners.createStdoutListener(new Observer<byte[]>() { @Override public void onSubscribe(@NonNull Disposable disposable) {} @Override public void onNext(@NonNull byte[] bytes) { assertThat(bytes).isEqualTo(expectedStdoutBytes); s.release(); } @Override public void onError(@NonNull Throwable throwable) { fail("Error from observable"); s.release(); } @Override public void onComplete() {} }); jobManager.submit(STANDARD_VALID_REQUEST, listeners); if (!s.tryAcquire(1, SECONDS)) { fail("Timed out before any bytes received"); } }
Example 7
Source File: JobManagerTest.java From jobson with Apache License 2.0 | 5 votes |
@Test public void testSubmitJobEventListenersEchoStderrWhenExecutorEchoesStderr() throws InterruptedException { final Subject<byte[]> stderr = ReplaySubject.create(); final byte[] stderrBytes = generateRandomBytes(); stderr.onNext(stderrBytes); final JobExecutor jobExecutor = MockJobExecutor.thatUses(Observable.never(), stderr); final JobManager jobManager = createManagerWith(jobExecutor); final Semaphore s = new Semaphore(1); s.acquire(); final JobEventListeners listeners = JobEventListeners.createStderrListener(new Observer<byte[]>() { @Override public void onSubscribe(@NonNull Disposable disposable) {} @Override public void onNext(@NonNull byte[] bytes) { assertThat(bytes).isEqualTo(stderrBytes); s.release(); } @Override public void onError(@NonNull Throwable throwable) { fail("Error from observable"); s.release(); } @Override public void onComplete() {} }); jobManager.submit(STANDARD_VALID_REQUEST, listeners); if (!s.tryAcquire(1, SECONDS)) { fail("Timed out before any bytes received"); } }
Example 8
Source File: RxBus.java From Toutiao with Apache License 2.0 | 5 votes |
public void post(@NonNull Object tag, @NonNull Object content) { List<Subject> subjects = subjectMapper.get(tag); if (!subjects.isEmpty()) { for (Subject subject : subjects) { subject.onNext(content); } } }
Example 9
Source File: RxBusOlder.java From SweetMusicPlayer with Apache License 2.0 | 5 votes |
public void post(@NonNull Object tag, @NonNull Object content) { List<Subject> subjects = mSubjectsMapper.get(tag); if (subjects != null && !subjects.isEmpty()) { for (Subject subject : subjects) { subject.onNext(content); } } if (DEBUG) { Timber.d("[send] mSubjectsMapper: " + mSubjectsMapper); } }