當前位置: 首頁>>代碼示例>>Java>>正文


Java TestSubscriber.request方法代碼示例

本文整理匯總了Java中io.reactivex.subscribers.TestSubscriber.request方法的典型用法代碼示例。如果您正苦於以下問題:Java TestSubscriber.request方法的具體用法?Java TestSubscriber.request怎麽用?Java TestSubscriber.request使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.reactivex.subscribers.TestSubscriber的用法示例。


在下文中一共展示了TestSubscriber.request方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testOnBackpressureLatest

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的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

示例2: testOnBackpressureDrop

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testOnBackpressureDrop() {
    PublishProcessor<String> in = PublishProcessor.create();

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

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

    TestSubscriber<String> fast = rxFrom(fanOutStreamId)
            .test(0);
    TestSubscriber<String> slow = rxFrom(fanOutStreamId)
            .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", "I");
    assertThat(slow.values()).containsOnly("A", "I", "J");
}
 
開發者ID:streamingpool,項目名稱:streamingpool-core,代碼行數:45,代碼來源:FanOutStreamFactoryTest.java

示例3: testOnBackpressureBuffer

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testOnBackpressureBuffer() {
    PublishProcessor<String> in = PublishProcessor.create();

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

    FanOutStreamId<String> fanOutStreamId = FanOutStreamId.fanOut(inStreamId, onBackpressureBuffer(2,
            DROP_OLDEST));

    TestSubscriber<String> fast = rxFrom(fanOutStreamId)
            .test(0);
    TestSubscriber<String> slow = rxFrom(fanOutStreamId)
            .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(3);
    in.onNext("I");
    in.onNext("J");
    sleep(); // necessary for the propagation between threads
    slow.request(1);

    fast.awaitCount(8);
    slow.awaitCount(3);
    fast.assertValueCount(8);
    slow.assertValueCount(3);
    System.out.println("fast: " + fast.values());
    System.out.println("slow: " + slow.values());
    assertThat(fast.values()).containsOnly("A", "B", "C", "D", "E", "G", "H", "I");
    assertThat(slow.values()).containsOnly("A", "G", "I");
}
 
開發者ID:streamingpool,項目名稱:streamingpool-core,代碼行數:46,代碼來源:FanOutStreamFactoryTest.java

示例4: testWithPureFlowable

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testWithPureFlowable() {
    PublishProcessor<String> in = PublishProcessor.create();

    Flowable<String> input = in
            .observeOn(Schedulers.newThread(), false)
            .share()
            .observeOn(Schedulers.newThread(), false)
            .onBackpressureLatest();

    TestSubscriber<String> fast = input
            .doOnError(e -> System.out.println("ERROR: " + e))
            .test(0);
    TestSubscriber<String> slow = input
            .doOnError(e -> System.out.println("ERROR: " + e))
            .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);

    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.subscribers.TestSubscriber.request方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。