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


Java TestSubscriber.dispose方法代碼示例

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


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

示例1: clientCanCancelServerStreamExplicitly

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void clientCanCancelServerStreamExplicitly() throws InterruptedException {
    RxNumbersGrpc.RxNumbersStub stub = RxNumbersGrpc.newRxStub(channel);
    TestSubscriber<NumberProto.Number> subscription = stub
            .responsePressure(Single.just(Empty.getDefaultInstance()))
            .doOnNext(number -> System.out.println(number.getNumber(0)))
            .doOnError(throwable -> System.out.println(throwable.getMessage()))
            .doOnComplete(() -> System.out.println("Completed"))
            .doOnCancel(() -> System.out.println("Client canceled"))
            .test();

    Thread.sleep(250);
    subscription.dispose();
    Thread.sleep(250);

    subscription.awaitTerminalEvent(3, TimeUnit.SECONDS);
    // Cancellation may or may not deliver the last generated message due to delays in the gRPC processing thread
    assertThat(Math.abs(subscription.valueCount() - svc.getLastNumberProduced())).isLessThanOrEqualTo(3);
    assertThat(svc.wasCanceled()).isTrue();
}
 
開發者ID:salesforce,項目名稱:reactive-grpc,代碼行數:21,代碼來源:CancellationPropagationIntegrationTest.java

示例2: clientCanCancelServerStreamImplicitly

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void clientCanCancelServerStreamImplicitly() throws InterruptedException {
    RxNumbersGrpc.RxNumbersStub stub = RxNumbersGrpc.newRxStub(channel);
    TestSubscriber<NumberProto.Number> subscription = stub
            .responsePressure(Single.just(Empty.getDefaultInstance()))
            .doOnNext(number -> System.out.println(number.getNumber(0)))
            .doOnError(throwable -> System.out.println(throwable.getMessage()))
            .doOnComplete(() -> System.out.println("Completed"))
            .doOnCancel(() -> System.out.println("Client canceled"))
            .take(10)
            .test();

    // Consume some work
    Thread.sleep(TimeUnit.SECONDS.toMillis(1));
    subscription.dispose();

    subscription.awaitTerminalEvent(3, TimeUnit.SECONDS);
    subscription.assertValueCount(10);
    subscription.assertTerminated();
    assertThat(svc.wasCanceled()).isTrue();
}
 
開發者ID:salesforce,項目名稱:reactive-grpc,代碼行數:22,代碼來源:CancellationPropagationIntegrationTest.java

示例3: testBufferingWithNoUpdates

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testBufferingWithNoUpdates() throws InterruptedException
{
    TestScheduler testScheduler = new TestScheduler();
    SimpleFlowableList<Integer> list = new SimpleFlowableList<>();
    FlowableList<Integer> bufferedList = list.buffer(50, TimeUnit.MILLISECONDS, testScheduler);

    TestSubscriber testSubscriber = new TestSubscriber();

    bufferedList.updates().subscribe(testSubscriber);

    testScheduler.advanceTimeBy(50, TimeUnit.MILLISECONDS);
    testScheduler.triggerActions();
    testSubscriber.awaitCount(1);

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);

    testScheduler.advanceTimeBy(50, TimeUnit.MILLISECONDS);
    testScheduler.triggerActions();
    testSubscriber.awaitCount(1);

    testSubscriber.dispose();
}
 
開發者ID:mproberts,項目名稱:rxtools,代碼行數:25,代碼來源:BackpressureFlowableListTest.java

示例4: testDownstreamCancel_output

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testDownstreamCancel_output() throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(1);
    TestSubscriber<OutputHarvester.Crop> testSubscriber = publisher.doOnCancel(latch::countDown).compose(harvesterFactory.forOutput(publisher, cmd)).test();
    testSubscriber.assertNotTerminated();

    testSubscriber.dispose();

    assertThat(latch.await(1, TimeUnit.SECONDS), is(true));
}
 
