|
@@ -62,7 +62,6 @@ public class TestDistCpSync {
|
|
|
|
|
|
options = new DistCpOptions(Arrays.asList(source), target);
|
|
options = new DistCpOptions(Arrays.asList(source), target);
|
|
options.setSyncFolder(true);
|
|
options.setSyncFolder(true);
|
|
- options.setDeleteMissing(true);
|
|
|
|
options.setUseDiff(true, "s1", "s2");
|
|
options.setUseDiff(true, "s1", "s2");
|
|
options.appendToConf(conf);
|
|
options.appendToConf(conf);
|
|
|
|
|
|
@@ -87,7 +86,7 @@ public class TestDistCpSync {
|
|
@Test
|
|
@Test
|
|
public void testFallback() throws Exception {
|
|
public void testFallback() throws Exception {
|
|
// the source/target dir are not snapshottable dir
|
|
// the source/target dir are not snapshottable dir
|
|
- Assert.assertFalse(DistCpSync.sync(options, conf));
|
|
|
|
|
|
+ Assert.assertFalse(sync());
|
|
// make sure the source path has been updated to the snapshot path
|
|
// make sure the source path has been updated to the snapshot path
|
|
final Path spath = new Path(source,
|
|
final Path spath = new Path(source,
|
|
HdfsConstants.DOT_SNAPSHOT_DIR + Path.SEPARATOR + "s2");
|
|
HdfsConstants.DOT_SNAPSHOT_DIR + Path.SEPARATOR + "s2");
|
|
@@ -98,7 +97,7 @@ public class TestDistCpSync {
|
|
// the source/target does not have the given snapshots
|
|
// the source/target does not have the given snapshots
|
|
dfs.allowSnapshot(source);
|
|
dfs.allowSnapshot(source);
|
|
dfs.allowSnapshot(target);
|
|
dfs.allowSnapshot(target);
|
|
- Assert.assertFalse(DistCpSync.sync(options, conf));
|
|
|
|
|
|
+ Assert.assertFalse(sync());
|
|
Assert.assertEquals(spath, options.getSourcePaths().get(0));
|
|
Assert.assertEquals(spath, options.getSourcePaths().get(0));
|
|
|
|
|
|
// reset source path in options
|
|
// reset source path in options
|
|
@@ -106,21 +105,38 @@ public class TestDistCpSync {
|
|
dfs.createSnapshot(source, "s1");
|
|
dfs.createSnapshot(source, "s1");
|
|
dfs.createSnapshot(source, "s2");
|
|
dfs.createSnapshot(source, "s2");
|
|
dfs.createSnapshot(target, "s1");
|
|
dfs.createSnapshot(target, "s1");
|
|
- Assert.assertTrue(DistCpSync.sync(options, conf));
|
|
|
|
|
|
+ Assert.assertTrue(sync());
|
|
|
|
|
|
// reset source paths in options
|
|
// reset source paths in options
|
|
options.setSourcePaths(Arrays.asList(source));
|
|
options.setSourcePaths(Arrays.asList(source));
|
|
// changes have been made in target
|
|
// changes have been made in target
|
|
final Path subTarget = new Path(target, "sub");
|
|
final Path subTarget = new Path(target, "sub");
|
|
dfs.mkdirs(subTarget);
|
|
dfs.mkdirs(subTarget);
|
|
- Assert.assertFalse(DistCpSync.sync(options, conf));
|
|
|
|
|
|
+ Assert.assertFalse(sync());
|
|
// make sure the source path has been updated to the snapshot path
|
|
// make sure the source path has been updated to the snapshot path
|
|
Assert.assertEquals(spath, options.getSourcePaths().get(0));
|
|
Assert.assertEquals(spath, options.getSourcePaths().get(0));
|
|
|
|
|
|
// reset source paths in options
|
|
// reset source paths in options
|
|
options.setSourcePaths(Arrays.asList(source));
|
|
options.setSourcePaths(Arrays.asList(source));
|
|
dfs.delete(subTarget, true);
|
|
dfs.delete(subTarget, true);
|
|
- Assert.assertTrue(DistCpSync.sync(options, conf));
|
|
|
|
|
|
+ Assert.assertTrue(sync());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void enableAndCreateFirstSnapshot() throws Exception {
|
|
|
|
+ dfs.allowSnapshot(source);
|
|
|
|
+ dfs.allowSnapshot(target);
|
|
|
|
+ dfs.createSnapshot(source, "s1");
|
|
|
|
+ dfs.createSnapshot(target, "s1");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void syncAndVerify() throws Exception {
|
|
|
|
+ Assert.assertTrue(sync());
|
|
|
|
+ verifyCopy(dfs.getFileStatus(source), dfs.getFileStatus(target), false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private boolean sync() throws Exception {
|
|
|
|
+ DistCpSync distCpSync = new DistCpSync(options, conf);
|
|
|
|
+ return distCpSync.sync();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -164,23 +180,30 @@ public class TestDistCpSync {
|
|
* foo/ f4
|
|
* foo/ f4
|
|
* f1(new)
|
|
* f1(new)
|
|
*/
|
|
*/
|
|
- private void changeData(Path dir) throws Exception {
|
|
|
|
|
|
+ private int changeData(Path dir) throws Exception {
|
|
final Path foo = new Path(dir, "foo");
|
|
final Path foo = new Path(dir, "foo");
|
|
final Path bar = new Path(dir, "bar");
|
|
final Path bar = new Path(dir, "bar");
|
|
final Path d1 = new Path(foo, "d1");
|
|
final Path d1 = new Path(foo, "d1");
|
|
final Path f2 = new Path(bar, "f2");
|
|
final Path f2 = new Path(bar, "f2");
|
|
|
|
|
|
final Path bar_d1 = new Path(bar, "d1");
|
|
final Path bar_d1 = new Path(bar, "d1");
|
|
|
|
+ int numCreatedModified = 0;
|
|
dfs.rename(d1, bar_d1);
|
|
dfs.rename(d1, bar_d1);
|
|
|
|
+ numCreatedModified += 1; // modify ./foo
|
|
|
|
+ numCreatedModified += 1; // modify ./bar
|
|
final Path f3 = new Path(bar_d1, "f3");
|
|
final Path f3 = new Path(bar_d1, "f3");
|
|
dfs.delete(f3, true);
|
|
dfs.delete(f3, true);
|
|
final Path newfoo = new Path(bar_d1, "foo");
|
|
final Path newfoo = new Path(bar_d1, "foo");
|
|
dfs.rename(foo, newfoo);
|
|
dfs.rename(foo, newfoo);
|
|
|
|
+ numCreatedModified += 1; // modify ./foo/d1
|
|
final Path f1 = new Path(newfoo, "f1");
|
|
final Path f1 = new Path(newfoo, "f1");
|
|
dfs.delete(f1, true);
|
|
dfs.delete(f1, true);
|
|
DFSTestUtil.createFile(dfs, f1, 2 * BLOCK_SIZE, DATA_NUM, 0);
|
|
DFSTestUtil.createFile(dfs, f1, 2 * BLOCK_SIZE, DATA_NUM, 0);
|
|
|
|
+ numCreatedModified += 1; // create ./foo/f1
|
|
DFSTestUtil.appendFile(dfs, f2, (int) BLOCK_SIZE);
|
|
DFSTestUtil.appendFile(dfs, f2, (int) BLOCK_SIZE);
|
|
|
|
+ numCreatedModified += 1; // modify ./bar/f2
|
|
dfs.rename(bar, new Path(dir, "foo"));
|
|
dfs.rename(bar, new Path(dir, "foo"));
|
|
|
|
+ return numCreatedModified;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -190,13 +213,10 @@ public class TestDistCpSync {
|
|
public void testSync() throws Exception {
|
|
public void testSync() throws Exception {
|
|
initData(source);
|
|
initData(source);
|
|
initData(target);
|
|
initData(target);
|
|
- dfs.allowSnapshot(source);
|
|
|
|
- dfs.allowSnapshot(target);
|
|
|
|
- dfs.createSnapshot(source, "s1");
|
|
|
|
- dfs.createSnapshot(target, "s1");
|
|
|
|
|
|
+ enableAndCreateFirstSnapshot();
|
|
|
|
|
|
// make changes under source
|
|
// make changes under source
|
|
- changeData(source);
|
|
|
|
|
|
+ int numCreatedModified = changeData(source);
|
|
dfs.createSnapshot(source, "s2");
|
|
dfs.createSnapshot(source, "s2");
|
|
|
|
|
|
// before sync, make some further changes on source. this should not affect
|
|
// before sync, make some further changes on source. this should not affect
|
|
@@ -206,17 +226,22 @@ public class TestDistCpSync {
|
|
final Path newdir = new Path(source, "foo/d1/foo/newdir");
|
|
final Path newdir = new Path(source, "foo/d1/foo/newdir");
|
|
dfs.mkdirs(newdir);
|
|
dfs.mkdirs(newdir);
|
|
|
|
|
|
|
|
+ SnapshotDiffReport report = dfs.getSnapshotDiffReport(source, "s1", "s2");
|
|
|
|
+ System.out.println(report);
|
|
|
|
+
|
|
|
|
+ DistCpSync distCpSync = new DistCpSync(options, conf);
|
|
|
|
+
|
|
// do the sync
|
|
// do the sync
|
|
- Assert.assertTrue(DistCpSync.sync(options, conf));
|
|
|
|
|
|
+ Assert.assertTrue(distCpSync.sync());
|
|
|
|
|
|
// make sure the source path has been updated to the snapshot path
|
|
// make sure the source path has been updated to the snapshot path
|
|
final Path spath = new Path(source,
|
|
final Path spath = new Path(source,
|
|
- HdfsConstants.DOT_SNAPSHOT_DIR + Path.SEPARATOR + "s2");
|
|
|
|
|
|
+ HdfsConstants.DOT_SNAPSHOT_DIR + Path.SEPARATOR + "s2");
|
|
Assert.assertEquals(spath, options.getSourcePaths().get(0));
|
|
Assert.assertEquals(spath, options.getSourcePaths().get(0));
|
|
|
|
|
|
// build copy listing
|
|
// build copy listing
|
|
final Path listingPath = new Path("/tmp/META/fileList.seq");
|
|
final Path listingPath = new Path("/tmp/META/fileList.seq");
|
|
- CopyListing listing = new GlobbedCopyListing(conf, new Credentials());
|
|
|
|
|
|
+ CopyListing listing = new SimpleCopyListing(conf, new Credentials(), distCpSync);
|
|
listing.buildListing(listingPath, options);
|
|
listing.buildListing(listingPath, options);
|
|
|
|
|
|
Map<Text, CopyListingFileStatus> copyListing = getListing(listingPath);
|
|
Map<Text, CopyListingFileStatus> copyListing = getListing(listingPath);
|
|
@@ -232,6 +257,9 @@ public class TestDistCpSync {
|
|
copyMapper.map(entry.getKey(), entry.getValue(), context);
|
|
copyMapper.map(entry.getKey(), entry.getValue(), context);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // verify that we only list modified and created files/directories
|
|
|
|
+ Assert.assertEquals(numCreatedModified, copyListing.size());
|
|
|
|
+
|
|
// verify that we only copied new appended data of f2 and the new file f1
|
|
// verify that we only copied new appended data of f2 and the new file f1
|
|
Assert.assertEquals(BLOCK_SIZE * 3, stubContext.getReporter()
|
|
Assert.assertEquals(BLOCK_SIZE * 3, stubContext.getReporter()
|
|
.getCounter(CopyMapper.Counter.BYTESCOPIED).getValue());
|
|
.getCounter(CopyMapper.Counter.BYTESCOPIED).getValue());
|
|
@@ -285,16 +313,13 @@ public class TestDistCpSync {
|
|
options.setUseDiff(true, "s1", ".");
|
|
options.setUseDiff(true, "s1", ".");
|
|
initData(source);
|
|
initData(source);
|
|
initData(target);
|
|
initData(target);
|
|
- dfs.allowSnapshot(source);
|
|
|
|
- dfs.allowSnapshot(target);
|
|
|
|
- dfs.createSnapshot(source, "s1");
|
|
|
|
- dfs.createSnapshot(target, "s1");
|
|
|
|
|
|
+ enableAndCreateFirstSnapshot();
|
|
|
|
|
|
// make changes under source
|
|
// make changes under source
|
|
changeData(source);
|
|
changeData(source);
|
|
|
|
|
|
// do the sync
|
|
// do the sync
|
|
- Assert.assertTrue(DistCpSync.sync(options, conf));
|
|
|
|
|
|
+ sync();
|
|
// make sure the source path is still unchanged
|
|
// make sure the source path is still unchanged
|
|
Assert.assertEquals(source, options.getSourcePaths().get(0));
|
|
Assert.assertEquals(source, options.getSourcePaths().get(0));
|
|
}
|
|
}
|
|
@@ -328,10 +353,7 @@ public class TestDistCpSync {
|
|
public void testSync2() throws Exception {
|
|
public void testSync2() throws Exception {
|
|
initData2(source);
|
|
initData2(source);
|
|
initData2(target);
|
|
initData2(target);
|
|
- dfs.allowSnapshot(source);
|
|
|
|
- dfs.allowSnapshot(target);
|
|
|
|
- dfs.createSnapshot(source, "s1");
|
|
|
|
- dfs.createSnapshot(target, "s1");
|
|
|
|
|
|
+ enableAndCreateFirstSnapshot();
|
|
|
|
|
|
// make changes under source
|
|
// make changes under source
|
|
changeData2(source);
|
|
changeData2(source);
|
|
@@ -340,9 +362,7 @@ public class TestDistCpSync {
|
|
SnapshotDiffReport report = dfs.getSnapshotDiffReport(source, "s1", "s2");
|
|
SnapshotDiffReport report = dfs.getSnapshotDiffReport(source, "s1", "s2");
|
|
System.out.println(report);
|
|
System.out.println(report);
|
|
|
|
|
|
- // do the sync
|
|
|
|
- Assert.assertTrue(DistCpSync.sync(options, conf));
|
|
|
|
- verifyCopy(dfs.getFileStatus(source), dfs.getFileStatus(target), false);
|
|
|
|
|
|
+ syncAndVerify();
|
|
}
|
|
}
|
|
|
|
|
|
private void initData3(Path dir) throws Exception {
|
|
private void initData3(Path dir) throws Exception {
|
|
@@ -375,16 +395,13 @@ public class TestDistCpSync {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Test a case where there are multiple source files with the same name
|
|
|
|
|
|
+ * Test a case where there are multiple source files with the same name.
|
|
*/
|
|
*/
|
|
@Test
|
|
@Test
|
|
public void testSync3() throws Exception {
|
|
public void testSync3() throws Exception {
|
|
initData3(source);
|
|
initData3(source);
|
|
initData3(target);
|
|
initData3(target);
|
|
- dfs.allowSnapshot(source);
|
|
|
|
- dfs.allowSnapshot(target);
|
|
|
|
- dfs.createSnapshot(source, "s1");
|
|
|
|
- dfs.createSnapshot(target, "s1");
|
|
|
|
|
|
+ enableAndCreateFirstSnapshot();
|
|
|
|
|
|
// make changes under source
|
|
// make changes under source
|
|
changeData3(source);
|
|
changeData3(source);
|
|
@@ -393,8 +410,268 @@ public class TestDistCpSync {
|
|
SnapshotDiffReport report = dfs.getSnapshotDiffReport(source, "s1", "s2");
|
|
SnapshotDiffReport report = dfs.getSnapshotDiffReport(source, "s1", "s2");
|
|
System.out.println(report);
|
|
System.out.println(report);
|
|
|
|
|
|
|
|
+ syncAndVerify();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void initData4(Path dir) throws Exception {
|
|
|
|
+ final Path d1 = new Path(dir, "d1");
|
|
|
|
+ final Path d2 = new Path(d1, "d2");
|
|
|
|
+ final Path f1 = new Path(d2, "f1");
|
|
|
|
+
|
|
|
|
+ DFSTestUtil.createFile(dfs, f1, BLOCK_SIZE, DATA_NUM, 0L);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void changeData4(Path dir) throws Exception {
|
|
|
|
+ final Path d1 = new Path(dir, "d1");
|
|
|
|
+ final Path d11 = new Path(dir, "d11");
|
|
|
|
+ final Path d2 = new Path(d1, "d2");
|
|
|
|
+ final Path d21 = new Path(d1, "d21");
|
|
|
|
+ final Path f1 = new Path(d2, "f1");
|
|
|
|
+
|
|
|
|
+ dfs.delete(f1, false);
|
|
|
|
+ dfs.rename(d2, d21);
|
|
|
|
+ dfs.rename(d1, d11);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Test a case where multiple level dirs are renamed.
|
|
|
|
+ */
|
|
|
|
+ @Test
|
|
|
|
+ public void testSync4() throws Exception {
|
|
|
|
+ initData4(source);
|
|
|
|
+ initData4(target);
|
|
|
|
+ enableAndCreateFirstSnapshot();
|
|
|
|
+
|
|
|
|
+ // make changes under source
|
|
|
|
+ changeData4(source);
|
|
|
|
+ dfs.createSnapshot(source, "s2");
|
|
|
|
+
|
|
|
|
+ SnapshotDiffReport report = dfs.getSnapshotDiffReport(source, "s1", "s2");
|
|
|
|
+ System.out.println(report);
|
|
|
|
+
|
|
|
|
+ syncAndVerify();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void initData5(Path dir) throws Exception {
|
|
|
|
+ final Path d1 = new Path(dir, "d1");
|
|
|
|
+ final Path d2 = new Path(dir, "d2");
|
|
|
|
+ final Path f1 = new Path(d1, "f1");
|
|
|
|
+ final Path f2 = new Path(d2, "f2");
|
|
|
|
+
|
|
|
|
+ DFSTestUtil.createFile(dfs, f1, BLOCK_SIZE, DATA_NUM, 0L);
|
|
|
|
+ DFSTestUtil.createFile(dfs, f2, BLOCK_SIZE, DATA_NUM, 0L);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void changeData5(Path dir) throws Exception {
|
|
|
|
+ final Path d1 = new Path(dir, "d1");
|
|
|
|
+ final Path d2 = new Path(dir, "d2");
|
|
|
|
+ final Path f1 = new Path(d1, "f1");
|
|
|
|
+ final Path tmp = new Path(dir, "tmp");
|
|
|
|
+
|
|
|
|
+ dfs.delete(f1, false);
|
|
|
|
+ dfs.rename(d1, tmp);
|
|
|
|
+ dfs.rename(d2, d1);
|
|
|
|
+ final Path f2 = new Path(d1, "f2");
|
|
|
|
+ dfs.delete(f2, false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Test a case with different delete and rename sequences.
|
|
|
|
+ */
|
|
|
|
+ @Test
|
|
|
|
+ public void testSync5() throws Exception {
|
|
|
|
+ initData5(source);
|
|
|
|
+ initData5(target);
|
|
|
|
+ enableAndCreateFirstSnapshot();
|
|
|
|
+
|
|
|
|
+ // make changes under source
|
|
|
|
+ changeData5(source);
|
|
|
|
+ dfs.createSnapshot(source, "s2");
|
|
|
|
+
|
|
|
|
+ SnapshotDiffReport report = dfs.getSnapshotDiffReport(source, "s1", "s2");
|
|
|
|
+ System.out.println(report);
|
|
|
|
+
|
|
|
|
+ syncAndVerify();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void testAndVerify(int numCreatedModified)
|
|
|
|
+ throws Exception{
|
|
|
|
+ SnapshotDiffReport report = dfs.getSnapshotDiffReport(source, "s1", "s2");
|
|
|
|
+ System.out.println(report);
|
|
|
|
+
|
|
|
|
+ DistCpSync distCpSync = new DistCpSync(options, conf);
|
|
// do the sync
|
|
// do the sync
|
|
- Assert.assertTrue(DistCpSync.sync(options, conf));
|
|
|
|
- verifyCopy(dfs.getFileStatus(source), dfs.getFileStatus(target), false);
|
|
|
|
|
|
+ Assert.assertTrue(distCpSync.sync());
|
|
|
|
+
|
|
|
|
+ // make sure the source path has been updated to the snapshot path
|
|
|
|
+ final Path spath = new Path(source,
|
|
|
|
+ HdfsConstants.DOT_SNAPSHOT_DIR + Path.SEPARATOR + "s2");
|
|
|
|
+ Assert.assertEquals(spath, options.getSourcePaths().get(0));
|
|
|
|
+
|
|
|
|
+ // build copy listing
|
|
|
|
+ final Path listingPath = new Path("/tmp/META/fileList.seq");
|
|
|
|
+ CopyListing listing = new SimpleCopyListing(conf, new Credentials(), distCpSync);
|
|
|
|
+ listing.buildListing(listingPath, options);
|
|
|
|
+
|
|
|
|
+ Map<Text, CopyListingFileStatus> copyListing = getListing(listingPath);
|
|
|
|
+ CopyMapper copyMapper = new CopyMapper();
|
|
|
|
+ StubContext stubContext = new StubContext(conf, null, 0);
|
|
|
|
+ Mapper<Text, CopyListingFileStatus, Text, Text>.Context context =
|
|
|
|
+ stubContext.getContext();
|
|
|
|
+ // Enable append
|
|
|
|
+ context.getConfiguration().setBoolean(
|
|
|
|
+ DistCpOptionSwitch.APPEND.getConfigLabel(), true);
|
|
|
|
+ copyMapper.setup(context);
|
|
|
|
+ for (Map.Entry<Text, CopyListingFileStatus> entry :
|
|
|
|
+ copyListing.entrySet()) {
|
|
|
|
+ copyMapper.map(entry.getKey(), entry.getValue(), context);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // verify that we only list modified and created files/directories
|
|
|
|
+ Assert.assertEquals(numCreatedModified, copyListing.size());
|
|
|
|
+
|
|
|
|
+ // verify the source and target now has the same structure
|
|
|
|
+ verifyCopy(dfs.getFileStatus(spath), dfs.getFileStatus(target), false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void initData6(Path dir) throws Exception {
|
|
|
|
+ final Path foo = new Path(dir, "foo");
|
|
|
|
+ final Path bar = new Path(dir, "bar");
|
|
|
|
+ final Path foo_f1 = new Path(foo, "f1");
|
|
|
|
+ final Path bar_f1 = new Path(bar, "f1");
|
|
|
|
+
|
|
|
|
+ DFSTestUtil.createFile(dfs, foo_f1, BLOCK_SIZE, DATA_NUM, 0L);
|
|
|
|
+ DFSTestUtil.createFile(dfs, bar_f1, BLOCK_SIZE, DATA_NUM, 0L);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private int changeData6(Path dir) throws Exception {
|
|
|
|
+ final Path foo = new Path(dir, "foo");
|
|
|
|
+ final Path bar = new Path(dir, "bar");
|
|
|
|
+ final Path foo2 = new Path(dir, "foo2");
|
|
|
|
+ final Path foo_f1 = new Path(foo, "f1");
|
|
|
|
+
|
|
|
|
+ int numCreatedModified = 0;
|
|
|
|
+ dfs.rename(foo, foo2);
|
|
|
|
+ dfs.rename(bar, foo);
|
|
|
|
+ dfs.rename(foo2, bar);
|
|
|
|
+ DFSTestUtil.appendFile(dfs, foo_f1, (int) BLOCK_SIZE);
|
|
|
|
+ numCreatedModified += 1; // modify ./bar/f1
|
|
|
|
+ return numCreatedModified;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Test a case where there is a cycle in renaming dirs.
|
|
|
|
+ */
|
|
|
|
+ @Test
|
|
|
|
+ public void testSync6() throws Exception {
|
|
|
|
+ initData6(source);
|
|
|
|
+ initData6(target);
|
|
|
|
+ enableAndCreateFirstSnapshot();
|
|
|
|
+ int numCreatedModified = changeData6(source);
|
|
|
|
+ dfs.createSnapshot(source, "s2");
|
|
|
|
+
|
|
|
|
+ testAndVerify(numCreatedModified);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void initData7(Path dir) throws Exception {
|
|
|
|
+ final Path foo = new Path(dir, "foo");
|
|
|
|
+ final Path bar = new Path(dir, "bar");
|
|
|
|
+ final Path foo_f1 = new Path(foo, "f1");
|
|
|
|
+ final Path bar_f1 = new Path(bar, "f1");
|
|
|
|
+
|
|
|
|
+ DFSTestUtil.createFile(dfs, foo_f1, BLOCK_SIZE, DATA_NUM, 0L);
|
|
|
|
+ DFSTestUtil.createFile(dfs, bar_f1, BLOCK_SIZE, DATA_NUM, 0L);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private int changeData7(Path dir) throws Exception {
|
|
|
|
+ final Path foo = new Path(dir, "foo");
|
|
|
|
+ final Path foo2 = new Path(dir, "foo2");
|
|
|
|
+ final Path foo_f1 = new Path(foo, "f1");
|
|
|
|
+ final Path foo2_f2 = new Path(foo2, "f2");
|
|
|
|
+ final Path foo_d1 = new Path(foo, "d1");
|
|
|
|
+ final Path foo_d1_f3 = new Path(foo_d1, "f3");
|
|
|
|
+
|
|
|
|
+ int numCreatedModified = 0;
|
|
|
|
+ dfs.rename(foo, foo2);
|
|
|
|
+ DFSTestUtil.createFile(dfs, foo_f1, BLOCK_SIZE, DATA_NUM, 0L);
|
|
|
|
+ numCreatedModified += 2; // create ./foo and ./foo/f1
|
|
|
|
+ DFSTestUtil.appendFile(dfs, foo_f1, (int) BLOCK_SIZE);
|
|
|
|
+ dfs.rename(foo_f1, foo2_f2);
|
|
|
|
+ numCreatedModified -= 1; // mv ./foo/f1
|
|
|
|
+ numCreatedModified += 2; // "M ./foo" and "+ ./foo/f2"
|
|
|
|
+ DFSTestUtil.createFile(dfs, foo_d1_f3, BLOCK_SIZE, DATA_NUM, 0L);
|
|
|
|
+ numCreatedModified += 2; // create ./foo/d1 and ./foo/d1/f3
|
|
|
|
+ return numCreatedModified;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Test a case where rename a dir, then create a new dir with the same name
|
|
|
|
+ * and sub dir.
|
|
|
|
+ */
|
|
|
|
+ @Test
|
|
|
|
+ public void testSync7() throws Exception {
|
|
|
|
+ initData7(source);
|
|
|
|
+ initData7(target);
|
|
|
|
+ enableAndCreateFirstSnapshot();
|
|
|
|
+ int numCreatedModified = changeData7(source);
|
|
|
|
+ dfs.createSnapshot(source, "s2");
|
|
|
|
+
|
|
|
|
+ testAndVerify(numCreatedModified);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void initData8(Path dir) throws Exception {
|
|
|
|
+ final Path foo = new Path(dir, "foo");
|
|
|
|
+ final Path bar = new Path(dir, "bar");
|
|
|
|
+ final Path d1 = new Path(dir, "d1");
|
|
|
|
+ final Path foo_f1 = new Path(foo, "f1");
|
|
|
|
+ final Path bar_f1 = new Path(bar, "f1");
|
|
|
|
+ final Path d1_f1 = new Path(d1, "f1");
|
|
|
|
+
|
|
|
|
+ DFSTestUtil.createFile(dfs, foo_f1, BLOCK_SIZE, DATA_NUM, 0L);
|
|
|
|
+ DFSTestUtil.createFile(dfs, bar_f1, BLOCK_SIZE, DATA_NUM, 0L);
|
|
|
|
+ DFSTestUtil.createFile(dfs, d1_f1, BLOCK_SIZE, DATA_NUM, 0L);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private int changeData8(Path dir) throws Exception {
|
|
|
|
+ final Path foo = new Path(dir, "foo");
|
|
|
|
+ final Path createdDir = new Path(dir, "c");
|
|
|
|
+ final Path d1 = new Path(dir, "d1");
|
|
|
|
+ final Path d1_f1 = new Path(d1, "f1");
|
|
|
|
+ final Path createdDir_f1 = new Path(createdDir, "f1");
|
|
|
|
+ final Path foo_f3 = new Path(foo, "f3");
|
|
|
|
+ final Path new_foo = new Path(createdDir, "foo");
|
|
|
|
+ final Path foo_f4 = new Path(foo, "f4");
|
|
|
|
+ final Path foo_d1 = new Path(foo, "d1");
|
|
|
|
+ final Path bar = new Path(dir, "bar");
|
|
|
|
+ final Path bar1 = new Path(dir, "bar1");
|
|
|
|
+
|
|
|
|
+ int numCreatedModified = 0;
|
|
|
|
+ DFSTestUtil.createFile(dfs, foo_f3, BLOCK_SIZE, DATA_NUM, 0L);
|
|
|
|
+ numCreatedModified += 1; // create ./c/foo/f3
|
|
|
|
+ DFSTestUtil.createFile(dfs, createdDir_f1, BLOCK_SIZE, DATA_NUM, 0L);
|
|
|
|
+ numCreatedModified += 1; // create ./c
|
|
|
|
+ dfs.rename(createdDir_f1, foo_f4);
|
|
|
|
+ numCreatedModified += 1; // create ./c/foo/f4
|
|
|
|
+ dfs.rename(d1_f1, createdDir_f1); // rename ./d1/f1 -> ./c/f1
|
|
|
|
+ numCreatedModified += 1; // modify ./c/foo/d1
|
|
|
|
+ dfs.rename(d1, foo_d1);
|
|
|
|
+ numCreatedModified += 1; // modify ./c/foo
|
|
|
|
+ dfs.rename(foo, new_foo);
|
|
|
|
+ dfs.rename(bar, bar1);
|
|
|
|
+ return numCreatedModified;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Test a case where create a dir, then mv a existed dir into it.
|
|
|
|
+ */
|
|
|
|
+ @Test
|
|
|
|
+ public void testSync8() throws Exception {
|
|
|
|
+ initData8(source);
|
|
|
|
+ initData8(target);
|
|
|
|
+ enableAndCreateFirstSnapshot();
|
|
|
|
+ int numCreatedModified = changeData8(source);
|
|
|
|
+ dfs.createSnapshot(source, "s2");
|
|
|
|
+
|
|
|
|
+ testAndVerify(numCreatedModified);
|
|
}
|
|
}
|
|
}
|
|
}
|