Skip to content

Commit 9d77677

Browse files
Viktor KlangAlan Bateman
Viktor Klang
authored and
Alan Bateman
committed
8321124: java/util/stream/GatherersTest.java times out
Reviewed-by: alanb
1 parent 4c96aac commit 9d77677

9 files changed

+787
-370
lines changed

test/jdk/ProblemList.txt

-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,6 @@ com/sun/jdi/InvokeHangTest.java 8218463 linux-al
722722

723723
java/util/Locale/LocaleProvidersRun.java 8268379 macosx-x64
724724
sun/util/locale/provider/CalendarDataRegression.java 8268379 macosx-x64
725-
java/util/stream/GatherersTest.java 8321124 generic-all
726725

727726
############################################################################
728727

test/jdk/java/util/stream/GathererTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ public void testCompositionOfStatefulGatherers(Config config) {
349349
@ParameterizedTest
350350
@MethodSource("configurations")
351351
public void testMassivelyComposedGatherers(Config config) {
352-
final int ITERATIONS = 512; // Total number of compositions is 1 + (iterations*2)
352+
final int ITERATIONS = 256; // Total number of compositions is 1 + (iterations*2)
353353
Gatherer<Integer,?,Integer> g = addOne;
354354
for(int i = 0;i < ITERATIONS;++i) {
355355
g = g.andThen(timesTwo).andThen(addOne);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import java.util.List;
25+
import java.util.stream.Gatherers;
26+
import java.util.stream.Stream;
27+
28+
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.params.ParameterizedTest;
30+
import org.junit.jupiter.params.provider.MethodSource;
31+
import static org.junit.jupiter.api.Assertions.*;
32+
import static org.junit.jupiter.api.Assumptions.*;
33+
34+
/**
35+
* @test
36+
* @summary Tests the API and contract of Gatherers.fold
37+
* @enablePreview
38+
* @run junit GatherersFoldTest
39+
*/
40+
41+
public class GatherersFoldTest {
42+
43+
record Config(int streamSize, boolean parallel) {
44+
Stream<Integer> stream() {
45+
var stream = Stream.iterate(1, i -> i + 1).limit(streamSize);
46+
stream = parallel ? stream.parallel() : stream.sequential();
47+
return stream;
48+
}
49+
}
50+
51+
static final Stream<Integer> sizes(){
52+
return Stream.of(0,1,10,33,99,9999);
53+
}
54+
55+
static final Stream<Config> sequentialAndParallel(int size) {
56+
return Stream.of(false, true)
57+
.map(parallel ->
58+
new Config(size, parallel));
59+
}
60+
61+
static final Stream<Config> configurations() {
62+
return sizes().flatMap(i -> sequentialAndParallel(i));
63+
}
64+
65+
@Test
66+
public void throwsNPEWhenStateSupplierIsNull() {
67+
assertThrows(NullPointerException.class, () -> Gatherers.<String, String>fold(null, (state, next) -> state));
68+
}
69+
70+
@Test
71+
public void throwsNPEWhenFolderFunctionIsNull() {
72+
assertThrows(NullPointerException.class, () -> Gatherers.<String, String>fold(() -> "", null));
73+
}
74+
75+
@ParameterizedTest
76+
@MethodSource("configurations")
77+
public void behavesAsExpected(Config config) {
78+
final var expectedResult = List.of(
79+
config.stream()
80+
.sequential()
81+
.reduce(0L, (acc, next) -> acc + next,(l, r) -> {
82+
throw new IllegalStateException();
83+
})
84+
);
85+
86+
final var result = config.stream()
87+
.gather(Gatherers.fold(() -> 0L, (acc, next) -> acc + next))
88+
.toList();
89+
90+
assertEquals(expectedResult, result);
91+
}
92+
}

0 commit comments

Comments
 (0)