開發者ID:d4rken,項目名稱:RxShell,代碼行數:11,代碼來源:HarvesterTest.java

示例5: testDownstreamCancel_errors

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testDownstreamCancel_errors() throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(1);
    TestSubscriber<OutputHarvester.Crop> testSubscriber = publisher.doOnCancel(latch::countDown).compose(harvesterFactory.forOutput(publisher, cmd)).test();
    testSubscriber.assertNotTerminated();

    testSubscriber.dispose();

    assertThat(latch.await(1, TimeUnit.SECONDS), is(true));
}
 
開發者ID:d4rken,項目名稱:RxShell,代碼行數:11,代碼來源:HarvesterTest.java

示例6: dataStream_withPermissionsAndSensorIsReady_returnsFlowable

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void dataStream_withPermissionsAndSensorIsReady_returnsFlowable() throws Exception {
    TestSubscriber<SensorRecord> test = sensorGatherer.recordStream().test();

    test.assertSubscribed();
    test.dispose();
}
 
開發者ID:ubikgs,項目名稱:AndroidSensors,代碼行數:8,代碼來源:SensorGathererTest.java

示例7: testBindAndRebind

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testBindAndRebind()
{
    SimpleFlowableList<Integer> a = new SimpleFlowableList<>();
    SimpleFlowableList<Integer> b = new SimpleFlowableList<>();

    a.add(1);
    a.add(2);

    b.add(3);
    b.add(4);

    FlowableList<?> list = FlowableList.concat(Arrays.<FlowableList<Integer>>asList(a, b));
    TestSubscriber testSubscriber1 = new TestSubscriber();
    TestSubscriber testSubscriber2 = new TestSubscriber();
    TestSubscriber testSubscriber3 = new TestSubscriber();

    list.updates().subscribe(testSubscriber1);

    b.add(5);

    list.updates().subscribe(testSubscriber2);

    b.add(6);

    list.updates().subscribe(testSubscriber3);

    testSubscriber1.dispose();

    b.add(7);

    List<Update> onNextEvents1 = testSubscriber1.values();
    List<Update> onNextEvents2 = testSubscriber2.values();
    List<Update> onNextEvents3 = testSubscriber3.values();

    // test subscriber 1
    testSubscriber1.assertValueCount(3);

    Update reload1 = onNextEvents1.get(0);
    Update insert5 = onNextEvents1.get(1);
    Update insert61 = onNextEvents1.get(2);

    assertEquals(Arrays.asList(Change.reloaded()), reload1.changes);
    assertEquals(Arrays.asList(1, 2, 3, 4), reload1.list);

    assertEquals(Arrays.asList(Change.inserted(4)), insert5.changes);
    assertEquals(Arrays.asList(1, 2, 3, 4, 5), insert5.list);

    assertEquals(Arrays.asList(Change.inserted(5)), insert61.changes);
    assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6), insert61.list);

    // test subscriber 2
    testSubscriber2.assertValueCount(3);

    Update reload2 = onNextEvents2.get(0);
    Update insert62 = onNextEvents2.get(1);
    Update insert72 = onNextEvents2.get(2);

    assertEquals(Arrays.asList(Change.reloaded()), reload2.changes);
    assertEquals(Arrays.asList(1, 2, 3, 4, 5), reload2.list);

    assertEquals(Arrays.asList(Change.inserted(5)), insert62.changes);
    assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6), insert62.list);

    assertEquals(Arrays.asList(Change.inserted(6)), insert72.changes);
    assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7), insert72.list);

    // test subscriber 3
    testSubscriber3.assertValueCount(2);

    Update reload3 = onNextEvents3.get(0);
    Update insert73 = onNextEvents3.get(1);

    assertEquals(Arrays.asList(Change.reloaded()), reload3.changes);
    assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6), reload3.list);

    assertEquals(Arrays.asList(Change.inserted(6)), insert73.changes);
    assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7), insert73.list);
}
 
