|
@@ -17,6 +17,7 @@
|
|
|
*/
|
|
|
package org.apache.hadoop.hdfs;
|
|
|
|
|
|
+import static org.junit.Assert.assertEquals;
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
import java.io.File;
|
|
@@ -337,4 +338,47 @@ public class TestFileAppend{
|
|
|
cluster.shutdown();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /** Tests appending after soft-limit expires. */
|
|
|
+ @Test
|
|
|
+ public void testAppendAfterSoftLimit()
|
|
|
+ throws IOException, InterruptedException {
|
|
|
+ Configuration conf = new HdfsConfiguration();
|
|
|
+ conf.setInt(DFSConfigKeys.DFS_REPLICATION_KEY, 1);
|
|
|
+ conf.setBoolean(DFSConfigKeys.DFS_SUPPORT_APPEND_KEY, true);
|
|
|
+ //Set small soft-limit for lease
|
|
|
+ final long softLimit = 1L;
|
|
|
+ final long hardLimit = 9999999L;
|
|
|
+
|
|
|
+ MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1)
|
|
|
+ .build();
|
|
|
+ cluster.setLeasePeriod(softLimit, hardLimit);
|
|
|
+ cluster.waitActive();
|
|
|
+
|
|
|
+ FileSystem fs = cluster.getFileSystem();
|
|
|
+ FileSystem fs2 = new DistributedFileSystem();
|
|
|
+ fs2.initialize(fs.getUri(), conf);
|
|
|
+
|
|
|
+ final Path testPath = new Path("/testAppendAfterSoftLimit");
|
|
|
+ final byte[] fileContents = AppendTestUtil.initBuffer(32);
|
|
|
+
|
|
|
+ // create a new file without closing
|
|
|
+ FSDataOutputStream out = fs.create(testPath);
|
|
|
+ out.write(fileContents);
|
|
|
+
|
|
|
+ //Wait for > soft-limit
|
|
|
+ Thread.sleep(250);
|
|
|
+
|
|
|
+ try {
|
|
|
+ FSDataOutputStream appendStream2 = fs2.append(testPath);
|
|
|
+ appendStream2.write(fileContents);
|
|
|
+ appendStream2.close();
|
|
|
+ assertEquals(fileContents.length, fs.getFileStatus(testPath).getLen());
|
|
|
+ } finally {
|
|
|
+ fs.close();
|
|
|
+ fs2.close();
|
|
|
+ cluster.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|