Search in sources :

Example 61 with FileInfo

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);
}
Also used : FileInfo(alluxio.wire.FileInfo) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 62 with FileInfo

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));
}
Also used : FileSystemMasterView(alluxio.master.file.meta.FileSystemMasterView) FileInfo(alluxio.wire.FileInfo) LineageStoreView(alluxio.master.lineage.meta.LineageStoreView) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 63 with FileInfo

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);
}
Also used : TestBufferedBlockOutStream(alluxio.client.block.TestBufferedBlockOutStream) BufferedBlockInStream(alluxio.client.block.BufferedBlockInStream) TestBufferedBlockInStream(alluxio.client.block.TestBufferedBlockInStream) ArrayList(java.util.ArrayList) TestBufferedBlockOutStream(alluxio.client.block.TestBufferedBlockOutStream) BufferedBlockOutStream(alluxio.client.block.BufferedBlockOutStream) TestBufferedBlockInStream(alluxio.client.block.TestBufferedBlockInStream) InStreamOptions(alluxio.client.file.options.InStreamOptions) OutStreamOptions(alluxio.client.file.options.OutStreamOptions) FileInfo(alluxio.wire.FileInfo) InvocationOnMock(org.mockito.invocation.InvocationOnMock) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) AlluxioBlockStore(alluxio.client.block.AlluxioBlockStore) Before(org.junit.Before)

Example 64 with FileInfo

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);
}
Also used : FileInfo(alluxio.wire.FileInfo) OpenFileOptions(alluxio.client.file.options.OpenFileOptions) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 65 with FileInfo

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);
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) FileInfo(alluxio.wire.FileInfo) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

FileInfo (alluxio.wire.FileInfo)81 AlluxioURI (alluxio.AlluxioURI)60 Test (org.junit.Test)54 URIStatus (alluxio.client.file.URIStatus)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 CreateFileOptions (alluxio.master.file.options.CreateFileOptions)9 ArrayList (java.util.ArrayList)9 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)7 RestApiTest (alluxio.rest.RestApiTest)7 TestCase (alluxio.rest.TestCase)7 SetAndRestoreAuthenticatedUser (alluxio.SetAndRestoreAuthenticatedUser)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 FileSystemMaster (alluxio.master.file.FileSystemMaster)4 CreateOptions (alluxio.underfs.options.CreateOptions)4 OutputStream (java.io.OutputStream)4 InvalidPathException (alluxio.exception.InvalidPathException)3 FileSystemMasterView (alluxio.master.file.meta.FileSystemMasterView)3 LockedInodePath (alluxio.master.file.meta.LockedInodePath)3 FileBlockInfo (alluxio.wire.FileBlockInfo)3 IOException (java.io.IOException)3