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


Java PublishProcessor类代码示例

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


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

示例1: testCommand_callback_sync

import io.reactivex.processors.PublishProcessor; //导入依赖的package包/类
@Test
public void testCommand_callback_sync() throws IOException, InterruptedException {
    processor.attach(session);

    int cnt = 100;
    List<Pair<TestObserver<Cmd.Result>, TestSubscriber<String>>> testSubscribers = new ArrayList<>();
    for (int j = 0; j < cnt; j++) {
        List<String> cmds = new ArrayList<>();
        for (int i = 0; i < 10; i++) cmds.add("echo " + i);
        cmds.add("echo " + j);

        PublishProcessor<String> outputListener = PublishProcessor.create();
        TestSubscriber<String> outputObserver = outputListener.doOnEach(stringNotification -> TestHelper.sleep(1)).test();
        final Cmd cmd = Cmd.builder(cmds).outputProcessor(outputListener).build();
        final TestObserver<Cmd.Result> resultObserver = processor.submit(cmd).subscribeOn(Schedulers.newThread()).test();
        testSubscribers.add(new Pair<>(resultObserver, outputObserver));
    }
    for (Pair<TestObserver<Cmd.Result>, TestSubscriber<String>> pair : testSubscribers) {
        pair.first.awaitDone(5, TimeUnit.SECONDS).assertNoTimeout().assertComplete();
        pair.second.awaitDone(5, TimeUnit.SECONDS).assertNoTimeout().assertValueCount(11);
    }
}
 
开发者ID:d4rken,项目名称:RxShell,代码行数:23,代码来源:CmdProcessorTest.java

示例2: testCommand_callback_async

import io.reactivex.processors.PublishProcessor; //导入依赖的package包/类
@Test
public void testCommand_callback_async() throws IOException, InterruptedException {
    processor.attach(session);

    int cnt = 100;
    List<Pair<TestObserver<Cmd.Result>, TestSubscriber<String>>> testSubscribers = new ArrayList<>();
    for (int j = 0; j < cnt; j++) {
        List<String> cmds = new ArrayList<>();
        for (int i = 0; i < 10; i++) cmds.add("echo " + i);
        cmds.add("echo " + j);

        PublishProcessor<String> outputListener = PublishProcessor.create();
        TestSubscriber<String> outputObserver = outputListener.observeOn(Schedulers.newThread()).doOnEach(stringNotification -> TestHelper.sleep(1)).test();
        final Cmd cmd = Cmd.builder(cmds).outputProcessor(outputListener).build();
        final TestObserver<Cmd.Result> resultObserver = processor.submit(cmd).subscribeOn(Schedulers.newThread()).test();
        testSubscribers.add(new Pair<>(resultObserver, outputObserver));
    }
    for (Pair<TestObserver<Cmd.Result>, TestSubscriber<String>> pair : testSubscribers) {
        pair.first.awaitDone(5, TimeUnit.SECONDS).assertNoTimeout().assertComplete();
        pair.second.awaitDone(5, TimeUnit.SECONDS).assertNoTimeout().assertValueCount(11);
    }
}
 
开发者ID:d4rken,项目名称:RxShell,代码行数:23,代码来源:CmdProcessorTest.java

示例3: testBuilder_from

import io.reactivex.processors.PublishProcessor; //导入依赖的package包/类
@Test
public void testBuilder_from() {
    Cmd orig = Cmd.builder(UUID.randomUUID().toString())
            .outputBuffer(false)
            .errorBuffer(false)
            .timeout(1337)
            .outputProcessor(PublishProcessor.create())
            .errorProcessor(PublishProcessor.create())
            .build();

    Cmd copy = Cmd.from(orig).build();
    assertEquals(orig.getCommands(), copy.getCommands());
    assertEquals(orig.isOutputBufferEnabled(), copy.isOutputBufferEnabled());
    assertEquals(orig.isErrorBufferEnabled(), copy.isErrorBufferEnabled());
    assertEquals(orig.getTimeout(), copy.getTimeout());
    assertEquals(orig.getOutputProcessor(), copy.getOutputProcessor());
    assertEquals(orig.getErrorProcessor(), copy.getErrorProcessor());
}
 
开发者ID:d4rken,项目名称:RxShell,代码行数:19,代码来源:CmdBuilderTest.java

示例4: testBuild

