1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.io.input;
18
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.nio.file.StandardOpenOption;
22
23 import org.junit.jupiter.api.BeforeEach;
24
25 /**
26 * Tests {@link ReadAheadInputStream}.
27 *
28 * This class was ported and adapted from Apache Spark commit 933dc6cb7b3de1d8ccaf73d124d6eb95b947ed19 where it was called {@code ReadAheadInputStreamSuite}.
29 */
30 public class ReadAheadInputStreamTest extends AbstractInputStreamTest {
31
32 @SuppressWarnings("resource")
33 @Override
34 @BeforeEach
35 public void setUp() throws IOException {
36 super.setUp();
37 inputStreams = new InputStream[] {
38 // Tests equal and aligned buffers of wrapped an outer stream.
39 new ReadAheadInputStream(new BufferedFileChannelInputStream(inputFile, 8 * 1024), 8 * 1024),
40 // Tests aligned buffers, wrapped bigger than outer.
41 new ReadAheadInputStream(new BufferedFileChannelInputStream(inputFile, 3 * 1024), 2 * 1024),
42 // Tests aligned buffers, wrapped smaller than outer.
43 new ReadAheadInputStream(new BufferedFileChannelInputStream(inputFile, 2 * 1024), 3 * 1024),
44 // Tests unaligned buffers, wrapped bigger than outer.
45 new ReadAheadInputStream(new BufferedFileChannelInputStream(inputFile, 321), 123),
46 // Tests unaligned buffers, wrapped smaller than outer.
47 new ReadAheadInputStream(new BufferedFileChannelInputStream(inputFile, 123), 321),
48 //
49 // Tests equal and aligned buffers of wrapped an outer stream.
50 ReadAheadInputStream.builder().setInputStream(new BufferedFileChannelInputStream(inputFile, 8 * 1024)).setBufferSize(8 * 1024).get(),
51 // Tests aligned buffers, wrapped bigger than outer.
52 ReadAheadInputStream.builder().setInputStream(new BufferedFileChannelInputStream(inputFile, 3 * 1024)).setBufferSize(2 * 1024).get(),
53 // Tests aligned buffers, wrapped smaller than outer.
54 ReadAheadInputStream.builder().setInputStream(new BufferedFileChannelInputStream(inputFile, 2 * 1024)).setBufferSize(3 * 1024).get(),
55 // Tests unaligned buffers, wrapped bigger than outer.
56 ReadAheadInputStream.builder().setInputStream(new BufferedFileChannelInputStream(inputFile, 321)).setBufferSize(123).get(),
57 // Tests unaligned buffers, wrapped smaller than outer.
58 ReadAheadInputStream.builder().setInputStream(new BufferedFileChannelInputStream(inputFile, 123)).setBufferSize(321).get(),
59 ReadAheadInputStream.builder().setPath(inputFile).setOpenOptions(StandardOpenOption.READ).get() };
60 }
61 }