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


Java PublishProcessor.onNext方法代码示例

本文整理汇总了Java中io.reactivex.processors.PublishProcessor.onNext方法的典型用法代码示例。如果您正苦于以下问题:Java PublishProcessor.onNext方法的具体用法?Java PublishProcessor.onNext怎么用?Java PublishProcessor.onNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.reactivex.processors.PublishProcessor的用法示例。


在下文中一共展示了PublishProcessor.onNext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test

import io.reactivex.processors.PublishProcessor; //导入方法依赖的package包/类
@Test public void test() {

        PublishProcessor<String> subject = PublishProcessor.create();
        Flowable<String> source = subject.hide();



        TestSubscriber testSubscriber = new TestSubscriber();
        CompositeDisposable composite = new CompositeDisposable();
        Disposable disposable = source
                .compose(DisposableAttach.<String>to(composite))
                .subscribeWith(testSubscriber);

        subject.onNext("Foo");
        testSubscriber.assertValue("Foo");
        assertTrue(composite.size() == 1);
        composite.dispose();
        assertTrue(composite.size() == 0);
        assertTrue(composite.isDisposed());
        assertTrue(disposable.isDisposed());
        assertTrue(testSubscriber.isDisposed());
    }
 
开发者ID:cp949,项目名称:DisposableAttach,代码行数:23,代码来源:DisposableAttachFlowableTest.java

示例2: autoDispose_withMaybe_interrupted

import io.reactivex.processors.PublishProcessor; //导入方法依赖的package包/类
@Test public void autoDispose_withMaybe_interrupted() {
  PublishProcessor<Integer> source = PublishProcessor.create();
  MaybeSubject<Integer> lifecycle = MaybeSubject.create();
  TestSubscriber<Integer> o = source
          .as(AutoDispose.<Integer>autoDisposable(lifecycle))
          .test();
  o.assertSubscribed();

  assertThat(source.hasSubscribers()).isTrue();
  assertThat(lifecycle.hasObservers()).isTrue();

  source.onNext(1);
  o.assertValue(1);

  lifecycle.onSuccess(2);
  source.onNext(2);

  // No more events
  o.assertValue(1);

  // Unsubscribed
  assertThat(source.hasSubscribers()).isFalse();
  assertThat(lifecycle.hasObservers()).isFalse();
}
 
开发者ID:uber,项目名称:AutoDispose,代码行数:25,代码来源:AutoDisposeSubscriberTest.java

示例3: errorImmediate

import io.reactivex.processors.PublishProcessor; //导入方法依赖的package包/类
@Test
public void errorImmediate() {
    TestScheduler scheduler = new TestScheduler();

    PublishProcessor<Integer> pp = PublishProcessor.create();

    TestSubscriber<Integer> ts = pp
        .compose(FlowableTransformers.<Integer>spanout(100, TimeUnit.MILLISECONDS, scheduler))
        .test();

    pp.onNext(1);
    pp.onError(new IOException());

    scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS);

    ts.assertFailure(IOException.class);
}
 
开发者ID:akarnokd,项目名称:RxJava2Extensions,代码行数:18,代码来源:FlowableSpanoutTest.java

示例4: errorDelayed

import io.reactivex.processors.PublishProcessor; //导入方法依赖的package包/类
@Test
public void errorDelayed() {
    TestScheduler scheduler = new TestScheduler();

    PublishProcessor<Integer> pp = PublishProcessor.create();

    TestSubscriber<Integer> ts = pp
        .compose(FlowableTransformers.<Integer>spanout(100L, TimeUnit.MILLISECONDS, scheduler, true))
        .test();

    pp.onNext(1);
    pp.onError(new IOException());

    scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS);

    ts.assertFailure(IOException.class, 1);
}
 
开发者ID:akarnokd,项目名称:RxJava2Extensions,代码行数:18,代码来源:FlowableSpanoutTest.java

示例5: depthEmitCancelRace

import io.reactivex.processors.PublishProcessor; //导入方法依赖的package包/类
@Test
public void depthEmitCancelRace() {
    for (int i = 0; i < 1000; i++) {

        final PublishProcessor<Integer> pp = PublishProcessor.create();

        final TestSubscriber<Integer> ts = Flowable.just(0)
        .compose(FlowableTransformers.<Integer>expand(Functions.justFunction(pp), ExpandStrategy.DEPTH_FIRST))
        .test(1);

        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                pp.onNext(1);
            }
        };
        Runnable r2 = new Runnable() {
            @Override
            public void run() {
                ts.cancel();
            }
        };

        TestHelper.race(r1, r2, Schedulers.single());
    }
}
 
开发者ID:akarnokd,项目名称:RxJava2Extensions,代码行数:27,代码来源:FlowableExpandTest.java

示例6: flowableProcessorToFlowProcessor

