hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sur...@apache.org
Subject svn commit: r1096038 - in /hadoop/common/branches/yahoo-merge: ./ src/contrib/ec2/ src/docs/ src/java/ src/java/org/apache/hadoop/fs/ src/test/core/ src/test/core/org/apache/hadoop/fs/ src/test/core/org/apache/hadoop/fs/loadGenerator/
Date Fri, 22 Apr 2011 21:04:16 GMT
Author: suresh
Date: Fri Apr 22 21:04:15 2011
New Revision: 1096038

URL: http://svn.apache.org/viewvc?rev=1096038&view=rev
Log:
Merging change r1092565 from trunk

Modified:
    hadoop/common/branches/yahoo-merge/   (props changed)
    hadoop/common/branches/yahoo-merge/CHANGES.txt   (contents, props changed)
    hadoop/common/branches/yahoo-merge/src/contrib/ec2/   (props changed)
    hadoop/common/branches/yahoo-merge/src/docs/   (props changed)
    hadoop/common/branches/yahoo-merge/src/java/   (props changed)
    hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/ChecksumFs.java
    hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/CreateFlag.java
    hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FileContext.java
    hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FileSystem.java
    hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java
    hadoop/common/branches/yahoo-merge/src/test/core/   (props changed)
    hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java
    hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/loadGenerator/DataGenerator.java
    hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/loadGenerator/LoadGenerator.java

Propchange: hadoop/common/branches/yahoo-merge/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Apr 22 21:04:15 2011
@@ -1,2 +1,2 @@
-/hadoop/common/trunk:1043117,1080396
+/hadoop/common/trunk:1043117,1080396,1092565
 /hadoop/core/branches/branch-0.19/core:713112

Modified: hadoop/common/branches/yahoo-merge/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/CHANGES.txt?rev=1096038&r1=1096037&r2=1096038&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/CHANGES.txt (original)
+++ hadoop/common/branches/yahoo-merge/CHANGES.txt Fri Apr 22 21:04:15 2011
@@ -1,4 +1,4 @@
-Hadoop Change Log
+Hn jaadoop Change Log
 
 Trunk (unreleased changes)
 
@@ -22,6 +22,10 @@ Trunk (unreleased changes)
 
   BUG FIXES
 
+    HADOOP-7223. FileContext createFlag combinations are not clearly defined.
+    (suresh)
+
+
 Release 0.22.0 - Unreleased
 
   INCOMPATIBLE CHANGES

Propchange: hadoop/common/branches/yahoo-merge/CHANGES.txt
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Apr 22 21:04:15 2011
@@ -1,4 +1,4 @@
-/hadoop/common/trunk/CHANGES.txt:1043117,1080396,1091618,1092832
+/hadoop/common/trunk/CHANGES.txt:1043117,1080396,1091618,1092565,1092832
 /hadoop/core/branches/branch-0.18/CHANGES.txt:727226
 /hadoop/core/branches/branch-0.19/CHANGES.txt:713112
 /hadoop/core/trunk/CHANGES.txt:776175-785643,785929-786278

Propchange: hadoop/common/branches/yahoo-merge/src/contrib/ec2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Apr 22 21:04:15 2011
@@ -1,3 +1,3 @@
-/hadoop/common/trunk/src/contrib/ec2:1043117
+/hadoop/common/trunk/src/contrib/ec2:1043117,1092565
 /hadoop/core/branches/branch-0.19/core/src/contrib/ec2:713112
 /hadoop/core/trunk/src/contrib/ec2:776175-784663

Propchange: hadoop/common/branches/yahoo-merge/src/docs/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Apr 22 21:04:15 2011
@@ -1,2 +1,2 @@
-/hadoop/common/trunk/src/docs:1043117,1080396
+/hadoop/common/trunk/src/docs:1043117,1080396,1092565
 /hadoop/core/branches/branch-0.19/src/docs:713112

Propchange: hadoop/common/branches/yahoo-merge/src/java/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Apr 22 21:04:15 2011
@@ -1,3 +1,3 @@
-/hadoop/common/trunk/src/java:1043117,1080396
+/hadoop/common/trunk/src/java:1043117,1080396,1092565
 /hadoop/core/branches/branch-0.19/core/src/java:713112
 /hadoop/core/trunk/src/core:776175-785643,785929-786278

