Search in sources :

Example 26 with InStreamOptions

use of alluxio.client.file.options.InStreamOptions in project alluxio by Alluxio.

the class AlluxioFileInStreamTest method longSeekBackwardCachingPartiallyReadBlocks.

/**
 * Tests seeking with incomplete block caching enabled. It seeks backward for more than a block.
 */
@Test
public void longSeekBackwardCachingPartiallyReadBlocks() throws IOException {
    OpenFilePOptions options = OpenFilePOptions.newBuilder().setReadType(ReadPType.CACHE_PROMOTE).build();
    mTestStream = new AlluxioFileInStream(mStatus, new InStreamOptions(mStatus, options, mConf), mContext);
    int seekAmount = (int) (BLOCK_LENGTH / 4 + BLOCK_LENGTH);
    int readAmount = (int) (BLOCK_LENGTH * 3 - BLOCK_LENGTH / 2);
    byte[] buffer = new byte[readAmount];
    mTestStream.read(buffer);
    // Seek backward.
    mTestStream.seek(readAmount - seekAmount);
    // Block 2 is cached though it is not fully read.
    validatePartialCaching(2, (int) BLOCK_LENGTH / 2);
}
Also used : OpenFilePOptions(alluxio.grpc.OpenFilePOptions) InStreamOptions(alluxio.client.file.options.InStreamOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 27 with InStreamOptions

use of alluxio.client.file.options.InStreamOptions in project alluxio by Alluxio.

the class AlluxioFileInStreamTest method seekBackwardSmallSeekBuffer.

/**
 * Tests skipping backwards when the seek buffer size is smaller than block size.
 */
@Test
public void seekBackwardSmallSeekBuffer() throws IOException {
    OpenFilePOptions options = OpenFilePOptions.newBuilder().setReadType(ReadPType.CACHE_PROMOTE).build();
    mTestStream = new AlluxioFileInStream(mStatus, new InStreamOptions(mStatus, options, mConf), mContext);
    int readAmount = (int) (BLOCK_LENGTH / 2);
    byte[] buffer = new byte[readAmount];
    mTestStream.read(buffer);
    mTestStream.seek(readAmount - 1);
    validatePartialCaching(0, readAmount);
}
Also used : OpenFilePOptions(alluxio.grpc.OpenFilePOptions) InStreamOptions(alluxio.client.file.options.InStreamOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 28 with InStreamOptions

use of alluxio.client.file.options.InStreamOptions in project alluxio by Alluxio.

the class AlluxioFileInStreamTest method seekAndClose.

@Test
public void seekAndClose() throws IOException {
    OpenFilePOptions options = OpenFilePOptions.newBuilder().setReadType(ReadPType.CACHE_PROMOTE).build();
    mTestStream = new AlluxioFileInStream(mStatus, new InStreamOptions(mStatus, options, mConf), mContext);
    int seekAmount = (int) (BLOCK_LENGTH / 2);
    mTestStream.seek(seekAmount);
    mTestStream.close();
    // Block 0 is cached though it is not fully read.
    validatePartialCaching(0, 0);
}
Also used : OpenFilePOptions(alluxio.grpc.OpenFilePOptions) InStreamOptions(alluxio.client.file.options.InStreamOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 29 with InStreamOptions

use of alluxio.client.file.options.InStreamOptions in project alluxio by Alluxio.

the class AlluxioFileInStreamTest method seekBackwardToFileBeginning.

/**
 * Tests seeking with incomplete block caching enabled. It seeks forward for more than a block
 * and then seek to the file beginning.
 */
@Test
public void seekBackwardToFileBeginning() throws IOException {
    OpenFilePOptions options = OpenFilePOptions.newBuilder().setReadType(ReadPType.CACHE_PROMOTE).build();
    mTestStream = new AlluxioFileInStream(mStatus, new InStreamOptions(mStatus, options, mConf), mContext);
    int seekAmount = (int) (BLOCK_LENGTH / 4 + BLOCK_LENGTH);
    // Seek forward.
    mTestStream.seek(seekAmount);
    // Block 1 is partially cached though it is not fully read.
    validatePartialCaching(1, 0);
    // Seek backward.
    mTestStream.seek(0);
    // Block 1 is fully cached though it is not fully read.
    validatePartialCaching(1, 0);
    mTestStream.close();
    // block 0 is cached
    validatePartialCaching(0, 0);
}
Also used : OpenFilePOptions(alluxio.grpc.OpenFilePOptions) InStreamOptions(alluxio.client.file.options.InStreamOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 30 with InStreamOptions

use of alluxio.client.file.options.InStreamOptions in project alluxio by Alluxio.

the class AlluxioBlockStoreTest method getInStreamUfsLocalFirst.

@Test
public void getInStreamUfsLocalFirst() throws Exception {
    WorkerNetAddress remote = new WorkerNetAddress().setHost("remote");
    WorkerNetAddress local = new WorkerNetAddress().setHost(WORKER_HOSTNAME_LOCAL);
    BlockInfo info = new BlockInfo().setBlockId(0);
    URIStatus dummyStatus = new URIStatus(new FileInfo().setPersisted(true).setBlockIds(Collections.singletonList(0L)).setFileBlockInfos(Collections.singletonList(new FileBlockInfo().setBlockInfo(info))));
    OpenFilePOptions readOptions = OpenFilePOptions.newBuilder().build();
    InStreamOptions options = new InStreamOptions(dummyStatus, readOptions, sConf);
    when(mMasterClient.getBlockInfo(BLOCK_ID)).thenReturn(new BlockInfo());
    when(mContext.getCachedWorkers()).thenReturn(Lists.newArrayList(new BlockWorkerInfo(remote, 100, 0), new BlockWorkerInfo(local, 100, 0)));
    BlockInStream stream = mBlockStore.getInStream(BLOCK_ID, options);
    assertEquals(local, stream.getAddress());
    assertEquals(GrpcDataReader.Factory.class.getName(), stream.getDataReaderFactory().getClass().getName());
}
Also used : BlockInStream(alluxio.client.block.stream.BlockInStream) FileInfo(alluxio.wire.FileInfo) WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) TieredIdentityFactory(alluxio.network.TieredIdentityFactory) URIStatus(alluxio.client.file.URIStatus) FileBlockInfo(alluxio.wire.FileBlockInfo) OpenFilePOptions(alluxio.grpc.OpenFilePOptions) InStreamOptions(alluxio.client.file.options.InStreamOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

InStreamOptions (alluxio.client.file.options.InStreamOptions)36 Test (org.junit.Test)26 OpenFilePOptions (alluxio.grpc.OpenFilePOptions)23 BlockInfo (alluxio.wire.BlockInfo)22 URIStatus (alluxio.client.file.URIStatus)21 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)19 WorkerNetAddress (alluxio.wire.WorkerNetAddress)18 FileBlockInfo (alluxio.wire.FileBlockInfo)17 FileInfo (alluxio.wire.FileInfo)16 BlockInStream (alluxio.client.block.stream.BlockInStream)10 AlluxioURI (alluxio.AlluxioURI)9 AlluxioBlockStore (alluxio.client.block.AlluxioBlockStore)7 FileSystemContext (alluxio.client.file.FileSystemContext)7 AlluxioConfiguration (alluxio.conf.AlluxioConfiguration)7 IOException (java.io.IOException)7 BlockLocationPolicy (alluxio.client.block.policy.BlockLocationPolicy)6 BlockLocation (alluxio.wire.BlockLocation)6 Before (org.junit.Before)6 BlockWorkerClient (alluxio.client.block.stream.BlockWorkerClient)5 BlockWorkerDataReader (alluxio.client.block.stream.BlockWorkerDataReader)5