8148838: Stream.flatMap(...).spliterator() cannot properly split after tryAdvance()

Reviewed-by: psandoz
This commit is contained in:
Tagir F. Valeev 2016-02-08 15:33:53 +01:00
parent e41fea88e7
commit 0e250ec504
2 changed files with 25 additions and 19 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -186,7 +186,7 @@ class StreamSpliterators {
@Override
public Spliterator<P_OUT> trySplit() {
if (isParallel && !finished) {
if (isParallel && buffer == null && !finished) {
init();
Spliterator<P_IN> split = spliterator.trySplit();

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -20,6 +20,12 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 8148838
*/
package org.openjdk.tests.java.util.stream;
import java.util.Arrays;
@ -282,7 +288,7 @@ public class StreamSpliteratorTest extends OpTestCase {
}
}
@Test(dataProvider = "StreamTestData<Integer>",
@Test(dataProvider = "StreamTestData<Integer>.small",
dataProviderClass = StreamTestDataProvider.class,
groups = { "serialization-hostile" })
public void testStreamSpliterators(String name, TestData.OfRef<Integer> data) {
@ -303,14 +309,14 @@ public class StreamSpliteratorTest extends OpTestCase {
}
}
@Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
@Test(dataProvider = "StreamTestData<Integer>.small", dataProviderClass = StreamTestDataProvider.class)
public void testSpliterators(String name, TestData.OfRef<Integer> data) {
for (Function<Stream<Integer>, Stream<Integer>> f : streamFunctions()) {
SpliteratorTestHelper.testSpliterator(() -> f.apply(data.stream()).spliterator());
}
}
@Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
@Test(dataProvider = "StreamTestData<Integer>.small", dataProviderClass = StreamTestDataProvider.class)
public void testParSpliterators(String name, TestData.OfRef<Integer> data) {
for (Function<Stream<Integer>, Stream<Integer>> f : streamFunctions()) {
SpliteratorTestHelper.testSpliterator(() -> f.apply(data.parallelStream()).spliterator());
@ -323,7 +329,7 @@ public class StreamSpliteratorTest extends OpTestCase {
if (streamFunctions == null) {
List<Function<Stream<Integer>, Stream<Integer>>> opFunctions = Arrays.asList(
s -> s.filter(pEven),
s -> s.map(mDoubler),
s -> s.flatMap(x -> Stream.of(x, x)),
// @@@ Add distinct once asserting results with or without order
// is correctly supported
// s -> s.distinct(),
@ -378,7 +384,7 @@ public class StreamSpliteratorTest extends OpTestCase {
}
}
@Test(dataProvider = "IntStreamTestData",
@Test(dataProvider = "IntStreamTestData.small",
dataProviderClass = IntStreamTestDataProvider.class,
groups = { "serialization-hostile" })
public void testIntStreamSpliterators(String name, TestData.OfInt data) {
@ -399,14 +405,14 @@ public class StreamSpliteratorTest extends OpTestCase {
}
}
@Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class)
@Test(dataProvider = "IntStreamTestData.small", dataProviderClass = IntStreamTestDataProvider.class)
public void testIntSpliterators(String name, TestData.OfInt data) {
for (Function<IntStream, IntStream> f : intStreamFunctions()) {
SpliteratorTestHelper.testIntSpliterator(() -> f.apply(data.stream()).spliterator());
}
}
@Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class)
@Test(dataProvider = "IntStreamTestData.small", dataProviderClass = IntStreamTestDataProvider.class)
public void testIntParSpliterators(String name, TestData.OfInt data) {
for (Function<IntStream, IntStream> f : intStreamFunctions()) {
SpliteratorTestHelper.testIntSpliterator(() -> f.apply(data.parallelStream()).spliterator());
@ -419,7 +425,7 @@ public class StreamSpliteratorTest extends OpTestCase {
if (intStreamFunctions == null) {
List<Function<IntStream, IntStream>> opFunctions = Arrays.asList(
s -> s.filter(ipEven),
s -> s.map(irDoubler),
s -> s.flatMap(x -> IntStream.of(x, x)),
s -> s.sorted());
intStreamFunctions = permuteStreamFunctions(opFunctions);
@ -471,7 +477,7 @@ public class StreamSpliteratorTest extends OpTestCase {
}
}
@Test(dataProvider = "LongStreamTestData",
@Test(dataProvider = "LongStreamTestData.small",
dataProviderClass = LongStreamTestDataProvider.class,
groups = { "serialization-hostile" })
public void testLongStreamSpliterators(String name, TestData.OfLong data) {
@ -492,14 +498,14 @@ public class StreamSpliteratorTest extends OpTestCase {
}
}
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class)
@Test(dataProvider = "LongStreamTestData.small", dataProviderClass = LongStreamTestDataProvider.class)
public void testLongSpliterators(String name, TestData.OfLong data) {
for (Function<LongStream, LongStream> f : longStreamFunctions()) {
SpliteratorTestHelper.testLongSpliterator(() -> f.apply(data.stream()).spliterator());
}
}
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class)
@Test(dataProvider = "LongStreamTestData.small", dataProviderClass = LongStreamTestDataProvider.class)
public void testLongParSpliterators(String name, TestData.OfLong data) {
for (Function<LongStream, LongStream> f : longStreamFunctions()) {
SpliteratorTestHelper.testLongSpliterator(() -> f.apply(data.parallelStream()).spliterator());
@ -512,7 +518,7 @@ public class StreamSpliteratorTest extends OpTestCase {
if (longStreamFunctions == null) {
List<Function<LongStream, LongStream>> opFunctions = Arrays.asList(
s -> s.filter(lpEven),
s -> s.map(x -> x * 2L),
s -> s.flatMap(x -> LongStream.of(x, x)),
s -> s.sorted());
longStreamFunctions = permuteStreamFunctions(opFunctions);
@ -564,7 +570,7 @@ public class StreamSpliteratorTest extends OpTestCase {
}
}
@Test(dataProvider = "DoubleStreamTestData",
@Test(dataProvider = "DoubleStreamTestData.small",
dataProviderClass = DoubleStreamTestDataProvider.class,
groups = { "serialization-hostile" })
public void testDoubleStreamSpliterators(String name, TestData.OfDouble data) {
@ -585,14 +591,14 @@ public class StreamSpliteratorTest extends OpTestCase {
}
}
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
@Test(dataProvider = "DoubleStreamTestData.small", dataProviderClass = DoubleStreamTestDataProvider.class)
public void testDoubleSpliterators(String name, TestData.OfDouble data) {
for (Function<DoubleStream, DoubleStream> f : doubleStreamFunctions()) {
SpliteratorTestHelper.testDoubleSpliterator(() -> f.apply(data.stream()).spliterator());
}
}
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
@Test(dataProvider = "DoubleStreamTestData.small", dataProviderClass = DoubleStreamTestDataProvider.class)
public void testDoubleParSpliterators(String name, TestData.OfDouble data) {
for (Function<DoubleStream, DoubleStream> f : doubleStreamFunctions()) {
SpliteratorTestHelper.testDoubleSpliterator(() -> f.apply(data.parallelStream()).spliterator());
@ -605,7 +611,7 @@ public class StreamSpliteratorTest extends OpTestCase {
if (doubleStreamFunctions == null) {
List<Function<DoubleStream, DoubleStream>> opFunctions = Arrays.asList(
s -> s.filter(dpEven),
s -> s.map(x -> x * 2.0),
s -> s.flatMap(x -> DoubleStream.of(x, x)),
s -> s.sorted());
doubleStreamFunctions = permuteStreamFunctions(opFunctions);