当前位置: 首页>>代码示例>>Java>>正文


Java Subject.onNext方法代码示例

本文整理汇总了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!")
    );
}
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:19,代码来源:Ch5_25.java

示例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());
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:18,代码来源:JobsDAOTest.java

示例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());
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:18,代码来源:JobsDAOTest.java

示例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);
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:27,代码来源:JobManagerTest.java

示例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);
}
 
开发者ID:adamkewley,项目名称:jobson,代码行数:27,代码来源:JobManagerTest.java

示例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();
}
 
开发者ID:k-kagurazaka,项目名称:rx-property-android,代码行数:22,代码来源:RxCommandTest.java

示例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();
}
 
开发者ID:k-kagurazaka,项目名称:rx-property-android,代码行数:20,代码来源:RxCommandTest.java

示例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();
}
 
开发者ID:k-kagurazaka,项目名称:rx-property-android,代码行数:26,代码来源:RxCommandTest.java

示例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();
}
 
开发者ID:k-kagurazaka,项目名称:rx-property-android,代码行数:19,代码来源:RxPropertyTest.java

示例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();
}
 
开发者ID:k-kagurazaka,项目名称:rx-property-android,代码行数:20,代码来源:RxPropertyTest.java

示例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();
}
 
开发者ID:k-kagurazaka,项目名称:rx-property-android,代码行数:20,代码来源:RxPropertyTest.java

示例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();
}
 
开发者ID:k-kagurazaka,项目名称:rx-property-android,代码行数:20,代码来源:RxPropertyTest.java

示例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();
}
 
开发者ID:k-kagurazaka,项目名称:rx-property-android,代码行数:20,代码来源:RxPropertyTest.java

示例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();
}
 
开发者ID:k-kagurazaka,项目名称:rx-property-android,代码行数:20,代码来源:RxPropertyTest.java

示例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();
}
 
开发者ID:k-kagurazaka,项目名称:rx-property-android,代码行数:20,代码来源:RxPropertyTest.java


注:本文中的io.reactivex.subjects.Subject.onNext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。