Debian Codegraph @

src/test/java/io/reactivex/rxjava3/internal/operators/flowable/FlowableDoOnRequestTest.java

raw
1 /*
2 * Copyright (c) 2016-present, RxJava Contributors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11 * the License for the specific language governing permissions and limitations under the License.
12 */
13
14 package io.reactivex.rxjava3.internal.operators.flowable;
15
16 import static org.junit.Assert.*;
17
18 import java.util.*;
19 import java.util.concurrent.atomic.AtomicBoolean;
20
21 import org.junit.Test;
22
23 import io.reactivex.rxjava3.core.*;
24 import io.reactivex.rxjava3.functions.*;
25 import io.reactivex.rxjava3.subscribers.DefaultSubscriber;
26
27 public class FlowableDoOnRequestTest extends RxJavaTest {
28
29 @Test
30 public void unsubscribeHappensAgainstParent() {
31 final AtomicBoolean unsubscribed = new AtomicBoolean(false);
32 Flowable.just(1).concatWith(Flowable.<Integer>never())
33 //
34 .doOnCancel(new Action() {
35 @Override
36 public void run() {
37 unsubscribed.set(true);
38 }
39 })
40 //
41 .doOnRequest(new LongConsumer() {
42 @Override
43 public void accept(long n) {
44 // do nothing
45 }
46 })
47 //
48 .subscribe().dispose();
49 assertTrue(unsubscribed.get());
50 }
51
52 @Test
53 public void doRequest() {
54 final List<Long> requests = new ArrayList<>();
55 Flowable.range(1, 5)
56 //
57 .doOnRequest(new LongConsumer() {
58 @Override
59 public void accept(long n) {
60 requests.add(n);
61 }
62 })
63 //
64 .subscribe(new DefaultSubscriber<Integer>() {
65
66 @Override
67 public void onStart() {
68 request(3);
69 }
70
71 @Override
72 public void onComplete() {
73
74 }
75
76 @Override
77 public void onError(Throwable e) {
78
79 }
80
81 @Override
82 public void onNext(Integer t) {
83 request(t);
84 }
85 });
86 assertEquals(Arrays.asList(3L, 1L, 2L, 3L, 4L, 5L), requests);
87 }
88 }