import io.reactivex.processors.PublishProcessor; //导入方法依赖的package包/类
@Test
public void flowableProcessorToFlowProcessor() {
    PublishProcessor<Integer> pp = PublishProcessor.create();

    Flow.Processor<Integer, Integer> fp = FlowInterop.toFlowProcessor(pp);

    FlowTestSubscriber<Integer> ts = new FlowTestSubscriber<>();
    fp.subscribe(ts);

    pp.onNext(1);
    pp.onNext(2);
    pp.onNext(3);
    pp.onNext(4);
    pp.onNext(5);
    pp.onComplete();

    ts.assertResult(1, 2, 3, 4, 5);
}
 
开发者ID:akarnokd,项目名称:RxJava2Jdk9Interop,代码行数:19,代码来源:FlowInteropTest.java

示例7: fatalExceptionDuringReplayThrown

import io.reactivex.processors.PublishProcessor; //导入方法依赖的package包/类
@SuppressWarnings("CheckReturnValue")
@Test public void fatalExceptionDuringReplayThrown() {
  PublishProcessor<String> subject = PublishProcessor.create();
  Flowable<String> flowable = subject.compose(ReplayingShare.<String>instance());

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

  Consumer<String> brokenAction = new Consumer<String>() {
    @Override public void accept(String s) {
      throw new OutOfMemoryError("broken!");
    }
  };
  try {
    flowable.subscribe(brokenAction);
  } catch (OutOfMemoryError e) {
    assertEquals("broken!", e.getMessage());
  }
}
 
开发者ID:JakeWharton,项目名称:RxReplayingShare,代码行数:20,代码来源:ReplayingShareFlowableTest.java

示例8: flowableProcessorToFlowProcessorError

import io.reactivex.processors.PublishProcessor; //导入方法依赖的package包/类
@Test
public void flowableProcessorToFlowProcessorError() {
    PublishProcessor<Integer> pp = PublishProcessor.create();

    Flow.Processor<Integer, Integer> fp = FlowInterop.toFlowProcessor(pp);

    FlowTestSubscriber<Integer> ts = new FlowTestSubscriber<>();
    fp.subscribe(ts);

    pp.onNext(1);
    pp.onNext(2);
    pp.onNext(3);
    pp.onNext(4);
    pp.onNext(5);
    pp.onError(new IOException());

    ts.assertFailure(IOException.class, 1, 2, 3, 4, 5);
}
 
开发者ID:akarnokd,项目名称:RxJava2Jdk9Interop,代码行数:19,代码来源:FlowInteropTest.java

示例9: cancelAfterOneBackpressured

import io.reactivex.processors.PublishProcessor; //导入方法依赖的package包/类
@Test
public void cancelAfterOneBackpressured() {
    PublishProcessor<Integer> pp1 = PublishProcessor.create();
    PublishProcessor<Integer> pp2 = PublishProcessor.create();

    TestSubscriber<String> ts = new TestSubscriber<String>(1) {
        @Override
        public void onNext(String t) {
            super.onNext(t);
            cancel();
            onComplete();
        }
    };

    Flowables.zipLatest(pp1, pp2, toString2).subscribe(ts);
    ts.assertEmpty();

    pp1.onNext(1);

    ts.assertEmpty();

    pp2.onNext(2);

    ts.assertResult("[1, 2]");
}
 
开发者ID:akarnokd,项目名称:RxJava2Extensions,代码行数:26,代码来源:FlowableZipLatestTest.java

示例10: post

import io.reactivex.processors.PublishProcessor; //导入方法依赖的package包/类
public void post(@NonNull Object tag, @NonNull Object content) {
    List<PublishProcessor> processorList = mPublishMap.get(tag);
    if (!processorList.isEmpty()) {
        for (PublishProcessor processor : processorList) {
            processor.onNext(content);
        }
    }
}
 
开发者ID:iMeiji,项目名称:Daily,代码行数:9,代码来源:RxBus.java

示例11: unbound_shouldStillPassValues

import io.reactivex.processors.PublishProcessor; //导入方法依赖的package包/类
@Test public void unbound_shouldStillPassValues() {
  PublishProcessor<Integer> s = PublishProcessor.create();
  TestSubscriber<Integer> o = s
          .as(AutoDispose.<Integer>autoDisposable(ScopeProvider.UNBOUND))
          .test();

  s.onNext(1);
  o.assertValue(1);
  o.dispose();
}
 
开发者ID:uber,项目名称:AutoDispose,代码行数:11,代码来源:AutoDisposeSubscriberTest.java

示例12: emissionRace

