mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
refactor on tests
This commit is contained in:
parent
42b1884275
commit
3871541b5d
2 changed files with 337 additions and 321 deletions
|
|
@ -34,7 +34,8 @@
|
|||
<url>http://www.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<alluxio.version>1.0.0</alluxio.version>
|
||||
<alluxio.version>1.0.0</alluxio.version>
|
||||
<powermock.version>1.6.1</powermock.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
|
@ -72,6 +73,41 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<version>1.10.8</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito</artifactId>
|
||||
<version>${powermock.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-core</artifactId>
|
||||
<version>${powermock.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>${powermock.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-reflect</artifactId>
|
||||
<version>${powermock.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.alluxio</groupId>
|
||||
<artifactId>alluxio-core-server</artifactId>
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ package org.apache.zeppelin.alluxio;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -28,39 +27,36 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import alluxio.client.WriteType;
|
||||
import alluxio.client.file.URIStatus;
|
||||
import org.apache.zeppelin.interpreter.InterpreterResult;
|
||||
import org.apache.zeppelin.interpreter.InterpreterResult.Code;
|
||||
import org.junit.*;
|
||||
|
||||
import alluxio.Configuration;
|
||||
import alluxio.Constants;
|
||||
import alluxio.AlluxioURI;
|
||||
import alluxio.client.FileSystemTestUtils;
|
||||
import alluxio.client.AlluxioStorageType;
|
||||
import alluxio.client.UnderStorageType;
|
||||
import alluxio.client.file.FileInStream;
|
||||
import alluxio.client.file.FileSystem;
|
||||
import alluxio.client.file.options.InStreamOptions;
|
||||
import alluxio.exception.ExceptionMessage;
|
||||
import alluxio.exception.AlluxioException;
|
||||
import alluxio.master.LocalAlluxioCluster;
|
||||
import alluxio.shell.AlluxioShell;
|
||||
import alluxio.thrift.FileInfo;
|
||||
import alluxio.shell.command.CommandUtils;
|
||||
import alluxio.util.FormatUtils;
|
||||
import alluxio.util.io.BufferUtils;
|
||||
import alluxio.util.io.PathUtils;
|
||||
|
||||
|
||||
public class AlluxioInterpreterTest {
|
||||
private AlluxioInterpreter tachyonInterpreter;
|
||||
private AlluxioInterpreter alluxioInterpreter;
|
||||
private static final int SIZE_BYTES = Constants.MB * 10;
|
||||
private LocalAlluxioCluster mLocalAlluxioCluster = null;
|
||||
private FileSystem mTfs = null;
|
||||
private FileSystem fs = null;
|
||||
|
||||
@After
|
||||
public final void after() throws Exception {
|
||||
if (tachyonInterpreter != null) {
|
||||
tachyonInterpreter.close();
|
||||
if (alluxioInterpreter != null) {
|
||||
alluxioInterpreter.close();
|
||||
}
|
||||
mLocalAlluxioCluster.stop();
|
||||
}
|
||||
|
|
@ -69,13 +65,13 @@ public class AlluxioInterpreterTest {
|
|||
public final void before() throws Exception {
|
||||
mLocalAlluxioCluster = new LocalAlluxioCluster(SIZE_BYTES, 1000);
|
||||
mLocalAlluxioCluster.start();
|
||||
mTfs = mLocalAlluxioCluster.getClient();
|
||||
fs = mLocalAlluxioCluster.getClient();
|
||||
|
||||
final Properties props = new Properties();
|
||||
props.put(AlluxioInterpreter.ALLUXIO_MASTER_HOSTNAME, mLocalAlluxioCluster.getMasterHostname());
|
||||
props.put(AlluxioInterpreter.ALLUXIO_MASTER_PORT, mLocalAlluxioCluster.getMasterPort() + "");
|
||||
tachyonInterpreter = new AlluxioInterpreter(props);
|
||||
tachyonInterpreter.open();
|
||||
alluxioInterpreter = new AlluxioInterpreter(props);
|
||||
alluxioInterpreter.open();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -88,25 +84,25 @@ public class AlluxioInterpreterTest {
|
|||
List<String> expectedResultThree = Arrays.asList("copyFromLocal", "copyToLocal");
|
||||
List<String> expectedResultNone = new ArrayList<String>();
|
||||
|
||||
List<String> resultOne = tachyonInterpreter.completion("c", 0);
|
||||
List<String> resultTwo = tachyonInterpreter.completion("co", 0);
|
||||
List<String> resultThree = tachyonInterpreter.completion("copy", 0);
|
||||
List<String> resultNotMatch = tachyonInterpreter.completion("notMatch", 0);
|
||||
List<String> resultAll = tachyonInterpreter.completion("", 0);
|
||||
List<String> resultOne = alluxioInterpreter.completion("c", 0);
|
||||
List<String> resultTwo = alluxioInterpreter.completion("co", 0);
|
||||
List<String> resultThree = alluxioInterpreter.completion("copy", 0);
|
||||
List<String> resultNotMatch = alluxioInterpreter.completion("notMatch", 0);
|
||||
List<String> resultAll = alluxioInterpreter.completion("", 0);
|
||||
|
||||
Assert.assertEquals(expectedResultOne, resultOne);
|
||||
Assert.assertEquals(expectedResultTwo, resultTwo);
|
||||
Assert.assertEquals(expectedResultThree, resultThree);
|
||||
Assert.assertEquals(expectedResultNone, resultNotMatch);
|
||||
Assert.assertEquals(tachyonInterpreter.keywords, resultAll);
|
||||
Assert.assertEquals(alluxioInterpreter.keywords, resultAll);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void catDirectoryTest() throws IOException {
|
||||
String expected = "Successfully created directory /testDir\n\n" +
|
||||
"/testDir is not a file.\n";
|
||||
"Path /testDir must be a file\n";
|
||||
|
||||
InterpreterResult output = tachyonInterpreter.interpret("mkdir /testDir" +
|
||||
InterpreterResult output = alluxioInterpreter.interpret("mkdir /testDir" +
|
||||
"\ncat /testDir", null);
|
||||
|
||||
Assert.assertEquals(Code.ERROR, output.code());
|
||||
|
|
@ -115,208 +111,204 @@ public class AlluxioInterpreterTest {
|
|||
|
||||
@Test
|
||||
public void catNotExistTest() throws IOException {
|
||||
InterpreterResult output = tachyonInterpreter.interpret("cat /testFile", null);
|
||||
InterpreterResult output = alluxioInterpreter.interpret("cat /testFile", null);
|
||||
Assert.assertEquals(Code.ERROR, output.code());
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void catTest() throws IOException {
|
||||
// FileSystemTestUtils.createByteFile(mTfs, "/testFile", AlluxioStorageType.STORE,
|
||||
// UnderStorageType.NO_PERSIST, 10);
|
||||
// InterpreterResult output = tachyonInterpreter.interpret("cat /testFile", null);
|
||||
//
|
||||
// byte[] expected = BufferUtils.getIncreasingByteArray(10);
|
||||
//
|
||||
// Assert.assertEquals(Code.SUCCESS, output.code());
|
||||
// Assert.assertArrayEquals(expected,
|
||||
// output.message().substring(0, output.message().length() - 1).getBytes());
|
||||
// }
|
||||
@Test
|
||||
public void catTest() throws IOException {
|
||||
FileSystemTestUtils.createByteFile(fs, "/testFile", WriteType.MUST_CACHE,
|
||||
10, 10);
|
||||
InterpreterResult output = alluxioInterpreter.interpret("cat /testFile", null);
|
||||
|
||||
// @Test
|
||||
// public void copyFromLocalLargeTest() throws IOException, AlluxioException {
|
||||
// File testFile = new File(mLocalAlluxioCluster.getAlluxioHome() + "/testFile");
|
||||
// testFile.createNewFile();
|
||||
// FileOutputStream fos = new FileOutputStream(testFile);
|
||||
// byte[] toWrite = BufferUtils.getIncreasingByteArray(SIZE_BYTES);
|
||||
// fos.write(toWrite);
|
||||
// fos.close();
|
||||
//
|
||||
// InterpreterResult output = tachyonInterpreter.interpret("copyFromLocal " +
|
||||
// testFile.getAbsolutePath() + " /testFile", null);
|
||||
// Assert.assertEquals(
|
||||
// "Copied " + testFile.getAbsolutePath() + " to /testFile\n\n",
|
||||
// output.message());
|
||||
//
|
||||
// FileInStream tFile = mTfs.openFile(new AlluxioURI("/testFile"));
|
||||
// FileInfo fileInfo = mTfs.getInfo(tFile);
|
||||
// Assert.assertNotNull(fileInfo);
|
||||
// Assert.assertEquals(SIZE_BYTES, tFile.length);
|
||||
//
|
||||
// InStreamOptions options =
|
||||
// new InStreamOptions.Builder(new Configuration()).setAlluxioStorageType(
|
||||
// AlluxioStorageType.NO_STORE).build();
|
||||
// FileInStream tfis = mTfs.getInStream(tFile, options);
|
||||
// byte[] read = new byte[SIZE_BYTES];
|
||||
// tfis.read(read);
|
||||
// Assert.assertTrue(BufferUtils.equalIncreasingByteArray(SIZE_BYTES, read));
|
||||
// }
|
||||
byte[] expected = BufferUtils.getIncreasingByteArray(10);
|
||||
|
||||
// @Test
|
||||
// public void loadFileTest() throws IOException, AlluxioException {
|
||||
// TachyonFile file =
|
||||
// FileSystemTestUtils.createByteFile(mTfs, "/testFile", AlluxioStorageType.NO_STORE,
|
||||
// UnderStorageType.SYNC_PERSIST, 10);
|
||||
// FileInfo fileInfo = mTfs.getInfo(file);
|
||||
// Assert.assertFalse(fileInfo.getInMemoryPercentage() == 100);
|
||||
//
|
||||
// tachyonInterpreter.interpret("load /testFile", null);
|
||||
//
|
||||
// fileInfo = mTfs.getInfo(file);
|
||||
// Assert.assertTrue(fileInfo.getInMemoryPercentage() == 100);
|
||||
// }
|
||||
Assert.assertEquals(Code.SUCCESS, output.code());
|
||||
Assert.assertArrayEquals(expected,
|
||||
output.message().substring(0, output.message().length() - 1).getBytes());
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void loadDirTest() throws IOException, AlluxioException {
|
||||
// TachyonFile fileA = FileSystemTestUtils.createByteFile(mTfs, "/testRoot/testFileA",
|
||||
// AlluxioStorageType.NO_STORE, UnderStorageType.SYNC_PERSIST, 10);
|
||||
// TachyonFile fileB = FileSystemTestUtils.createByteFile(mTfs, "/testRoot/testFileB",
|
||||
// AlluxioStorageType.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);
|
||||
//
|
||||
// tachyonInterpreter.interpret("load /testRoot", null);
|
||||
//
|
||||
// fileInfoA = mTfs.getInfo(fileA);
|
||||
// fileInfoB = mTfs.getInfo(fileB);
|
||||
// Assert.assertTrue(fileInfoA.getInMemoryPercentage() == 100);
|
||||
// Assert.assertTrue(fileInfoB.getInMemoryPercentage() == 100);
|
||||
// }
|
||||
@Test
|
||||
public void copyFromLocalLargeTest() throws IOException, AlluxioException {
|
||||
File testFile = new File(mLocalAlluxioCluster.getAlluxioHome() + "/testFile");
|
||||
testFile.createNewFile();
|
||||
FileOutputStream fos = new FileOutputStream(testFile);
|
||||
byte[] toWrite = BufferUtils.getIncreasingByteArray(SIZE_BYTES);
|
||||
fos.write(toWrite);
|
||||
fos.close();
|
||||
|
||||
// @Test
|
||||
// public void copyFromLocalTest() throws IOException, AlluxioException {
|
||||
// File testDir = new File(mLocalAlluxioCluster.getAlluxioHome() + "/testDir");
|
||||
// testDir.mkdir();
|
||||
// File testDirInner = new File(mLocalAlluxioCluster.getAlluxioHome() + "/testDir/testDirInner");
|
||||
// testDirInner.mkdir();
|
||||
// File testFile =
|
||||
// generateFileContent("/testDir/testFile", BufferUtils.getIncreasingByteArray(10));
|
||||
//
|
||||
// generateFileContent("/testDir/testDirInner/testFile2",
|
||||
// BufferUtils.getIncreasingByteArray(10, 20));
|
||||
//
|
||||
// InterpreterResult output = tachyonInterpreter.interpret("copyFromLocal " +
|
||||
// testFile.getParent() + " /testDir", null);
|
||||
// Assert.assertEquals(
|
||||
// "Copied " + testFile.getParent() + " to /testDir\n\n",
|
||||
// output.message());
|
||||
//
|
||||
// TachyonFile file1 = mTfs.open(new AlluxioURI("/testDir/testFile"));
|
||||
// TachyonFile file2 = mTfs.open(new AlluxioURI("/testDir/testDirInner/testFile2"));
|
||||
// FileInfo fileInfo1 = mTfs.getInfo(file1);
|
||||
// FileInfo fileInfo2 = mTfs.getInfo(file2);
|
||||
// Assert.assertNotNull(fileInfo1);
|
||||
// Assert.assertNotNull(fileInfo2);
|
||||
// Assert.assertEquals(10, fileInfo1.length);
|
||||
// Assert.assertEquals(20, fileInfo2.length);
|
||||
//
|
||||
// byte[] read = readContent(file1, 10);
|
||||
// Assert.assertTrue(BufferUtils.equalIncreasingByteArray(10, read));
|
||||
// read = readContent(file2, 20);
|
||||
// Assert.assertTrue(BufferUtils.equalIncreasingByteArray(10, 20, read));
|
||||
// }
|
||||
InterpreterResult output = alluxioInterpreter.interpret("copyFromLocal " +
|
||||
testFile.getAbsolutePath() + " /testFile", null);
|
||||
Assert.assertEquals(
|
||||
"Copied " + testFile.getAbsolutePath() + " to /testFile\n\n",
|
||||
output.message());
|
||||
|
||||
// @Test
|
||||
// public void copyFromLocalTestWithFullURI() throws IOException, AlluxioException {
|
||||
// File testFile = generateFileContent("/srcFileURI", BufferUtils.getIncreasingByteArray(10));
|
||||
// String tachyonURI = "tachyon://" + mLocalAlluxioCluster.getMasterHostname() + ":"
|
||||
// + mLocalAlluxioCluster.getMasterPort() + "/destFileURI";
|
||||
//
|
||||
// InterpreterResult output = tachyonInterpreter.interpret("copyFromLocal " +
|
||||
// testFile.getPath() + " " + tachyonURI, null);
|
||||
// Assert.assertEquals(
|
||||
// "Copied " + testFile.getPath() + " to " + tachyonURI + "\n\n",
|
||||
// output.message());
|
||||
//
|
||||
// TachyonFile file = mTfs.open(new AlluxioURI("/destFileURI"));
|
||||
// FileInfo fileInfo = mTfs.getInfo(file);
|
||||
// Assert.assertEquals(10L, fileInfo.length);
|
||||
// byte[] read = readContent(file, 10);
|
||||
// Assert.assertTrue(BufferUtils.equalIncreasingByteArray(10, read));
|
||||
// }
|
||||
FileInStream tFile = fs.openFile(new AlluxioURI("/testFile"));
|
||||
long fileLength = fs.getStatus(new AlluxioURI("/testFile")).getLength();
|
||||
Assert.assertEquals(SIZE_BYTES, fileLength);
|
||||
|
||||
// @Test
|
||||
// public void copyFromLocalFileToDstPathTest() throws IOException, AlluxioException {
|
||||
// String dataString = "copyFromLocalFileToDstPathTest";
|
||||
// byte[] data = dataString.getBytes();
|
||||
// File localDir = new File(mLocalAlluxioCluster.getAlluxioHome() + "/localDir");
|
||||
// localDir.mkdir();
|
||||
// File localFile = generateFileContent("/localDir/testFile", data);
|
||||
//
|
||||
// tachyonInterpreter.interpret("mkdir /dstDir", null);
|
||||
// tachyonInterpreter.interpret("copyFromLocal " + localFile.getPath() + " /dstDir", null);
|
||||
//
|
||||
// TachyonFile file = mTfs.open(new AlluxioURI("/dstDir/testFile"));
|
||||
// FileInfo fileInfo = mTfs.getInfo(file);
|
||||
// Assert.assertNotNull(fileInfo);
|
||||
// byte[] read = readContent(file, data.length);
|
||||
// Assert.assertEquals(new String(read), dataString);
|
||||
// }
|
||||
FileInStream fStream = fs.openFile(new AlluxioURI("/testFile"));
|
||||
byte[] read = new byte[SIZE_BYTES];
|
||||
fStream.read(read);
|
||||
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(SIZE_BYTES, read));
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void copyToLocalLargeTest() throws IOException {
|
||||
// copyToLocalWithBytes(SIZE_BYTES);
|
||||
// }
|
||||
@Test
|
||||
public void loadFileTest() throws IOException, AlluxioException {
|
||||
FileSystemTestUtils.createByteFile(fs, "/testFile", WriteType.CACHE_THROUGH, 10, 10);
|
||||
|
||||
// @Test
|
||||
// public void copyToLocalTest() throws IOException {
|
||||
// copyToLocalWithBytes(10);
|
||||
// }
|
||||
int memPercentage = fs.getStatus(new AlluxioURI("/testFile")).getInMemoryPercentage();
|
||||
Assert.assertFalse(memPercentage == 0);
|
||||
|
||||
// private void copyToLocalWithBytes(int bytes) throws IOException {
|
||||
// FileSystemTestUtils.createByteFile(mTfs, "/testFile", AlluxioStorageType.STORE,
|
||||
// UnderStorageType.NO_PERSIST, bytes);
|
||||
//
|
||||
// InterpreterResult output = tachyonInterpreter.interpret("copyToLocal /testFile " +
|
||||
// mLocalAlluxioCluster.getAlluxioHome() + "/testFile", null);
|
||||
//
|
||||
// Assert.assertEquals(
|
||||
// "Copied /testFile to " + mLocalAlluxioCluster.getAlluxioHome() + "/testFile\n\n",
|
||||
// output.message());
|
||||
// fileReadTest("/testFile", 10);
|
||||
// }
|
||||
alluxioInterpreter.interpret("load /testFile", null);
|
||||
|
||||
memPercentage = fs.getStatus(new AlluxioURI("/testFile")).getInMemoryPercentage();
|
||||
Assert.assertTrue(memPercentage == 100);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadDirTest() throws IOException, AlluxioException {
|
||||
FileSystemTestUtils.createByteFile(fs, "/testRoot/testFileA", WriteType.CACHE_THROUGH, 10, 10);
|
||||
FileSystemTestUtils.createByteFile(fs, "/testRoot/testFileB", WriteType.MUST_CACHE, 10, 10);
|
||||
|
||||
int memPercentageA = fs.getStatus(new AlluxioURI("/testRoot/testFileA")).getInMemoryPercentage();
|
||||
int memPercentageB = fs.getStatus(new AlluxioURI("/testRoot/testFileB")).getInMemoryPercentage();
|
||||
Assert.assertFalse(memPercentageA == 0);
|
||||
Assert.assertTrue(memPercentageB == 100);
|
||||
|
||||
alluxioInterpreter.interpret("load /testRoot", null);
|
||||
|
||||
memPercentageA = fs.getStatus(new AlluxioURI("/testRoot/testFileA")).getInMemoryPercentage();
|
||||
memPercentageB = fs.getStatus(new AlluxioURI("/testRoot/testFileB")).getInMemoryPercentage();
|
||||
Assert.assertTrue(memPercentageA == 100);
|
||||
Assert.assertTrue(memPercentageB == 100);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyFromLocalTest() throws IOException, AlluxioException {
|
||||
File testDir = new File(mLocalAlluxioCluster.getAlluxioHome() + "/testDir");
|
||||
testDir.mkdir();
|
||||
File testDirInner = new File(mLocalAlluxioCluster.getAlluxioHome() + "/testDir/testDirInner");
|
||||
testDirInner.mkdir();
|
||||
File testFile =
|
||||
generateFileContent("/testDir/testFile", BufferUtils.getIncreasingByteArray(10));
|
||||
|
||||
generateFileContent("/testDir/testDirInner/testFile2",
|
||||
BufferUtils.getIncreasingByteArray(10, 20));
|
||||
|
||||
InterpreterResult output = alluxioInterpreter.interpret("copyFromLocal " +
|
||||
testFile.getParent() + " /testDir", null);
|
||||
Assert.assertEquals(
|
||||
"Copied " + testFile.getParent() + " to /testDir\n\n",
|
||||
output.message());
|
||||
|
||||
long fileLength1 = fs.getStatus(new AlluxioURI("/testDir/testFile")).getLength();
|
||||
long fileLength2 = fs.getStatus(new AlluxioURI("/testDir/testDirInner/testFile2")).getLength();
|
||||
Assert.assertEquals(10, fileLength1);
|
||||
Assert.assertEquals(20, fileLength2);
|
||||
|
||||
FileInStream fStream1 = fs.openFile(new AlluxioURI("/testDir/testFile"));
|
||||
FileInStream fStream2 = fs.openFile(new AlluxioURI("/testDir/testDirInner/testFile2"));
|
||||
byte[] read = new byte[10];
|
||||
fStream1.read(read);
|
||||
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(10, read));
|
||||
read = new byte[20];
|
||||
fStream2.read(read);
|
||||
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(10, 20, read));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyFromLocalTestWithFullURI() throws IOException, AlluxioException {
|
||||
File testFile = generateFileContent("/srcFileURI", BufferUtils.getIncreasingByteArray(10));
|
||||
String uri = "tachyon://" + mLocalAlluxioCluster.getMasterHostname() + ":"
|
||||
+ mLocalAlluxioCluster.getMasterPort() + "/destFileURI";
|
||||
|
||||
InterpreterResult output = alluxioInterpreter.interpret("copyFromLocal " +
|
||||
testFile.getPath() + " " + uri, null);
|
||||
Assert.assertEquals(
|
||||
"Copied " + testFile.getPath() + " to " + uri + "\n\n",
|
||||
output.message());
|
||||
|
||||
long fileLength = fs.getStatus(new AlluxioURI("/destFileURI")).getLength();
|
||||
Assert.assertEquals(10L, fileLength);
|
||||
|
||||
FileInStream fStream = fs.openFile(new AlluxioURI("/destFileURI"));
|
||||
byte[] read = new byte[10];
|
||||
fStream.read(read);
|
||||
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(10, read));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyFromLocalFileToDstPathTest() throws IOException, AlluxioException {
|
||||
String dataString = "copyFromLocalFileToDstPathTest";
|
||||
byte[] data = dataString.getBytes();
|
||||
File localDir = new File(mLocalAlluxioCluster.getAlluxioHome() + "/localDir");
|
||||
localDir.mkdir();
|
||||
File localFile = generateFileContent("/localDir/testFile", data);
|
||||
|
||||
alluxioInterpreter.interpret("mkdir /dstDir", null);
|
||||
alluxioInterpreter.interpret("copyFromLocal " + localFile.getPath() + " /dstDir", null);
|
||||
|
||||
FileInStream fStream = fs.openFile(new AlluxioURI("/dstDir/testFile"));
|
||||
long fileLength = fs.getStatus(new AlluxioURI("/dstDir/testFile")).getLength();
|
||||
|
||||
byte[] read = new byte[(int) fileLength];
|
||||
fStream.read(read);
|
||||
Assert.assertEquals(new String(read), dataString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyToLocalLargeTest() throws IOException {
|
||||
copyToLocalWithBytes(SIZE_BYTES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyToLocalTest() throws IOException {
|
||||
copyToLocalWithBytes(10);
|
||||
}
|
||||
|
||||
private void copyToLocalWithBytes(int bytes) throws IOException {
|
||||
FileSystemTestUtils.createByteFile(fs, "/testFile", WriteType.MUST_CACHE, 10, 10);
|
||||
|
||||
InterpreterResult output = alluxioInterpreter.interpret("copyToLocal /testFile " +
|
||||
mLocalAlluxioCluster.getAlluxioHome() + "/testFile", null);
|
||||
|
||||
Assert.assertEquals(
|
||||
"Copied /testFile to " + mLocalAlluxioCluster.getAlluxioHome() + "/testFile\n\n",
|
||||
output.message());
|
||||
fileReadTest("/testFile", 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void countNotExistTest() throws IOException {
|
||||
InterpreterResult output = tachyonInterpreter.interpret("count /NotExistFile", null);
|
||||
InterpreterResult output = alluxioInterpreter.interpret("count /NotExistFile", null);
|
||||
Assert.assertEquals(Code.ERROR, output.code());
|
||||
Assert.assertEquals(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage("/NotExistFile") + "\n",
|
||||
output.message());
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void countTest() throws IOException {
|
||||
// FileSystemTestUtils.createByteFile(mTfs, "/testRoot/testFileA", AlluxioStorageType.STORE,
|
||||
// UnderStorageType.NO_PERSIST, 10);
|
||||
// FileSystemTestUtils.createByteFile(mTfs, "/testRoot/testDir/testFileB", AlluxioStorageType.STORE,
|
||||
// UnderStorageType.NO_PERSIST, 20);
|
||||
// FileSystemTestUtils.createByteFile(mTfs, "/testRoot/testFileB", AlluxioStorageType.STORE,
|
||||
// UnderStorageType.NO_PERSIST, 30);
|
||||
//
|
||||
// InterpreterResult output = tachyonInterpreter.interpret("count /testRoot", null);
|
||||
//
|
||||
// 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);
|
||||
// expected += "\n";
|
||||
// Assert.assertEquals(expected, output.message());
|
||||
// }
|
||||
@Test
|
||||
public void countTest() throws IOException {
|
||||
FileSystemTestUtils.createByteFile(fs, "/testRoot/testFileA",
|
||||
WriteType.CACHE_THROUGH, 10, 10);
|
||||
FileSystemTestUtils.createByteFile(fs, "/testRoot/testDir/testFileB",
|
||||
WriteType.CACHE_THROUGH, 20, 20);
|
||||
FileSystemTestUtils.createByteFile(fs, "/testRoot/testFileB",
|
||||
WriteType.CACHE_THROUGH, 30, 30);
|
||||
|
||||
InterpreterResult output = alluxioInterpreter.interpret("count /testRoot", null);
|
||||
|
||||
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);
|
||||
expected += "\n";
|
||||
Assert.assertEquals(expected, output.message());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fileinfoNotExistTest() throws IOException {
|
||||
InterpreterResult output = tachyonInterpreter.interpret("fileinfo /NotExistFile", null);
|
||||
InterpreterResult output = alluxioInterpreter.interpret("fileInfo /NotExistFile", null);
|
||||
Assert.assertEquals(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage("/NotExistFile") + "\n",
|
||||
output.message());
|
||||
Assert.assertEquals(Code.ERROR, output.code());
|
||||
|
|
@ -324,137 +316,135 @@ public class AlluxioInterpreterTest {
|
|||
|
||||
@Test
|
||||
public void locationNotExistTest() throws IOException {
|
||||
InterpreterResult output = tachyonInterpreter.interpret("location /NotExistFile", null);
|
||||
InterpreterResult output = alluxioInterpreter.interpret("location /NotExistFile", null);
|
||||
Assert.assertEquals(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage("/NotExistFile") + "\n",
|
||||
output.message());
|
||||
Assert.assertEquals(Code.ERROR, output.code());
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void lsTest() throws IOException, AlluxioException {
|
||||
// FileInfo[] files = new FileInfo[3];
|
||||
//
|
||||
// TachyonFile fileA = FileSystemTestUtils.createByteFile(mTfs, "/testRoot/testFileA",
|
||||
// AlluxioStorageType.STORE, UnderStorageType.NO_PERSIST, 10);
|
||||
// files[0] = mTfs.getInfo(fileA);
|
||||
// FileSystemTestUtils.createByteFile(mTfs, "/testRoot/testDir/testFileB", AlluxioStorageType.STORE,
|
||||
// UnderStorageType.NO_PERSIST, 20);
|
||||
// files[1] = mTfs.getInfo(mTfs.open(new AlluxioURI("/testRoot/testDir")));
|
||||
// TachyonFile fileC = FileSystemTestUtils.createByteFile(mTfs, "/testRoot/testFileC",
|
||||
// AlluxioStorageType.NO_STORE, UnderStorageType.SYNC_PERSIST, 30);
|
||||
// files[2] = mTfs.getInfo(fileC);
|
||||
//
|
||||
// InterpreterResult output = tachyonInterpreter.interpret("ls /testRoot", null);
|
||||
//
|
||||
// String expected = "";
|
||||
// String format = "%-10s%-25s%-15s%-5s\n";
|
||||
// expected += String.format(format, FormatUtils.getSizeFromBytes(10),
|
||||
// AlluxioShell.convertMsToDate(files[0].getCreationTimeMs()), "In Memory", "/testRoot/testFileA");
|
||||
// expected += String.format(format, FormatUtils.getSizeFromBytes(0),
|
||||
// AlluxioShell.convertMsToDate(files[1].getCreationTimeMs()), "", "/testRoot/testDir");
|
||||
// expected += String.format(format, FormatUtils.getSizeFromBytes(30),
|
||||
// AlluxioShell.convertMsToDate(files[2].getCreationTimeMs()), "Not In Memory",
|
||||
// "/testRoot/testFileC");
|
||||
// expected += "\n";
|
||||
//
|
||||
// Assert.assertEquals(Code.SUCCESS, output.code());
|
||||
// Assert.assertEquals(expected, output.message());
|
||||
// }
|
||||
@Test
|
||||
public void lsTest() throws IOException, AlluxioException {
|
||||
URIStatus[] files = new URIStatus[3];
|
||||
|
||||
// @Test
|
||||
// public void lsrTest() throws IOException, AlluxioException {
|
||||
// FileInfo[] files = new FileInfo[4];
|
||||
// TachyonFile fileA = FileSystemTestUtils.createByteFile(mTfs, "/testRoot/testFileA",
|
||||
// AlluxioStorageType.STORE, UnderStorageType.NO_PERSIST, 10);
|
||||
// files[0] = mTfs.getInfo(fileA);
|
||||
// FileSystemTestUtils.createByteFile(mTfs, "/testRoot/testDir/testFileB", AlluxioStorageType.STORE,
|
||||
// UnderStorageType.NO_PERSIST, 20);
|
||||
// files[1] = mTfs.getInfo(mTfs.open(new AlluxioURI("/testRoot/testDir")));
|
||||
// files[2] = mTfs.getInfo(mTfs.open(new AlluxioURI("/testRoot/testDir/testFileB")));
|
||||
// TachyonFile fileC = FileSystemTestUtils.createByteFile(mTfs, "/testRoot/testFileC",
|
||||
// AlluxioStorageType.NO_STORE, UnderStorageType.SYNC_PERSIST, 30);
|
||||
// files[3] = mTfs.getInfo(fileC);
|
||||
//
|
||||
// InterpreterResult output = tachyonInterpreter.interpret("lsr /testRoot", null);
|
||||
//
|
||||
// String expected = "";
|
||||
// String format = "%-10s%-25s%-15s%-5s\n";
|
||||
// expected +=
|
||||
// String.format(format, FormatUtils.getSizeFromBytes(10),
|
||||
// AlluxioShell.convertMsToDate(files[0].getCreationTimeMs()), "In Memory",
|
||||
// "/testRoot/testFileA");
|
||||
// expected +=
|
||||
// String.format(format, FormatUtils.getSizeFromBytes(0),
|
||||
// AlluxioShell.convertMsToDate(files[1].getCreationTimeMs()), "", "/testRoot/testDir");
|
||||
// expected +=
|
||||
// String.format(format, FormatUtils.getSizeFromBytes(20),
|
||||
// AlluxioShell.convertMsToDate(files[2].getCreationTimeMs()), "In Memory",
|
||||
// "/testRoot/testDir/testFileB");
|
||||
// expected +=
|
||||
// String.format(format, FormatUtils.getSizeFromBytes(30),
|
||||
// AlluxioShell.convertMsToDate(files[3].getCreationTimeMs()), "Not In Memory",
|
||||
// "/testRoot/testFileC");
|
||||
// expected += "\n";
|
||||
// Assert.assertEquals(expected, output.message());
|
||||
// }
|
||||
FileSystemTestUtils.createByteFile(fs, "/testRoot/testFileA",
|
||||
WriteType.MUST_CACHE, 10, 10);
|
||||
FileSystemTestUtils.createByteFile(fs, "/testRoot/testDir/testFileB",
|
||||
WriteType.MUST_CACHE, 20, 20);
|
||||
FileSystemTestUtils.createByteFile(fs, "/testRoot/testFileC",
|
||||
WriteType.THROUGH, 30, 30);
|
||||
|
||||
// @Test
|
||||
// public void mkdirComplexPathTest() throws IOException, AlluxioException {
|
||||
// InterpreterResult output = tachyonInterpreter.interpret(
|
||||
// "mkdir /Complex!@#$%^&*()-_=+[]{};\"'<>,.?/File", null);
|
||||
//
|
||||
// TachyonFile tFile = mTfs.open(new AlluxioURI("/Complex!@#$%^&*()-_=+[]{};\"'<>,.?/File"));
|
||||
// FileInfo fileInfo = mTfs.getInfo(tFile);
|
||||
// Assert.assertNotNull(fileInfo);
|
||||
// Assert.assertEquals(
|
||||
// "Successfully created directory /Complex!@#$%^&*()-_=+[]{};\"'<>,.?/File\n\n",
|
||||
// output.message());
|
||||
// Assert.assertTrue(fileInfo.isIsFolder());
|
||||
// }
|
||||
files[0] = fs.getStatus(new AlluxioURI("/testRoot/testFileA"));
|
||||
files[1] = fs.getStatus(new AlluxioURI("/testRoot/testDir"));
|
||||
files[2] = fs.getStatus(new AlluxioURI("/testRoot/testFileC"));
|
||||
|
||||
InterpreterResult output = alluxioInterpreter.interpret("ls /testRoot", null);
|
||||
|
||||
String expected = "";
|
||||
String format = "%-10s%-25s%-15s%-5s\n";
|
||||
expected += String.format(format, FormatUtils.getSizeFromBytes(10),
|
||||
CommandUtils.convertMsToDate(files[0].getCreationTimeMs()), "In Memory", "/testRoot/testFileA");
|
||||
expected += String.format(format, FormatUtils.getSizeFromBytes(0),
|
||||
CommandUtils.convertMsToDate(files[1].getCreationTimeMs()), "", "/testRoot/testDir");
|
||||
expected += String.format(format, FormatUtils.getSizeFromBytes(30),
|
||||
CommandUtils.convertMsToDate(files[2].getCreationTimeMs()), "Not In Memory",
|
||||
"/testRoot/testFileC");
|
||||
expected += "\n";
|
||||
|
||||
Assert.assertEquals(Code.SUCCESS, output.code());
|
||||
Assert.assertEquals(expected, output.message());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lsRecursiveTest() throws IOException, AlluxioException {
|
||||
URIStatus[] files = new URIStatus[4];
|
||||
|
||||
FileSystemTestUtils.createByteFile(fs, "/testRoot/testFileA",
|
||||
WriteType.MUST_CACHE, 10, 10);
|
||||
FileSystemTestUtils.createByteFile(fs, "/testRoot/testDir/testFileB",
|
||||
WriteType.MUST_CACHE, 20, 20);
|
||||
FileSystemTestUtils.createByteFile(fs, "/testRoot/testFileC",
|
||||
WriteType.THROUGH, 30, 30);
|
||||
|
||||
files[0] = fs.getStatus(new AlluxioURI("/testRoot/testFileA"));
|
||||
files[1] = fs.getStatus(new AlluxioURI("/testRoot/testDir"));
|
||||
files[2] = fs.getStatus(new AlluxioURI("/testRoot/testDir/testFileB"));
|
||||
files[3] = fs.getStatus(new AlluxioURI("/testRoot/testFileC"));
|
||||
|
||||
InterpreterResult output = alluxioInterpreter.interpret("ls -R /testRoot", null);
|
||||
|
||||
String expected = "";
|
||||
String format = "%-10s%-25s%-15s%-5s\n";
|
||||
expected +=
|
||||
String.format(format, FormatUtils.getSizeFromBytes(10),
|
||||
CommandUtils.convertMsToDate(files[0].getCreationTimeMs()), "In Memory",
|
||||
"/testRoot/testFileA");
|
||||
expected +=
|
||||
String.format(format, FormatUtils.getSizeFromBytes(0),
|
||||
CommandUtils.convertMsToDate(files[1].getCreationTimeMs()), "", "/testRoot/testDir");
|
||||
expected +=
|
||||
String.format(format, FormatUtils.getSizeFromBytes(20),
|
||||
CommandUtils.convertMsToDate(files[2].getCreationTimeMs()), "In Memory",
|
||||
"/testRoot/testDir/testFileB");
|
||||
expected +=
|
||||
String.format(format, FormatUtils.getSizeFromBytes(30),
|
||||
CommandUtils.convertMsToDate(files[3].getCreationTimeMs()), "Not In Memory",
|
||||
"/testRoot/testFileC");
|
||||
expected += "\n";
|
||||
|
||||
Assert.assertEquals(expected, output.message());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mkdirComplexPathTest() throws IOException, AlluxioException {
|
||||
InterpreterResult output = alluxioInterpreter.interpret(
|
||||
"mkdir /Complex!@#$%^&*()-_=+[]{};\"'<>,.?/File", null);
|
||||
|
||||
boolean existsDir = fs.exists(new AlluxioURI("/Complex!@#$%^&*()-_=+[]{};\"'<>,.?/File"));
|
||||
Assert.assertEquals(
|
||||
"Successfully created directory /Complex!@#$%^&*()-_=+[]{};\"'<>,.?/File\n\n",
|
||||
output.message());
|
||||
Assert.assertTrue(existsDir);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mkdirExistingTest() throws IOException {
|
||||
String command = "mkdir /festFile1";
|
||||
Assert.assertEquals(Code.SUCCESS, tachyonInterpreter.interpret(command, null).code());
|
||||
Assert.assertEquals(Code.SUCCESS, tachyonInterpreter.interpret(command, null).code());
|
||||
Assert.assertEquals(Code.SUCCESS, alluxioInterpreter.interpret(command, null).code());
|
||||
Assert.assertEquals(Code.ERROR, alluxioInterpreter.interpret(command, null).code());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mkdirInvalidPathTest() throws IOException {
|
||||
Assert.assertEquals(
|
||||
Code.ERROR,
|
||||
tachyonInterpreter.interpret("mkdir /test File Invalid Path", null).code());
|
||||
alluxioInterpreter.interpret("mkdir /test File Invalid Path", null).code());
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void mkdirShortPathTest() throws IOException, AlluxioException {
|
||||
// InterpreterResult output = tachyonInterpreter.interpret("mkdir /root/testFile1", null);
|
||||
// TachyonFile tFile = mTfs.open(new AlluxioURI("/root/testFile1"));
|
||||
// FileInfo fileInfo = mTfs.getInfo(tFile);
|
||||
// Assert.assertNotNull(fileInfo);
|
||||
// Assert.assertEquals(
|
||||
// "Successfully created directory /root/testFile1\n\n",
|
||||
// output.message());
|
||||
// Assert.assertTrue(fileInfo.isIsFolder());
|
||||
// }
|
||||
@Test
|
||||
public void mkdirShortPathTest() throws IOException, AlluxioException {
|
||||
InterpreterResult output = alluxioInterpreter.interpret("mkdir /root/testFile1", null);
|
||||
boolean existsDir = fs.exists(new AlluxioURI("/root/testFile1"));
|
||||
Assert.assertEquals(
|
||||
"Successfully created directory /root/testFile1\n\n",
|
||||
output.message());
|
||||
Assert.assertTrue(existsDir);
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void mkdirTest() throws IOException, AlluxioException {
|
||||
// String qualifiedPath =
|
||||
// "tachyon://" + mLocalAlluxioCluster.getMasterHostname() + ":"
|
||||
// + mLocalAlluxioCluster.getMasterPort() + "/root/testFile1";
|
||||
// InterpreterResult output = tachyonInterpreter.interpret("mkdir " + qualifiedPath, null);
|
||||
// TachyonFile tFile = mTfs.open(new AlluxioURI("/root/testFile1"));
|
||||
// FileInfo fileInfo = mTfs.getInfo(tFile);
|
||||
// Assert.assertNotNull(fileInfo);
|
||||
// Assert.assertEquals(
|
||||
// "Successfully created directory " + qualifiedPath + "\n\n",
|
||||
// output.message());
|
||||
// Assert.assertTrue(fileInfo.isIsFolder());
|
||||
// }
|
||||
@Test
|
||||
public void mkdirTest() throws IOException, AlluxioException {
|
||||
String qualifiedPath =
|
||||
"tachyon://" + mLocalAlluxioCluster.getMasterHostname() + ":"
|
||||
+ mLocalAlluxioCluster.getMasterPort() + "/root/testFile1";
|
||||
InterpreterResult output = alluxioInterpreter.interpret("mkdir " + qualifiedPath, null);
|
||||
boolean existsDir = fs.exists(new AlluxioURI("/root/testFile1"));
|
||||
Assert.assertEquals(
|
||||
"Successfully created directory " + qualifiedPath + "\n\n",
|
||||
output.message());
|
||||
Assert.assertTrue(existsDir);
|
||||
}
|
||||
|
||||
private File generateFileContent(String path, byte[] toWrite)
|
||||
throws IOException, FileNotFoundException {
|
||||
throws IOException {
|
||||
File testFile = new File(mLocalAlluxioCluster.getAlluxioHome() + path);
|
||||
testFile.createNewFile();
|
||||
FileOutputStream fos = new FileOutputStream(testFile);
|
||||
|
|
@ -463,16 +453,6 @@ public class AlluxioInterpreterTest {
|
|||
return testFile;
|
||||
}
|
||||
|
||||
// private byte[] readContent(TachyonFile tFile, int length) throws IOException, AlluxioException {
|
||||
// InStreamOptions options =
|
||||
// new InStreamOptions.Builder(new Configuration()).setAlluxioStorageType(
|
||||
// AlluxioStorageType.NO_STORE).build();
|
||||
// FileInStream tfis = mTfs.getInStream(tFile, options);
|
||||
// byte[] read = new byte[length];
|
||||
// tfis.read(read);
|
||||
// return read;
|
||||
// }
|
||||
|
||||
private void fileReadTest(String fileName, int size) throws IOException {
|
||||
File testFile = new File(PathUtils.concatPath(mLocalAlluxioCluster.getAlluxioHome(), fileName));
|
||||
FileInputStream fis = new FileInputStream(testFile);
|
||||
|
|
|
|||
Loading…
Reference in a new issue