You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-commits@hadoop.apache.org by ji...@apache.org on 2014/01/09 01:53:08 UTC
svn commit: r1556688 [5/5] - in
/hadoop/common/branches/HDFS-5698/hadoop-hdfs-project:
hadoop-hdfs-nfs/src/main/java/org/apache/hadoop/hdfs/nfs/nfs3/ hadoop-hdfs/
hadoop-hdfs/src/main/java/
hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/ hadoop-hdfs/...
Modified: hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRenameWithSnapshots.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRenameWithSnapshots.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRenameWithSnapshots.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestRenameWithSnapshots.java Thu Jan 9 00:53:04 2014
@@ -44,6 +44,7 @@ import org.apache.hadoop.fs.permission.F
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.DFSOutputStream;
import org.apache.hadoop.hdfs.DFSTestUtil;
+import org.apache.hadoop.hdfs.DFSUtil;
import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.client.HdfsDataOutputStream.SyncFlag;
@@ -72,6 +73,7 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
+;
/** Testing rename with snapshots. */
public class TestRenameWithSnapshots {
@@ -402,9 +404,11 @@ public class TestRenameWithSnapshots {
final Path foo_s3 = SnapshotTestHelper.getSnapshotPath(sdir1, "s3",
"foo");
assertFalse(hdfs.exists(foo_s3));
+ INodeDirectorySnapshottable sdir2Node =
+ (INodeDirectorySnapshottable) fsdir.getINode(sdir2.toString());
+ Snapshot s2 = sdir2Node.getSnapshot(DFSUtil.string2Bytes("s2"));
INodeFile sfoo = fsdir.getINode(newfoo.toString()).asFile();
- assertEquals("s2", sfoo.getDiffs().getLastSnapshot().getRoot()
- .getLocalName());
+ assertEquals(s2.getId(), sfoo.getDiffs().getLastSnapshotId());
}
/**
@@ -604,8 +608,10 @@ public class TestRenameWithSnapshots {
INodeFile snode = fsdir.getINode(newfoo.toString()).asFile();
assertEquals(1, snode.getDiffs().asList().size());
- assertEquals("s2", snode.getDiffs().getLastSnapshot().getRoot()
- .getLocalName());
+ INodeDirectorySnapshottable sdir2Node =
+ (INodeDirectorySnapshottable) fsdir.getINode(sdir2.toString());
+ Snapshot s2 = sdir2Node.getSnapshot(DFSUtil.string2Bytes("s2"));
+ assertEquals(s2.getId(), snode.getDiffs().getLastSnapshotId());
// restart cluster
restartClusterAndCheckImage(true);
@@ -758,12 +764,14 @@ public class TestRenameWithSnapshots {
assertEquals(2, fooWithCount.getReferenceCount());
INodeDirectory foo = fooWithCount.asDirectory();
assertEquals(1, foo.getDiffs().asList().size());
- assertEquals("s1", foo.getDirectoryWithSnapshotFeature().getLastSnapshot()
- .getRoot().getLocalName());
+ INodeDirectorySnapshottable sdir1Node =
+ (INodeDirectorySnapshottable) fsdir.getINode(sdir1.toString());
+ Snapshot s1 = sdir1Node.getSnapshot(DFSUtil.string2Bytes("s1"));
+ assertEquals(s1.getId(), foo.getDirectoryWithSnapshotFeature()
+ .getLastSnapshotId());
INodeFile bar1 = fsdir.getINode4Write(bar1_dir1.toString()).asFile();
assertEquals(1, bar1.getDiffs().asList().size());
- assertEquals("s1", bar1.getDiffs().getLastSnapshot().getRoot()
- .getLocalName());
+ assertEquals(s1.getId(), bar1.getDiffs().getLastSnapshotId());
INodeReference barRef = fsdir.getINode4Write(bar2_dir1.toString())
.asReference();
@@ -772,8 +780,7 @@ public class TestRenameWithSnapshots {
assertEquals(2, barWithCount.getReferenceCount());
INodeFile bar = barWithCount.asFile();
assertEquals(1, bar.getDiffs().asList().size());
- assertEquals("s1", bar.getDiffs().getLastSnapshot().getRoot()
- .getLocalName());
+ assertEquals(s1.getId(), bar.getDiffs().getLastSnapshotId());
// restart the cluster and check fsimage
restartClusterAndCheckImage(true);
@@ -967,6 +974,13 @@ public class TestRenameWithSnapshots {
hdfs.rename(bar_dir2, bar_dir1);
// check the internal details
+ INodeDirectorySnapshottable sdir1Node =
+ (INodeDirectorySnapshottable) fsdir.getINode(sdir1.toString());
+ INodeDirectorySnapshottable sdir2Node =
+ (INodeDirectorySnapshottable) fsdir.getINode(sdir2.toString());
+ INodeDirectorySnapshottable sdir3Node =
+ (INodeDirectorySnapshottable) fsdir.getINode(sdir3.toString());
+
INodeReference fooRef = fsdir.getINode4Write(foo_dir1.toString())
.asReference();
INodeReference.WithCount fooWithCount = (WithCount) fooRef.getReferredINode();
@@ -975,16 +989,22 @@ public class TestRenameWithSnapshots {
INodeDirectory foo = fooWithCount.asDirectory();
List<DirectoryDiff> fooDiffs = foo.getDiffs().asList();
assertEquals(4, fooDiffs.size());
- assertEquals("s2222", fooDiffs.get(3).snapshot.getRoot().getLocalName());
- assertEquals("s333", fooDiffs.get(2).snapshot.getRoot().getLocalName());
- assertEquals("s22", fooDiffs.get(1).snapshot.getRoot().getLocalName());
- assertEquals("s1", fooDiffs.get(0).snapshot.getRoot().getLocalName());
+
+ Snapshot s2222 = sdir2Node.getSnapshot(DFSUtil.string2Bytes("s2222"));
+ Snapshot s333 = sdir3Node.getSnapshot(DFSUtil.string2Bytes("s333"));
+ Snapshot s22 = sdir2Node.getSnapshot(DFSUtil.string2Bytes("s22"));
+ Snapshot s1 = sdir1Node.getSnapshot(DFSUtil.string2Bytes("s1"));
+
+ assertEquals(s2222.getId(), fooDiffs.get(3).getSnapshotId());
+ assertEquals(s333.getId(), fooDiffs.get(2).getSnapshotId());
+ assertEquals(s22.getId(), fooDiffs.get(1).getSnapshotId());
+ assertEquals(s1.getId(), fooDiffs.get(0).getSnapshotId());
INodeFile bar1 = fsdir.getINode4Write(bar1_dir1.toString()).asFile();
List<FileDiff> bar1Diffs = bar1.getDiffs().asList();
assertEquals(3, bar1Diffs.size());
- assertEquals("s333", bar1Diffs.get(2).snapshot.getRoot().getLocalName());
- assertEquals("s22", bar1Diffs.get(1).snapshot.getRoot().getLocalName());
- assertEquals("s1", bar1Diffs.get(0).snapshot.getRoot().getLocalName());
+ assertEquals(s333.getId(), bar1Diffs.get(2).getSnapshotId());
+ assertEquals(s22.getId(), bar1Diffs.get(1).getSnapshotId());
+ assertEquals(s1.getId(), bar1Diffs.get(0).getSnapshotId());
INodeReference barRef = fsdir.getINode4Write(bar_dir1.toString())
.asReference();
@@ -994,10 +1014,10 @@ public class TestRenameWithSnapshots {
INodeFile bar = barWithCount.asFile();
List<FileDiff> barDiffs = bar.getDiffs().asList();
assertEquals(4, barDiffs.size());
- assertEquals("s2222", barDiffs.get(3).snapshot.getRoot().getLocalName());
- assertEquals("s333", barDiffs.get(2).snapshot.getRoot().getLocalName());
- assertEquals("s22", barDiffs.get(1).snapshot.getRoot().getLocalName());
- assertEquals("s1", barDiffs.get(0).snapshot.getRoot().getLocalName());
+ assertEquals(s2222.getId(), barDiffs.get(3).getSnapshotId());
+ assertEquals(s333.getId(), barDiffs.get(2).getSnapshotId());
+ assertEquals(s22.getId(), barDiffs.get(1).getSnapshotId());
+ assertEquals(s1.getId(), barDiffs.get(0).getSnapshotId());
// restart the cluster and check fsimage
restartClusterAndCheckImage(true);
@@ -1033,10 +1053,10 @@ public class TestRenameWithSnapshots {
foo = fooWithCount.asDirectory();
fooDiffs = foo.getDiffs().asList();
assertEquals(4, fooDiffs.size());
- assertEquals("s2222", fooDiffs.get(3).snapshot.getRoot().getLocalName());
+ assertEquals(s2222.getId(), fooDiffs.get(3).getSnapshotId());
bar1Diffs = bar1.getDiffs().asList();
assertEquals(3, bar1Diffs.size());
- assertEquals("s333", bar1Diffs.get(2).snapshot.getRoot().getLocalName());
+ assertEquals(s333.getId(), bar1Diffs.get(2).getSnapshotId());
barRef = fsdir.getINode(bar_s2222.toString()).asReference();
barWithCount = (WithCount) barRef.getReferredINode();
@@ -1044,7 +1064,7 @@ public class TestRenameWithSnapshots {
bar = barWithCount.asFile();
barDiffs = bar.getDiffs().asList();
assertEquals(4, barDiffs.size());
- assertEquals("s2222", barDiffs.get(3).snapshot.getRoot().getLocalName());
+ assertEquals(s2222.getId(), barDiffs.get(3).getSnapshotId());
}
/**
@@ -1164,6 +1184,9 @@ public class TestRenameWithSnapshots {
assertTrue(hdfs.exists(bar_s2));
// check internal details
+ INodeDirectorySnapshottable sdir2Node =
+ (INodeDirectorySnapshottable) fsdir.getINode(sdir2.toString());
+ Snapshot s2 = sdir2Node.getSnapshot(DFSUtil.string2Bytes("s2"));
final Path foo_s2 = SnapshotTestHelper.getSnapshotPath(sdir2, "s2", "foo");
INodeReference fooRef = fsdir.getINode(foo_s2.toString()).asReference();
assertTrue(fooRef instanceof INodeReference.WithName);
@@ -1172,7 +1195,7 @@ public class TestRenameWithSnapshots {
INodeDirectory fooDir = fooWC.getReferredINode().asDirectory();
List<DirectoryDiff> diffs = fooDir.getDiffs().asList();
assertEquals(1, diffs.size());
- assertEquals("s2", diffs.get(0).snapshot.getRoot().getLocalName());
+ assertEquals(s2.getId(), diffs.get(0).getSnapshotId());
// restart the cluster and check fsimage
restartClusterAndCheckImage(true);
@@ -1260,7 +1283,7 @@ public class TestRenameWithSnapshots {
INodeDirectory dir2 = fsdir.getINode4Write(sdir2.toString()).asDirectory();
INodeDirectory mockDir2 = spy(dir2);
doReturn(false).when(mockDir2).addChild((INode) anyObject(), anyBoolean(),
- (Snapshot) anyObject());
+ Mockito.anyInt());
INodeDirectory root = fsdir.getINode4Write("/").asDirectory();
root.replaceChild(dir2, mockDir2, fsdir.getINodeMap());
@@ -1271,12 +1294,14 @@ public class TestRenameWithSnapshots {
// check the current internal details
INodeDirectorySnapshottable dir1Node = (INodeDirectorySnapshottable) fsdir
.getINode4Write(sdir1.toString());
- ReadOnlyList<INode> dir1Children = dir1Node.getChildrenList(null);
+ Snapshot s1 = dir1Node.getSnapshot(DFSUtil.string2Bytes("s1"));
+ ReadOnlyList<INode> dir1Children = dir1Node
+ .getChildrenList(Snapshot.CURRENT_STATE_ID);
assertEquals(1, dir1Children.size());
assertEquals(foo.getName(), dir1Children.get(0).getLocalName());
List<DirectoryDiff> dir1Diffs = dir1Node.getDiffs().asList();
assertEquals(1, dir1Diffs.size());
- assertEquals("s1", dir1Diffs.get(0).snapshot.getRoot().getLocalName());
+ assertEquals(s1.getId(), dir1Diffs.get(0).getSnapshotId());
// after the undo of rename, both the created and deleted list of sdir1
// should be empty
@@ -1288,7 +1313,7 @@ public class TestRenameWithSnapshots {
assertTrue(fooNode.isDirectory() && fooNode.asDirectory().isWithSnapshot());
List<DirectoryDiff> fooDiffs = fooNode.asDirectory().getDiffs().asList();
assertEquals(1, fooDiffs.size());
- assertEquals("s1", fooDiffs.get(0).snapshot.getRoot().getLocalName());
+ assertEquals(s1.getId(), fooDiffs.get(0).getSnapshotId());
final Path foo_s1 = SnapshotTestHelper.getSnapshotPath(sdir1, "s1", "foo");
INode fooNode_s1 = fsdir.getINode(foo_s1.toString());
@@ -1299,7 +1324,8 @@ public class TestRenameWithSnapshots {
INodeDirectory dir2Node = fsdir.getINode4Write(sdir2.toString())
.asDirectory();
assertFalse(dir2Node.isWithSnapshot());
- ReadOnlyList<INode> dir2Children = dir2Node.getChildrenList(null);
+ ReadOnlyList<INode> dir2Children = dir2Node
+ .getChildrenList(Snapshot.CURRENT_STATE_ID);
assertEquals(1, dir2Children.size());
assertEquals(dir2file.getName(), dir2Children.get(0).getLocalName());
}
@@ -1327,7 +1353,7 @@ public class TestRenameWithSnapshots {
INodeDirectory dir2 = fsdir.getINode4Write(sdir2.toString()).asDirectory();
INodeDirectory mockDir2 = spy(dir2);
doReturn(false).when(mockDir2).addChild((INode) anyObject(), anyBoolean(),
- (Snapshot) anyObject());
+ Mockito.anyInt());
INodeDirectory root = fsdir.getINode4Write("/").asDirectory();
root.replaceChild(dir2, mockDir2, fsdir.getINodeMap());
@@ -1338,12 +1364,14 @@ public class TestRenameWithSnapshots {
// check the current internal details
INodeDirectorySnapshottable dir1Node = (INodeDirectorySnapshottable) fsdir
.getINode4Write(sdir1.toString());
- ReadOnlyList<INode> dir1Children = dir1Node.getChildrenList(null);
+ Snapshot s1 = dir1Node.getSnapshot(DFSUtil.string2Bytes("s1"));
+ ReadOnlyList<INode> dir1Children = dir1Node
+ .getChildrenList(Snapshot.CURRENT_STATE_ID);
assertEquals(1, dir1Children.size());
assertEquals(foo.getName(), dir1Children.get(0).getLocalName());
List<DirectoryDiff> dir1Diffs = dir1Node.getDiffs().asList();
assertEquals(1, dir1Diffs.size());
- assertEquals("s1", dir1Diffs.get(0).snapshot.getRoot().getLocalName());
+ assertEquals(s1.getId(), dir1Diffs.get(0).getSnapshotId());
// after the undo of rename, the created list of sdir1 should contain
// 1 element
@@ -1363,7 +1391,8 @@ public class TestRenameWithSnapshots {
INodeDirectory dir2Node = fsdir.getINode4Write(sdir2.toString())
.asDirectory();
assertFalse(dir2Node.isWithSnapshot());
- ReadOnlyList<INode> dir2Children = dir2Node.getChildrenList(null);
+ ReadOnlyList<INode> dir2Children = dir2Node
+ .getChildrenList(Snapshot.CURRENT_STATE_ID);
assertEquals(1, dir2Children.size());
assertEquals(dir2file.getName(), dir2Children.get(0).getLocalName());
}
@@ -1389,7 +1418,7 @@ public class TestRenameWithSnapshots {
INodeDirectory dir3 = fsdir.getINode4Write(sdir3.toString()).asDirectory();
INodeDirectory mockDir3 = spy(dir3);
doReturn(false).when(mockDir3).addChild((INode) anyObject(), anyBoolean(),
- (Snapshot) anyObject());
+ Mockito.anyInt());
INodeDirectory root = fsdir.getINode4Write("/").asDirectory();
root.replaceChild(dir3, mockDir3, fsdir.getINodeMap());
@@ -1400,13 +1429,18 @@ public class TestRenameWithSnapshots {
assertFalse(result);
// check the current internal details
+ INodeDirectorySnapshottable dir1Node = (INodeDirectorySnapshottable) fsdir
+ .getINode4Write(sdir1.toString());
+ Snapshot s1 = dir1Node.getSnapshot(DFSUtil.string2Bytes("s1"));
INodeDirectorySnapshottable dir2Node = (INodeDirectorySnapshottable) fsdir
.getINode4Write(sdir2.toString());
- ReadOnlyList<INode> dir2Children = dir2Node.getChildrenList(null);
+ Snapshot s2 = dir2Node.getSnapshot(DFSUtil.string2Bytes("s2"));
+ ReadOnlyList<INode> dir2Children = dir2Node
+ .getChildrenList(Snapshot.CURRENT_STATE_ID);
assertEquals(1, dir2Children.size());
List<DirectoryDiff> dir2Diffs = dir2Node.getDiffs().asList();
assertEquals(1, dir2Diffs.size());
- assertEquals("s2", Snapshot.getSnapshotName(dir2Diffs.get(0).snapshot));
+ assertEquals(s2.getId(), dir2Diffs.get(0).getSnapshotId());
ChildrenDiff childrenDiff = dir2Diffs.get(0).getChildrenDiff();
assertEquals(0, childrenDiff.getList(ListType.DELETED).size());
assertEquals(1, childrenDiff.getList(ListType.CREATED).size());
@@ -1418,7 +1452,7 @@ public class TestRenameWithSnapshots {
assertTrue(fooNode instanceof INodeReference.DstReference);
List<DirectoryDiff> fooDiffs = fooNode.asDirectory().getDiffs().asList();
assertEquals(1, fooDiffs.size());
- assertEquals("s1", fooDiffs.get(0).snapshot.getRoot().getLocalName());
+ assertEquals(s1.getId(), fooDiffs.get(0).getSnapshotId());
// create snapshot on sdir2 and rename again
hdfs.createSnapshot(sdir2, "s3");
@@ -1428,13 +1462,14 @@ public class TestRenameWithSnapshots {
// check internal details again
dir2Node = (INodeDirectorySnapshottable) fsdir.getINode4Write(sdir2
.toString());
+ Snapshot s3 = dir2Node.getSnapshot(DFSUtil.string2Bytes("s3"));
fooNode = fsdir.getINode4Write(foo_dir2.toString());
- dir2Children = dir2Node.getChildrenList(null);
+ dir2Children = dir2Node.getChildrenList(Snapshot.CURRENT_STATE_ID);
assertEquals(1, dir2Children.size());
dir2Diffs = dir2Node.getDiffs().asList();
assertEquals(2, dir2Diffs.size());
- assertEquals("s2", Snapshot.getSnapshotName(dir2Diffs.get(0).snapshot));
- assertEquals("s3", Snapshot.getSnapshotName(dir2Diffs.get(1).snapshot));
+ assertEquals(s2.getId(), dir2Diffs.get(0).getSnapshotId());
+ assertEquals(s3.getId(), dir2Diffs.get(1).getSnapshotId());
childrenDiff = dir2Diffs.get(0).getChildrenDiff();
assertEquals(0, childrenDiff.getList(ListType.DELETED).size());
@@ -1452,8 +1487,8 @@ public class TestRenameWithSnapshots {
assertTrue(fooNode instanceof INodeReference.DstReference);
fooDiffs = fooNode.asDirectory().getDiffs().asList();
assertEquals(2, fooDiffs.size());
- assertEquals("s1", fooDiffs.get(0).snapshot.getRoot().getLocalName());
- assertEquals("s3", fooDiffs.get(1).snapshot.getRoot().getLocalName());
+ assertEquals(s1.getId(), fooDiffs.get(0).getSnapshotId());
+ assertEquals(s3.getId(), fooDiffs.get(1).getSnapshotId());
}
/**
@@ -1489,9 +1524,9 @@ public class TestRenameWithSnapshots {
INodeDirectory mockDir3 = spy(dir3);
// fail the rename but succeed in undo
doReturn(false).when(mockDir3).addChild((INode) Mockito.isNull(),
- anyBoolean(), (Snapshot) anyObject());
+ anyBoolean(), Mockito.anyInt());
Mockito.when(mockDir3.addChild((INode) Mockito.isNotNull(), anyBoolean(),
- (Snapshot) anyObject())).thenReturn(false).thenCallRealMethod();
+ Mockito.anyInt())).thenReturn(false).thenCallRealMethod();
INodeDirectory root = fsdir.getINode4Write("/").asDirectory();
root.replaceChild(dir3, mockDir3, fsdir.getINodeMap());
foo3Node.setParent(mockDir3);
@@ -1551,7 +1586,7 @@ public class TestRenameWithSnapshots {
INodeDirectory dir1Node = fsdir.getINode4Write(dir1.toString())
.asDirectory();
List<INode> childrenList = ReadOnlyList.Util.asList(dir1Node
- .getChildrenList(null));
+ .getChildrenList(Snapshot.CURRENT_STATE_ID));
assertEquals(1, childrenList.size());
INode fooNode = childrenList.get(0);
assertTrue(fooNode.asDirectory().isWithSnapshot());
@@ -1572,7 +1607,7 @@ public class TestRenameWithSnapshots {
assertEquals(3, counts.get(Quota.NAMESPACE));
assertEquals(0, counts.get(Quota.DISKSPACE));
childrenList = ReadOnlyList.Util.asList(dir2Node.asDirectory()
- .getChildrenList(null));
+ .getChildrenList(Snapshot.CURRENT_STATE_ID));
assertEquals(1, childrenList.size());
INode subdir2Node = childrenList.get(0);
assertSame(dir2Node, subdir2Node.getParent());
@@ -1627,7 +1662,7 @@ public class TestRenameWithSnapshots {
INodeDirectory dir1Node = fsdir.getINode4Write(dir1.toString())
.asDirectory();
List<INode> childrenList = ReadOnlyList.Util.asList(dir1Node
- .getChildrenList(null));
+ .getChildrenList(Snapshot.CURRENT_STATE_ID));
assertEquals(1, childrenList.size());
INode fooNode = childrenList.get(0);
assertTrue(fooNode.asDirectory().isWithSnapshot());
@@ -1646,7 +1681,7 @@ public class TestRenameWithSnapshots {
assertEquals(4, counts.get(Quota.NAMESPACE));
assertEquals(0, counts.get(Quota.DISKSPACE));
childrenList = ReadOnlyList.Util.asList(dir2Node.asDirectory()
- .getChildrenList(null));
+ .getChildrenList(Snapshot.CURRENT_STATE_ID));
assertEquals(1, childrenList.size());
INode subdir2Node = childrenList.get(0);
assertTrue(subdir2Node.asDirectory().isWithSnapshot());
@@ -1690,14 +1725,18 @@ public class TestRenameWithSnapshots {
}
// check
+ INodeDirectorySnapshottable rootNode = (INodeDirectorySnapshottable) fsdir
+ .getINode4Write(root.toString());
INodeDirectory fooNode = fsdir.getINode4Write(foo.toString()).asDirectory();
- ReadOnlyList<INode> children = fooNode.getChildrenList(null);
+ ReadOnlyList<INode> children = fooNode
+ .getChildrenList(Snapshot.CURRENT_STATE_ID);
assertEquals(1, children.size());
List<DirectoryDiff> diffList = fooNode.getDiffs().asList();
assertEquals(1, diffList.size());
DirectoryDiff diff = diffList.get(0);
// this diff is generated while renaming
- assertEquals(snap1, Snapshot.getSnapshotName(diff.snapshot));
+ Snapshot s1 = rootNode.getSnapshot(DFSUtil.string2Bytes(snap1));
+ assertEquals(s1.getId(), diff.getSnapshotId());
// after undo, the diff should be empty
assertTrue(diff.getChildrenDiff().getList(ListType.DELETED).isEmpty());
assertTrue(diff.getChildrenDiff().getList(ListType.CREATED).isEmpty());
@@ -1709,7 +1748,7 @@ public class TestRenameWithSnapshots {
List<FileDiff> barDiffList = barNode.getDiffs().asList();
assertEquals(1, barDiffList.size());
FileDiff barDiff = barDiffList.get(0);
- assertEquals(snap1, Snapshot.getSnapshotName(barDiff.snapshot));
+ assertEquals(s1.getId(), barDiff.getSnapshotId());
// restart cluster multiple times to make sure the fsimage and edits log are
// correct. Note that when loading fsimage, foo and bar will be converted
@@ -1941,12 +1980,14 @@ public class TestRenameWithSnapshots {
(WithCount) fooRef.asReference().getReferredINode();
assertEquals(1, wc.getReferenceCount());
INodeDirectory fooNode = wc.getReferredINode().asDirectory();
- ReadOnlyList<INode> children = fooNode.getChildrenList(null);
+ ReadOnlyList<INode> children = fooNode
+ .getChildrenList(Snapshot.CURRENT_STATE_ID);
assertEquals(1, children.size());
assertEquals(bar.getName(), children.get(0).getLocalName());
List<DirectoryDiff> diffList = fooNode.getDiffs().asList();
assertEquals(1, diffList.size());
- assertEquals("s1", Snapshot.getSnapshotName(diffList.get(0).snapshot));
+ Snapshot s1 = dir1Node.getSnapshot(DFSUtil.string2Bytes("s1"));
+ assertEquals(s1.getId(), diffList.get(0).getSnapshotId());
ChildrenDiff diff = diffList.get(0).getChildrenDiff();
assertEquals(0, diff.getList(ListType.CREATED).size());
assertEquals(0, diff.getList(ListType.DELETED).size());
@@ -2009,14 +2050,16 @@ public class TestRenameWithSnapshots {
(WithCount) fooRef.asReference().getReferredINode();
assertEquals(2, wc.getReferenceCount());
INodeDirectory fooNode = wc.getReferredINode().asDirectory();
- ReadOnlyList<INode> children = fooNode.getChildrenList(null);
+ ReadOnlyList<INode> children = fooNode
+ .getChildrenList(Snapshot.CURRENT_STATE_ID);
assertEquals(3, children.size());
assertEquals(bar.getName(), children.get(0).getLocalName());
assertEquals(bar2.getName(), children.get(1).getLocalName());
assertEquals(bar3.getName(), children.get(2).getLocalName());
List<DirectoryDiff> diffList = fooNode.getDiffs().asList();
assertEquals(1, diffList.size());
- assertEquals("s1", Snapshot.getSnapshotName(diffList.get(0).snapshot));
+ Snapshot s1 = dir1Node.getSnapshot(DFSUtil.string2Bytes("s1"));
+ assertEquals(s1.getId(), diffList.get(0).getSnapshotId());
ChildrenDiff diff = diffList.get(0).getChildrenDiff();
// bar2 and bar3 in the created list
assertEquals(2, diff.getList(ListType.CREATED).size());
@@ -2134,11 +2177,12 @@ public class TestRenameWithSnapshots {
// recordModification before the rename
assertTrue(fooNode.isWithSnapshot());
assertTrue(fooNode.getDiffs().asList().isEmpty());
- INodeDirectory barNode = fooNode.getChildrenList(null).get(0).asDirectory();
+ INodeDirectory barNode = fooNode.getChildrenList(Snapshot.CURRENT_STATE_ID)
+ .get(0).asDirectory();
// bar should also be INodeDirectory (With Snapshot), and both of its diff
// list and children list are empty
assertTrue(barNode.getDiffs().asList().isEmpty());
- assertTrue(barNode.getChildrenList(null).isEmpty());
+ assertTrue(barNode.getChildrenList(Snapshot.CURRENT_STATE_ID).isEmpty());
restartClusterAndCheckImage(true);
}
@@ -2210,7 +2254,10 @@ public class TestRenameWithSnapshots {
List<DirectoryDiff> barDiffList = barNode.getDiffs().asList();
assertEquals(1, barDiffList.size());
DirectoryDiff diff = barDiffList.get(0);
- assertEquals("s0", Snapshot.getSnapshotName(diff.snapshot));
+ INodeDirectorySnapshottable testNode =
+ (INodeDirectorySnapshottable) fsdir.getINode4Write(test.toString());
+ Snapshot s0 = testNode.getSnapshot(DFSUtil.string2Bytes("s0"));
+ assertEquals(s0.getId(), diff.getSnapshotId());
// and file should be stored in the deleted list of this snapshot diff
assertEquals("file", diff.getChildrenDiff().getList(ListType.DELETED)
.get(0).getLocalName());
@@ -2276,7 +2323,7 @@ public class TestRenameWithSnapshots {
final Path barInS0 = SnapshotTestHelper.getSnapshotPath(test, "s0",
"foo/bar");
INodeDirectory barNode = fsdir.getINode(barInS0.toString()).asDirectory();
- assertEquals(0, barNode.getChildrenList(null).size());
+ assertEquals(0, barNode.getChildrenList(Snapshot.CURRENT_STATE_ID).size());
List<DirectoryDiff> diffList = barNode.getDiffs().asList();
assertEquals(1, diffList.size());
DirectoryDiff diff = diffList.get(0);
Modified: hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSetQuotaWithSnapshot.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSetQuotaWithSnapshot.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSetQuotaWithSnapshot.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSetQuotaWithSnapshot.java Thu Jan 9 00:53:04 2014
@@ -28,6 +28,7 @@ import org.apache.hadoop.conf.Configurat
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.hdfs.DFSTestUtil;
+import org.apache.hadoop.hdfs.DFSUtil;
import org.apache.hadoop.hdfs.DistributedFileSystem;
import org.apache.hadoop.hdfs.MiniDFSCluster;
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
@@ -153,7 +154,9 @@ public class TestSetQuotaWithSnapshot {
assertTrue(subNode.asDirectory().isWithSnapshot());
List<DirectoryDiff> diffList = subNode.asDirectory().getDiffs().asList();
assertEquals(1, diffList.size());
- assertEquals("s2", Snapshot.getSnapshotName(diffList.get(0).snapshot));
+ Snapshot s2 = ((INodeDirectorySnapshottable) dirNode).getSnapshot(DFSUtil
+ .string2Bytes("s2"));
+ assertEquals(s2.getId(), diffList.get(0).getSnapshotId());
List<INode> createdList = diffList.get(0).getChildrenDiff().getList(ListType.CREATED);
assertEquals(1, createdList.size());
assertSame(fsdir.getINode4Write(file.toString()), createdList.get(0));
Modified: hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDeletion.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDeletion.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDeletion.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotDeletion.java Thu Jan 9 00:53:04 2014
@@ -268,7 +268,8 @@ public class TestSnapshotDeletion {
(INodeDirectory) fsdir.getINode(snapshotNoChangeDir.toString());
// should still be an INodeDirectory
assertEquals(INodeDirectory.class, snapshotNode.getClass());
- ReadOnlyList<INode> children = snapshotNode.getChildrenList(null);
+ ReadOnlyList<INode> children = snapshotNode
+ .getChildrenList(Snapshot.CURRENT_STATE_ID);
// check 2 children: noChangeFile and metaChangeFile2
assertEquals(2, children.size());
INode noChangeFileSCopy = children.get(1);
@@ -286,11 +287,11 @@ public class TestSnapshotDeletion {
// check the replication factor of metaChangeFile2SCopy
assertEquals(REPLICATION_1,
- metaChangeFile2SCopy.getFileReplication(null));
+ metaChangeFile2SCopy.getFileReplication(Snapshot.CURRENT_STATE_ID));
assertEquals(REPLICATION_1,
- metaChangeFile2SCopy.getFileReplication(snapshot1));
+ metaChangeFile2SCopy.getFileReplication(snapshot1.getId()));
assertEquals(REPLICATION,
- metaChangeFile2SCopy.getFileReplication(snapshot0));
+ metaChangeFile2SCopy.getFileReplication(snapshot0.getId()));
// Case 4: delete directory sub
// before deleting sub, we first create a new file under sub
@@ -316,23 +317,25 @@ public class TestSnapshotDeletion {
assertTrue(snapshotNode4Sub.isWithSnapshot());
// the snapshot copy of sub has only one child subsub.
// newFile should have been destroyed
- assertEquals(1, snapshotNode4Sub.getChildrenList(null).size());
+ assertEquals(1, snapshotNode4Sub.getChildrenList(Snapshot.CURRENT_STATE_ID)
+ .size());
// but should have two children, subsub and noChangeDir, when s1 was taken
- assertEquals(2, snapshotNode4Sub.getChildrenList(snapshot1).size());
+ assertEquals(2, snapshotNode4Sub.getChildrenList(snapshot1.getId()).size());
// check the snapshot copy of subsub, which is contained in the subtree of
// sub's snapshot copy
- INode snapshotNode4Subsub = snapshotNode4Sub.getChildrenList(null).get(0);
+ INode snapshotNode4Subsub = snapshotNode4Sub.getChildrenList(
+ Snapshot.CURRENT_STATE_ID).get(0);
assertTrue(snapshotNode4Subsub.asDirectory().isWithSnapshot());
assertTrue(snapshotNode4Sub == snapshotNode4Subsub.getParent());
// check the children of subsub
INodeDirectory snapshotSubsubDir = (INodeDirectory) snapshotNode4Subsub;
- children = snapshotSubsubDir.getChildrenList(null);
+ children = snapshotSubsubDir.getChildrenList(Snapshot.CURRENT_STATE_ID);
assertEquals(2, children.size());
assertEquals(children.get(0).getLocalName(), metaChangeFile1.getName());
assertEquals(children.get(1).getLocalName(), newFileAfterS0.getName());
// only one child before snapshot s0
- children = snapshotSubsubDir.getChildrenList(snapshot0);
+ children = snapshotSubsubDir.getChildrenList(snapshot0.getId());
assertEquals(1, children.size());
INode child = children.get(0);
assertEquals(child.getLocalName(), metaChangeFile1.getName());
@@ -341,11 +344,11 @@ public class TestSnapshotDeletion {
assertTrue(metaChangeFile1SCopy.isWithSnapshot());
assertFalse(metaChangeFile1SCopy.isUnderConstruction());
assertEquals(REPLICATION_1,
- metaChangeFile1SCopy.getFileReplication(null));
+ metaChangeFile1SCopy.getFileReplication(Snapshot.CURRENT_STATE_ID));
assertEquals(REPLICATION_1,
- metaChangeFile1SCopy.getFileReplication(snapshot1));
+ metaChangeFile1SCopy.getFileReplication(snapshot1.getId()));
assertEquals(REPLICATION,
- metaChangeFile1SCopy.getFileReplication(snapshot0));
+ metaChangeFile1SCopy.getFileReplication(snapshot0.getId()));
}
/**
@@ -474,9 +477,10 @@ public class TestSnapshotDeletion {
(INodeDirectorySnapshottable) fsdir.getINode(dir.toString());
Snapshot snapshot0 = dirNode.getSnapshot(DFSUtil.string2Bytes("s0"));
assertNull(snapshot0);
+ Snapshot snapshot1 = dirNode.getSnapshot(DFSUtil.string2Bytes("s1"));
DirectoryDiffList diffList = dirNode.getDiffs();
assertEquals(1, diffList.asList().size());
- assertEquals("s1", diffList.getLast().snapshot.getRoot().getLocalName());
+ assertEquals(snapshot1.getId(), diffList.getLast().getSnapshotId());
diffList = fsdir.getINode(metaChangeDir.toString()).asDirectory()
.getDiffs();
assertEquals(0, diffList.asList().size());
Modified: hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotRename.java Thu Jan 9 00:53:04 2014
@@ -101,7 +101,8 @@ public class TestSnapshotRename {
List<DirectoryDiff> listByTime = srcRoot.getDiffs().asList();
assertEquals(names.length, listByTime.size());
for (int i = 0; i < listByTime.size(); i++) {
- assertEquals(names[i], listByTime.get(i).getSnapshot().getRoot().getLocalName());
+ Snapshot s = srcRoot.getSnapshotById(listByTime.get(i).getSnapshotId());
+ assertEquals(names[i], s.getRoot().getLocalName());
}
}
Modified: hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotReplication.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotReplication.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotReplication.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/snapshot/TestSnapshotReplication.java Thu Jan 9 00:53:04 2014
@@ -150,7 +150,7 @@ public class TestSnapshotReplication {
assertEquals(expectedBlockRep, ssInode.getBlockReplication());
// Also check the number derived from INodeFile#getFileReplication
assertEquals(snapshotRepMap.get(ss).shortValue(),
- ssInode.getFileReplication(iip.getPathSnapshot()));
+ ssInode.getFileReplication(iip.getPathSnapshotId()));
}
}
Modified: hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java?rev=1556688&r1=1556687&r2=1556688&view=diff
==============================================================================
--- hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java (original)
+++ hadoop/common/branches/HDFS-5698/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/TestOfflineEditsViewer.java Thu Jan 9 00:53:04 2014
@@ -26,8 +26,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
-import java.util.HashMap;
-import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -36,168 +34,142 @@ import org.apache.hadoop.hdfs.server.nam
import org.apache.hadoop.hdfs.server.namenode.OfflineEditsViewerHelper;
import org.apache.hadoop.hdfs.tools.offlineEditsViewer.OfflineEditsViewer.Flags;
import org.apache.hadoop.test.PathUtils;
+import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
-public class TestOfflineEditsViewer {
- private static final Log LOG = LogFactory.getLog(TestOfflineEditsViewer.class);
-
- private static final Map<FSEditLogOpCodes, Boolean> obsoleteOpCodes =
- new HashMap<FSEditLogOpCodes, Boolean>();
-
- private static final Map<FSEditLogOpCodes, Boolean> missingOpCodes =
- new HashMap<FSEditLogOpCodes, Boolean>();
+import com.google.common.collect.ImmutableSet;
- static {
- initializeObsoleteOpCodes();
- initializeMissingOpCodes();
- }
-
- private static String buildDir =
- PathUtils.getTestDirName(TestOfflineEditsViewer.class);
+public class TestOfflineEditsViewer {
+ private static final Log LOG = LogFactory
+ .getLog(TestOfflineEditsViewer.class);
- private static String cacheDir =
- System.getProperty("test.cache.data", "build/test/cache");
+ private static String buildDir = PathUtils
+ .getTestDirName(TestOfflineEditsViewer.class);
// to create edits and get edits filename
- private static final OfflineEditsViewerHelper nnHelper
- = new OfflineEditsViewerHelper();
+ private static final OfflineEditsViewerHelper nnHelper = new OfflineEditsViewerHelper();
+ private static final ImmutableSet<FSEditLogOpCodes> skippedOps = skippedOps();
- /**
- * Initialize obsoleteOpCodes
- *
- * Reason for suppressing "deprecation" warnings:
- *
- * These are the opcodes that are not used anymore, some
- * are marked deprecated, we need to include them here to make
- * sure we exclude them when checking for completeness of testing,
- * that's why the "deprecation" warnings are suppressed.
- */
@SuppressWarnings("deprecation")
- private static void initializeObsoleteOpCodes() {
- obsoleteOpCodes.put(FSEditLogOpCodes.OP_DATANODE_ADD, true);
- obsoleteOpCodes.put(FSEditLogOpCodes.OP_DATANODE_REMOVE, true);
- obsoleteOpCodes.put(FSEditLogOpCodes.OP_SET_NS_QUOTA, true);
- obsoleteOpCodes.put(FSEditLogOpCodes.OP_CLEAR_NS_QUOTA, true);
+ private static ImmutableSet<FSEditLogOpCodes> skippedOps() {
+ ImmutableSet.Builder<FSEditLogOpCodes> b = ImmutableSet
+ .<FSEditLogOpCodes> builder();
+
+ // Deprecated opcodes
+ b.add(FSEditLogOpCodes.OP_DATANODE_ADD)
+ .add(FSEditLogOpCodes.OP_DATANODE_REMOVE)
+ .add(FSEditLogOpCodes.OP_SET_NS_QUOTA)
+ .add(FSEditLogOpCodes.OP_CLEAR_NS_QUOTA)
+ .add(FSEditLogOpCodes.OP_SET_GENSTAMP_V1);
+
+ // Cannot test delegation token related code in insecure set up
+ b.add(FSEditLogOpCodes.OP_GET_DELEGATION_TOKEN)
+ .add(FSEditLogOpCodes.OP_RENEW_DELEGATION_TOKEN)
+ .add(FSEditLogOpCodes.OP_CANCEL_DELEGATION_TOKEN);
+
+ // Skip invalid opcode
+ b.add(FSEditLogOpCodes.OP_INVALID);
+ return b.build();
}
- /**
- * Initialize missingOpcodes
- *
- * Opcodes that are not available except after uprade from
- * an older version. We don't test these here.
- */
- private static void initializeMissingOpCodes() {
- obsoleteOpCodes.put(FSEditLogOpCodes.OP_SET_GENSTAMP_V1, true);
- }
+ @Rule
+ public final TemporaryFolder folder = new TemporaryFolder();
@Before
- public void setup() {
- new File(cacheDir).mkdirs();
+ public void setUp() throws IOException {
+ nnHelper.startCluster(buildDir + "/dfs/");
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ nnHelper.shutdownCluster();
}
-
+
/**
* Test the OfflineEditsViewer
*/
@Test
public void testGenerated() throws IOException {
-
- LOG.info("START - testing with generated edits");
-
- nnHelper.startCluster(buildDir + "/dfs/");
-
// edits generated by nnHelper (MiniDFSCluster), should have all op codes
// binary, XML, reparsed binary
- String edits = nnHelper.generateEdits();
- String editsParsedXml = cacheDir + "/editsParsed.xml";
- String editsReparsed = cacheDir + "/editsReparsed";
+ String edits = nnHelper.generateEdits();
+ String editsParsedXml = folder.newFile("editsParsed.xml").getAbsolutePath();
+ String editsReparsed = folder.newFile("editsParsed").getAbsolutePath();
// parse to XML then back to binary
assertEquals(0, runOev(edits, editsParsedXml, "xml", false));
assertEquals(0, runOev(editsParsedXml, editsReparsed, "binary", false));
// judgment time
+ assertTrue("Edits " + edits + " should have all op codes",
+ hasAllOpCodes(edits));
+ LOG.info("Comparing generated file " + editsReparsed
+ + " with reference file " + edits);
assertTrue(
- "Edits " + edits + " should have all op codes",
- hasAllOpCodes(edits));
- LOG.info("Comparing generated file " + editsReparsed +
- " with reference file " + edits);
- assertTrue(
- "Generated edits and reparsed (bin to XML to bin) should be same",
- filesEqualIgnoreTrailingZeros(edits, editsReparsed));
-
- // removes edits so do this at the end
- nnHelper.shutdownCluster();
-
- LOG.info("END");
+ "Generated edits and reparsed (bin to XML to bin) should be same",
+ filesEqualIgnoreTrailingZeros(edits, editsReparsed));
}
@Test
public void testRecoveryMode() throws IOException {
- LOG.info("START - testing with generated edits");
-
- nnHelper.startCluster(buildDir + "/dfs/");
-
// edits generated by nnHelper (MiniDFSCluster), should have all op codes
// binary, XML, reparsed binary
- String edits = nnHelper.generateEdits();
-
+ String edits = nnHelper.generateEdits();
+ FileOutputStream os = new FileOutputStream(edits, true);
// Corrupt the file by truncating the end
- FileChannel editsFile = new FileOutputStream(edits, true).getChannel();
+ FileChannel editsFile = os.getChannel();
editsFile.truncate(editsFile.size() - 5);
-
- String editsParsedXml = cacheDir + "/editsRecoveredParsed.xml";
- String editsReparsed = cacheDir + "/editsRecoveredReparsed";
- String editsParsedXml2 = cacheDir + "/editsRecoveredParsed2.xml";
+
+ String editsParsedXml = folder.newFile("editsRecoveredParsed.xml")
+ .getAbsolutePath();
+ String editsReparsed = folder.newFile("editsRecoveredReparsed")
+ .getAbsolutePath();
+ String editsParsedXml2 = folder.newFile("editsRecoveredParsed2.xml")
+ .getAbsolutePath();
// Can't read the corrupted file without recovery mode
assertEquals(-1, runOev(edits, editsParsedXml, "xml", false));
-
+
// parse to XML then back to binary
assertEquals(0, runOev(edits, editsParsedXml, "xml", true));
- assertEquals(0, runOev(editsParsedXml, editsReparsed, "binary", false));
+ assertEquals(0, runOev(editsParsedXml, editsReparsed, "binary", false));
assertEquals(0, runOev(editsReparsed, editsParsedXml2, "xml", false));
// judgment time
assertTrue("Test round trip",
- filesEqualIgnoreTrailingZeros(editsParsedXml, editsParsedXml2));
+ filesEqualIgnoreTrailingZeros(editsParsedXml, editsParsedXml2));
- // removes edits so do this at the end
- nnHelper.shutdownCluster();
-
- LOG.info("END");
+ os.close();
}
@Test
public void testStored() throws IOException {
-
- LOG.info("START - testing with stored reference edits");
-
// reference edits stored with source code (see build.xml)
+ final String cacheDir = System.getProperty("test.cache.data",
+ "build/test/cache");
// binary, XML, reparsed binary
- String editsStored = cacheDir + "/editsStored";
- String editsStoredParsedXml = cacheDir + "/editsStoredParsed.xml";
- String editsStoredReparsed = cacheDir + "/editsStoredReparsed";
+ String editsStored = cacheDir + "/editsStored";
+ String editsStoredParsedXml = cacheDir + "/editsStoredParsed.xml";
+ String editsStoredReparsed = cacheDir + "/editsStoredReparsed";
// reference XML version of editsStored (see build.xml)
- String editsStoredXml = cacheDir + "/editsStored.xml";
-
+ String editsStoredXml = cacheDir + "/editsStored.xml";
+
// parse to XML then back to binary
assertEquals(0, runOev(editsStored, editsStoredParsedXml, "xml", false));
- assertEquals(0, runOev(editsStoredParsedXml, editsStoredReparsed,
- "binary", false));
+ assertEquals(0,
+ runOev(editsStoredParsedXml, editsStoredReparsed, "binary", false));
// judgement time
+ assertTrue("Edits " + editsStored + " should have all op codes",
+ hasAllOpCodes(editsStored));
+ assertTrue("Reference XML edits and parsed to XML should be same",
+ filesEqual(editsStoredXml, editsStoredParsedXml));
assertTrue(
- "Edits " + editsStored + " should have all op codes",
- hasAllOpCodes(editsStored));
- assertTrue(
- "Reference XML edits and parsed to XML should be same",
- filesEqual(editsStoredXml, editsStoredParsedXml));
- assertTrue(
- "Reference edits and reparsed (bin to XML to bin) should be same",
- filesEqualIgnoreTrailingZeros(editsStored, editsStoredReparsed));
-
- LOG.info("END");
+ "Reference edits and reparsed (bin to XML to bin) should be same",
+ filesEqualIgnoreTrailingZeros(editsStored, editsStoredReparsed));
}
/**
@@ -233,22 +205,17 @@ public class TestOfflineEditsViewer {
OfflineEditsViewer oev = new OfflineEditsViewer();
if (oev.go(inFilename, outFilename, "stats", new Flags(), visitor) != 0)
return false;
- LOG.info("Statistics for " + inFilename + "\n" +
- visitor.getStatisticsString());
-
+ LOG.info("Statistics for " + inFilename + "\n"
+ + visitor.getStatisticsString());
+
boolean hasAllOpCodes = true;
- for(FSEditLogOpCodes opCode : FSEditLogOpCodes.values()) {
+ for (FSEditLogOpCodes opCode : FSEditLogOpCodes.values()) {
// don't need to test obsolete opCodes
- if(obsoleteOpCodes.containsKey(opCode)) {
+ if (skippedOps.contains(opCode))
continue;
- } else if (missingOpCodes.containsKey(opCode)) {
- continue;
- } else if (opCode == FSEditLogOpCodes.OP_INVALID) {
- continue;
- }
Long count = visitor.getStatistics().get(opCode);
- if((count == null) || (count == 0)) {
+ if ((count == null) || (count == 0)) {
hasAllOpCodes = false;
LOG.info("Opcode " + opCode + " not tested in " + inFilename);
}
@@ -257,9 +224,9 @@ public class TestOfflineEditsViewer {
}
/**
- * Compare two files, ignore trailing zeros at the end,
- * for edits log the trailing zeros do not make any difference,
- * throw exception is the files are not same
+ * Compare two files, ignore trailing zeros at the end, for edits log the
+ * trailing zeros do not make any difference, throw exception is the files are
+ * not same
*
* @param filenameSmall first file to compare (doesn't have to be smaller)
* @param filenameLarge second file to compare (doesn't have to be larger)
@@ -271,7 +238,7 @@ public class TestOfflineEditsViewer {
ByteBuffer large = ByteBuffer.wrap(DFSTestUtil.loadFile(filenameLarge));
// now correct if it's otherwise
- if(small.capacity() > large.capacity()) {
+ if (small.capacity() > large.capacity()) {
ByteBuffer tmpByteBuffer = small;
small = large;
large = tmpByteBuffer;
@@ -288,13 +255,15 @@ public class TestOfflineEditsViewer {
large.limit(small.capacity());
// compares position to limit
- if(!small.equals(large)) { return false; }
+ if (!small.equals(large)) {
+ return false;
+ }
// everything after limit should be 0xFF
int i = large.limit();
large.clear();
- for(; i < large.capacity(); i++) {
- if(large.get(i) != FSEditLogOpCodes.OP_INVALID.getOpCode()) {
+ for (; i < large.capacity(); i++) {
+ if (large.get(i) != FSEditLogOpCodes.OP_INVALID.getOpCode()) {
return false;
}
}