本文整理匯總了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());
}
示例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();
}
示例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);
}
示例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);
}
示例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());
}
}
示例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);
}
示例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());
}
}
示例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);
}
示例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]");
}
示例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);
}
}
}
示例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();
}
示例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();
}
}
示例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();
}
示例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();
}
示例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");
}