svn merge -c 1310522 from trunk for HDFS-2505. Add a test to verify getFileChecksum(..) with ViewFS.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1310570 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tsz-wo Sze 2012-04-06 20:16:10 +00:00
parent 906589c912
commit 95ab2e4cc4
2 changed files with 38 additions and 8 deletions

View File

@ -658,6 +658,9 @@ Release 0.23.3 - UNRELEASED
IMPROVEMENTS IMPROVEMENTS
HDFS-2505. Add a test to verify getFileChecksum(..) with ViewFS. (Ravi
Prakash via szetszwo)
OPTIMIZATIONS OPTIMIZATIONS
BUG FIXES BUG FIXES

View File

@ -30,6 +30,7 @@ import java.net.URISyntaxException;
import javax.security.auth.login.LoginException; import javax.security.auth.login.LoginException;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileChecksum;
import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.FileSystemTestHelper; import org.apache.hadoop.fs.FileSystemTestHelper;
@ -48,13 +49,13 @@ import static org.junit.Assert.*;
public class TestViewFsFileStatusHdfs { public class TestViewFsFileStatusHdfs {
static final String testfilename = "/tmp/testFileStatusSerialziation"; static final String testfilename = "/tmp/testFileStatusSerialziation";
static final String someFile = "/hdfstmp/someFileForTestGetFileChecksum";
private static MiniDFSCluster cluster; private static MiniDFSCluster cluster;
private static Path defaultWorkingDirectory; private static Path defaultWorkingDirectory;
private static Configuration CONF = new Configuration(); private static Configuration CONF = new Configuration();
private static FileSystem fHdfs; private static FileSystem fHdfs;
private static FileSystem vfs;
@BeforeClass @BeforeClass
public static void clusterSetupAtBegining() throws IOException, public static void clusterSetupAtBegining() throws IOException,
@ -65,18 +66,19 @@ public class TestViewFsFileStatusHdfs {
defaultWorkingDirectory = fHdfs.makeQualified( new Path("/user/" + defaultWorkingDirectory = fHdfs.makeQualified( new Path("/user/" +
UserGroupInformation.getCurrentUser().getShortUserName())); UserGroupInformation.getCurrentUser().getShortUserName()));
fHdfs.mkdirs(defaultWorkingDirectory); fHdfs.mkdirs(defaultWorkingDirectory);
// Setup the ViewFS to be used for all tests.
Configuration conf = ViewFileSystemTestSetup.createConfig();
ConfigUtil.addLink(conf, "/vfstmp", new URI(fHdfs.getUri() + "/hdfstmp"));
ConfigUtil.addLink(conf, "/tmp", new URI(fHdfs.getUri() + "/tmp"));
vfs = FileSystem.get(FsConstants.VIEWFS_URI, conf);
assertEquals(ViewFileSystem.class, vfs.getClass());
} }
@Test @Test
public void testFileStatusSerialziation() public void testFileStatusSerialziation()
throws IOException, URISyntaxException { throws IOException, URISyntaxException {
long len = FileSystemTestHelper.createFile(fHdfs, testfilename); long len = FileSystemTestHelper.createFile(fHdfs, testfilename);
Configuration conf = ViewFileSystemTestSetup.createConfig();
ConfigUtil.addLink(conf, "/tmp", new URI(fHdfs.getUri().toString() + "/tmp"));
FileSystem vfs = FileSystem.get(FsConstants.VIEWFS_URI, conf);
assertEquals(ViewFileSystem.class, vfs.getClass());
FileStatus stat = vfs.getFileStatus(new Path(testfilename)); FileStatus stat = vfs.getFileStatus(new Path(testfilename));
assertEquals(len, stat.getLen()); assertEquals(len, stat.getLen());
// check serialization/deserialization // check serialization/deserialization
@ -89,9 +91,34 @@ public class TestViewFsFileStatusHdfs {
assertEquals(len, deSer.getLen()); assertEquals(len, deSer.getLen());
} }
@Test
public void testGetFileChecksum() throws IOException, URISyntaxException {
// Create two different files in HDFS
FileSystemTestHelper.createFile(fHdfs, someFile);
FileSystemTestHelper.createFile(fHdfs, FileSystemTestHelper
.getTestRootPath(fHdfs, someFile + "other"), 1, 512);
// Get checksum through ViewFS
FileChecksum viewFSCheckSum = vfs.getFileChecksum(
new Path("/vfstmp/someFileForTestGetFileChecksum"));
// Get checksum through HDFS.
FileChecksum hdfsCheckSum = fHdfs.getFileChecksum(
new Path(someFile));
// Get checksum of different file in HDFS
FileChecksum otherHdfsFileCheckSum = fHdfs.getFileChecksum(
new Path(someFile+"other"));
// Checksums of the same file (got through HDFS and ViewFS should be same)
assertEquals("HDFS and ViewFS checksums were not the same", viewFSCheckSum,
hdfsCheckSum);
// Checksum of different files should be different.
assertFalse("Some other HDFS file which should not have had the same " +
"checksum as viewFS did!", viewFSCheckSum.equals(otherHdfsFileCheckSum));
}
@AfterClass @AfterClass
public static void cleanup() throws IOException { public static void cleanup() throws IOException {
fHdfs.delete(new Path(testfilename), true); fHdfs.delete(new Path(testfilename), true);
fHdfs.delete(new Path(someFile), true);
fHdfs.delete(new Path(someFile + "other"), true);
} }
} }