Modified: hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/ChecksumFs.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/ChecksumFs.java?rev=1096038&r1=1096037&r2=1096038&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/ChecksumFs.java (original)
+++ hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/ChecksumFs.java Fri Apr
22 21:04:15 2011
@@ -337,8 +337,9 @@ public abstract class ChecksumFs extends
       int bytesPerSum = fs.getBytesPerSum();
       int sumBufferSize = fs.getSumBufferSize(bytesPerSum, bufferSize);
       this.sums = fs.getRawFs().createInternal(fs.getChecksumFile(file),
-          EnumSet.of(CreateFlag.OVERWRITE), absolutePermission, sumBufferSize,
-          replication,  blockSize,  progress, bytesPerChecksum,  createParent);
+          EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE),
+          absolutePermission, sumBufferSize, replication, blockSize, progress,
+          bytesPerChecksum, createParent);
       sums.write(CHECKSUM_VERSION, 0, CHECKSUM_VERSION.length);
       sums.writeInt(bytesPerSum);
     }

Modified: hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/CreateFlag.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/CreateFlag.java?rev=1096038&r1=1096037&r2=1096038&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/CreateFlag.java (original)
+++ hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/CreateFlag.java Fri Apr
22 21:04:15 2011
@@ -17,49 +17,63 @@
  */
 package org.apache.hadoop.fs;
 
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.EnumSet;
+
+import org.apache.hadoop.HadoopIllegalArgumentException;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 
 /****************************************************************
- *CreateFlag specifies the file create semantic. Users can combine flags like:<br>
- *<code>
+ * CreateFlag specifies the file create semantic. Users can combine flags like: <br>
+ * <code>
  * EnumSet.of(CreateFlag.CREATE, CreateFlag.APPEND)
  * <code>
- * and pass it to {@link org.apache.hadoop.fs.FileSystem #create(Path f, FsPermission permission,
- * EnumSet<CreateFlag> flag, int bufferSize, short replication, long blockSize,
- * Progressable progress)}.
- * 
  * <p>
- * Combine {@link #OVERWRITE} with either {@link #CREATE} 
- * or {@link #APPEND} does the same as only use 
- * {@link #OVERWRITE}. <br>
- * Combine {@link #CREATE} with {@link #APPEND} has the semantic:
+ * 
+ * Use the CreateFlag as follows:
+ * <ol>
+ * <li> CREATE - to create a file if it does not exist, 
+ * else throw FileAlreadyExists.</li>
+ * <li> APPEND - to append to a file if it exists, 
+ * else throw FileNotFoundException.</li>
+ * <li> OVERWRITE - to truncate a file if it exists, 
+ * else throw FileNotFoundException.</li>
+ * <li> CREATE|APPEND - to create a file if it does not exist, 
+ * else append to an existing file.</li>
+ * <li> CREATE|OVERWRITE - to create a file if it does not exist, 
+ * else overwrite an existing file.</li>
+ * </ol>
+ * 
+ * Following combination is not valid and will result in 
+ * {@link HadoopIllegalArgumentException}:
  * <ol>
- * <li> create the file if it does not exist;
- * <li> append the file if it already exists.
+ * <li> APPEND|OVERWRITE</li>
+ * <li> CREATE|APPEND|OVERWRITE</li>
  * </ol>
  *****************************************************************/
 @InterfaceAudience.Public
