@Test
public void testSaveOutput() throws Exception {

    String outputFileName = "output.txt";
    String[] argsRaw = {"zookeeper", "table", "--output=" + outputFileName};
    Args args = new StatArgs(argsRaw);
    Load load = new Load(new LevelClass(TableName.class), args);
    LoadIO loadIO = createLoadIO(load);
    try {
        Files.delete(Paths.get(outputFileName));
    } catch (NoSuchFileException e) {
        if (!e.getMessage().contains(outputFileName)) throw e;
    }
    List<String> strings;
    try {
        // iteration 1
        load.update(null, args);
        strings = Files.readAllLines(Paths.get(outputFileName), Charset.defaultCharset());
        for (String string : strings) {
            System.out.println(string);
        }
        long timestamp1 = load.getTimestampIteration();
        assertEquals(3, strings.size());
        assertEquals("\"Table\",\"Timestamp\",\"Reads\",\"Writes\",\"Regions\",\"Files\",\"FileSize\",\"FileSizeUncomp\",\"MemstoreSize\",\"CompactedKVs\"", strings.get(0));
        assertEquals("\"rec1\",\"" + timestamp1 + "\",\"2\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"", strings.get(1));
        assertEquals("\"rec2\",\"" + timestamp1 + "\",\"1\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"", strings.get(2));
        // iteration 2
        Thread.sleep(1);
        load.update(null, args);
        strings = Files.readAllLines(Paths.get(outputFileName), Charset.defaultCharset());
        for (String string : strings) {
            System.out.println(string);
        }
        assertEquals(5, strings.size());
        long timestamp2 = load.getTimestampIteration();
        assertEquals("\"Table\",\"Timestamp\",\"Reads\",\"Writes\",\"Regions\",\"Files\",\"FileSize\",\"FileSizeUncomp\",\"MemstoreSize\",\"CompactedKVs\"", strings.get(0));
        assertEquals("\"rec1\",\"" + timestamp1 + "\",\"2\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"", strings.get(1));
        assertEquals("\"rec2\",\"" + timestamp1 + "\",\"1\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"", strings.get(2));
        assertEquals("\"rec1\",\"" + timestamp2 + "\",\"2\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"", strings.get(3));
        assertEquals("\"rec2\",\"" + timestamp2 + "\",\"1\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"", strings.get(4));
        assertEquals(0, loadIO.savedFileNameList(args).size());
    } finally {
        Files.delete(Paths.get(outputFileName));
    }
}