Debian Codegraph @

src/test/java/io/reactivex/rxjava3/tck/ReplayProcessorTimeBoundAsPublisherTckTest.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.tck;
15
16 import java.util.concurrent.TimeUnit;
17
18 import org.reactivestreams.Publisher;
19 import org.testng.annotations.Test;
20
21 import io.reactivex.rxjava3.processors.ReplayProcessor;
22 import io.reactivex.rxjava3.schedulers.Schedulers;
23
24 @Test
25 public class ReplayProcessorTimeBoundAsPublisherTckTest extends BaseTck<Integer> {
26
27 public ReplayProcessorTimeBoundAsPublisherTckTest() {
28 super(100);
29 }
30
31 @Override
32 public Publisher<Integer> createPublisher(final long elements) {
33 final ReplayProcessor<Integer> pp = ReplayProcessor.createWithTime(1, TimeUnit.MINUTES, Schedulers.computation());
34
35 Schedulers.io().scheduleDirect(new Runnable() {
36 @Override
37 public void run() {
38 long start = System.currentTimeMillis();
39 while (!pp.hasSubscribers()) {
40 try {
41 Thread.sleep(1);
42 } catch (InterruptedException ex) {
43 return;
44 }
45
46 if (System.currentTimeMillis() - start > 200) {
47 return;
48 }
49 }
50
51 for (int i = 0; i < elements; i++) {
52 pp.onNext(i);
53 }
54 pp.onComplete();
55 }
56 });
57 return pp;
58 }
59 }