-@InterfaceStability.Stable
+@InterfaceStability.Evolving
 public enum CreateFlag {
 
   /**
-   * create the file if it does not exist, and throw an IOException if it
+   * Create a file. See javadoc for more description
    * already exists
    */
   CREATE((short) 0x01),
 
   /**
-   * create the file if it does not exist, if it exists, overwrite it.
+   * Truncate/overwrite a file. Same as POSIX O_TRUNC. See javadoc for description.
    */
   OVERWRITE((short) 0x02),
 
   /**
-   * append to a file, and throw an IOException if it does not exist
+   * Append to a file. See javadoc for more description.
    */
   APPEND((short) 0x04);
 
-  private short mode;
+  private final short mode;
 
   private CreateFlag(short mode) {
     this.mode = mode;
@@ -68,4 +82,49 @@ public enum CreateFlag {
   short getMode() {
     return mode;
   }
+  
+  /**
+   * Validate the CreateFlag and throw exception if it is invalid
+   * @param flag set of CreateFlag
+   * @throws HadoopIllegalArgumentException if the CreateFlag is invalid
+   */
+  public static void validate(EnumSet<CreateFlag> flag) {
+    if (flag == null || flag.isEmpty()) {
+      throw new HadoopIllegalArgumentException(flag
+          + " does not specify any options");
+    }
+    final boolean append = flag.contains(APPEND);
+    final boolean overwrite = flag.contains(OVERWRITE);
+    
+    // Both append and overwrite is an error
+    if (append && overwrite) {
+      throw new HadoopIllegalArgumentException(
+          flag + "Both append and overwrite options cannot be enabled.");
+    }
+  }
+  
+  /**
+   * Validate the CreateFlag for create operation
+   * @param path Object representing the path; usually String or {@link Path}
+   * @param pathExists pass true if the path exists in the file system
+   * @param flag set of CreateFlag
+   * @throws IOException on error
+   * @throws HadoopIllegalArgumentException if the CreateFlag is invalid
+   */
+  public static void validate(Object path, boolean pathExists,
+      EnumSet<CreateFlag> flag) throws IOException {
+    validate(flag);
+    final boolean append = flag.contains(APPEND);
+    final boolean overwrite = flag.contains(OVERWRITE);
+    if (pathExists) {
+      if (!(append || overwrite)) {
+        throw new FileAlreadyExistsException("File already exists: "
+            + path.toString()
+            + ". Append or overwrite option must be specified in " + flag);
+      }
+    } else if (!flag.contains(CREATE)) {
+      throw new FileNotFoundException("Non existing file: " + path.toString()
+          + ". Create option is not specified in " + flag);
+    }
+  }
 }
\ No newline at end of file

Modified: hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FileContext.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FileContext.java?rev=1096038&r1=1096037&r2=1096038&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FileContext.java (original)
+++ hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FileContext.java Fri
Apr 22 21:04:15 2011
@@ -567,7 +567,7 @@ public final class FileContext {
    * writing into the file.
    * 
    * @param f the file name to open
-   * @param createFlag gives the semantics of create: overwrite, append etc.
+   * @param createFlag gives the semantics of create; see {@link CreateFlag}
    * @param opts file creation options; see {@link Options.CreateOpts}.
    *          <ul>
    *          <li>Progress - to report progress on the operation - default null
@@ -2095,7 +2095,10 @@ public final class FileContext {
         OutputStream out = null;
         try {
           in = open(qSrc);
-          out = create(qDst, EnumSet.of(CreateFlag.OVERWRITE));
+          EnumSet<CreateFlag> createFlag = overwrite ? EnumSet.of(
+              CreateFlag.CREATE, CreateFlag.OVERWRITE) : 
+                EnumSet.of(CreateFlag.CREATE);
+          out = create(qDst, createFlag);
           IOUtils.copyBytes(in, out, conf, true);
         } catch (IOException e) {
           IOUtils.closeStream(out);

Modified: hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FileSystem.java?rev=1096038&r1=1096037&r2=1096038&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FileSystem.java (original)
+++ hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FileSystem.java Fri Apr
22 21:04:15 2011
@@ -728,24 +728,21 @@ public abstract class FileSystem extends
      FsPermission absolutePermission, EnumSet<CreateFlag> flag, int bufferSize,
      short replication, long blockSize, Progressable progress,
      int bytesPerChecksum) throws IOException {
+
+    boolean pathExists = exists(f);
+    CreateFlag.validate(f, pathExists, flag);
     
     // Default impl  assumes that permissions do not matter and 
     // nor does the bytesPerChecksum  hence
     // calling the regular create is good enough.
     // FSs that implement permissions should override this.
 
-    if (exists(f)) {
-      if (flag.contains(CreateFlag.APPEND)) {
-        return append(f, bufferSize, progress);
-      } else if (!flag.contains(CreateFlag.OVERWRITE)) {
-        throw new IOException("File already exists: " + f);
-      }
-    } else {
-      if (flag.contains(CreateFlag.APPEND) && !flag.contains(CreateFlag.CREATE))
-        throw new IOException("File already exists: " + f.toString());
+    if (pathExists && flag.contains(CreateFlag.APPEND)) {
+      return append(f, bufferSize, progress);
     }
     
-    return this.create(f, absolutePermission, flag.contains(CreateFlag.OVERWRITE), bufferSize,
replication,
+    return this.create(f, absolutePermission,
+        flag.contains(CreateFlag.OVERWRITE), bufferSize, replication,
         blockSize, progress);
   }
   

Modified: hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java?rev=1096038&r1=1096037&r2=1096038&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java
(original)
+++ hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/RawLocalFileSystem.java
Fri Apr 22 21:04:15 2011
@@ -262,28 +262,6 @@ public class RawLocalFileSystem extends 
     return out;
   }
   
-
-  @Override
-  protected FSDataOutputStream primitiveCreate(Path f,
-      FsPermission absolutePermission, EnumSet<CreateFlag> flag,
-      int bufferSize, short replication, long blockSize, Progressable progress,
-      int bytesPerChecksum) throws IOException {
-    
-    if(flag.contains(CreateFlag.APPEND)){
-      if (!exists(f)){
-        if(flag.contains(CreateFlag.CREATE)) {
-          return create(f, false, bufferSize, replication, blockSize, null);
-        }
-      }
-      return append(f, bufferSize, null);
-    }
- 
-    FSDataOutputStream out = create(f, flag.contains(CreateFlag.OVERWRITE),
-                                 bufferSize, replication, blockSize, progress);
-    setPermission(f, absolutePermission);
-    return out;
-  }
-
   public boolean rename(Path src, Path dst) throws IOException {
     if (pathToFile(src).renameTo(pathToFile(dst))) {
       return true;

Propchange: hadoop/common/branches/yahoo-merge/src/test/core/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Apr 22 21:04:15 2011
@@ -1,3 +1,3 @@
-/hadoop/common/trunk/src/test/core:1043117,1080396
+/hadoop/common/trunk/src/test/core:1043117,1080396,1092565
 /hadoop/core/branches/branch-0.19/core/src/test/core:713112
 /hadoop/core/trunk/src/test/core:776175-785643,785929-786278

Modified: hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java?rev=1096038&r1=1096037&r2=1096038&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java
(original)
+++ hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java
Fri Apr 22 21:04:15 2011
@@ -21,8 +21,8 @@ package org.apache.hadoop.fs;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.EnumSet;
-import java.util.Iterator;
 
+import org.apache.hadoop.HadoopIllegalArgumentException;
 import org.apache.hadoop.fs.Options.CreateOpts;
 import org.apache.hadoop.fs.Options.Rename;
 import org.apache.hadoop.fs.permission.FsPermission;
@@ -33,6 +33,7 @@ import org.junit.Test;
 import org.apache.hadoop.util.Progressable;
 
 import static org.apache.hadoop.fs.FileContextTestHelper.*;
+import static org.apache.hadoop.fs.CreateFlag.*;
 
 /**
  * <p>
@@ -160,7 +161,7 @@ public abstract class FileContextMainOpe
     
     // Now open a file relative to the wd we just set above.
     Path absolutePath = new Path(absoluteDir, "foo");
-    fc.create(absolutePath, EnumSet.of(CreateFlag.CREATE)).close();
+    fc.create(absolutePath, EnumSet.of(CREATE)).close();
     fc.open(new Path("foo")).close();
     
     
@@ -650,7 +651,7 @@ public abstract class FileContextMainOpe
     
     fc.mkdir(path.getParent(), FsPermission.getDefault(), true);
 
-    FSDataOutputStream out = fc.create(path, EnumSet.of(CreateFlag.CREATE),
+    FSDataOutputStream out = fc.create(path, EnumSet.of(CREATE),
         CreateOpts.repFac((short) 1), CreateOpts
             .blockSize(getDefaultBlockSize()));
     out.write(data, 0, len);
@@ -675,31 +676,93 @@ public abstract class FileContextMainOpe
 
   }
   
+  @Test(expected=HadoopIllegalArgumentException.class)
+  public void testNullCreateFlag() throws IOException {
+    Path p = getTestRootPath(fc, "test/file");
+    fc.create(p, null);
+    Assert.fail("Excepted exception not thrown");
+  }
+  
+  @Test(expected=HadoopIllegalArgumentException.class)
+  public void testEmptyCreateFlag() throws IOException {
+    Path p = getTestRootPath(fc, "test/file");
+    fc.create(p, EnumSet.noneOf(CreateFlag.class));
+    Assert.fail("Excepted exception not thrown");
+  }
+  
+  @Test(expected=FileAlreadyExistsException.class)
+  public void testCreateFlagCreateExistingFile() throws IOException {
+    Path p = getTestRootPath(fc, "test/testCreateFlagCreateExistingFile");
+    createFile(p);
+    fc.create(p, EnumSet.of(CREATE));
+    Assert.fail("Excepted exception not thrown");
+  }
+  
+  @Test(expected=FileNotFoundException.class)
+  public void testCreateFlagOverwriteNonExistingFile() throws IOException {
+    Path p = getTestRootPath(fc, "test/testCreateFlagOverwriteNonExistingFile");
+    fc.create(p, EnumSet.of(OVERWRITE));
+    Assert.fail("Excepted exception not thrown");
+  }
+  
   @Test
-  public void testOverwrite() throws IOException {
-    Path path = getTestRootPath(fc, "test/hadoop/file");
-    
-    fc.mkdir(path.getParent(), FsPermission.getDefault(), true);
-
-    createFile(path);
-    
-    Assert.assertTrue("Exists", exists(fc, path));
-    Assert.assertEquals("Length", data.length, fc.getFileStatus(path).getLen());
-    
-    try {
-      fc.create(path, EnumSet.of(CreateFlag.CREATE));
-      Assert.fail("Should throw IOException.");
-    } catch (IOException e) {
-      // Expected
-    }
-    
-    FSDataOutputStream out = fc.create(path,EnumSet.of(CreateFlag.OVERWRITE));
+  public void testCreateFlagOverwriteExistingFile() throws IOException {
+    Path p = getTestRootPath(fc, "test/testCreateFlagOverwriteExistingFile");
+    createFile(p);
+    FSDataOutputStream out = fc.create(p, EnumSet.of(OVERWRITE));
+    writeData(fc, p, out, data, data.length);
+  }
+  
+  @Test(expected=FileNotFoundException.class)
+  public void testCreateFlagAppendNonExistingFile() throws IOException {
+    Path p = getTestRootPath(fc, "test/testCreateFlagAppendNonExistingFile");
+    fc.create(p, EnumSet.of(APPEND));
+    Assert.fail("Excepted exception not thrown");
+  }
+  
+  @Test
+  public void testCreateFlagAppendExistingFile() throws IOException {
+    Path p = getTestRootPath(fc, "test/testCreateFlagAppendExistingFile");
+    createFile(p);
+    FSDataOutputStream out = fc.create(p, EnumSet.of(APPEND));
+    writeData(fc, p, out, data, 2 * data.length);
+  }
+  
+  @Test
+  public void testCreateFlagCreateAppendNonExistingFile() throws IOException {
+    Path p = getTestRootPath(fc, "test/testCreateFlagCreateAppendNonExistingFile");
+    FSDataOutputStream out = fc.create(p, EnumSet.of(CREATE, APPEND));
+    writeData(fc, p, out, data, data.length);
+  }
+  
+  @Test
+  public void testCreateFlagCreateAppendExistingFile() throws IOException {
+    Path p = getTestRootPath(fc, "test/testCreateFlagCreateAppendExistingFile");
+    createFile(p);
+    FSDataOutputStream out = fc.create(p, EnumSet.of(CREATE, APPEND));
+    writeData(fc, p, out, data, 2*data.length);
+  }
+  
+  @Test(expected=HadoopIllegalArgumentException.class)
+  public void testCreateFlagAppendOverwrite() throws IOException {
+    Path p = getTestRootPath(fc, "test/nonExistent");
+    fc.create(p, EnumSet.of(APPEND, OVERWRITE));
+    Assert.fail("Excepted exception not thrown");
+  }
+  
+  @Test(expected=HadoopIllegalArgumentException.class)
+  public void testCreateFlagAppendCreateOverwrite() throws IOException {
+    Path p = getTestRootPath(fc, "test/nonExistent");
+    fc.create(p, EnumSet.of(CREATE, APPEND, OVERWRITE));
+    Assert.fail("Excepted exception not thrown");
+  }
+  
+  private static void writeData(FileContext fc, Path p, FSDataOutputStream out,
+      byte[] data, long expectedLen) throws IOException {
     out.write(data, 0, data.length);
     out.close();
-    
-    Assert.assertTrue("Exists", exists(fc, path));
-    Assert.assertEquals("Length", data.length, fc.getFileStatus(path).getLen());
-    
+    Assert.assertTrue("Exists", exists(fc, p));
+    Assert.assertEquals("Length", expectedLen, fc.getFileStatus(p).getLen());
   }
   
   @Test
@@ -1063,7 +1126,7 @@ public abstract class FileContextMainOpe
     //streams should have no effect. 
     Path src = getTestRootPath(fc, "test/hadoop/file");
     Progressable prog = new TestProgress();
-    FSDataOutputStream out = fc.create(src, EnumSet.of(CreateFlag.CREATE),
+    FSDataOutputStream out = fc.create(src, EnumSet.of(CREATE),
             Options.CreateOpts.createParent(),
             Options.CreateOpts.Progress.progress(prog));
     
@@ -1098,7 +1161,7 @@ public abstract class FileContextMainOpe
   }
   
   protected void createFile(Path path) throws IOException {
-    FSDataOutputStream out = fc.create(path, EnumSet.of(CreateFlag.CREATE),
+    FSDataOutputStream out = fc.create(path, EnumSet.of(CREATE),
         Options.CreateOpts.createParent());
     out.write(data, 0, data.length);
     out.close();

Modified: hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/loadGenerator/DataGenerator.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/loadGenerator/DataGenerator.java?rev=1096038&r1=1096037&r2=1096038&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/loadGenerator/DataGenerator.java
(original)
+++ hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/loadGenerator/DataGenerator.java
Fri Apr 22 21:04:15 2011
@@ -140,7 +140,8 @@ public class DataGenerator extends Confi
    * a length of <code>fileSize</code>. The file is filled with character 'a'.
    */
   private void genFile(Path file, long fileSize) throws IOException {
-    FSDataOutputStream out = fc.create(file, EnumSet.of(CreateFlag.OVERWRITE),
+    FSDataOutputStream out = fc.create(file,
+        EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE),
         CreateOpts.createParent(), CreateOpts.bufferSize(4096),
         CreateOpts.repFac((short) 3));
     for(long i=0; i<fileSize; i++) {

Modified: hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/loadGenerator/LoadGenerator.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/loadGenerator/LoadGenerator.java?rev=1096038&r1=1096037&r2=1096038&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/loadGenerator/LoadGenerator.java
(original)
+++ hadoop/common/branches/yahoo-merge/src/test/core/org/apache/hadoop/fs/loadGenerator/LoadGenerator.java
Fri Apr 22 21:04:15 2011
@@ -584,7 +584,8 @@ public class LoadGenerator extends Confi
    */
   private void genFile(Path file, long fileSize) throws IOException {
     long startTime = System.currentTimeMillis();
-    FSDataOutputStream out = fc.create(file, EnumSet.of(CreateFlag.OVERWRITE),
+    FSDataOutputStream out = fc.create(file,
+        EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE),
         CreateOpts.createParent(), CreateOpts.bufferSize(4096),
         CreateOpts.repFac((short) 3));
     executionTime[CREATE] += (System.currentTimeMillis()-startTime);



Mime
View raw message