Skip to content

Commit

Permalink
HDFS-10337. OfflineEditsViewer stats option should print 0 instead of…
Browse files Browse the repository at this point in the history
… null for the count of operations. Contributed by Yiqun Lin.
  • Loading branch information
aajisaka committed May 8, 2016
1 parent 2750fb9 commit 411fb4b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
Expand Up @@ -107,16 +107,17 @@ public Map<FSEditLogOpCodes, Long> getStatistics() {
* @return statistics in in string format, suitable for printing
*/
public String getStatisticsString() {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append(String.format(
" %-30.30s : %d%n",
"VERSION", version));
for(FSEditLogOpCodes opCode : FSEditLogOpCodes.values()) {
Long count = opCodeCount.get(opCode);
sb.append(String.format(
" %-30.30s (%3d): %d%n",
opCode.toString(),
opCode.getOpCode(),
opCodeCount.get(opCode)));
" %-30.30s (%3d): %d%n",
opCode.toString(),
opCode.getOpCode(),
count == null ? Long.valueOf(0L) : count));
}
return sb.toString();
}
Expand Down
Expand Up @@ -28,6 +28,7 @@
import java.io.PrintStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
Expand Down Expand Up @@ -308,4 +309,33 @@ public void testOfflineEditsViewerHelpMessage() throws Throwable {
IOUtils.closeStream(out);
}
}

@Test
public void testStatisticsStrWithNullOpCodeCount() throws IOException {
String editFilename = nnHelper.generateEdits();
String outFilename = editFilename + ".stats";
FileOutputStream fout = new FileOutputStream(outFilename);
StatisticsEditsVisitor visitor = new StatisticsEditsVisitor(fout);
OfflineEditsViewer oev = new OfflineEditsViewer();

String statisticsStr = null;
if (oev.go(editFilename, outFilename, "stats", new Flags(), visitor) == 0) {
statisticsStr = visitor.getStatisticsString();
}
Assert.assertNotNull(statisticsStr);

String str;
Long count;
Map<FSEditLogOpCodes, Long> opCodeCount = visitor.getStatistics();
for (FSEditLogOpCodes opCode : FSEditLogOpCodes.values()) {
count = opCodeCount.get(opCode);
// Verify the str when the opCode's count is null
if (count == null) {
str =
String.format(" %-30.30s (%3d): %d%n", opCode.toString(),
opCode.getOpCode(), Long.valueOf(0L));
assertTrue(statisticsStr.contains(str));
}
}
}
}

0 comments on commit 411fb4b

Please sign in to comment.