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


Java TestSubscriber.assertValueCount方法代碼示例

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


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

示例1: completeTask_retrievedTaskIsComplete

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void completeTask_retrievedTaskIsComplete() {
    // Given a new task in the persistent repository
    final Task newTask = new Task(TITLE, "");
    mLocalDataSource.saveTask(newTask);

    // When completed in the persistent repository
    mLocalDataSource.completeTask(newTask);

    // Then the task can be retrieved from the persistent repository and is complete
    TestSubscriber<Optional<Task>> testSubscriber = new TestSubscriber<>();
    mLocalDataSource.getTask(newTask.getId()).subscribe(testSubscriber);
    testSubscriber.assertValueCount(1);
    Task result = testSubscriber.values().get(0).get();
    assertThat(result.isCompleted(), is(true));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:TasksLocalDataSourceTest.java

示例2: activateTask_retrievedTaskIsActive

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void activateTask_retrievedTaskIsActive() {
    // Given a new completed task in the persistent repository
    final Task newTask = new Task(TITLE, "");
    mLocalDataSource.saveTask(newTask);
    mLocalDataSource.completeTask(newTask);

    // When activated in the persistent repository
    mLocalDataSource.activateTask(newTask);

    // Then the task can be retrieved from the persistent repository and is active
    TestSubscriber<Optional<Task>> testSubscriber = new TestSubscriber<>();
    mLocalDataSource.getTask(newTask.getId()).subscribe(testSubscriber);
    testSubscriber.assertValueCount(1);
    Task result = testSubscriber.values().get(0).get();
    assertThat(result.isActive(), is(true));
    assertThat(result.isCompleted(), is(false));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:TasksLocalDataSourceTest.java

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

示例4: testWeakTransform

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

    SimpleFlowableList<Integer> list = new SimpleFlowableList<>(Arrays.asList(1, 2, 3));
    FlowableList<Integer> transformedList = list.cachedMap(new Function<Integer, Integer>() {
        @Override
        public Integer apply(Integer integer) {
            return integer + 12;
        }
    });

    transformedList.updates().subscribe(testSubscriber);

    testSubscriber.assertValueCount(1);

    List<Update<Integer>> onNextEvents = testSubscriber.values();

    assertEquals(Arrays.asList(Change.reloaded()), onNextEvents.get(0).changes);
    assertEquals(Arrays.asList(13, 14, 15), onNextEvents.get(0).list);
}
 
開發者ID:mproberts,項目名稱:rxtools,代碼行數:23,代碼來源:TransformFlowableListTest.java

示例5: testUpdatesChecked

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testUpdatesChecked() throws Exception {
    RxPaperBook book = RxPaperBook.with("UPDATES_CH", Schedulers.trampoline());
    final String key = "hello";
    final ComplexObject value = ComplexObject.random();
    final TestSubscriber<ComplexObject> updatesSubscriber = TestSubscriber.create();
    book.observe(key, ComplexObject.class, BackpressureStrategy.MISSING).subscribe(updatesSubscriber);
    updatesSubscriber.assertValueCount(0);
    book.write(key, value).subscribe();
    updatesSubscriber.assertValueCount(1);
    updatesSubscriber.assertValues(value);
    final ComplexObject newValue = ComplexObject.random();
    book.write(key, newValue).subscribe();
    updatesSubscriber.assertValueCount(2);
    updatesSubscriber.assertValues(value, newValue);
    // Error value
    final int wrongValue = 3;
    book.write(key, wrongValue).test().assertComplete().assertNoErrors();
    updatesSubscriber.assertValueCount(2);
    updatesSubscriber.assertValues(value, newValue);
    updatesSubscriber.assertNoErrors();
}
 
開發者ID:pakoito,項目名稱:RxPaper2,代碼行數:23,代碼來源:RxPaperBookTest.java

示例6: test_just_Flowable

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void test_just_Flowable() {

	Flowable<String> observable = Flowable.just("mango", "papaya", "guava");
	TestSubscriber<String> testSubscriber = new TestSubscriber<>();

	observable.subscribe(testSubscriber);

	List<String> items = testSubscriber.values();
	testSubscriber.assertComplete();
	testSubscriber.assertSubscribed();
	testSubscriber.assertNoErrors();
	testSubscriber.assertValueCount(3);
	testSubscriber.assertValues("mango", "papaya", "guava");

}
 
開發者ID:PacktPublishing,項目名稱:Reactive-Programming-With-Java-9,代碼行數:17,代碼來源:Modern_Testing.java

示例7: testSingleList

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testSingleList()
{
    List<FlowableList<Integer>> flowableLists = Arrays.asList(FlowableList.of(1, 2, 3));
    FlowableList<?> list = FlowableList.concat(flowableLists);
    TestSubscriber testSubscriber = new TestSubscriber();

    list.updates().subscribe(testSubscriber);

    testSubscriber.assertValueCount(1);

    List<Update> onNextEvents = testSubscriber.values();

    Update update = onNextEvents.get(0);

    assertEquals(Change.reloaded(), update.changes.get(0));
    assertEquals(Arrays.asList(1, 2, 3), update.list);
}
 
開發者ID:mproberts,項目名稱:rxtools,代碼行數:19,代碼來源:ConcatFlowableListTest.java

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

示例9: testItemRemoval

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testItemRemoval()
{
    VisibleItem<Integer> item1 = new VisibleItem<>(1, true);
    VisibleItem<Integer> item2 = new VisibleItem<>(2, true);
    VisibleItem<Integer> item3 = new VisibleItem<>(3, true);

    SimpleFlowableList<VisibleItem<Integer>> simpleList = new SimpleFlowableList<>();
    FlowableList<Integer> list = FlowableList.collapseVisibility(simpleList);
    TestSubscriber testSubscriber = new TestSubscriber();

    simpleList.add(item1);
    simpleList.add(item2);
    simpleList.add(item3);

    list.updates().subscribe(testSubscriber);

    simpleList.remove(1);

    List<Update> onNextEvents = testSubscriber.values();
    testSubscriber.assertValueCount(2);

    Update update1 = onNextEvents.get(0);
    Update update2 = onNextEvents.get(1);

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

    assertEquals(Arrays.asList(Change.removed(1)), update2.changes);
    assertEquals(Arrays.asList(1, 3), update2.list);
}
 
開發者ID:mproberts,項目名稱:rxtools,代碼行數:32,代碼來源:VisibilityStateFlowableListTest.java

示例10: testBasicVisibility

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testBasicVisibility()
{
    VisibleItem<Integer> item1 = new VisibleItem<>(1, true);
    VisibleItem<Integer> item2 = new VisibleItem<>(2, true);
    VisibleItem<Integer> item3 = new VisibleItem<>(3, true);
    VisibleItem<Integer> item4 = new VisibleItem<>(4, true);

    SimpleFlowableList<VisibleItem<Integer>> simpleList = new SimpleFlowableList<>();
    FlowableList<Integer> list = FlowableList.collapseVisibility(simpleList);
    TestSubscriber testSubscriber = new TestSubscriber();

    simpleList.add(item1);
    simpleList.add(item2);
    simpleList.add(item3);
    simpleList.add(item4);

    list.updates().subscribe(testSubscriber);

    List<Update> onNextEvents = testSubscriber.values();
    testSubscriber.assertValueCount(1);

    Update update = onNextEvents.get(0);

    assertEquals(Arrays.asList(Change.reloaded()), update.changes);
    assertEquals(Arrays.asList(1, 2, 3, 4), update.list);
}
 
開發者ID:mproberts,項目名稱:rxtools,代碼行數:28,代碼來源:VisibilityStateFlowableListTest.java

示例11: testAddTransform

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testAddTransform()
{
    SimpleFlowableList<Integer> list = new SimpleFlowableList<>(Arrays.asList(1, 2, 3));

    TestSubscriber<Update<Flowable<String>>> testSubscriber = createIndexedList(list);

    testSubscriber.assertValueCount(1);

    List<Update<Flowable<String>>> onNextEvents = testSubscriber.values();

    assertEquals(Arrays.asList(Change.reloaded()), onNextEvents.get(0).changes);

    List<Flowable<String>> list1 = onNextEvents.get(0).list;

    Flowable<String> item1 = list1.get(0);
    Flowable<String> item2 = list1.get(1);
    Flowable<String> item3 = list1.get(2);

    TestSubscriber<String> test1 = item1.test();
    TestSubscriber<String> test2 = item2.test();
    TestSubscriber<String> test3 = item3.test();

    test1.assertValue("? < 1 > 2");
    test2.assertValue("1 < 2 > 3");
    test3.assertValue("2 < 3 > ?");

    list.add(1, 4);

    test1.assertValues("? < 1 > 2", "? < 1 > 4");
    test2.assertValues("1 < 2 > 3", "4 < 2 > 3");
    test3.assertValueCount(1);

    list.add(5);

    test1.assertValues("? < 1 > 2", "? < 1 > 4");
    test2.assertValues("1 < 2 > 3", "4 < 2 > 3");
    test3.assertValues("2 < 3 > ?", "2 < 3 > 5");
}
 
開發者ID:mproberts,項目名稱:rxtools,代碼行數:40,代碼來源:IndexedFlowableListTest.java

示例12: testRemoveTransform

import io.reactivex.subscribers.TestSubscriber; //導入方法依賴的package包/類
@Test
public void testRemoveTransform()
{
    SimpleFlowableList<Integer> list = new SimpleFlowableList<>(Arrays.asList(1, 2, 3, 4));

    TestSubscriber<Update<Flowable<String>>> testSubscriber = createIndexedList(list);

    testSubscriber.assertValueCount(1);

    List<Update<Flowable<String>>> onNextEvents = testSubscriber.values();

    assertEquals(Arrays.asList(Change.reloaded()), onNextEvents.get(0).changes);

    List<Flowable<String>> list1 = onNextEvents.get(0).list;

    Flowable<String> item1 = list1.get(0);
    Flowable<String> item2 = list1.get(1);
    Flowable<String> item3 = list1.get(2);
    Flowable<String> item4 = list1.get(3);

    TestSubscriber<String> test1 = item1.test();
    TestSubscriber<String> test2 = item2.test();
    TestSubscriber<String> test3 = item3.test();
    TestSubscriber<String> test4 = item4.test();

    test1.assertValue("? < 1 > 2");
    test2.assertValue("1 < 2 > 3");
    test3.assertValue("2 < 3 > 4");
    test4.assertValue("3 < 4 > ?");

    list.remove(3);

    test3.assertValues("2 < 3 > 4", "2 < 3 > ?");

    list.remove(1);

    test1.assertValues("? < 1 > 2", "? < 1 > 3");
    test3.assertValues("2 < 3 > 4", "2 < 3 > ?", "1 < 3 > ?");
}
 
開發者ID:mproberts,項目名稱:rxtools,代碼行數:40,代碼來源:IndexedFlowableListTest.java

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

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

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


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