192 for (int limit : limits) {
193 Collection<Integer> sr = exerciseOpsInt(data,
194 st -> st.limit(limit),
195 st -> st.limit(limit),
196 st -> st.limit(limit),
197 st -> st.limit(limit));
198 assertEquals(sr.size(), sliceSize(data.size(), 0, limit));
199
200 sr = exerciseOpsInt(data,
201 st -> st.limit(limit).limit(limit / 2),
202 st -> st.limit(limit).limit(limit / 2),
203 st -> st.limit(limit).limit(limit / 2),
204 st -> st.limit(limit).limit(limit / 2));
205 assertEquals(sr.size(), sliceSize(sliceSize(data.size(), 0, limit), 0, limit/2));
206 }
207 }
208
209 public void testLimitSort() {
210 List<Integer> l = countTo(100);
211 Collections.reverse(l);
212 exerciseOps(l, s -> s.limit(10).sorted(Comparators.naturalOrder()));
213 }
214
215 @Test(groups = { "serialization-hostile" })
216 public void testLimitShortCircuit() {
217 for (int l : Arrays.asList(0, 10)) {
218 AtomicInteger ai = new AtomicInteger();
219 countTo(100).stream()
220 .peek(i -> ai.getAndIncrement())
221 .limit(l).toArray();
222 // For the case of a zero limit, one element will get pushed through the sink chain
223 assertEquals(ai.get(), l, "tee block was called too many times");
224 }
225 }
226
227 public void testSkipParallel() {
228 List<Integer> l = countTo(1000).parallelStream().substream(200).limit(200).sequential().collect(Collectors.toList());
229 assertEquals(l.size(), 200);
230 assertEquals(l.get(l.size() -1).intValue(), 400);
231 }
232
|
192 for (int limit : limits) {
193 Collection<Integer> sr = exerciseOpsInt(data,
194 st -> st.limit(limit),
195 st -> st.limit(limit),
196 st -> st.limit(limit),
197 st -> st.limit(limit));
198 assertEquals(sr.size(), sliceSize(data.size(), 0, limit));
199
200 sr = exerciseOpsInt(data,
201 st -> st.limit(limit).limit(limit / 2),
202 st -> st.limit(limit).limit(limit / 2),
203 st -> st.limit(limit).limit(limit / 2),
204 st -> st.limit(limit).limit(limit / 2));
205 assertEquals(sr.size(), sliceSize(sliceSize(data.size(), 0, limit), 0, limit/2));
206 }
207 }
208
209 public void testLimitSort() {
210 List<Integer> l = countTo(100);
211 Collections.reverse(l);
212 exerciseOps(l, s -> s.limit(10).sorted(Comparator.naturalOrder()));
213 }
214
215 @Test(groups = { "serialization-hostile" })
216 public void testLimitShortCircuit() {
217 for (int l : Arrays.asList(0, 10)) {
218 AtomicInteger ai = new AtomicInteger();
219 countTo(100).stream()
220 .peek(i -> ai.getAndIncrement())
221 .limit(l).toArray();
222 // For the case of a zero limit, one element will get pushed through the sink chain
223 assertEquals(ai.get(), l, "tee block was called too many times");
224 }
225 }
226
227 public void testSkipParallel() {
228 List<Integer> l = countTo(1000).parallelStream().substream(200).limit(200).sequential().collect(Collectors.toList());
229 assertEquals(l.size(), 200);
230 assertEquals(l.get(l.size() -1).intValue(), 400);
231 }
232
|