@Test public void rmrTest() throws IOException { StringBuilder toCompare = new StringBuilder(); mFsShell.run(new String[] {"mkdir", "/testFolder1/testFolder2"}); toCompare.append(getCommandOutput(new String[] {"mkdir", "/testFolder1/testFolder2"})); mFsShell.run(new String[] {"touch", "/testFolder1/testFolder2/testFile2"}); toCompare.append( getCommandOutput(new String[] {"touch", "/testFolder1/testFolder2/testFile2"})); TachyonURI testFolder1 = new TachyonURI("/testFolder1"); TachyonURI testFolder2 = new TachyonURI("/testFolder1/testFolder2"); TachyonURI testFile2 = new TachyonURI("/testFolder1/testFolder2/testFile2"); Assert.assertTrue(isFileExist(testFolder1)); Assert.assertTrue(isFileExist(testFolder2)); Assert.assertTrue(isFileExist(testFile2)); mFsShell.run(new String[] {"rmr", "/testFolder1/testFolder2/testFile2"}); toCompare.append(getCommandOutput(new String[] {"rm", "/testFolder1/testFolder2/testFile2"})); Assert.assertEquals(toCompare.toString(), mOutput.toString()); Assert.assertTrue(isFileExist(testFolder1)); Assert.assertTrue(isFileExist(testFolder2)); Assert.assertFalse(isFileExist(testFile2)); mFsShell.run(new String[] {"rmr", "/testFolder1"}); toCompare.append(getCommandOutput(new String[] {"rmr", "/testFolder1"})); Assert.assertEquals(toCompare.toString(), mOutput.toString()); Assert.assertFalse(isFileExist(testFolder1)); Assert.assertFalse(isFileExist(testFolder2)); Assert.assertFalse(isFileExist(testFile2)); }
@Test public void duTest() throws IOException { TachyonFSTestUtils.createByteFile( mTfs, "/testRoot/testFileA", TachyonStorageType.STORE, UnderStorageType.NO_PERSIST, 10); TachyonFSTestUtils.createByteFile( mTfs, "/testRoot/testDir/testFileB", TachyonStorageType.STORE, UnderStorageType.NO_PERSIST, 20); TachyonFSTestUtils.createByteFile( mTfs, "/testRoot/testDir/testDir/testFileC", TachyonStorageType.STORE, UnderStorageType.NO_PERSIST, 30); String expected = ""; // du a non-existing file mFsShell.run(new String[] {"du", "/testRoot/noneExisting"}); expected += "Could not find path: /testRoot/noneExisting\n"; // du a file mFsShell.run(new String[] {"du", "/testRoot/testFileA"}); expected += "/testRoot/testFileA is 10 bytes\n"; // du a folder mFsShell.run(new String[] {"du", "/testRoot/testDir"}); expected += "/testRoot/testDir is 50 bytes\n"; Assert.assertEquals(expected, mOutput.toString()); }
@Test public void rmNotExistingDirTest() throws IOException { StringBuilder toCompare = new StringBuilder(); mFsShell.run(new String[] {"mkdir", "/testFolder"}); toCompare.append(getCommandOutput(new String[] {"mkdir", "/testFolder"})); mFsShell.run(new String[] {"rm", "/testFolder"}); toCompare.append("rm: cannot remove a directory, please try rmr <path>\n"); Assert.assertEquals(toCompare.toString(), mOutput.toString()); }
@Test public void catDirectoryTest() throws IOException { String[] command = new String[] {"mkdir", "/testDir"}; mFsShell.run(command); int ret = mFsShell.run(new String[] {"cat", "/testDir"}); Assert.assertEquals(-1, ret); String expected = getCommandOutput(command); expected += "/testDir is not a file.\n"; Assert.assertEquals(expected, mOutput.toString()); }
@Test public void renameToExistingFileTest() throws IOException { StringBuilder toCompare = new StringBuilder(); mFsShell.run(new String[] {"mkdir", "/testFolder"}); toCompare.append(getCommandOutput(new String[] {"mkdir", "/testFolder"})); mFsShell.run(new String[] {"mkdir", "/testFolder1"}); toCompare.append(getCommandOutput(new String[] {"mkdir", "/testFolder1"})); Assert.assertEquals( -1, mFsShell.rename(new String[] {"rename", "/testFolder1", "/testFolder"})); }
@Test public void tailEmptyFileTest() throws IOException { TachyonFSTestUtils.createByteFile( mTfs, "/emptyFile", TachyonStorageType.STORE, UnderStorageType.NO_PERSIST, 0); int ret = mFsShell.run(new String[] {"tail", "/emptyFile"}); Assert.assertEquals(0, ret); }
@Test public void catTest() throws IOException { TachyonFSTestUtils.createByteFile( mTfs, "/testFile", TachyonStorageType.STORE, UnderStorageType.NO_PERSIST, 10); mFsShell.run(new String[] {"cat", "/testFile"}); byte[] expect = BufferUtils.getIncreasingByteArray(10); Assert.assertArrayEquals(expect, mOutput.toByteArray()); }
@Test public void mkdirShortPathTest() throws IOException, TException { mFsShell.run(new String[] {"mkdir", "/root/testFile1"}); TachyonFile tFile = mTfs.open(new TachyonURI("/root/testFile1")); FileInfo fileInfo = mTfs.getInfo(tFile); Assert.assertNotNull(fileInfo); Assert.assertEquals( getCommandOutput(new String[] {"mkdir", "/root/testFile1"}), mOutput.toString()); Assert.assertTrue(fileInfo.isIsFolder()); }
@Test public void touchTest() throws IOException, TException { String[] argv = new String[] {"touch", "/testFile"}; mFsShell.run(argv); TachyonFile tFile = mTfs.open(new TachyonURI("/testFile")); FileInfo fileInfo = mTfs.getInfo(tFile); Assert.assertNotNull(fileInfo); Assert.assertEquals(getCommandOutput(argv), mOutput.toString()); Assert.assertFalse(fileInfo.isFolder); }
@Test public void freeTest() throws IOException, TException { TachyonFile file = TachyonFSTestUtils.createByteFile( mTfs, "/testFile", TachyonStorageType.STORE, UnderStorageType.NO_PERSIST, 10); mFsShell.run(new String[] {"free", "/testFile"}); TachyonConf tachyonConf = mLocalTachyonCluster.getMasterTachyonConf(); CommonUtils.sleepMs(tachyonConf.getInt(Constants.WORKER_TO_MASTER_HEARTBEAT_INTERVAL_MS)); Assert.assertFalse(mTfs.getInfo(file).getInMemoryPercentage() == 100); }
@Test public void mkdirComplexPathTest() throws IOException, TException { mFsShell.run(new String[] {"mkdir", "/Complex!@#$%^&*()-_=+[]{};\"'<>,.?/File"}); TachyonFile tFile = mTfs.open(new TachyonURI("/Complex!@#$%^&*()-_=+[]{};\"'<>,.?/File")); FileInfo fileInfo = mTfs.getInfo(tFile); Assert.assertNotNull(fileInfo); Assert.assertEquals( getCommandOutput(new String[] {"mkdir", "/Complex!@#$%^&*()-_=+[]{};\"'<>,.?/File"}), mOutput.toString()); Assert.assertTrue(fileInfo.isIsFolder()); }
/* * @Test public void locationTest() throws IOException { TachyonFile file = * TachyonFSTestUtils.createByteFile(mTfs, "/testFile", CacheType.STORE, * UnderStorageType.NO_PERSIST, 10); mFsShell.run(new String[] {"location", "/testFile"}); * * FileInfo fileInfo = mTfs.getInfo(file); Assert.assertNotNull(fileInfo); List<String> * locationsList = tFile.getLocationHosts(); String[] commandParameters = new String[3 + * locationsList.size()]; commandParameters[0] = "location"; commandParameters[1] = "/testFile"; * commandParameters[2] = String.valueOf(file.getFileId()); Iterator<String> iter = * locationsList.iterator(); int i = 3; while (iter.hasNext()) { commandParameters[i ++] = * iter.next(); } Assert.assertEquals(getCommandOutput(commandParameters), mOutput.toString()); } */ @Test public void lsrTest() throws IOException, TException { FileInfo[] files = new FileInfo[4]; TachyonFile fileA = TachyonFSTestUtils.createByteFile( mTfs, "/testRoot/testFileA", TachyonStorageType.STORE, UnderStorageType.NO_PERSIST, 10); files[0] = mTfs.getInfo(fileA); TachyonFSTestUtils.createByteFile( mTfs, "/testRoot/testDir/testFileB", TachyonStorageType.STORE, UnderStorageType.NO_PERSIST, 20); files[1] = mTfs.getInfo(mTfs.open(new TachyonURI("/testRoot/testDir"))); files[2] = mTfs.getInfo(mTfs.open(new TachyonURI("/testRoot/testDir/testFileB"))); TachyonFile fileC = TachyonFSTestUtils.createByteFile( mTfs, "/testRoot/testFileC", TachyonStorageType.NO_STORE, UnderStorageType.PERSIST, 30); files[3] = mTfs.getInfo(fileC); mFsShell.run(new String[] {"lsr", "/testRoot"}); String expected = ""; String format = "%-10s%-25s%-15s%-5s\n"; expected += String.format( format, FormatUtils.getSizeFromBytes(10), TFsShell.convertMsToDate(files[0].getCreationTimeMs()), "In Memory", "/testRoot/testFileA"); expected += String.format( format, FormatUtils.getSizeFromBytes(0), TFsShell.convertMsToDate(files[1].getCreationTimeMs()), "", "/testRoot/testDir"); expected += String.format( format, FormatUtils.getSizeFromBytes(20), TFsShell.convertMsToDate(files[2].getCreationTimeMs()), "In Memory", "/testRoot/testDir/testFileB"); expected += String.format( format, FormatUtils.getSizeFromBytes(30), TFsShell.convertMsToDate(files[3].getCreationTimeMs()), "Not In Memory", "/testRoot/testFileC"); Assert.assertEquals(expected, mOutput.toString()); }
@Test public void renameTest() throws IOException { StringBuilder toCompare = new StringBuilder(); mFsShell.run(new String[] {"mkdir", "/testFolder1"}); toCompare.append(getCommandOutput(new String[] {"mkdir", "/testFolder1"})); Assert.assertTrue(isFileExist(new TachyonURI("/testFolder1"))); mFsShell.rename(new String[] {"rename", "/testFolder1", "/testFolder"}); toCompare.append(getCommandOutput(new String[] {"mv", "/testFolder1", "/testFolder"})); Assert.assertEquals(toCompare.toString(), mOutput.toString()); Assert.assertTrue(isFileExist(new TachyonURI("/testFolder"))); Assert.assertFalse(isFileExist(new TachyonURI("/testFolder1"))); }
@Test public void loadFileTest() throws IOException, TException { TachyonFile file = TachyonFSTestUtils.createByteFile( mTfs, "/testFile", TachyonStorageType.NO_STORE, UnderStorageType.PERSIST, 10); FileInfo fileInfo = mTfs.getInfo(file); Assert.assertFalse(fileInfo.getInMemoryPercentage() == 100); // Testing loading of a single file mFsShell.run(new String[] {"load", "/testFile"}); fileInfo = mTfs.getInfo(file); Assert.assertTrue(fileInfo.getInMemoryPercentage() == 100); }
@Test public void copyFromLocalFileToDstPathTest() throws IOException, TException { String dataString = "copyFromLocalFileToDstPathTest"; byte[] data = dataString.getBytes(); File localDir = new File(mLocalTachyonCluster.getTachyonHome() + "/localDir"); localDir.mkdir(); File localFile = generateFileContent("/localDir/testFile", data); mFsShell.run(new String[] {"mkdir", "/dstDir"}); mFsShell.copyFromLocal(new String[] {"copyFromLocal", localFile.getPath(), "/dstDir"}); TachyonFile file = mTfs.open(new TachyonURI("/dstDir/testFile")); FileInfo fileInfo = mTfs.getInfo(file); Assert.assertNotNull(fileInfo); byte[] read = readContent(file, data.length); Assert.assertEquals(new String(read), dataString); }
@Test public void mkdirTest() throws IOException, TException { String qualifiedPath = "tachyon://" + mLocalTachyonCluster.getMasterHostname() + ":" + mLocalTachyonCluster.getMasterPort() + "/root/testFile1"; mFsShell.run(new String[] {"mkdir", qualifiedPath}); TachyonFile tFile = mTfs.open(new TachyonURI("/root/testFile1")); FileInfo fileInfo = mTfs.getInfo(tFile); Assert.assertNotNull(fileInfo); Assert.assertEquals( getCommandOutput(new String[] {"mkdir", qualifiedPath}), mOutput.toString()); Assert.assertTrue(fileInfo.isIsFolder()); }
@Test public void touchTestWithFullURI() throws IOException, TException { String tachyonURI = "tachyon://" + mLocalTachyonCluster.getMasterHostname() + ":" + mLocalTachyonCluster.getMasterPort() + "/destFileURI"; // when String[] argv = new String[] {"touch", tachyonURI}; mFsShell.run(argv); // then TachyonFile tFile = mTfs.open(new TachyonURI("/destFileURI")); FileInfo fileInfo = mTfs.getInfo(tFile); Assert.assertNotNull(fileInfo); Assert.assertEquals(getCommandOutput(argv), mOutput.toString()); Assert.assertFalse(fileInfo.isFolder); }
@Test public void countTest() throws IOException { TachyonFSTestUtils.createByteFile( mTfs, "/testRoot/testFileA", TachyonStorageType.STORE, UnderStorageType.NO_PERSIST, 10); TachyonFSTestUtils.createByteFile( mTfs, "/testRoot/testDir/testFileB", TachyonStorageType.STORE, UnderStorageType.NO_PERSIST, 20); TachyonFSTestUtils.createByteFile( mTfs, "/testRoot/testFileB", TachyonStorageType.STORE, UnderStorageType.NO_PERSIST, 30); mFsShell.run(new String[] {"count", "/testRoot"}); String expected = ""; String format = "%-25s%-25s%-15s\n"; expected += String.format(format, "File Count", "Folder Count", "Total Bytes"); expected += String.format(format, 3, 2, 60); Assert.assertEquals(expected, mOutput.toString()); }
@Test public void loadDirTest() throws IOException, TException { TachyonFile fileA = TachyonFSTestUtils.createByteFile( mTfs, "/testRoot/testFileA", TachyonStorageType.NO_STORE, UnderStorageType.PERSIST, 10); TachyonFile fileB = TachyonFSTestUtils.createByteFile( mTfs, "/testRoot/testFileB", TachyonStorageType.STORE, UnderStorageType.NO_PERSIST, 10); FileInfo fileInfoA = mTfs.getInfo(fileA); FileInfo fileInfoB = mTfs.getInfo(fileB); Assert.assertFalse(fileInfoA.getInMemoryPercentage() == 100); Assert.assertTrue(fileInfoB.getInMemoryPercentage() == 100); // Testing loading of a directory mFsShell.run(new String[] {"load", "/testRoot"}); fileInfoA = mTfs.getInfo(fileA); fileInfoB = mTfs.getInfo(fileB); Assert.assertTrue(fileInfoA.getInMemoryPercentage() == 100); Assert.assertTrue(fileInfoB.getInMemoryPercentage() == 100); }
@Test public void catNotExistTest() throws IOException { int ret = mFsShell.run(new String[] {"cat", "/testFile"}); Assert.assertEquals(-1, ret); }
@Test public void countNotExistTest() throws IOException { int ret = mFsShell.run(new String[] {"count", "/NotExistFile"}); Assert.assertEquals("Could not find path: /NotExistFile\n", mOutput.toString()); Assert.assertEquals(-1, ret); }
@Test public void locationNotExistTest() throws IOException { int ret = mFsShell.run(new String[] {"location", "/NotExistFile"}); Assert.assertEquals("/NotExistFile does not exist.\n", mOutput.toString()); Assert.assertEquals(-1, ret); }
@Test public void mkdirExistingTest() throws IOException { Assert.assertEquals(0, mFsShell.run(new String[] {"mkdir", "/testFile1"})); Assert.assertEquals(0, mFsShell.run(new String[] {"mkdir", "/testFile1"})); }
@Test public void mkdirInvalidPathTest() throws IOException { Assert.assertEquals(-1, mFsShell.run(new String[] {"mkdir", "/test File Invalid Path"})); }
@Test public void rmNotExistingFileTest() throws IOException { mFsShell.run(new String[] {"rm", "/testFile"}); String expected = "rm: cannot remove '/testFile': No such file or directory\n"; Assert.assertEquals(expected, mOutput.toString()); }