Sha256: 3e0462ee6299de87496733dce44d823fa48876185a4bb3845ad6e499806cfab4
Contents?: true
Size: 1.91 KB
Versions: 10
Compression:
Stored size: 1.91 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()); } 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
10 entries across 10 versions & 1 rubygems