Sha256: faf96272bca6d0582c4cdb829e809a83d6336b80d0ce60861423fcd059744996
Contents?: true
Size: 1.95 KB
Versions: 7
Compression:
Stored size: 1.95 KB
Contents
package org.embulk.spi; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import java.io.ByteArrayOutputStream; import java.util.Random; import org.junit.Rule; import org.junit.Test; import org.embulk.spi.util.ListFileInput; import org.embulk.spi.util.FileInputInputStream; import org.embulk.spi.util.FileOutputOutputStream; import org.embulk.EmbulkTestRuntime; public class TestFileInputInputStream { @Rule public EmbulkTestRuntime runtime = new EmbulkTestRuntime(); private ListFileInput fileInput; private MockFileOutput fileOutput; private FileInputInputStream in; private FileOutputOutputStream out; private void newOutputStream() { fileOutput = new MockFileOutput(); out = new FileOutputOutputStream(fileOutput, runtime.getBufferAllocator(), FileOutputOutputStream.CloseMode.CLOSE); } private void newInputStream() { fileInput = new ListFileInput(fileOutput.getFiles()); in = new FileInputInputStream(fileInput); } @Test public void testRandomReadWrite() throws Exception { newOutputStream(); out.nextFile(); ByteArrayOutputStream expectedOut = new ByteArrayOutputStream(); Random rand = runtime.getRandom(); byte[] buffer = new byte[rand.nextInt() % 1024 + 1024]; for (int i = 0; i < 256; i++) { rand.nextBytes(buffer); expectedOut.write(buffer); out.write(buffer); } out.finish(); byte[] expected = expectedOut.toByteArray(); byte[] actual = new byte[expected.length]; newInputStream(); in.nextFile(); int pos = 0; while (pos < actual.length) { int n = in.read(actual, pos, actual.length - pos); if (n < 0) { break; } pos += n; } assertEquals(expected.length, pos); assertArrayEquals(expected, actual); } }
Version data entries
7 entries across 7 versions & 1 rubygems