Skip to content

Commit

Permalink
[TACHYON-590] Add unit tests for 'copyFromLocal' and adjust the old u…
Browse files Browse the repository at this point in the history
…nit tests for the new implementation
  • Loading branch information
tianyin committed Aug 29, 2015
1 parent fa0597b commit bb18687
Showing 1 changed file with 49 additions and 4 deletions.
53 changes: 49 additions & 4 deletions shell/src/test/java/tachyon/shell/TFsShellTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void copyFromLocalLargeTest() throws IOException {
byte[] toWrite = BufferUtils.getIncreasingByteArray(SIZE_BYTES);
fos.write(toWrite);
fos.close();
mFsShell.copyFromLocal(new String[] {"copyFromLocal", testFile.getAbsolutePath(), "/testFile"});
mFsShell.run(new String[] {"copyFromLocal", testFile.getAbsolutePath(), "/testFile"});
Assert.assertEquals(getCommandOutput(new String[] {"copyFromLocal", testFile.getAbsolutePath(),
"/testFile"}), mOutput.toString());
TachyonFile tFile = mTfs.getFile(new TachyonURI("/testFile"));
Expand Down Expand Up @@ -153,7 +153,7 @@ public void copyFromLocalTest() throws IOException {
generateFileContent("/testDir/testFile", BufferUtils.getIncreasingByteArray(10));
generateFileContent("/testDir/testDirInner/testFile2",
BufferUtils.getIncreasingByteArray(10, 20));
mFsShell.copyFromLocal(new String[] {"copyFromLocal", testFile.getParent(), "/testDir"});
mFsShell.run(new String[] {"copyFromLocal", testFile.getParent(), "/testDir"});
Assert.assertEquals(getCommandOutput(new String[] {"copyFromLocal", testFile.getParent(),
"/testDir"}), mOutput.toString());
TachyonFile tFile = mTfs.getFile(new TachyonURI("/testDir/testFile"));
Expand All @@ -175,7 +175,7 @@ public void copyFromLocalTestWithFullURI() throws IOException {
"tachyon://" + mLocalTachyonCluster.getMasterHostname() + ":"
+ mLocalTachyonCluster.getMasterPort() + "/destFileURI";
// when
mFsShell.copyFromLocal(new String[] {"copyFromLocal", testFile.getPath(), tachyonURI});
mFsShell.run(new String[] {"copyFromLocal", testFile.getPath(), tachyonURI});
String cmdOut =
getCommandOutput(new String[] {"copyFromLocal", testFile.getPath(), tachyonURI});
// then
Expand All @@ -194,7 +194,7 @@ public void copyFromLocalFileToDstPathTest() throws IOException {
localDir.mkdir();
File localFile = generateFileContent("/localDir/testFile", data);
mFsShell.run(new String[] {"mkdir", "/dstDir"});
mFsShell.copyFromLocal(new String[] {"copyFromLocal", localFile.getPath(), "/dstDir"});
mFsShell.run(new String[] {"copyFromLocal", localFile.getPath(), "/dstDir"});

TachyonFile tFile = mTfs.getFile(new TachyonURI("/dstDir/testFile"));
Assert.assertNotNull(tFile);
Expand Down Expand Up @@ -850,4 +850,49 @@ public void loadWildcardTest() throws IOException {
mFsShell.run(new String[] {"load", "/testWildCards/*"});
Assert.assertTrue(mTfs.getFile(new TachyonURI("/testWildCards/foobar4")).isInMemory());
}

@Test
public void copyFromLocalWildcardTest() throws IOException {
TFsShellUtilsTest.resetLocalFileHierarchy(mLocalTachyonCluster);
int ret = mFsShell.run(new String[] {"copyFromLocal",
mLocalTachyonCluster.getTachyonHome() + "/testWildCards/*/foo*", "/testDir"});
Assert.assertEquals(ret, 0);
Assert.assertNotNull(mTfs.getFile(new TachyonURI("/testDir/foobar1")));
Assert.assertNotNull(mTfs.getFile(new TachyonURI("/testDir/foobar2")));
Assert.assertNotNull(mTfs.getFile(new TachyonURI("/testDir/foobar3")));
}

@Test
public void copyFromLocalWildcardExistingDirTest() throws IOException {
TFsShellUtilsTest.resetLocalFileHierarchy(mLocalTachyonCluster);
mTfs.mkdir(new TachyonURI("/testDir"));
int ret = mFsShell.run(new String[] {"copyFromLocal",
mLocalTachyonCluster.getTachyonHome() + "/testWildCards/*/foo*", "/testDir"});
Assert.assertEquals(ret, 0);
Assert.assertNotNull(mTfs.getFile(new TachyonURI("/testDir/foobar1")));
Assert.assertNotNull(mTfs.getFile(new TachyonURI("/testDir/foobar2")));
Assert.assertNotNull(mTfs.getFile(new TachyonURI("/testDir/foobar3")));
}

@Test
public void copyFromLocalWildcardNotDirTest() throws IOException {
TFsShellUtilsTest.resetTachyonFileHierarchy(mTfs, WriteType.MUST_CACHE);
int ret = mFsShell.run(new String[] {"copyFromLocal",
mLocalTachyonCluster.getTachyonHome() + "/testWildCards/*/foo*", "/testWildCards/foobar4"});
Assert.assertEquals(ret, -1);
}

@Test
public void copyFromLocalWildcardHierTest() throws IOException {
TFsShellUtilsTest.resetLocalFileHierarchy(mLocalTachyonCluster);
int ret = mFsShell.run(new String[] {"copyFromLocal",
mLocalTachyonCluster.getTachyonHome() + "/testWildCards/*", "/testDir"});

mFsShell.run(new String[] {"ls", "/testDir"});
Assert.assertEquals(ret, 0);
Assert.assertNotNull(mTfs.getFile(new TachyonURI("/testDir/foobar1")));
Assert.assertNotNull(mTfs.getFile(new TachyonURI("/testDir/foobar2")));
Assert.assertNotNull(mTfs.getFile(new TachyonURI("/testDir/foobar3")));
Assert.assertNotNull(mTfs.getFile(new TachyonURI("/testDir/foobar4")));
}
}

0 comments on commit bb18687

Please sign in to comment.