HDFS-3478. Test quotas with Long.Max_Value. Contributed by Sujay Rau

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1349634 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Eli Collins 2012-06-13 05:04:20 +00:00
parent 6702d5dbd4
commit fda95a6a3d
2 changed files with 57 additions and 4 deletions

View File

@ -93,6 +93,8 @@ Trunk (unreleased changes)
HDFS-3049. During the normal NN startup process, fall back on a different HDFS-3049. During the normal NN startup process, fall back on a different
edit log if we see one that is corrupt (Colin Patrick McCabe via todd) edit log if we see one that is corrupt (Colin Patrick McCabe via todd)
HDFS-3478. Test quotas with Long.Max_Value. (Sujay Rau via eli)
OPTIMIZATIONS OPTIMIZATIONS
BUG FIXES BUG FIXES

View File

@ -17,9 +17,7 @@
*/ */
package org.apache.hadoop.hdfs; package org.apache.hadoop.hdfs;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.OutputStream; import java.io.OutputStream;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
@ -774,6 +772,59 @@ private static void checkContentSummary(final ContentSummary expected,
assertEquals(expected.toString(), computed.toString()); assertEquals(expected.toString(), computed.toString());
} }
/**
* Test limit cases for setting space quotas.
*/
@Test
public void testMaxSpaceQuotas() throws Exception {
final Configuration conf = new HdfsConfiguration();
final MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(2).build();
final FileSystem fs = cluster.getFileSystem();
assertTrue("Not a HDFS: "+fs.getUri(),
fs instanceof DistributedFileSystem);
final DistributedFileSystem dfs = (DistributedFileSystem)fs;
// create test directory
final Path testFolder = new Path("/testFolder");
assertTrue(dfs.mkdirs(testFolder));
// setting namespace quota to Long.MAX_VALUE - 1 should work
dfs.setQuota(testFolder, Long.MAX_VALUE - 1, 10);
ContentSummary c = dfs.getContentSummary(testFolder);
assertTrue("Quota not set properly", c.getQuota() == Long.MAX_VALUE - 1);
// setting diskspace quota to Long.MAX_VALUE - 1 should work
dfs.setQuota(testFolder, 10, Long.MAX_VALUE - 1);
c = dfs.getContentSummary(testFolder);
assertTrue("Quota not set properly", c.getSpaceQuota() == Long.MAX_VALUE - 1);
// setting namespace quota to Long.MAX_VALUE should not work + no error
dfs.setQuota(testFolder, Long.MAX_VALUE, 10);
c = dfs.getContentSummary(testFolder);
assertTrue("Quota should not have changed", c.getQuota() == 10);
// setting diskspace quota to Long.MAX_VALUE should not work + no error
dfs.setQuota(testFolder, 10, Long.MAX_VALUE);
c = dfs.getContentSummary(testFolder);
assertTrue("Quota should not have changed", c.getSpaceQuota() == 10);
// setting namespace quota to Long.MAX_VALUE + 1 should not work + error
try {
dfs.setQuota(testFolder, Long.MAX_VALUE + 1, 10);
fail("Exception not thrown");
} catch (IllegalArgumentException e) {
// Expected
}
// setting diskspace quota to Long.MAX_VALUE + 1 should not work + error
try {
dfs.setQuota(testFolder, 10, Long.MAX_VALUE + 1);
fail("Exception not thrown");
} catch (IllegalArgumentException e) {
// Expected
}
}
/** /**
* Violate a space quota using files of size < 1 block. Test that block * Violate a space quota using files of size < 1 block. Test that block
* allocation conservatively assumes that for quota checking the entire * allocation conservatively assumes that for quota checking the entire