use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class FileSystemMasterTest method setAttribute.
/**
* Tests the {@link FileSystemMaster#setAttribute(AlluxioURI, SetAttributeOptions)} method and
* that an exception is thrown when trying to set a TTL for a directory.
*/
@Test
public void setAttribute() throws Exception {
mFileSystemMaster.createFile(NESTED_FILE_URI, mNestedFileOptions);
FileInfo fileInfo = mFileSystemMaster.getFileInfo(NESTED_FILE_URI);
Assert.assertFalse(fileInfo.isPinned());
Assert.assertEquals(Constants.NO_TTL, fileInfo.getTtl());
// No State.
mFileSystemMaster.setAttribute(NESTED_FILE_URI, SetAttributeOptions.defaults());
fileInfo = mFileSystemMaster.getFileInfo(NESTED_FILE_URI);
Assert.assertFalse(fileInfo.isPinned());
Assert.assertEquals(Constants.NO_TTL, fileInfo.getTtl());
// Just set pinned flag.
mFileSystemMaster.setAttribute(NESTED_FILE_URI, SetAttributeOptions.defaults().setPinned(true));
fileInfo = mFileSystemMaster.getFileInfo(NESTED_FILE_URI);
Assert.assertTrue(fileInfo.isPinned());
Assert.assertEquals(Constants.NO_TTL, fileInfo.getTtl());
// Both pinned flag and ttl value.
mFileSystemMaster.setAttribute(NESTED_FILE_URI, SetAttributeOptions.defaults().setPinned(false).setTtl(1));
fileInfo = mFileSystemMaster.getFileInfo(NESTED_FILE_URI);
Assert.assertFalse(fileInfo.isPinned());
Assert.assertEquals(1, fileInfo.getTtl());
mFileSystemMaster.setAttribute(NESTED_URI, SetAttributeOptions.defaults().setTtl(1));
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class PermissionCheckTest method setPermissionSuccess.
@Test
public void setPermissionSuccess() throws Exception {
// super user
verifySetAcl(TEST_USER_ADMIN, TEST_FILE_URI, null, null, (short) 0600, false);
// super group
verifySetAcl(TEST_USER_SUPERGROUP, TEST_DIR_URI, null, null, (short) 0700, true);
FileInfo fileInfo = mFileSystemMaster.getFileInfo(mFileSystemMaster.getFileId(new AlluxioURI(TEST_DIR_FILE_URI)));
Assert.assertEquals((short) 0700, fileInfo.getMode());
// owner enlarge the permission
verifySetAcl(TEST_USER_1, TEST_DIR_URI, null, null, (short) 0777, true);
fileInfo = mFileSystemMaster.getFileInfo(mFileSystemMaster.getFileId(new AlluxioURI(TEST_DIR_FILE_URI)));
Assert.assertEquals((short) 0777, fileInfo.getMode());
// other user can operate under this enlarged permission
verifyCreateFile(TEST_USER_2, TEST_DIR_URI + "/newFile", false);
verifyDelete(TEST_USER_2, TEST_DIR_FILE_URI, false);
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class PermissionCheckTest method setAclSuccess.
@Test
public void setAclSuccess() throws Exception {
// super user sets owner, group, and permission
verifySetAcl(TEST_USER_ADMIN, TEST_FILE_URI, TEST_USER_1.getUser(), TEST_USER_1.getGroup(), (short) 0600, false);
// owner sets group and permission
verifySetAcl(TEST_USER_1, TEST_DIR_URI, null, TEST_USER_2.getGroup(), (short) 0777, true);
FileInfo fileInfo = mFileSystemMaster.getFileInfo(mFileSystemMaster.getFileId(new AlluxioURI(TEST_DIR_FILE_URI)));
Assert.assertEquals(TEST_USER_2.getGroup(), fileInfo.getGroup());
Assert.assertEquals((short) 0777, fileInfo.getMode());
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class FileOutStreamTest method before.
/**
* Sets up the different contexts and clients before a test runs.
*/
@Before
public void before() throws Exception {
GroupMappingServiceTestUtils.resetCache();
ClientTestUtils.setSmallBufferSizes();
// PowerMock enums and final classes
mFileSystemContext = PowerMockito.mock(FileSystemContext.class);
mBlockStore = PowerMockito.mock(AlluxioBlockStore.class);
mFileSystemMasterClient = PowerMockito.mock(FileSystemMasterClient.class);
mFactory = PowerMockito.mock(UnderFileSystemFileOutStream.Factory.class);
PowerMockito.mockStatic(AlluxioBlockStore.class);
PowerMockito.when(AlluxioBlockStore.create(mFileSystemContext)).thenReturn(mBlockStore);
when(mFileSystemContext.acquireMasterClientResource()).thenReturn(new DummyCloseableResource<>(mFileSystemMasterClient));
when(mFileSystemMasterClient.getStatus(any(AlluxioURI.class))).thenReturn(new URIStatus(new FileInfo()));
// Worker file client mocking
mWorkerClient = PowerMockito.mock(FileSystemWorkerClient.class);
when(mFileSystemContext.createFileSystemWorkerClient()).thenReturn(mWorkerClient);
when(mWorkerClient.createUfsFile(any(AlluxioURI.class), any(CreateUfsFileOptions.class))).thenReturn(UFS_FILE_ID);
// Return sequentially increasing numbers for new block ids
when(mFileSystemMasterClient.getNewBlockIdForFile(FILE_NAME)).thenAnswer(new Answer<Long>() {
private long mCount = 0;
@Override
public Long answer(InvocationOnMock invocation) throws Throwable {
return mCount++;
}
});
// Set up out streams. When they are created, add them to outStreamMap
final Map<Long, TestBufferedBlockOutStream> outStreamMap = new HashMap<>();
when(mBlockStore.getOutStream(anyLong(), eq(BLOCK_LENGTH), any(OutStreamOptions.class))).thenAnswer(new Answer<BufferedBlockOutStream>() {
@Override
public BufferedBlockOutStream answer(InvocationOnMock invocation) throws Throwable {
Long blockId = invocation.getArgumentAt(0, Long.class);
if (!outStreamMap.containsKey(blockId)) {
TestBufferedBlockOutStream newStream = new TestBufferedBlockOutStream(blockId, BLOCK_LENGTH, mFileSystemContext);
outStreamMap.put(blockId, newStream);
}
return outStreamMap.get(blockId);
}
});
BlockWorkerInfo workerInfo = new BlockWorkerInfo(new WorkerNetAddress().setHost("localhost").setRpcPort(1).setDataPort(2).setWebPort(3), Constants.GB, 0);
when(mBlockStore.getWorkerInfoList()).thenReturn(Lists.newArrayList(workerInfo));
mAlluxioOutStreamMap = outStreamMap;
// Create an under storage stream so that we can check whether it has been flushed
final AtomicBoolean underStorageFlushed = new AtomicBoolean(false);
mUnderStorageOutputStream = new ByteArrayOutputStream() {
@Override
public void flush() {
underStorageFlushed.set(true);
}
};
mUnderStorageFlushed = underStorageFlushed;
when(mFactory.create(any(FileSystemContext.class), any(InetSocketAddress.class), anyLong())).thenReturn(mUnderStorageOutputStream);
// Set up underFileStorage so that we can test UnderStorageType.SYNC_PERSIST
mUnderFileSystem = ClientMockUtils.mockUnderFileSystem();
when(mUnderFileSystem.create(anyString())).thenReturn(mUnderStorageOutputStream);
when(mUnderFileSystem.create(anyString(), any(CreateOptions.class))).thenReturn(mUnderStorageOutputStream);
when(mUnderFileSystem.isDirectory(anyString())).thenReturn(true);
OutStreamOptions options = OutStreamOptions.defaults().setBlockSizeBytes(BLOCK_LENGTH).setWriteType(WriteType.CACHE_THROUGH).setUfsPath(FILE_NAME.getPath());
mTestStream = createTestStream(FILE_NAME, options);
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class UnderFileSystemUtilsTest method createStatus.
private URIStatus createStatus(String owner, String group, Mode mode, boolean isMountPoint) {
FileInfo info = new FileInfo();
info.setMountPoint(true);
info.setOwner(owner);
info.setGroup(group);
info.setMode(mode.toShort());
info.setMountPoint(isMountPoint);
return new URIStatus(info);
}
Aggregations