HDFS-6645. Add test for successive Snapshots between XAttr modifications. Contributed by Stephen Chu.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1609388 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jing Zhao 2014-07-10 05:01:41 +00:00
parent d9c5f20333
commit 36492f084b
2 changed files with 65 additions and 2 deletions

View File

@ -275,6 +275,9 @@ Release 2.6.0 - UNRELEASED
HDFS-6627. Rename DataNode#checkWriteAccess to checkReadAccess.
(Liang Xie via cnauroth)
HDFS-6645. Add test for successive Snapshots between XAttr modifications.
(Stephen Chu via jing9)
OPTIMIZATIONS
BUG FIXES

View File

@ -57,8 +57,8 @@ public class TestXAttrWithSnapshot {
private static Configuration conf;
private static DistributedFileSystem hdfs;
private static int pathCount = 0;
private static Path path, snapshotPath;
private static String snapshotName;
private static Path path, snapshotPath, snapshotPath2, snapshotPath3;
private static String snapshotName, snapshotName2, snapshotName3;
private final int SUCCESS = 0;
// XAttrs
private static final String name1 = "user.a1";
@ -90,7 +90,11 @@ public class TestXAttrWithSnapshot {
++pathCount;
path = new Path("/p" + pathCount);
snapshotName = "snapshot" + pathCount;
snapshotName2 = snapshotName + "-2";
snapshotName3 = snapshotName + "-3";
snapshotPath = new Path(path, new Path(".snapshot", snapshotName));
snapshotPath2 = new Path(path, new Path(".snapshot", snapshotName2));
snapshotPath3 = new Path(path, new Path(".snapshot", snapshotName3));
}
/**
@ -260,6 +264,62 @@ public class TestXAttrWithSnapshot {
Assert.assertArrayEquals(value2, xattrs.get(name2));
}
/**
* Test successive snapshots in between modifications of XAttrs.
* Also verify that snapshot XAttrs are not altered when a
* snapshot is deleted.
*/
@Test
public void testSuccessiveSnapshotXAttrChanges() throws Exception {
// First snapshot
FileSystem.mkdirs(hdfs, path, FsPermission.createImmutable((short) 0700));
hdfs.setXAttr(path, name1, value1);
SnapshotTestHelper.createSnapshot(hdfs, path, snapshotName);
Map<String, byte[]> xattrs = hdfs.getXAttrs(snapshotPath);
Assert.assertEquals(1, xattrs.size());
Assert.assertArrayEquals(value1, xattrs.get(name1));
// Second snapshot
hdfs.setXAttr(path, name1, newValue1);
hdfs.setXAttr(path, name2, value2);
SnapshotTestHelper.createSnapshot(hdfs, path, snapshotName2);
xattrs = hdfs.getXAttrs(snapshotPath2);
Assert.assertEquals(2, xattrs.size());
Assert.assertArrayEquals(newValue1, xattrs.get(name1));
Assert.assertArrayEquals(value2, xattrs.get(name2));
// Third snapshot
hdfs.setXAttr(path, name1, value1);
hdfs.removeXAttr(path, name2);
SnapshotTestHelper.createSnapshot(hdfs, path, snapshotName3);
xattrs = hdfs.getXAttrs(snapshotPath3);
Assert.assertEquals(1, xattrs.size());
Assert.assertArrayEquals(value1, xattrs.get(name1));
// Check that the first and second snapshots'
// XAttrs have stayed constant
xattrs = hdfs.getXAttrs(snapshotPath);
Assert.assertEquals(1, xattrs.size());
Assert.assertArrayEquals(value1, xattrs.get(name1));
xattrs = hdfs.getXAttrs(snapshotPath2);
Assert.assertEquals(2, xattrs.size());
Assert.assertArrayEquals(newValue1, xattrs.get(name1));
Assert.assertArrayEquals(value2, xattrs.get(name2));
// Remove the second snapshot and verify the first and
// third snapshots' XAttrs have stayed constant
hdfs.deleteSnapshot(path, snapshotName2);
xattrs = hdfs.getXAttrs(snapshotPath);
Assert.assertEquals(1, xattrs.size());
Assert.assertArrayEquals(value1, xattrs.get(name1));
xattrs = hdfs.getXAttrs(snapshotPath3);
Assert.assertEquals(1, xattrs.size());
Assert.assertArrayEquals(value1, xattrs.get(name1));
hdfs.deleteSnapshot(path, snapshotName);
hdfs.deleteSnapshot(path, snapshotName3);
}
/**
* Assert exception of setting xattr on read-only snapshot.
*/