開發者ID:mproberts,項目名稱:rxtools,代碼行數:80,代碼來源:ConcatFlowableListTest.java

示例8: testUnbindAndRebind

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testUnbindAndRebind()
{
    SimpleFlowableList<Integer> a = new SimpleFlowableList<>();
    SimpleFlowableList<Integer> b = new SimpleFlowableList<>();

    a.add(1);
    a.add(2);

    b.add(3);
    b.add(4);

    FlowableList<?> list = FlowableList.concat(Arrays.<FlowableList<Integer>>asList(a, b));
    TestSubscriber testSubscriber1 = new TestSubscriber();
    TestSubscriber testSubscriber2 = new TestSubscriber();

    list.updates().subscribe(testSubscriber1);

    b.add(5);
    b.add(6);

    testSubscriber1.dispose();
    list.updates().subscribe(testSubscriber2);

    b.add(7);

    List<Update> onNextEvents1 = testSubscriber1.values();
    List<Update> onNextEvents2 = testSubscriber2.values();

    // test subscriber 1
    testSubscriber1.assertValueCount(3);

    Update reload1 = onNextEvents1.get(0);
    Update insert5 = onNextEvents1.get(1);
    Update insert6 = onNextEvents1.get(2);

    assertEquals(Arrays.asList(Change.reloaded()), reload1.changes);
    assertEquals(Arrays.asList(1, 2, 3, 4), reload1.list);

    assertEquals(Arrays.asList(Change.inserted(4)), insert5.changes);
    assertEquals(Arrays.asList(1, 2, 3, 4, 5), insert5.list);

    assertEquals(Arrays.asList(Change.inserted(5)), insert6.changes);
    assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6), insert6.list);

    // test subscriber 2
    testSubscriber2.assertValueCount(2);

    Update reload2 = onNextEvents2.get(0);
    Update insert72 = onNextEvents2.get(1);

    assertEquals(Arrays.asList(Change.reloaded()), reload2.changes);
    assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6), reload2.list);

    assertEquals(Arrays.asList(Change.inserted(6)), insert72.changes);
    assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7), insert72.list);
}
 
開發者ID:mproberts,項目名稱:rxtools,代碼行數:58,代碼來源:ConcatFlowableListTest.java

示例9: testBufferingObservableList

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testBufferingObservableList() throws InterruptedException
{
    TestScheduler testScheduler = new TestScheduler();
    SimpleFlowableList<Integer> list = new SimpleFlowableList<>();
    FlowableList<Integer> bufferedList = list.buffer(50, TimeUnit.MILLISECONDS, testScheduler);

    TestSubscriber testSubscriber = new TestSubscriber();

    bufferedList.updates().subscribe(testSubscriber);

    for (int i = 0; i < 50; ++i) {
        list.add(i);
    }

    testScheduler.advanceTimeBy(50, TimeUnit.MILLISECONDS);
    testScheduler.triggerActions();
    testSubscriber.awaitCount(1);

    testSubscriber.assertNoErrors();
    testSubscriber.assertValueCount(1);

    for (int i = 0; i < 500; ++i) {
        list.add(i);
    }

    testScheduler.advanceTimeBy(50, TimeUnit.MILLISECONDS);
    testScheduler.triggerActions();
    testSubscriber.awaitCount(2);

    // should collapse initial reload + 100 inserts into a reload
    Update<Integer> update1 = (Update<Integer>) testSubscriber.values().get(0);

    // should collapse 500 inserts into one changeset
    Update<Integer> update2 = (Update<Integer>) testSubscriber.values().get(1);

    Change firstChange = update1.changes.get(0);

    assertEquals(Change.Type.Reloaded, firstChange.type);
    assertEquals(500, update2.changes.size());

    testSubscriber.dispose();
}
 
開發者ID:mproberts,項目名稱:rxtools,代碼行數:44,代碼來源:BackpressureFlowableListTest.java


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