forked from ReactiveX/RxJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseTck.java
More file actions
145 lines (121 loc) · 3.96 KB
/
BaseTck.java
File metadata and controls
145 lines (121 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Copyright (c) 2016-present, RxJava Contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
* the License for the specific language governing permissions and limitations under the License.
*/
package io.reactivex.rxjava3.tck;
import java.util.*;
import org.reactivestreams.Publisher;
import org.reactivestreams.tck.*;
import org.testng.annotations.Test;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.exceptions.TestException;
/**
* Base abstract class for Flowable verifications, contains support for creating
* Iterable range of values.
*
* @param <T> the element type
*/
@Test
public abstract class BaseTck<T> extends PublisherVerification<T> {
public BaseTck() {
this(25L);
}
public BaseTck(long timeout) {
super(new TestEnvironment(timeout));
}
@Override
public Publisher<T> createFailedPublisher() {
return Flowable.error(new TestException());
}
@Override
public long maxElementsFromPublisher() {
return 1024;
}
/**
* Creates an Iterable with the specified number of elements or an infinite one if
* {@code elements >} {@link Integer#MAX_VALUE}.
* @param elements the number of elements to return, {@link Integer#MAX_VALUE} means an infinite sequence
* @return the Iterable
*/
protected Iterable<Long> iterate(long elements) {
return iterate(elements > Integer.MAX_VALUE, elements);
}
protected Iterable<Long> iterate(boolean useInfinite, long elements) {
return useInfinite ? new InfiniteRange() : new FiniteRange(elements);
}
/**
* Create an array of Long values, ranging from 0L to elements - 1L.
* @param elements the number of elements to return
* @return the array
*/
protected Long[] array(long elements) {
Long[] a = new Long[(int)elements];
for (int i = 0; i < elements; i++) {
a[i] = (long)i;
}
return a;
}
static final class FiniteRange implements Iterable<Long> {
final long end;
FiniteRange(long end) {
this.end = end;
}
@Override
public Iterator<Long> iterator() {
return new FiniteRangeIterator(end);
}
static final class FiniteRangeIterator implements Iterator<Long> {
final long end;
long count;
FiniteRangeIterator(long end) {
this.end = end;
}
@Override
public boolean hasNext() {
return count != end;
}
@Override
public Long next() {
long c = count;
if (c != end) {
count = c + 1;
return c;
}
throw new NoSuchElementException();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}
}
static final class InfiniteRange implements Iterable<Long> {
@Override
public Iterator<Long> iterator() {
return new InfiniteRangeIterator();
}
static final class InfiniteRangeIterator implements Iterator<Long> {
long count;
@Override
public boolean hasNext() {
return true;
}
@Override
public Long next() {
return count++;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
}
}
}