本文整理汇总了Java中io.reactivex.Flowable.test方法的典型用法代码示例。如果您正苦于以下问题:Java Flowable.test方法的具体用法?Java Flowable.test怎么用?Java Flowable.test使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.Flowable
的用法示例。
在下文中一共展示了Flowable.test方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: manyToMany
import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void manyToMany() {
RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);
Flowable<HelloResponse> resp = stub.sayHelloBothStream(Flowable.just(HelloRequest.getDefaultInstance()));
TestSubscriber<HelloResponse> test = resp.test();
test.awaitTerminalEvent(3, TimeUnit.SECONDS);
test.assertError(t -> t instanceof StatusRuntimeException);
test.assertError(t -> ((StatusRuntimeException)t).getStatus() == Status.INTERNAL);
}
示例2: manyToMany
import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void manyToMany() {
RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);
Flowable<HelloRequest> req = Flowable.just(HelloRequest.getDefaultInstance());
Flowable<HelloResponse> resp = stub.sayHelloBothStream(req);
TestSubscriber<HelloResponse> test = resp.test();
test.awaitTerminalEvent(3, TimeUnit.SECONDS);
test.assertError(t -> t instanceof StatusRuntimeException);
test.assertError(t -> ((StatusRuntimeException)t).getStatus().getCode() == Status.Code.CANCELLED);
}
示例3: oneToMany
import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void oneToMany() {
RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);
Single<String> rxRequest = Single.just("World");
Flowable<String> rxResponse = stub.sayHelloRespStream(rxRequest.map(this::toRequest)).map(this::fromResponse);
TestSubscriber<String> test = rxResponse.test();
test.awaitTerminalEvent(1, TimeUnit.SECONDS);
test.assertNoErrors();
test.assertValues("Hello World", "Hi World", "Greetings World");
}
示例4: manyToMany
import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void manyToMany() {
RxGreeterGrpc.RxGreeterStub stub = RxGreeterGrpc.newRxStub(channel);
Flowable<String> rxRequest = Flowable.just("A", "B", "C", "D");
Flowable<String> rxResponse = stub.sayHelloBothStream(rxRequest.map(this::toRequest)).map(this::fromResponse);
TestSubscriber<String> test = rxResponse.test();
test.awaitTerminalEvent(1, TimeUnit.SECONDS);
test.assertNoErrors();
test.assertValues("Hello A and B", "Hello C and D");
}
示例5: shouldObserveOnThreadPool
import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test(timeout = 500)
public void shouldObserveOnThreadPool() {
Flowable<Long> source = Flowable.just(1L, 2L, 3L, 4L)
.share()
.onBackpressureLatest();
StreamId<Long> streamId = provide(source).withUniqueStreamId();
Flowable<Long> stream = rxFrom(streamId);
stream.subscribe(i -> SECONDS.sleep(10));
TestSubscriber<Long> test = stream.test();
test.awaitCount(4);
assertThat(test.values()).containsOnly(1L, 2L, 3L, 4L);
}
示例6: testAddTransform
import io.reactivex.Flowable; //导入方法依赖的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");
}
示例7: testRemoveTransform
import io.reactivex.Flowable; //导入方法依赖的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 > ?");
}
示例8: testBufferWithInterval
import io.reactivex.Flowable; //导入方法依赖的package包/类
/**
* This test ensures that the first element of the source stream is not ignored, and that the correct amount of
* values are buffered.
*/
@Test
public void testBufferWithInterval() {
TestScheduler testScheduler = new TestScheduler();
Flowable<Long> source = Flowable.interval(0, 2, SECONDS, testScheduler);
Flowable<Long> start = Flowable.interval(0, 20, SECONDS, testScheduler);
Flowable<Long> end = start.delay(11, SECONDS, testScheduler);
DiscoveryService discoveryService = Mockito.mock(DiscoveryService.class);
StreamId<Long> sourceId = Mockito.mock(StreamId.class);
StreamId<Long> startStreamId = Mockito.mock(StreamId.class);
StreamId<Long> endStreamId = Mockito.mock(StreamId.class);
EndStreamMatcher<?, ?> endStreamMatcher = EndStreamMatcher.endingOnEvery(endStreamId);
BufferSpecification bufferSpecification = ofStartEnd(startStreamId, singleton(endStreamMatcher));
OverlapBufferStreamId<?> streamId = OverlapBufferStreamId.of(sourceId, bufferSpecification);
when(discoveryService.discover(sourceId)).thenReturn(source);
when(discoveryService.discover(startStreamId)).thenReturn(start);
when(discoveryService.discover(endStreamId)).thenReturn(end);
Flowable<Object> data = fromPublisher(overlapBufferStreamFactory.create(streamId, discoveryService).data());
TestSubscriber<Object> testSubscriber = data.test();
List<Long> firstExpectedResult = Arrays.asList(0L, 1L, 2L, 3L, 4L, 5L);
List<Long> secondExpectedResult = Arrays.asList(10L, 11L, 12L, 13L, 14L, 15L);
List<Long> thirdExpectedResult = Arrays.asList(20L, 21L, 22L, 23L, 24L, 25L);
testScheduler.advanceTimeBy(11, SECONDS);
testSubscriber.assertValueCount(1);
testSubscriber.assertValueAt(0, firstExpectedResult::equals);
testScheduler.advanceTimeBy(21, SECONDS);
testSubscriber.assertValueCount(2);
testSubscriber.assertValueAt(1, secondExpectedResult::equals);
testScheduler.advanceTimeBy(10, SECONDS);
testSubscriber.assertValueCount(2);
testScheduler.advanceTimeBy(11, SECONDS);
testSubscriber.assertValueCount(3);
testSubscriber.assertValueAt(2, thirdExpectedResult::equals);
}
示例9: testMoveTransform
import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void testMoveTransform()
{
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.move(3, 1);
test1.assertValues("? < 1 > 2", "? < 1 > 4");
test2.assertValues("1 < 2 > 3", "4 < 2 > 3");
test3.assertValues("2 < 3 > 4", "2 < 3 > ?");
list.move(1, 3);
test1.assertValues("? < 1 > 2", "? < 1 > 4", "? < 1 > 2");
test2.assertValues("1 < 2 > 3", "4 < 2 > 3", "1 < 2 > 3");
test3.assertValues("2 < 3 > 4", "2 < 3 > ?", "2 < 3 > 4");
}