import io.reactivex.processors.PublishProcessor; //导入依赖的package包/类
@Test
public void testBuild() {
    final PublishProcessor<String> outputPub = PublishProcessor.create();
    final PublishProcessor<String> errorPub = PublishProcessor.create();
    Cmd cmd = Cmd.builder("cmd1")
            .outputBuffer(false)
            .errorBuffer(false)
            .timeout(1337)
            .outputProcessor(outputPub)
            .errorProcessor(errorPub)
            .build();
    assertThat(cmd.getCommands(), contains("cmd1"));
    assertThat(cmd.getOutputProcessor(), is(outputPub));
    assertThat(cmd.getErrorProcessor(), is(errorPub));
    assertThat(cmd.getTimeout(), is(1337L));
    assertThat(cmd.isOutputBufferEnabled(), is(false));
    assertThat(cmd.isErrorBufferEnabled(), is(false));
}
 
开发者ID:d4rken,项目名称:RxShell,代码行数:19,代码来源:CmdBuilderTest.java

示例5: process

import io.reactivex.processors.PublishProcessor; //导入依赖的package包/类
public Flowable<String> process(Flowable<Byte> observableInput){

        PublishProcessor<String> publishProcessor = PublishProcessor.create();

        StringBuilder sb = new StringBuilder();
        observableInput.subscribe(b->{
                if(b==32){ //send out a new word on a space
                    publishProcessor.onNext(sb.toString());
                    sb.setLength(0);
                }else{
                    sb.append((char)b.byteValue());
                }
            },
            e->LOG.error("Error in BytesToWordsProcessor [{}]", e),
            publishProcessor::onComplete
        );

        return publishProcessor;
    }
 
开发者ID:danielshaya,项目名称:reactivejournal,代码行数:20,代码来源:BytesToWordsProcessor.java

示例6: 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

示例7: isActive

import io.reactivex.processors.PublishProcessor; //导入依赖的package包/类
public boolean isActive()
{
    PublishProcessor<Optional<T>> next = null;

    if (_next != null) {
        next = _next.get();
    }

    if (next != null) {
        return true;
    }

    PublishProcessor<Optional<T>> previous = null;

    if (_previous != null) {
        previous = _previous.get();
    }

    return previous != null;
}
 
开发者ID:mproberts,项目名称:rxtools,代码行数:21,代码来源:IndexedFlowableList.java

示例8: evictCancels

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

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

    final TestSubscriber<Integer> ts = new TestSubscriber<Integer>(0L);

    pp
    .compose(FlowableTransformers.<Integer>onBackpressureTimeout(10, 1, TimeUnit.SECONDS, scheduler, new Consumer<Integer>() {
        @Override
        public void accept(Integer e) throws Exception {
            evicted.add(e);
            ts.cancel();
        }
    }))
    .subscribe(ts);

    TestHelper.emit(pp, 1, 2, 3, 4, 5);

    scheduler.advanceTimeBy(1, TimeUnit.MINUTES);

    Assert.assertEquals(Arrays.asList(1, 2, 3, 4, 5), evicted);
}
 
开发者ID:akarnokd,项目名称:RxJava2Extensions,代码行数:25,代码来源:FlowableOnBackpressureTimeoutTest.java

示例9: comeAndGo

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

    Flowable<Integer> source = pp
    .publish()
    .compose(FlowableTransformers.<Integer>refCount(1));

    TestSubscriber<Integer> ts1 = source.test(0);

    Assert.assertTrue(pp.hasSubscribers());

    for (int i = 0; i < 3; i++) {
        TestSubscriber<Integer> ts2 = source.test();
        ts1.cancel();
        ts1 = ts2;
    }

    ts1.cancel();

    Assert.assertFalse(pp.hasSubscribers());
}
 
开发者ID:akarnokd,项目名称:RxJava2Extensions,代码行数:23,代码来源:FlowableRefCountTimeoutTest.java

示例10: 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

示例11: 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

示例12: 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

示例13: depthCompleteCancelRace

import io.reactivex.processors.PublishProcessor; //导入依赖的package包/类
@Test
public void depthCompleteCancelRace() {
    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.onComplete();
            }
        };
        Runnable r2 = new Runnable() {
            @Override
            public void run() {
                ts.cancel();
            }
        };

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

示例14: cancel

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

    Flowable.range(1, 5)
    .compose(FlowableTransformers.filterAsync(new Function<Integer, Publisher<Boolean>>() {
        @Override
        public Publisher<Boolean> apply(Integer v) throws Exception {
            return pp;
        }
    }, 16))
    .test()
    .cancel();

    Assert.assertFalse(pp.hasSubscribers());
}
 
开发者ID:akarnokd,项目名称:RxJava2Extensions,代码行数:17,代码来源:FlowableFilterAsyncTest.java

示例15: 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


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