use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class FileSystemMasterIntegrationTest method createFile.
@Test
public void createFile() throws Exception {
mFsMaster.createFile(new AlluxioURI("/testFile"), CreateFileOptions.defaults());
FileInfo fileInfo = mFsMaster.getFileInfo(mFsMaster.getFileId(new AlluxioURI("/testFile")));
Assert.assertFalse(fileInfo.isFolder());
Assert.assertEquals("", fileInfo.getOwner());
Assert.assertEquals(0644, (short) fileInfo.getMode());
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class FileSystemMasterIntegrationTest method clientFileInfoEmptyFile.
@Test
public void clientFileInfoEmptyFile() throws Exception {
long fileId = mFsMaster.createFile(new AlluxioURI("/testFile"), CreateFileOptions.defaults());
FileInfo fileInfo = mFsMaster.getFileInfo(fileId);
Assert.assertEquals("testFile", fileInfo.getName());
Assert.assertEquals(fileId, fileInfo.getFileId());
Assert.assertEquals(0, fileInfo.getLength());
Assert.assertTrue(fileInfo.isCacheable());
Assert.assertFalse(fileInfo.isCompleted());
Assert.assertFalse(fileInfo.isFolder());
Assert.assertFalse(fileInfo.isPersisted());
Assert.assertFalse(fileInfo.isPinned());
Assert.assertEquals(Constants.NO_TTL, fileInfo.getTtl());
Assert.assertEquals(TtlAction.DELETE, fileInfo.getTtlAction());
Assert.assertEquals("", fileInfo.getOwner());
Assert.assertEquals(0644, (short) fileInfo.getMode());
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class LineageFileSystemTest method before.
/**
* Sets up all dependencies before running a test.
*/
@Before
public void before() throws Exception {
mLineageMasterClient = PowerMockito.mock(LineageMasterClient.class);
mLineageContext = PowerMockito.mock(LineageContext.class);
FileSystemContext fileSystemContext = PowerMockito.mock(FileSystemContext.class);
Mockito.when(mLineageContext.acquireMasterClient()).thenReturn(mLineageMasterClient);
FileSystemMasterClient fileSystemMasterClient = PowerMockito.mock(FileSystemMasterClient.class);
Mockito.when(fileSystemContext.acquireMasterClient()).thenReturn(fileSystemMasterClient);
Mockito.when(fileSystemMasterClient.getStatus(Mockito.any(AlluxioURI.class))).thenReturn(new URIStatus(new FileInfo()));
mAlluxioLineageFileSystem = LineageFileSystem.get(fileSystemContext, mLineageContext);
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class AbstractFileSystemTest method listStatus.
/**
* Tests that the {@link AbstractFileSystem#listStatus(Path)} method uses
* {@link URIStatus#getLastModificationTimeMs()} correctly.
*/
@Test
public void listStatus() throws Exception {
FileInfo fileInfo1 = new FileInfo().setLastModificationTimeMs(111L).setFolder(false).setOwner("user1").setGroup("group1").setMode(00755);
FileInfo fileInfo2 = new FileInfo().setLastModificationTimeMs(222L).setFolder(true).setOwner("user2").setGroup("group2").setMode(00644);
Path path = new Path("/dir");
alluxio.client.file.FileSystem alluxioFs = Mockito.mock(alluxio.client.file.FileSystem.class);
Mockito.when(alluxioFs.listStatus(new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)))).thenReturn(Lists.newArrayList(new URIStatus(fileInfo1), new URIStatus(fileInfo2)));
FileSystem alluxioHadoopFs = new FileSystem(alluxioFs);
FileStatus[] fileStatuses = alluxioHadoopFs.listStatus(path);
assertFileInfoEqualsFileStatus(fileInfo1, fileStatuses[0]);
assertFileInfoEqualsFileStatus(fileInfo2, fileStatuses[1]);
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class FileDataManagerTest method persistFileRateLimiting.
/**
* Tests the rate limiting functionality for asynchronous persistence.
*/
@Test
public void persistFileRateLimiting() throws Exception {
Configuration.set(PropertyKey.WORKER_FILE_PERSIST_RATE_LIMIT_ENABLED, "true");
Configuration.set(PropertyKey.WORKER_FILE_PERSIST_RATE_LIMIT, "100");
mMockRateLimiter = new MockRateLimiter(Configuration.getBytes(PropertyKey.WORKER_FILE_PERSIST_RATE_LIMIT));
mManager = new FileDataManager(mBlockWorker, mMockRateLimiter.getGuavaRateLimiter());
long fileId = 1;
List<Long> blockIds = Lists.newArrayList(1L, 2L, 3L);
FileInfo fileInfo = new FileInfo();
fileInfo.setPath("test");
Mockito.when(mBlockWorker.getFileInfo(fileId)).thenReturn(fileInfo);
BlockReader reader = Mockito.mock(BlockReader.class);
for (long blockId : blockIds) {
Mockito.when(mBlockWorker.lockBlock(Sessions.CHECKPOINT_SESSION_ID, blockId)).thenReturn(blockId);
Mockito.when(mBlockWorker.readBlockRemote(Sessions.CHECKPOINT_SESSION_ID, blockId, blockId)).thenReturn(reader);
BlockMeta mockedBlockMeta = PowerMockito.mock(BlockMeta.class);
Mockito.when(mockedBlockMeta.getBlockSize()).thenReturn(100L);
Mockito.when(mBlockWorker.getBlockMeta(Sessions.CHECKPOINT_SESSION_ID, blockId, blockId)).thenReturn(mockedBlockMeta);
}
String ufsRoot = Configuration.get(PropertyKey.UNDERFS_ADDRESS);
Mockito.when(mUfs.isDirectory(ufsRoot)).thenReturn(true);
OutputStream outputStream = Mockito.mock(OutputStream.class);
// mock BufferUtils
PowerMockito.mockStatic(BufferUtils.class);
String dstPath = PathUtils.concatPath(ufsRoot, fileInfo.getPath());
fileInfo.setUfsPath(dstPath);
Mockito.when(mUfs.create(dstPath)).thenReturn(outputStream);
Mockito.when(mUfs.create(Mockito.anyString(), Mockito.any(CreateOptions.class))).thenReturn(outputStream);
Mockito.when(mMockFileSystem.getStatus(Mockito.any(AlluxioURI.class))).thenReturn(new URIStatus(fileInfo));
mManager.lockBlocks(fileId, blockIds);
mManager.persistFile(fileId, blockIds);
List<String> expectedEvents = Lists.newArrayList("R0.00", "R1.00", "R1.00");
assertEquals(expectedEvents, mMockRateLimiter.readEventsAndClear());
// Simulate waiting for 1 second.
mMockRateLimiter.sleepMillis(1000);
mManager.lockBlocks(fileId, blockIds);
mManager.persistFile(fileId, blockIds);
// The first write will go through immediately without throttling.
expectedEvents = Lists.newArrayList("U1.00", "R0.00", "R1.00", "R1.00");
assertEquals(expectedEvents, mMockRateLimiter.readEventsAndClear());
// Repeat persistence without sleeping.
mManager.lockBlocks(fileId, blockIds);
mManager.persistFile(fileId, blockIds);
expectedEvents = Lists.newArrayList("R1.00", "R1.00", "R1.00");
assertEquals(expectedEvents, mMockRateLimiter.readEventsAndClear());
}
Aggregations