本文整理汇总了Java中io.reactivex.subjects.Subject.onNext方法的典型用法代码示例。如果您正苦于以下问题:Java Subject.onNext方法的具体用法?Java Subject.onNext怎么用?Java Subject.onNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.subjects.Subject
的用法示例。
在下文中一共展示了Subject.onNext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import io.reactivex.subjects.Subject; //导入方法依赖的package包/类
public static void main(String[] args) {
Subject<String> subject =
AsyncSubject.create();
subject.subscribe(s ->
System.out.println("Observer 1: " + s),
Throwable::printStackTrace,
() -> System.out.println("Observer 1 done!")
);
subject.onNext("Alpha");
subject.onNext("Beta");
subject.onNext("Gamma");
subject.onComplete();
subject.subscribe(s ->
System.out.println("Observer 2: " + s),
Throwable::printStackTrace,
() -> System.out.println("Observer 2 done!")
);
}
示例2: testPersistStdoutReturnsADisposableThatStopsFurtherReads
import io.reactivex.subjects.Subject; //导入方法依赖的package包/类
@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());
}
示例3: testPersistStderrReturnsADisposableThatStopsFurtherReads
import io.reactivex.subjects.Subject; //导入方法依赖的package包/类
@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());
}
示例4: testGetStdoutUpdatesEchoesUpdatesFromExecutorObservers
import io.reactivex.subjects.Subject; //导入方法依赖的package包/类
@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);
}
示例5: testGetStderrUpdatesEchoesUpdatesFromExecutorObservers
import io.reactivex.subjects.Subject; //导入方法依赖的package包/类
@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);
}
示例6: emitValueWhenBoundTriggerEmitsValue
import io.reactivex.subjects.Subject; //导入方法依赖的package包/类
@Test
public void emitValueWhenBoundTriggerEmitsValue() {
// given
Subject<NoParameter> trigger = PublishSubject.create();
RxCommand<NoParameter> command = new RxCommand<NoParameter>()
.bindTrigger(trigger);
TestObserver<NoParameter> testObserver = command.test();
// when
trigger.onNext(NoParameter.INSTANCE);
// then
testObserver.assertSubscribed()
.assertValue(NoParameter.INSTANCE)
.assertNoErrors()
.assertNotComplete()
.dispose();
// after
command.dispose();
}
示例7: emitsOnCompleteWhenBoundTriggerIsCompleted
import io.reactivex.subjects.Subject; //导入方法依赖的package包/类
@Test
public void emitsOnCompleteWhenBoundTriggerIsCompleted() {
// given
Subject<NoParameter> trigger = PublishSubject.create();
RxCommand<NoParameter> command = new RxCommand<NoParameter>()
.bindTrigger(trigger);
TestObserver<NoParameter> testObserver = command.test();
// when
trigger.onNext(NoParameter.INSTANCE);
trigger.onComplete();
// then
testObserver.assertResult(NoParameter.INSTANCE)
.dispose();
// after
command.dispose();
}
示例8: triggerBindingCanExecuteMoreThanOnce
import io.reactivex.subjects.Subject; //导入方法依赖的package包/类
@Test
public void triggerBindingCanExecuteMoreThanOnce() {
// given
Subject<NoParameter> firstTrigger = PublishSubject.create();
Subject<NoParameter> secondTrigger = PublishSubject.create();
RxCommand<NoParameter> command = new RxCommand<>();
TestObserver<NoParameter> testObserver = command.test();
// when
command.bindTrigger(firstTrigger);
firstTrigger.onNext(NoParameter.INSTANCE);
command.bindTrigger(secondTrigger);
firstTrigger.onNext(NoParameter.INSTANCE);
secondTrigger.onNext(NoParameter.INSTANCE);
// then
testObserver.assertSubscribed()
.assertValues(NoParameter.INSTANCE, NoParameter.INSTANCE)
.assertNoErrors()
.assertNotComplete()
.dispose();
// after
command.dispose();
}
示例9: followsSourceObservable
import io.reactivex.subjects.Subject; //导入方法依赖的package包/类
@Test
public void followsSourceObservable() {
// given
Subject<String> source = PublishSubject.create();
property = new RxProperty<>(source);
TestObserver<String> testObserver = property.test();
// when
source.onNext("First");
source.onNext("Second");
// then
testObserver.assertSubscribed()
.assertValues("First", "Second")
.assertNoErrors()
.assertNotComplete()
.dispose();
}
示例10: doesNotEmitSameValuesWhenSourceObservableEmitsSameValuesWithDistinctUntilChangeMode
import io.reactivex.subjects.Subject; //导入方法依赖的package包/类
@Test
public void doesNotEmitSameValuesWhenSourceObservableEmitsSameValuesWithDistinctUntilChangeMode() {
// given
Subject<String> source = PublishSubject.create();
property = new RxProperty<>(source);
TestObserver<String> testObserver = property.test();
// when
source.onNext("RxProperty");
source.onNext("RxProperty");
source.onNext("RxProperty");
// then
testObserver.assertSubscribed()
.assertValue("RxProperty")
.assertNoErrors()
.assertNotComplete()
.dispose();
}
示例11: emitsAllValuesWhenSourceObservableEmitsSameValuesWithoutDistinctUntilChangeMode
import io.reactivex.subjects.Subject; //导入方法依赖的package包/类
@Test
public void emitsAllValuesWhenSourceObservableEmitsSameValuesWithoutDistinctUntilChangeMode() {
// given
Subject<String> source = PublishSubject.create();
property = new RxProperty<>(source, EnumSet.of(RxProperty.Mode.NONE));
TestObserver<String> testObserver = property.test();
// when
source.onNext("RxProperty");
source.onNext("RxProperty");
source.onNext("RxProperty");
// then
testObserver.assertSubscribed()
.assertValues("RxProperty", "RxProperty", "RxProperty")
.assertNoErrors()
.assertNotComplete()
.dispose();
}
示例12: distinctUntilChangeWhenSourceObservableEmitsSameValuesWithDistinctUntilChangeMode
import io.reactivex.subjects.Subject; //导入方法依赖的package包/类
@Test
public void distinctUntilChangeWhenSourceObservableEmitsSameValuesWithDistinctUntilChangeMode() {
// given
Subject<String> source = PublishSubject.create();
property = new RxProperty<>(source);
TestObserver<String> testObserver = propertyObserver(property);
// when
source.onNext("RxProperty");
source.onNext("RxProperty");
source.onNext("RxProperty");
// then
testObserver.assertSubscribed()
.assertValue("RxProperty")
.assertNoErrors()
.assertNotComplete()
.dispose();
}
示例13: notifyAllValuesWhenSourceObservableEmitsSameValuesWithoutDistinctUntilChangeMode
import io.reactivex.subjects.Subject; //导入方法依赖的package包/类
@Test
public void notifyAllValuesWhenSourceObservableEmitsSameValuesWithoutDistinctUntilChangeMode() {
// given
Subject<String> source = PublishSubject.create();
property = new RxProperty<>(source, EnumSet.of(RxProperty.Mode.NONE));
TestObserver<String> testObserver = propertyObserver(property);
// when
source.onNext("RxProperty");
source.onNext("RxProperty");
source.onNext("RxProperty");
// then
testObserver.assertSubscribed()
.assertValues("RxProperty", "RxProperty", "RxProperty")
.assertNoErrors()
.assertNotComplete()
.dispose();
}
示例14: noLongerNotifyWhenSourceObservableEmitsError
import io.reactivex.subjects.Subject; //导入方法依赖的package包/类
@Test
public void noLongerNotifyWhenSourceObservableEmitsError() {
// given
Subject<String> source = PublishSubject.create();
property = new RxProperty<>(source);
TestObserver<String> testObserver = propertyObserver(property);
// when
source.onNext("First");
source.onError(new RuntimeException("Error in source observable"));
source.onNext("Second");
// then
testObserver.assertSubscribed()
.assertValue("First")
.assertNoErrors()
.assertNotComplete()
.dispose();
}
示例15: noLongerNotifyWhenSourceObservableIsCompleted
import io.reactivex.subjects.Subject; //导入方法依赖的package包/类
@Test
public void noLongerNotifyWhenSourceObservableIsCompleted() {
// given
Subject<String> source = PublishSubject.create();
property = new RxProperty<>(source);
TestObserver<String> testObserver = propertyObserver(property);
// when
source.onNext("First");
source.onComplete();
source.onNext("Second");
// then
testObserver.assertSubscribed()
.assertValue("First")
.assertNoErrors()
.assertNotComplete()
.dispose();
}