You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-commits@hadoop.apache.org by to...@apache.org on 2011/07/14 20:59:01 UTC

svn commit: r1146848 - in /hadoop/common/branches/HDFS-1073/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode: TestCheckpoint.java TestEditLogFileOutputStream.java

Author: todd
Date: Thu Jul 14 18:59:01 2011
New Revision: 1146848

URL: http://svn.apache.org/viewvc?rev=1146848&view=rev
Log:
Amend HDFS-2011 for HDFS-1073 branch. Update test cases for new behavior of EditLogFileOutputStream. Contributed by Todd Lipcon and Eli Collins.

Modified:
    hadoop/common/branches/HDFS-1073/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java
    hadoop/common/branches/HDFS-1073/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestEditLogFileOutputStream.java

Modified: hadoop/common/branches/HDFS-1073/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-1073/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java?rev=1146848&r1=1146847&r2=1146848&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-1073/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java (original)
+++ hadoop/common/branches/HDFS-1073/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestCheckpoint.java Thu Jul 14 18:59:01 2011
@@ -174,32 +174,6 @@ public class TestCheckpoint extends Test
     resurrectNameDir(first); // put back namedir
   }
 
-  /**
-   * Tests EditLogFileOutputStream doesn't throw NullPointerException on being
-   * closed twice.
-   * See https://issues.apache.org/jira/browse/HDFS-2011
-   */
-  public void testEditLogFileOutputStreamCloses()
-    throws IOException,NullPointerException {
-    System.out.println("Testing EditLogFileOutputStream doesn't throw " +
-                       "NullPointerException on being closed twice");
-    File editLogStreamFile = null;
-    try {
-      editLogStreamFile = new File(System.getProperty("test.build.data","/tmp"),
-                                   "editLogStream.dat");
-      EditLogFileOutputStream editLogStream =
-                             new EditLogFileOutputStream(editLogStreamFile, 0);
-      editLogStream.close();
-      //Closing an twice should not throw a NullPointerException
-      editLogStream.close();
-    } finally {
-      if (editLogStreamFile != null)
-        // Cleanup the editLogStream.dat file we created
-          editLogStreamFile.delete();
-    }
-    System.out.println("Successfully tested EditLogFileOutputStream doesn't " +
-           "throw NullPointerException on being closed twice");
-  }
 
   /**
    * Checks that an IOException in NNStorage.writeTransactionIdFile is handled

Modified: hadoop/common/branches/HDFS-1073/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestEditLogFileOutputStream.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-1073/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestEditLogFileOutputStream.java?rev=1146848&r1=1146847&r2=1146848&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-1073/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestEditLogFileOutputStream.java (original)
+++ hadoop/common/branches/HDFS-1073/hdfs/src/test/hdfs/org/apache/hadoop/hdfs/server/namenode/TestEditLogFileOutputStream.java Thu Jul 14 18:59:01 2011
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTru
 import java.io.File;
 import java.io.IOException;
 
+import org.apache.hadoop.util.StringUtils;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.DU;
 import org.apache.hadoop.fs.Path;
@@ -32,13 +33,22 @@ import org.apache.hadoop.hdfs.server.com
 import org.apache.hadoop.hdfs.server.namenode.FSEditLogLoader.EditLogValidation;
 import org.apache.hadoop.hdfs.HdfsConfiguration;
 import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.junit.Before;
 import org.junit.Test;
 
 public class TestEditLogFileOutputStream {
   
   private final static int HEADER_LEN = 17;
   private final static int MKDIR_LEN = 59;
-
+  private static final File TEST_EDITS =
+    new File(System.getProperty("test.build.data","/tmp"),
+             "editLogStream.dat");
+
+  @Before
+  public void deleteEditsFile() {
+    TEST_EDITS.delete();
+  }
+  
   @Test
   public void testPreallocation() throws IOException {
     Configuration conf = new HdfsConfiguration();
@@ -73,4 +83,48 @@ public class TestEditLogFileOutputStream
         256 * 4096 <= new DU(editLog, conf).getUsed());
   }
 
+  /**
+   * Tests EditLogFileOutputStream doesn't throw NullPointerException on
+   * close/abort sequence. See HDFS-2011.
+   */
+  @Test
+  public void testEditLogFileOutputStreamCloseAbort() throws IOException {
+    // abort after a close should just ignore
+    EditLogFileOutputStream editLogStream =
+      new EditLogFileOutputStream(TEST_EDITS, 0);
+    editLogStream.close();
+    editLogStream.abort();
+  }
+
+  /**
+   * Tests EditLogFileOutputStream doesn't throw NullPointerException on
+   * close/close sequence. See HDFS-2011.
+   */
+  @Test
+  public void testEditLogFileOutputStreamCloseClose() throws IOException {
+    // close after a close should result in an IOE
+    EditLogFileOutputStream editLogStream =
+      new EditLogFileOutputStream(TEST_EDITS, 0);
+    editLogStream.close();
+    try {
+      editLogStream.close();
+    } catch (IOException ioe) {
+      String msg = StringUtils.stringifyException(ioe);
+      assertTrue(msg, msg.contains("Trying to use aborted output stream"));
+    }
+  }
+  
+  /**
+   * Tests EditLogFileOutputStream doesn't throw NullPointerException on being
+   * abort/abort sequence. See HDFS-2011.
+   */
+  @Test
+  public void testEditLogFileOutputStreamAbortAbort() throws IOException {
+    // abort after a close should just ignore
+    EditLogFileOutputStream editLogStream =
+      new EditLogFileOutputStream(TEST_EDITS, 0);
+    editLogStream.abort();
+    editLogStream.abort();
+  }
+
 }