Search in sources :

Example 56 with CreateFilePOptions

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

the class UfsSyncIntegrationTest method writeMustCacheFile.

private void writeMustCacheFile(String path, int sizeFactor) throws Exception {
    CreateFilePOptions options = CreateFilePOptions.newBuilder().setWriteType(WritePType.MUST_CACHE).setRecursive(true).build();
    FileOutStream os = mFileSystem.createFile(new AlluxioURI(path), options);
    for (int i = 0; i < sizeFactor; i++) {
        os.write("test".getBytes());
    }
    os.close();
}
Also used : FileOutStream(alluxio.client.file.FileOutStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI)

Example 57 with CreateFilePOptions

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

the class ReadOnlyMountIntegrationTest method createFile.

@Test
public void createFile() throws IOException, AlluxioException {
    CreateFilePOptions writeBoth = CreateFilePOptions.newBuilder().setWriteType(WritePType.CACHE_THROUGH).build();
    AlluxioURI uri = new AlluxioURI(FILE_PATH + "_create");
    try {
        mFileSystem.createFile(uri, writeBoth).close();
        Assert.fail("createFile should not succeed under a readonly mount.");
    } catch (AccessControlException e) {
        Assert.assertThat(e.getMessage(), containsString(ExceptionMessage.MOUNT_READONLY.getMessage(uri, MOUNT_PATH)));
    }
    uri = new AlluxioURI(SUB_FILE_PATH + "_create");
    try {
        mFileSystem.createFile(uri, writeBoth).close();
        Assert.fail("createFile should not succeed under a readonly mount.");
    } catch (AccessControlException e) {
        Assert.assertThat(e.getMessage(), containsString(ExceptionMessage.MOUNT_READONLY.getMessage(uri, MOUNT_PATH)));
    }
}
Also used : AccessControlException(alluxio.exception.AccessControlException) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 58 with CreateFilePOptions

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

the class FileSystemTestUtils method createByteFile.

/**
 * Creates a simple file with {@code len} bytes.
 *
 * @param fs a {@link FileSystem} handler
 * @param fileName the name of the file to be created
 * @param writeType {@link WritePType} used to create the file
 * @param len file size
 * @param blockCapacityByte block size of the file
 */
public static void createByteFile(FileSystem fs, String fileName, WritePType writeType, int len, long blockCapacityByte) {
    CreateFilePOptions options = CreateFilePOptions.newBuilder().setWriteType(writeType).setBlockSizeBytes(blockCapacityByte).setRecursive(true).build();
    createByteFile(fs, new AlluxioURI(fileName), options, len);
}
Also used : CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI)

Example 59 with CreateFilePOptions

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

the class BaseFileSystemTest method createFile.

/**
 * Tests the creation of a file via the
 * {@link BaseFileSystem#createFile(AlluxioURI, CreateFilePOptions)} method.
 */
@Test
public void createFile() throws Exception {
    URIStatus status = new URIStatus(new FileInfo());
    AlluxioURI file = new AlluxioURI("/file");
    when(mFileSystemMasterClient.createFile(any(AlluxioURI.class), any(CreateFilePOptions.class))).thenReturn(status);
    mFileSystem.createFile(file, CreateFilePOptions.getDefaultInstance());
    verify(mFileSystemMasterClient).createFile(file, FileSystemOptions.createFileDefaults(mConf).toBuilder().mergeFrom(CreateFilePOptions.getDefaultInstance()).build());
    verifyFilesystemContextAcquiredAndReleased();
}
Also used : FileInfo(alluxio.wire.FileInfo) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 60 with CreateFilePOptions

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

the class CheckConsistencyIntegrationTest method largeTree.

/**
 * Tests the {@link FileSystemMaster#checkConsistency(AlluxioURI, CheckConsistencyContext)} method
 * when some files are consistent in a larger inode tree.
 */
@Test
public void largeTree() throws Exception {
    CreateDirectoryPOptions dirOptions = CreateDirectoryPOptions.newBuilder().setWriteType(WritePType.CACHE_THROUGH).build();
    CreateFilePOptions fileOptions = CreateFilePOptions.newBuilder().setWriteType(WritePType.CACHE_THROUGH).build();
    AlluxioURI nestedDir = DIRECTORY.join("/dir2");
    AlluxioURI topLevelFile = new AlluxioURI("/file");
    AlluxioURI thirdLevelFile = nestedDir.join("/file");
    mFileSystem.createDirectory(nestedDir, dirOptions);
    mFileSystem.createFile(topLevelFile, fileOptions).close();
    mFileSystem.createFile(thirdLevelFile, fileOptions).close();
    String ufsDirectory = mFileSystem.getStatus(nestedDir).getUfsPath();
    UnderFileSystem ufs = UnderFileSystem.Factory.create(ufsDirectory, ServerConfiguration.global());
    ufs.deleteDirectory(ufsDirectory, DeleteOptions.defaults().setRecursive(true));
    List<AlluxioURI> expected = Lists.newArrayList(nestedDir, thirdLevelFile);
    List<AlluxioURI> result = mFileSystemMaster.checkConsistency(new AlluxioURI("/"), CheckConsistencyContext.defaults());
    Collections.sort(expected);
    Collections.sort(result);
    Assert.assertEquals(expected, result);
}
Also used : CreateDirectoryPOptions(alluxio.grpc.CreateDirectoryPOptions) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest)

Aggregations

CreateFilePOptions (alluxio.grpc.CreateFilePOptions)68 AlluxioURI (alluxio.AlluxioURI)61 Test (org.junit.Test)49 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)36 FileInStream (alluxio.client.file.FileInStream)27 FileOutStream (alluxio.client.file.FileOutStream)16 URIStatus (alluxio.client.file.URIStatus)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 FileSystem (alluxio.client.file.FileSystem)4 AlluxioException (alluxio.exception.AlluxioException)4 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)4 CreateDirectoryPOptions (alluxio.grpc.CreateDirectoryPOptions)4 IOException (java.io.IOException)4 DirectoryNotEmptyException (alluxio.exception.DirectoryNotEmptyException)3 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)3 ArrayList (java.util.ArrayList)3 ConfigurationRule (alluxio.ConfigurationRule)2 BlockMaster (alluxio.master.block.BlockMaster)2 Mode (alluxio.security.authorization.Mode)2 UnderFileSystem (alluxio.underfs.UnderFileSystem)2