Skip to content

Commit 2a9ac41

Browse files
committed
add test on LinkedIO without known size
1 parent 4548b53 commit 2a9ac41

File tree

3 files changed

+58
-7
lines changed

3 files changed

+58
-7
lines changed

net.lecousin.core/src/main/java/net/lecousin/framework/io/LinkedIO.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.io.IOException;
44
import java.nio.ByteBuffer;
55
import java.util.ArrayList;
6-
import java.util.Collection;
76

87
import net.lecousin.framework.concurrent.CancelException;
98
import net.lecousin.framework.concurrent.Task;
@@ -26,11 +25,6 @@
2625
*/
2726
public abstract class LinkedIO extends ConcurrentCloseable implements IO {
2827

29-
protected LinkedIO(String description, Collection<IO> ios) {
30-
this.description = description;
31-
this.ios = new ArrayList<>(ios);
32-
}
33-
3428
protected LinkedIO(String description, IO[] ios) {
3529
this.description = description;
3630
this.ios = new ArrayList<>(ios.length);

net.lecousin.core/src/main/java/net/lecousin/framework/io/SubIO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ public AsyncWork<Integer, IOException> writeAsync(ByteBuffer buffer, RunnableWit
563563
public byte getPriority() { return io != null ? io.getPriority() : Task.PRIORITY_NORMAL; }
564564

565565
@Override
566-
public void setPriority(byte priority) { io.setPriority(priority); }
566+
public void setPriority(byte priority) { if (io != null) io.setPriority(priority); }
567567

568568
@Override
569569
protected ISynchronizationPoint<?> closeUnderlyingResources() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package net.lecousin.framework.core.tests.io;
2+
3+
import java.io.IOException;
4+
import java.util.Collection;
5+
6+
import org.junit.runner.RunWith;
7+
import org.junit.runners.Parameterized;
8+
import org.junit.runners.Parameterized.Parameters;
9+
10+
import net.lecousin.framework.concurrent.Task;
11+
import net.lecousin.framework.core.test.io.TestFragmented;
12+
import net.lecousin.framework.core.test.io.TestFragmented.FragmentedFile;
13+
import net.lecousin.framework.core.test.io.TestReadableBuffered;
14+
import net.lecousin.framework.io.FileIO;
15+
import net.lecousin.framework.io.IO;
16+
import net.lecousin.framework.io.LinkedIO;
17+
import net.lecousin.framework.io.SubIO;
18+
import net.lecousin.framework.io.buffering.BufferedIO;
19+
import net.lecousin.framework.io.buffering.PreBufferedReadable;
20+
import net.lecousin.framework.math.RangeLong;
21+
22+
@RunWith(Parameterized.class)
23+
public class TestLinkedIOWithSubIOReadableBuffered2 extends TestReadableBuffered {
24+
25+
@Parameters
26+
public static Collection<Object[]> parameters() throws IOException {
27+
return TestFragmented.generateTestCases();
28+
}
29+
30+
public TestLinkedIOWithSubIOReadableBuffered2(FragmentedFile f) {
31+
super(f.file, f.testBuf, f.nbBuf);
32+
this.f = f;
33+
}
34+
35+
private FragmentedFile f;
36+
37+
38+
@SuppressWarnings("resource")
39+
@Override
40+
protected IO.Readable.Buffered createReadableBufferedFromFile(FileIO.ReadOnly file, long fileSize) throws Exception {
41+
BufferedIO bio = new BufferedIO(file, file.getSizeSync(), 4096, 4096, true);
42+
IO.Readable.Buffered[] ios = new IO.Readable.Buffered[f.fragments.size()];
43+
int i = 0;
44+
for (RangeLong fragment : f.fragments)
45+
ios[i++] =
46+
new PreBufferedReadable(
47+
new SubIO.Readable.Seekable(bio, fragment.min, fragment.getLength(), "fragment " + i, false),
48+
fragment.getLength(), 512, Task.PRIORITY_NORMAL, 4096, Task.PRIORITY_NORMAL, 5);
49+
return new LinkedIO.Readable.Buffered.DeterminedSize("linked IO", ios);
50+
}
51+
52+
@Override
53+
protected boolean canSetPriority() {
54+
return !f.fragments.isEmpty() && f.nbBuf > 0;
55+
}
56+
57+
}

0 commit comments

Comments
 (0)