Github user anmolnar commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/439#discussion_r160245528
--- Diff: src/java/test/org/apache/zookeeper/test/LoadFromLogTest.java ---
@@ -307,4 +315,104 @@ public void testReloadSnapshotWithMissingParent()
throws Exception {
startServer();
}
+
+ /**
+ * Verify that FileTxnIterator doesn't throw an EOFException when the
+ * transaction log header is incomplete.
+ */
+ @Test
+ public void testIncompleteHeader() throws Exception {
+ ClientBase.setupTestEnv();
+ File dataDir = ClientBase.createTmpDir();
+ loadDatabase(dataDir, NUM_MESSAGES);
+
+ File logDir = new File(dataDir, FileTxnSnapLog.version +
+ FileTxnSnapLog.VERSION);
+ FileTxnLog.FileTxnIterator fileItr = new
FileTxnLog.FileTxnIterator(logDir, 0);
+ List<File> logFiles = fileItr.getStoredFiles();
+ int numTransactions = 0;
+ while (fileItr.next()) {
+ numTransactions++;
+ }
+ Assert.assertTrue("Verify the number of log files",
+ logFiles.size() > 0);
+ Assert.assertTrue("Verify the number of transactions",
+ numTransactions >= NUM_MESSAGES);
+
+ // Truncate the last log file.
+ File lastLogFile = logFiles.get(logFiles.size() - 1);
+ FileChannel channel = new
FileOutputStream(lastLogFile).getChannel();
+ channel.truncate(0);
+ channel.close();
+
+ // This shouldn't thow Exception.
+ fileItr = new FileTxnLog.FileTxnIterator(logDir, 0);
+ logFiles = fileItr.getStoredFiles();
+ numTransactions = 0;
--- End diff --
logFiles & numTransactions variables are not being used in the rest of this
test.
---