@Test @Category(UnitTest.class) public void testWriteSplits() throws Exception { subject = new FileSplit(); long[] startIds = {1L, 10L, 20L}; long[] endIds = {5L, 14L, 23L}; String[] names = {"split1", "split2", "split3"}; subject.generateSplits(startIds, endIds, names); Path parent = new Path(FileSplitTest.class.getName() + "-testParent"); Path splitsFile = new Path(parent, "splits"); PipedOutputStream out = new PipedOutputStream(); PipedInputStream in = new PipedInputStream(out); FileSystem mockFS = new FileSystemBuilder() .outputStream(splitsFile, out) .build(); FileSplit spySubject = new FileSplit(); subject = spy(spySubject); doReturn(mockFS).when(subject).getFileSystem(any(Path.class)); subject.generateSplits(startIds, endIds, names); subject.writeSplits(parent); Scanner reader = new Scanner(in); Assert.assertEquals("v3", reader.nextLine()); Assert.assertEquals(startIds.length, Integer.parseInt(reader.nextLine())); for (int i = 0; i < startIds.length; ++i) { Assert.assertEquals(startIds[i], reader.nextLong()); Assert.assertEquals(endIds[i], reader.nextLong()); Assert.assertEquals(names[i], reader.next()); Assert.assertEquals(i, reader.nextInt()); } }
public void writeSplits(OutputStream stream) throws SplitException { if (splits == null) { throw new SplitException("Splits not generated, call readSplits() or generateSplits() first"); } PrintWriter writer = new PrintWriter(stream); writer.println(VERSION); writer.println(splits.length); for (SplitInfo split : splits) { writer.print(((FileSplitInfo) split).getStartId()); writer.print(SPACER); writer.print(((FileSplitInfo) split).getEndId()); writer.print(SPACER); writer.print(((FileSplitInfo) split).getName()); writer.print(SPACER); writer.println(split.getPartition()); } writer.close(); }
FileSplit extends Splits { public void writeSplits(OutputStream stream) throws SplitException { if (splits == null) { throw new SplitException("Splits not generated, call readSplits() or generateSplits() first"); } PrintWriter writer = new PrintWriter(stream); writer.println(VERSION); writer.println(splits.length); for (SplitInfo split : splits) { writer.print(((FileSplitInfo) split).getStartId()); writer.print(SPACER); writer.print(((FileSplitInfo) split).getEndId()); writer.print(SPACER); writer.print(((FileSplitInfo) split).getName()); writer.print(SPACER); writer.println(split.getPartition()); } writer.close(); } }
FileSplit extends Splits { public void writeSplits(OutputStream stream) throws SplitException { if (splits == null) { throw new SplitException("Splits not generated, call readSplits() or generateSplits() first"); } PrintWriter writer = new PrintWriter(stream); writer.println(VERSION); writer.println(splits.length); for (SplitInfo split : splits) { writer.print(((FileSplitInfo) split).getStartId()); writer.print(SPACER); writer.print(((FileSplitInfo) split).getEndId()); writer.print(SPACER); writer.print(((FileSplitInfo) split).getName()); writer.print(SPACER); writer.println(split.getPartition()); } writer.close(); }  }
FileSplit extends Splits { public void writeSplits(OutputStream stream) throws SplitException { if (splits == null) { throw new SplitException("Splits not generated, call readSplits() or generateSplits() first"); } PrintWriter writer = new PrintWriter(stream); writer.println(VERSION); writer.println(splits.length); for (SplitInfo split : splits) { writer.print(((FileSplitInfo) split).getStartId()); writer.print(SPACER); writer.print(((FileSplitInfo) split).getEndId()); writer.print(SPACER); writer.print(((FileSplitInfo) split).getName()); writer.print(SPACER); writer.println(split.getPartition()); } writer.close(); }  void generateSplits(FileSplitInfo[] splits); void generateSplits(long[] startIds, long[] endIds, String[] names); void generateSplits(Path parent, Configuration conf); @Override String findSplitFile(Path parent); @Override void generateSplits(SplitGenerator generator); void readSplits(InputStream stream); @SuppressWarnings("squid:S1166") // Exception caught and handled boolean isVersion2(Path splitsfile); void readSplits(Path parent); void writeSplits(OutputStream stream); void writeSplits(Path parent); @Override void readExternal(ObjectInput in); }
FileSplit extends Splits { public void writeSplits(OutputStream stream) throws SplitException { if (splits == null) { throw new SplitException("Splits not generated, call readSplits() or generateSplits() first"); } PrintWriter writer = new PrintWriter(stream); writer.println(VERSION); writer.println(splits.length); for (SplitInfo split : splits) { writer.print(((FileSplitInfo) split).getStartId()); writer.print(SPACER); writer.print(((FileSplitInfo) split).getEndId()); writer.print(SPACER); writer.print(((FileSplitInfo) split).getName()); writer.print(SPACER); writer.println(split.getPartition()); } writer.close(); }  void generateSplits(FileSplitInfo[] splits); void generateSplits(long[] startIds, long[] endIds, String[] names); void generateSplits(Path parent, Configuration conf); @Override String findSplitFile(Path parent); @Override void generateSplits(SplitGenerator generator); void readSplits(InputStream stream); @SuppressWarnings("squid:S1166") // Exception caught and handled boolean isVersion2(Path splitsfile); void readSplits(Path parent); void writeSplits(OutputStream stream); void writeSplits(Path parent); @Override void readExternal(ObjectInput in); static final String SPLIT_FILE; static final String OLD_SPLIT_FILE; }