LoadIO { public void load(Args args, String input) { String fileName = getSavedFileName(input); if (fileName == null) return; try (CSVReader reader = new CSVReader(new FileReader(fileName), SEPARATOR)) { List<LoadEntry> savedLoadEntryList = new ArrayList<>(); readHeader(reader, savedLoadEntryList); Map<Level, LoadRecord> loadedLoadMap = new TreeMap<>(); readBody(reader, loadedLoadMap, savedLoadEntryList); load.setLoadMapStart(loadedLoadMap, getTimestamp(args, fileName)); System.out.println(fileName + " is loaded."); } catch (Throwable e) { e.printStackTrace(); } } LoadIO(Load load); String save(Args args); void load(Args args, String input); String showSavedFiles(Args args); static final String NO_SAVED_FILE; }
@Test public void testLoad() throws Exception { String filename = null; String[] argsRaw = {"zookeeper", "table"}; Args args = new StatArgs(argsRaw); Load load = new Load(new LevelClass(TableName.class), args); LoadIO loadIO = createLoadIO(load); try { assertTrue(loadIO.showSavedFiles(args).startsWith(LoadIO.NO_SAVED_FILE)); filename = loadIO.filename(args); loadIO.save(args); assertEquals(1, loadIO.savedFileNameList(args).size()); List<String> strings = Files.readAllLines(Paths.get(filename), Charset.defaultCharset()); for (String string : strings) { System.out.println(string); } assertFalse(loadIO.showSavedFiles(args).startsWith(LoadIO.NO_SAVED_FILE)); loadIO.load(args, "0"); assertEquals(filename, loadIO.getSavedFileName("0")); load.toggleDiffFromStart(); assertTrue(load.isDiffFromStart()); assertEquals(2, load.getLoadMap().size()); assertEquals(2L, ((LoadRecord) (load.getLoadMapPrev().values().toArray()[0])).get(LoadEntry.Reads)); assertEquals(1L, ((LoadRecord) (load.getLoadMapPrev().values().toArray()[1])).get(LoadEntry.Reads)); } finally { if (filename != null) Files.delete(Paths.get(filename)); } }