import io.reactivex.processors.PublishProcessor; //导入方法依赖的package包/类
@Test
public void emissionRace() {
    for (int i = 0; i < 1000; i++) {
        final PublishProcessor<Integer> pp1 = PublishProcessor.create();
        final PublishProcessor<Integer> pp2 = PublishProcessor.create();

        TestSubscriber<String> ts = Flowables.zipLatest(pp1, pp2, toString2)
        .test();

        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                for (int j = 0; j < 50; j++) {
                    pp1.onNext(j);
                }
                pp1.onComplete();
            }
        };

        Runnable r2 = new Runnable() {
            @Override
            public void run() {
                for (int j = 0; j < 50; j++) {
                    pp2.onNext(j);
                }
                pp2.onComplete();
            }
        };

        TestHelper.race(r1, r2, Schedulers.single());

        ts.assertNoErrors().assertComplete();
    }
}
 
开发者ID:akarnokd,项目名称:RxJava2Extensions,代码行数:35,代码来源:FlowableZipLatestTest.java

示例13: test

import io.reactivex.processors.PublishProcessor; //导入方法依赖的package包/类
@Test
public void test() {
TestScheduler scheduler = new TestScheduler();
PublishProcessor<String> pp = PublishProcessor.create();

Function<Flowable<String>, Flowable<List<String>>> f = o -> 
        o.buffer(o.filter(v -> v.contains("Start")), 
                v -> Flowable.merge(o.filter(w -> w.contains("End")), 
                        Flowable.timer(5, TimeUnit.MINUTES, scheduler))); 

pp.publish(f)
.subscribe(System.out::println);

pp.onNext("Start");
pp.onNext("A");
pp.onNext("B");
pp.onNext("End");

pp.onNext("Start");
pp.onNext("C");

scheduler.advanceTimeBy(5, TimeUnit.MINUTES);

pp.onNext("Start");
pp.onNext("D");
pp.onNext("End");
pp.onComplete();
    
}
 
开发者ID:akarnokd,项目名称:akarnokd-misc,代码行数:30,代码来源:BufferWithConditionAndTime.java

示例14: test

import io.reactivex.processors.PublishProcessor; //导入方法依赖的package包/类
@Test
public void test() {
    TestScheduler scheduler = new TestScheduler();
    PublishProcessor<String> pp = PublishProcessor.create();

    Function<Flowable<String>, Flowable<List<String>>> f = o -> 
            o.buffer(o.filter(v -> v.contains("Start")), 
                     v -> Flowable.merge(o.filter(w -> w.contains("Start")), 
                                         Flowable.timer(5, TimeUnit.MINUTES, scheduler))); 

    pp.publish(f)
    .doOnNext(v -> {
        int s = v.size();
        if (s > 1 && v.get(s - 1).contains("Start")) {
            v.remove(s - 1);
        }
    })
    .subscribe(System.out::println);

    pp.onNext("Start");
    pp.onNext("A");
    pp.onNext("B");
    pp.onNext("End");

    pp.onNext("Start");
    pp.onNext("C");

    scheduler.advanceTimeBy(5, TimeUnit.MINUTES);

    pp.onNext("Start");
    pp.onNext("D");
    pp.onNext("End");
    pp.onComplete();
}
 
开发者ID:akarnokd,项目名称:akarnokd-misc,代码行数:35,代码来源:BufferStartEndTest.java

示例15: testOnBackpressureLatest

import io.reactivex.processors.PublishProcessor; //导入方法依赖的package包/类
@Test
public void testOnBackpressureLatest() {
    PublishProcessor<String> in = PublishProcessor.create();

    StreamId<String> inStreamId = provide(in).withUniqueStreamId();

    FanOutStreamId<String> fanOutStreamId = FanOutStreamId
            .fanOut(inStreamId, BackpressureStrategies.onBackpressureLatest());

    TestSubscriber<String> fast = rxFrom(fanOutStreamId)
            //.onBackpressureLatest() // this is necessary because a backpressure strategy needs to be applied after the observeOn applied in TrackKeppingDiscoveryService
            .test(0);
    TestSubscriber<String> slow = rxFrom(fanOutStreamId)
            // .onBackpressureLatest()
            .test(0);

    slow.request(1);
    fast.request(1);
    in.onNext("A");
    fast.request(1);
    in.onNext("B");
    fast.request(1);
    in.onNext("C");
    fast.request(1);
    in.onNext("D");
    fast.request(1);
    in.onNext("E");
    in.onNext("F");
    in.onNext("G");
    in.onNext("H");
    sleep(); // necessary for the propagation between threads
    slow.request(1);
    fast.request(1);
    in.onNext("I");
    slow.request(1);
    in.onNext("J");

    fast.awaitCount(6);
    slow.awaitCount(3);
    fast.assertValueCount(6);
    slow.assertValueCount(3);
    System.out.println("fast: " + fast.values());
    System.out.println("slow: " + slow.values());
    assertThat(fast.values()).containsOnly("A", "B", "C", "D", "E", "H");
    assertThat(slow.values()).containsOnly("A", "H", "I");
}
 
开发者ID:streamingpool,项目名称:streamingpool-core,代码行数:47,代码来源:FanOutStreamFactoryTest.java


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