Search in sources :

Example 86 with AlluxioURI

use of alluxio.AlluxioURI in project alluxio by Alluxio.

the class CopyFromLocalCommandTest method copyFromLocalLarge.

@Test
public void copyFromLocalLarge() 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();
    mFsShell.run("copyFromLocal", testFile.getAbsolutePath(), "/testFile");
    Assert.assertEquals(getCommandOutput(new String[] { "copyFromLocal", testFile.getAbsolutePath(), "/testFile" }), mOutput.toString());
    AlluxioURI uri = new AlluxioURI("/testFile");
    URIStatus status = mFileSystem.getStatus(uri);
    Assert.assertNotNull(status);
    Assert.assertEquals(SIZE_BYTES, status.getLength());
    try (FileInStream tfis = mFileSystem.openFile(uri, OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE))) {
        byte[] read = new byte[SIZE_BYTES];
        tfis.read(read);
        Assert.assertTrue(BufferUtils.equalIncreasingByteArray(SIZE_BYTES, read));
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) FileInStream(alluxio.client.file.FileInStream) URIStatus(alluxio.client.file.URIStatus) File(java.io.File) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) AlluxioShellUtilsTest(alluxio.shell.AlluxioShellUtilsTest) AbstractAlluxioShellTest(alluxio.shell.AbstractAlluxioShellTest)

Example 87 with AlluxioURI

use of alluxio.AlluxioURI in project alluxio by Alluxio.

the class FileSystemMasterIntegrationTest method deleteEmptyDirectory.

@Test
public void deleteEmptyDirectory() throws Exception {
    mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryOptions.defaults());
    Assert.assertEquals(1, mFsMaster.getFileId(new AlluxioURI("/testFolder")));
    mFsMaster.delete(new AlluxioURI("/testFolder"), DeleteOptions.defaults().setRecursive(true));
    Assert.assertEquals(IdUtils.INVALID_FILE_ID, mFsMaster.getFileId(new AlluxioURI("/testFolder")));
}
Also used : AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 88 with AlluxioURI

use of alluxio.AlluxioURI in project alluxio by Alluxio.

the class FileSystemMasterIntegrationTest method concurrentCreateDelete.

@Test
public void concurrentCreateDelete() throws Exception {
    List<Future<?>> futures = new ArrayList<>();
    AlluxioURI directory = new AlluxioURI("/dir");
    AlluxioURI[] files = new AlluxioURI[10];
    final int numThreads = 8;
    final int testDurationMs = 3000;
    for (int i = 0; i < 10; i++) {
        files[i] = directory.join("file_" + i);
    }
    mFsMaster.createDirectory(directory, CreateDirectoryOptions.defaults());
    AtomicBoolean stopThreads = new AtomicBoolean(false);
    CyclicBarrier barrier = new CyclicBarrier(numThreads);
    ExecutorService threadPool = Executors.newCachedThreadPool();
    try {
        for (int i = 0; i < numThreads; i++) {
            futures.add(threadPool.submit(new ConcurrentCreateDelete(barrier, stopThreads, files)));
        }
        CommonUtils.sleepMs(testDurationMs);
        stopThreads.set(true);
        for (Future<?> future : futures) {
            future.get();
        }
        // Stop Alluxio.
        mLocalAlluxioClusterResource.get().stopFS();
        // Create the master using the existing journal.
        createFileSystemMasterFromJournal();
    } finally {
        threadPool.shutdownNow();
        threadPool.awaitTermination(SHUTDOWN_TIME_MS, TimeUnit.MILLISECONDS);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) AlluxioURI(alluxio.AlluxioURI) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.junit.Test)

Example 89 with AlluxioURI

use of alluxio.AlluxioURI in project alluxio by Alluxio.

the class FileSystemMasterIntegrationTest method createFileInvalidPathTest2.

@Test
public void createFileInvalidPathTest2() throws Exception {
    mThrown.expect(FileAlreadyExistsException.class);
    mFsMaster.createFile(new AlluxioURI("/"), CreateFileOptions.defaults());
}
Also used : AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 90 with AlluxioURI

use of alluxio.AlluxioURI in project alluxio by Alluxio.

the class FileSystemMasterIntegrationTest method listFiles.

@Test
public void listFiles() throws Exception {
    CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(64);
    HashSet<Long> ids = new HashSet<>();
    HashSet<Long> dirIds = new HashSet<>();
    for (int i = 0; i < 10; i++) {
        AlluxioURI dir = new AlluxioURI("/i" + i);
        mFsMaster.createDirectory(dir, CreateDirectoryOptions.defaults());
        dirIds.add(mFsMaster.getFileId(dir));
        for (int j = 0; j < 10; j++) {
            ids.add(mFsMaster.createFile(dir.join("j" + j), options));
        }
    }
    HashSet<Long> listedIds = new HashSet<>();
    HashSet<Long> listedDirIds = new HashSet<>();
    List<FileInfo> infoList = mFsMaster.listStatus(new AlluxioURI("/"), ListStatusOptions.defaults());
    for (FileInfo info : infoList) {
        long id = info.getFileId();
        listedDirIds.add(id);
        for (FileInfo fileInfo : mFsMaster.listStatus(new AlluxioURI(info.getPath()), ListStatusOptions.defaults())) {
            listedIds.add(fileInfo.getFileId());
        }
    }
    Assert.assertEquals(ids, listedIds);
    Assert.assertEquals(dirIds, listedDirIds);
}
Also used : CreateFileOptions(alluxio.master.file.options.CreateFileOptions) FileInfo(alluxio.wire.FileInfo) HashSet(java.util.HashSet) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Aggregations

AlluxioURI (alluxio.AlluxioURI)1552 Test (org.junit.Test)1094 URIStatus (alluxio.client.file.URIStatus)356 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)303 IOException (java.io.IOException)154 FileInStream (alluxio.client.file.FileInStream)152 FileInfo (alluxio.wire.FileInfo)130 AbstractFileSystemShellTest (alluxio.client.cli.fs.AbstractFileSystemShellTest)124 ArrayList (java.util.ArrayList)120 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)119 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)114 File (java.io.File)107 FileSystem (alluxio.client.file.FileSystem)99 FileOutStream (alluxio.client.file.FileOutStream)97 AlluxioException (alluxio.exception.AlluxioException)92 CreateFilePOptions (alluxio.grpc.CreateFilePOptions)76 InvalidPathException (alluxio.exception.InvalidPathException)68 AbstractAlluxioShellTest (alluxio.shell.AbstractAlluxioShellTest)63 UnderFileSystem (alluxio.underfs.UnderFileSystem)63 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)62