Search in sources :

Example 1 with RenamePOptions

use of alluxio.grpc.RenamePOptions in project alluxio by Alluxio.

the class BaseFileSystem method rename.

@Override
public void rename(AlluxioURI src, AlluxioURI dst, RenamePOptions options) throws FileDoesNotExistException, IOException, AlluxioException {
    checkUri(src);
    checkUri(dst);
    rpc(client -> {
        RenamePOptions mergedOptions = FileSystemOptions.renameDefaults(mFsContext.getPathConf(dst)).toBuilder().mergeFrom(options).build();
        // TODO(calvin): Update this code on the master side.
        client.rename(src, dst, mergedOptions);
        LOG.debug("Renamed {} to {}, options: {}", src.getPath(), dst.getPath(), mergedOptions);
        return null;
    });
}
Also used : RenamePOptions(alluxio.grpc.RenamePOptions)

Example 2 with RenamePOptions

use of alluxio.grpc.RenamePOptions in project alluxio by Alluxio.

the class UfsSyncIntegrationTest method renameFileSync.

@Test
public void renameFileSync() throws Exception {
    RenamePOptions options = RenamePOptions.newBuilder().setCommonOptions(PSYNC_ALWAYS).build();
    mFileSystem.rename(new AlluxioURI(alluxioPath(EXISTING_FILE)), new AlluxioURI(alluxioPath(NEW_FILE)), options);
}
Also used : RenamePOptions(alluxio.grpc.RenamePOptions) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 3 with RenamePOptions

use of alluxio.grpc.RenamePOptions in project alluxio by Alluxio.

the class UfsSyncIntegrationTest method renameFileNoSync.

@Test
public void renameFileNoSync() throws Exception {
    RenamePOptions options = RenamePOptions.newBuilder().setCommonOptions(PSYNC_NEVER).build();
    try {
        mFileSystem.rename(new AlluxioURI(alluxioPath(EXISTING_FILE)), new AlluxioURI(alluxioPath(NEW_FILE)), options);
        Assert.fail("Rename expected to fail.");
    } catch (FileDoesNotExistException e) {
    // expected
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) RenamePOptions(alluxio.grpc.RenamePOptions) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 4 with RenamePOptions

use of alluxio.grpc.RenamePOptions in project alluxio by Alluxio.

the class BaseFileSystemTest method rename.

/**
 * Tests for the {@link BaseFileSystem#rename(AlluxioURI, AlluxioURI, RenamePOptions)}
 * method.
 */
@Test
public void rename() throws Exception {
    AlluxioURI src = new AlluxioURI("/file");
    AlluxioURI dst = new AlluxioURI("/file2");
    RenamePOptions renameOptions = RenamePOptions.getDefaultInstance();
    doNothing().when(mFileSystemMasterClient).rename(src, dst, FileSystemOptions.renameDefaults(mConf).toBuilder().mergeFrom(renameOptions).build());
    mFileSystem.rename(src, dst, renameOptions);
    verify(mFileSystemMasterClient).rename(src, dst, FileSystemOptions.renameDefaults(mConf).toBuilder().mergeFrom(renameOptions).build());
}
Also used : RenamePOptions(alluxio.grpc.RenamePOptions) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with RenamePOptions

use of alluxio.grpc.RenamePOptions in project alluxio by Alluxio.

the class BaseFileSystemTest method renameException.

/**
 * Ensures that an exception is propagated successfully when renaming a file.
 */
@Test
public void renameException() throws Exception {
    AlluxioURI src = new AlluxioURI("/file");
    AlluxioURI dst = new AlluxioURI("/file2");
    RenamePOptions renameOptions = RenamePOptions.getDefaultInstance();
    doThrow(EXCEPTION).when(mFileSystemMasterClient).rename(src, dst, FileSystemOptions.renameDefaults(mConf).toBuilder().mergeFrom(renameOptions).build());
    try {
        mFileSystem.rename(src, dst, renameOptions);
        fail(SHOULD_HAVE_PROPAGATED_MESSAGE);
    } catch (Exception e) {
        assertSame(EXCEPTION, e);
    }
}
Also used : RenamePOptions(alluxio.grpc.RenamePOptions) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

RenamePOptions (alluxio.grpc.RenamePOptions)6 AlluxioURI (alluxio.AlluxioURI)4 Test (org.junit.Test)4 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)1