use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class LineageMasterTest method reinitializeFile.
/**
* Tests the {@link LineageMaster#reinitializeFile(String, long, long, TtlAction)} method.
*/
@Test
public void reinitializeFile() throws Exception {
FileInfo fileInfo = new FileInfo();
fileInfo.setCompleted(false);
Mockito.when(mFileSystemMaster.getFileInfo(Mockito.any(Long.class))).thenReturn(fileInfo);
mLineageMaster.start(true);
mLineageMaster.createLineage(new ArrayList<AlluxioURI>(), Lists.newArrayList(new AlluxioURI("/test1")), mJob);
mLineageMaster.reinitializeFile("/test1", 500L, 10L, TtlAction.DELETE);
Mockito.verify(mFileSystemMaster).reinitializeFile(new AlluxioURI("/test1"), 500L, 10L, TtlAction.DELETE);
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class CheckpointLatestPlannerTest method schedule.
/**
* Tests the {@link CheckpointLatestPlanner#generatePlan(LineageStoreView, FileSystemMasterView)}
* method.
*/
@Test
public void schedule() throws Exception {
long fileId1 = 1L;
long fileId2 = 2L;
long l1 = mLineageStore.createLineage(new ArrayList<Long>(), Lists.newArrayList(fileId1), mJob);
// Sleep for 1ms to guarantee that the next lineage's creation time is later than the first's
CommonUtils.sleepMs(1);
long l2 = mLineageStore.createLineage(Lists.newArrayList(fileId1), Lists.newArrayList(fileId2), mJob);
Mockito.when(mFileSystemMaster.getPersistenceState(fileId1)).thenReturn(PersistenceState.NOT_PERSISTED);
Mockito.when(mFileSystemMaster.getPersistenceState(fileId2)).thenReturn(PersistenceState.NOT_PERSISTED);
FileInfo fileInfo1 = new FileInfo();
fileInfo1.setCompleted(true);
Mockito.when(mFileSystemMaster.getFileInfo(fileId1)).thenReturn(fileInfo1);
FileInfo fileInfo2 = new FileInfo();
fileInfo2.setCompleted(false);
Mockito.when(mFileSystemMaster.getFileInfo(fileId2)).thenReturn(fileInfo2);
CheckpointPlan plan = mPlanner.generatePlan(new LineageStoreView(mLineageStore), new FileSystemMasterView(mFileSystemMaster));
Assert.assertEquals((Long) l1, plan.getLineagesToCheckpoint().get(0));
// complete file 2 and it's ready for checkpoint
fileInfo2.setCompleted(true);
plan = mPlanner.generatePlan(new LineageStoreView(mLineageStore), new FileSystemMasterView(mFileSystemMaster));
Assert.assertEquals((Long) l2, plan.getLineagesToCheckpoint().get(0));
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class FileInStreamTest method before.
/**
* Sets up the context and streams before a test runs.
*
* @throws AlluxioException when the worker ufs operations fail
* @throws IOException when the read and write streams fail
*/
@Before
public void before() throws Exception {
mInfo = new FileInfo().setBlockSizeBytes(BLOCK_LENGTH).setLength(FILE_LENGTH);
mDelegateUfsOps = Configuration.getBoolean(PropertyKey.USER_UFS_DELEGATION_ENABLED);
ClientTestUtils.setSmallBufferSizes();
mContext = PowerMockito.mock(FileSystemContext.class);
mBlockStore = Mockito.mock(AlluxioBlockStore.class);
PowerMockito.mockStatic(AlluxioBlockStore.class);
PowerMockito.when(AlluxioBlockStore.create(mContext)).thenReturn(mBlockStore);
PowerMockito.when(mBlockStore.getWorkerInfoList()).thenReturn(new ArrayList<BlockWorkerInfo>());
Mockito.mock(StreamFactory.class);
PowerMockito.mockStatic(StreamFactory.class);
// Set up BufferedBlockInStreams and caching streams
mCacheStreams = new ArrayList<>();
List<Long> blockIds = new ArrayList<>();
for (int i = 0; i < NUM_STREAMS; i++) {
blockIds.add((long) i);
mCacheStreams.add(new TestBufferedBlockOutStream(i, getBlockLength(i), mContext));
Mockito.when(mBlockStore.getInStream(Mockito.eq((long) i), Mockito.any(InStreamOptions.class))).thenAnswer(new Answer<BufferedBlockInStream>() {
@Override
public BufferedBlockInStream answer(InvocationOnMock invocation) throws Throwable {
long i = (Long) invocation.getArguments()[0];
byte[] input = BufferUtils.getIncreasingByteArray((int) (i * BLOCK_LENGTH), (int) getBlockLength((int) i));
return new TestBufferedBlockInStream(i, input);
}
});
Mockito.when(mBlockStore.getOutStream(Mockito.eq((long) i), Mockito.anyLong(), Mockito.any(WorkerNetAddress.class), Mockito.any(OutStreamOptions.class))).thenAnswer(new Answer<BufferedBlockOutStream>() {
@Override
public BufferedBlockOutStream answer(InvocationOnMock invocation) throws Throwable {
long i = (Long) invocation.getArguments()[0];
return mCacheStreams.get((int) i).isClosed() ? null : mCacheStreams.get((int) i);
}
});
}
mInfo.setBlockIds(blockIds);
mStatus = new URIStatus(mInfo);
mTestStream = new FileInStream(mStatus, InStreamOptions.defaults().setReadType(ReadType.CACHE_PROMOTE).setCachePartiallyReadBlock(false), mContext);
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class BaseFileSystemTest method openFile.
/**
* Tests for the {@link BaseFileSystem#openFile(AlluxioURI, OpenFileOptions)} method to
* complete successfully.
*/
@Test
public void openFile() throws Exception {
AlluxioURI file = new AlluxioURI("/file");
URIStatus status = new URIStatus(new FileInfo());
Mockito.when(mFileSystemMasterClient.getStatus(file)).thenReturn(status);
OpenFileOptions openOptions = OpenFileOptions.defaults();
mFileSystem.openFile(file, openOptions);
Mockito.verify(mFileSystemMasterClient).getStatus(file);
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class BaseFileSystemTest method createFile.
/**
* Tests the creation of a file via the
* {@link BaseFileSystem#createFile(AlluxioURI, CreateFileOptions)} method.
*/
@Test
public void createFile() throws Exception {
Mockito.doNothing().when(mFileSystemMasterClient).createFile(Mockito.any(AlluxioURI.class), Mockito.any(CreateFileOptions.class));
URIStatus status = new URIStatus(new FileInfo());
AlluxioURI file = new AlluxioURI("/file");
Mockito.when(mFileSystemMasterClient.getStatus(file)).thenReturn(status);
CreateFileOptions options = CreateFileOptions.defaults();
FileOutStream out = mFileSystem.createFile(file, options);
Mockito.verify(mFileSystemMasterClient).createFile(file, options);
Assert.assertEquals(out.mUri, file);
}
Aggregations