當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。