hadoop-hdfs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jiten...@apache.org
Subject svn commit: r1096875 - in /hadoop/hdfs/trunk/src: java/org/apache/hadoop/hdfs/DFSClient.java test/hdfs/org/apache/hadoop/hdfs/TestFileAppend.java
Date Tue, 26 Apr 2011 19:49:58 GMT
Author: jitendra
Date: Tue Apr 26 19:49:57 2011
New Revision: 1096875

URL: http://svn.apache.org/viewvc?rev=1096875&view=rev
Log:
HDFS-1843. Discover file not found early for file append. Contributed by Bharath Mundlapudi.

Modified:
    hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/DFSClient.java
    hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestFileAppend.java

Modified: hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/DFSClient.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/DFSClient.java?rev=1096875&r1=1096874&r2=1096875&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/DFSClient.java (original)
+++ hadoop/hdfs/trunk/src/java/org/apache/hadoop/hdfs/DFSClient.java Tue Apr 26 19:49:57 2011
@@ -755,10 +755,14 @@ public class DFSClient implements FSCons
    * 
    * @see ClientProtocol#append(String, String) 
    */
-  OutputStream append(String src, int buffersize, Progressable progress)
+  OutputStream append(String src, int buffersize, Progressable progress) 
       throws IOException {
     checkOpen();
     HdfsFileStatus stat = getFileInfo(src);
+    if (stat == null) { // No file found
+      throw new FileNotFoundException("failed to append to non-existent file "
+          + src + " on client " + clientName);
+    }
     OutputStream result = callAppend(stat, src, buffersize, progress);
     leasechecker.put(src, result);
     return result;

Modified: hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestFileAppend.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestFileAppend.java?rev=1096875&r1=1096874&r2=1096875&view=diff
==============================================================================
--- hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestFileAppend.java (original)
+++ hadoop/hdfs/trunk/src/test/hdfs/org/apache/hadoop/hdfs/TestFileAppend.java Tue Apr 26
19:49:57 2011
@@ -17,12 +17,15 @@
  */
 package org.apache.hadoop.hdfs;
 
+import static org.junit.Assert.*;
+
 import java.io.File;
 import java.io.IOException;
+import java.io.FileNotFoundException;
 import java.net.InetSocketAddress;
 import java.util.List;
 
-import junit.framework.TestCase;
+import org.junit.Test;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.BlockLocation;
@@ -41,7 +44,7 @@ import org.apache.hadoop.hdfs.server.dat
  * This class tests the building blocks that are needed to
  * support HDFS appends.
  */
-public class TestFileAppend extends TestCase {
+public class TestFileAppend{
   boolean simulatedStorage = false;
 
   private static byte[] fileContents = null;
@@ -101,6 +104,7 @@ public class TestFileAppend extends Test
    * Test that copy on write for blocks works correctly
    * @throws IOException an exception might be thrown
    */
+  @Test
   public void testCopyOnWrite() throws IOException {
     Configuration conf = new HdfsConfiguration();
     if (simulatedStorage) {
@@ -171,6 +175,7 @@ public class TestFileAppend extends Test
    * Test a simple flush on a simple HDFS file.
    * @throws IOException an exception might be thrown
    */
+  @Test
   public void testSimpleFlush() throws IOException {
     Configuration conf = new HdfsConfiguration();
     if (simulatedStorage) {
@@ -226,6 +231,7 @@ public class TestFileAppend extends Test
    * Test that file data can be flushed.
    * @throws IOException an exception might be thrown
    */
+  @Test
   public void testComplexFlush() throws IOException {
     Configuration conf = new HdfsConfiguration();
     if (simulatedStorage) {
@@ -268,4 +274,26 @@ public class TestFileAppend extends Test
       cluster.shutdown();
     }
   }
+ 
+  /**
+   * FileNotFoundException is expected for appending to a non-exisiting file
+   * 
+   * @throws FileNotFoundException as the result
+   */
+  @Test(expected = FileNotFoundException.class)
+  public void testFileNotFound() throws IOException {
+    Configuration conf = new HdfsConfiguration();
+    if (simulatedStorage) {
+      conf.setBoolean(SimulatedFSDataset.CONFIG_PROPERTY_SIMULATED, true);
+    }
+    MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();
+    FileSystem fs = cluster.getFileSystem();
+    try {
+      Path file1 = new Path("/nonexistingfile.dat");
+      fs.append(file1);
+    } finally {
+      fs.close();
+      cluster.shutdown();
+    }
+  }
 }



Mime
View raw message