@Test public void testSortAlreadySortedLargeFiles() throws IOException { File inputFile = tempFolder.newFile(); List<ObjectEntry> sortedDataSet = IntStream.range(0, 1000) .mapToObj(i -> new ObjectEntry().setObjectId("obj" + i).setSize(i)) .sorted(Comparator.comparing(ObjectEntry::getObjectId)) .collect(Collectors.toList()); try (LargeFileWriter<ObjectEntry> writer = fileWriterFactory.apply(inputFile)) { for (ObjectEntry objectEntry : sortedDataSet) { writer.writeEntry(objectEntry); } } File sortedFile = instance.sortLargeFile(inputFile); try (LargeFileReader<ObjectEntry> reader = fileReaderFactory.apply(sortedFile)) { List<ObjectEntry> objectEntries = IteratorUtils.toList(reader); assertThat(JsonHandler.unprettyPrint(objectEntries)).isEqualTo(JsonHandler.unprettyPrint(sortedDataSet)); } assertThat(tmpFileCounter).isGreaterThan(100); ensureAllTempFileCleaned(inputFile, sortedFile); }
public File sortLargeFile(File inputFile) throws IOException { try (LargeFileReader<T> reader = this.fileReaderFactory.apply(inputFile)) { List<File> filesToMerge = splitIntoInitialSortedChunkFiles(reader); return mergeSortFiles(filesToMerge); } }
LargeFileSorter { public File sortLargeFile(File inputFile) throws IOException { try (LargeFileReader<T> reader = this.fileReaderFactory.apply(inputFile)) { List<File> filesToMerge = splitIntoInitialSortedChunkFiles(reader); return mergeSortFiles(filesToMerge); } } }
LargeFileSorter { public File sortLargeFile(File inputFile) throws IOException { try (LargeFileReader<T> reader = this.fileReaderFactory.apply(inputFile)) { List<File> filesToMerge = splitIntoInitialSortedChunkFiles(reader); return mergeSortFiles(filesToMerge); } } LargeFileSorter(
        Function<File, LargeFileReader<T>> fileReaderFactory,
        Function<File, LargeFileWriter<T>> fileWriterFactory,
        Comparator<T> entryComparator,
        Supplier<File> tempFileCreator); @VisibleForTesting  LargeFileSorter(
        int initialFileChunkSizeToSortInMemory, int nbFilesToMergeSort,
        Function<File, LargeFileReader<T>> fileReaderFactory,
        Function<File, LargeFileWriter<T>> fileWriterFactory,
        Comparator<T> entryComparator,
        Supplier<File> tempFileCreator); }
LargeFileSorter { public File sortLargeFile(File inputFile) throws IOException { try (LargeFileReader<T> reader = this.fileReaderFactory.apply(inputFile)) { List<File> filesToMerge = splitIntoInitialSortedChunkFiles(reader); return mergeSortFiles(filesToMerge); } } LargeFileSorter(
        Function<File, LargeFileReader<T>> fileReaderFactory,
        Function<File, LargeFileWriter<T>> fileWriterFactory,
        Comparator<T> entryComparator,
        Supplier<File> tempFileCreator); @VisibleForTesting  LargeFileSorter(
        int initialFileChunkSizeToSortInMemory, int nbFilesToMergeSort,
        Function<File, LargeFileReader<T>> fileReaderFactory,
        Function<File, LargeFileWriter<T>> fileWriterFactory,
        Comparator<T> entryComparator,
        Supplier<File> tempFileCreator); File sortLargeFile(File inputFile); }
LargeFileSorter { public File sortLargeFile(File inputFile) throws IOException { try (LargeFileReader<T> reader = this.fileReaderFactory.apply(inputFile)) { List<File> filesToMerge = splitIntoInitialSortedChunkFiles(reader); return mergeSortFiles(filesToMerge); } } LargeFileSorter(
        Function<File, LargeFileReader<T>> fileReaderFactory,
        Function<File, LargeFileWriter<T>> fileWriterFactory,
        Comparator<T> entryComparator,
        Supplier<File> tempFileCreator); @VisibleForTesting  LargeFileSorter(
        int initialFileChunkSizeToSortInMemory, int nbFilesToMergeSort,
        Function<File, LargeFileReader<T>> fileReaderFactory,
        Function<File, LargeFileWriter<T>> fileWriterFactory,
        Comparator<T> entryComparator,
        Supplier<File> tempFileCreator); File sortLargeFile(File inputFile); static final int INITIAL_FILE_CHUNK_SIZE_TO_SORT_IN_MEMORY; static final int NB_FILES_TO_MERGE_SORT; }