@Test
public void testShowRate() throws Exception {

    Formatter formatter;
    String resultString;
    LoadRecord rec1;
    String expected;
    Map<Level, LoadRecord> loadMap;
    LoadRecord summary;
    Load load = new Load(new LevelClass(ServerName.class));
    // iteration 1
    loadMap = new TreeMap<>();
    rec1 = new LoadRecord();
    rec1.put(LoadEntry.MemstoreSize, 112233);
    rec1.put(LoadEntry.Writes, 0);
    rec1.put(LoadEntry.Reads, 0);
    rec1.put(LoadEntry.FileSize, 0);
    loadMap.put(new Level("rec11"), rec1);
    summary = new LoadRecord();
    summary.put(LoadEntry.MemstoreSize, 112233);
    summary.put(LoadEntry.Writes, 0);
    summary.put(LoadEntry.Reads, 0);
    summary.put(LoadEntry.FileSize, 0);
    load.setLoadMap(loadMap);
    load.setSummary(summary);
    load.updateChangeMap();
    Assert.assertFalse(load.isDiffFromStart());
    formatter = new Formatter("testTable", load);
    Assert.assertFalse(load.isShowRate());
    load.toggleShowRate();
    Assert.assertTrue(load.isShowRate());
    resultString = formatter.buildString(false, Formatter.Type.ANSI);
    System.out.println(resultString);
    expected = "RegionServer  Reads    Writes   Regions    Files      FileSize  FileSizeUncomp  MemstoreSize   CompactedKVs  \n" +
            " rec11        0 | N/A  0 | N/A  N/A | N/A  N/A | N/A  0m | N/A  N/A | N/A       112233m | N/A  N/A | N/A     \n" +
            " Total: 1     0 | N/A  0 | N/A  N/A | N/A  N/A | N/A  0m | N/A  N/A | N/A       112233m | N/A  N/A | N/A     \n";
    Assert.assertEquals(expected, Color.clearColor(resultString, Formatter.Type.ANSI));
    // iteration 2
    load.prepare();
    loadMap = new TreeMap<>();
    rec1 = new LoadRecord();
    rec1.put(LoadEntry.MemstoreSize, 112233);
    rec1.put(LoadEntry.Writes, 1000);
    rec1.put(LoadEntry.Reads, 1);
    rec1.put(LoadEntry.FileSize, 0);
    loadMap.put(new Level("rec11"), rec1);
    summary = new LoadRecord();
    summary.put(LoadEntry.MemstoreSize, 112233);
    summary.put(LoadEntry.Writes, 1000);
    summary.put(LoadEntry.Reads, 1);
    summary.put(LoadEntry.FileSize, 0);
    load.setLoadMap(loadMap);
    load.setSummary(summary);
    load.updateChangeMap();
    Assert.assertFalse(load.isDiffFromStart());
    load.setDuration(500);
    resultString = formatter.buildString(false, Formatter.Type.ANSI);
    Assert.assertTrue(load.isShowRate());
    System.out.println(resultString);
    expected = "RegionServer  Reads      Writes         Regions    Files      FileSize   FileSizeUncomp  MemstoreSize    CompactedKVs  \n" +
            " rec11        1 | 2.0/s  1000 | 2000/s  N/A | N/A  N/A | N/A  0m | 0m/s  N/A | N/A       112233m | 0m/s  N/A | N/A     \n" +
            " Total: 1     1 | 2.0/s  1000 | 2000/s  N/A | N/A  N/A | N/A  0m | 0m/s  N/A | N/A       112233m | 0m/s  N/A | N/A     \n";
    Assert.assertEquals(expected, Color.clearColor(resultString, Formatter.Type.ANSI));
}