Search in sources :

Example 1 with LockBlockTOptions

use of alluxio.thrift.LockBlockTOptions in project alluxio by Alluxio.

the class UnderFileSystemBlockStoreTest method before.

@Before
public void before() throws Exception {
    mAlluxioBlockStore = Mockito.mock(BlockStore.class);
    LockBlockTOptions options = new LockBlockTOptions();
    options.setMaxUfsReadConcurrency(5);
    options.setBlockSize(TEST_BLOCK_SIZE);
    options.setOffset(TEST_BLOCK_SIZE);
    options.setUfsPath(mFolder.newFile().getAbsolutePath());
    mOpenUfsBlockOptions = new OpenUfsBlockOptions(options);
}
Also used : OpenUfsBlockOptions(alluxio.worker.block.options.OpenUfsBlockOptions) LockBlockTOptions(alluxio.thrift.LockBlockTOptions) Before(org.junit.Before)

Example 2 with LockBlockTOptions

use of alluxio.thrift.LockBlockTOptions in project alluxio by Alluxio.

the class BlockWorkerTest method closeUnderFileSystemBlock.

@Test
public void closeUnderFileSystemBlock() throws Exception {
    long blockId = mRandom.nextLong();
    LockBlockTOptions lockBlockTOptions = new LockBlockTOptions();
    lockBlockTOptions.setMaxUfsReadConcurrency(10);
    lockBlockTOptions.setUfsPath("/a");
    OpenUfsBlockOptions openUfsBlockOptions = new OpenUfsBlockOptions(lockBlockTOptions);
    long sessionId = 1;
    for (; sessionId < 11; sessionId++) {
        Assert.assertTrue(mBlockWorker.openUfsBlock(sessionId, blockId, openUfsBlockOptions));
        mBlockWorker.closeUfsBlock(sessionId, blockId);
    }
    Assert.assertTrue(mBlockWorker.openUfsBlock(sessionId, blockId, openUfsBlockOptions));
}
Also used : OpenUfsBlockOptions(alluxio.worker.block.options.OpenUfsBlockOptions) LockBlockTOptions(alluxio.thrift.LockBlockTOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with LockBlockTOptions

use of alluxio.thrift.LockBlockTOptions in project alluxio by Alluxio.

the class BlockWorkerTest method openUnderFileSystemBlock.

@Test
public void openUnderFileSystemBlock() throws Exception {
    long blockId = mRandom.nextLong();
    LockBlockTOptions lockBlockTOptions = new LockBlockTOptions();
    lockBlockTOptions.setMaxUfsReadConcurrency(10);
    lockBlockTOptions.setUfsPath("/a");
    OpenUfsBlockOptions openUfsBlockOptions = new OpenUfsBlockOptions(lockBlockTOptions);
    long sessionId = 1;
    for (; sessionId < 11; sessionId++) {
        Assert.assertTrue(mBlockWorker.openUfsBlock(sessionId, blockId, openUfsBlockOptions));
    }
    Assert.assertFalse(mBlockWorker.openUfsBlock(sessionId, blockId, openUfsBlockOptions));
}
Also used : OpenUfsBlockOptions(alluxio.worker.block.options.OpenUfsBlockOptions) LockBlockTOptions(alluxio.thrift.LockBlockTOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with LockBlockTOptions

use of alluxio.thrift.LockBlockTOptions in project alluxio by Alluxio.

the class BlockServiceHandlerIntegrationTest method lockBlockFailure.

// Tests that lock block returns error on failure
@Test
public void lockBlockFailure() throws Exception {
    mFileSystem.createFile(new AlluxioURI("/testFile")).close();
    URIStatus file = mFileSystem.getStatus(new AlluxioURI("/testFile"));
    final long blockId = BlockId.createBlockId(BlockId.getContainerId(file.getFileId()), 0);
    Exception exception = null;
    try {
        mBlockWorkerServiceHandler.lockBlock(blockId, SESSION_ID, new LockBlockTOptions());
    } catch (AlluxioTException e) {
        exception = e;
    }
    // A file does not exist exception should have been thrown
    Assert.assertNotNull(exception);
}
Also used : AlluxioTException(alluxio.thrift.AlluxioTException) URIStatus(alluxio.client.file.URIStatus) LockBlockTOptions(alluxio.thrift.LockBlockTOptions) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioTException(alluxio.thrift.AlluxioTException) TException(org.apache.thrift.TException) IOException(java.io.IOException) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 5 with LockBlockTOptions

use of alluxio.thrift.LockBlockTOptions in project alluxio by Alluxio.

the class BlockServiceHandlerIntegrationTest method lockBlock.

// Tests that lock block returns the correct path
@Test
public void lockBlock() throws Exception {
    final int blockSize = (int) WORKER_CAPACITY_BYTES / 2;
    CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(blockSize).setWriteType(WriteType.MUST_CACHE);
    FileOutStream out = mFileSystem.createFile(new AlluxioURI("/testFile"), options);
    URIStatus file = mFileSystem.getStatus(new AlluxioURI("/testFile"));
    final long blockId = BlockId.createBlockId(BlockId.getContainerId(file.getFileId()), 0);
    out.write(BufferUtils.getIncreasingByteArray(blockSize));
    out.close();
    String localPath = mBlockWorkerServiceHandler.lockBlock(blockId, SESSION_ID, new LockBlockTOptions()).getBlockPath();
    // The local path should exist
    Assert.assertNotNull(localPath);
    UnderFileSystem ufs = UnderFileSystem.Factory.get(localPath);
    byte[] data = new byte[blockSize];
    InputStream in = ufs.open(localPath);
    int bytesRead = in.read(data);
    // The data in the local file should equal the data we wrote earlier
    Assert.assertEquals(blockSize, bytesRead);
    Assert.assertTrue(BufferUtils.equalIncreasingByteArray(bytesRead, data));
    mBlockWorkerServiceHandler.unlockBlock(blockId, SESSION_ID);
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) InputStream(java.io.InputStream) FileOutStream(alluxio.client.file.FileOutStream) URIStatus(alluxio.client.file.URIStatus) LockBlockTOptions(alluxio.thrift.LockBlockTOptions) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Aggregations

LockBlockTOptions (alluxio.thrift.LockBlockTOptions)7 OpenUfsBlockOptions (alluxio.worker.block.options.OpenUfsBlockOptions)4 Test (org.junit.Test)4 AlluxioURI (alluxio.AlluxioURI)2 URIStatus (alluxio.client.file.URIStatus)2 Before (org.junit.Before)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 FileOutStream (alluxio.client.file.FileOutStream)1 CreateFileOptions (alluxio.client.file.options.CreateFileOptions)1 InvalidPathException (alluxio.exception.InvalidPathException)1 AlluxioTException (alluxio.thrift.AlluxioTException)1 UnderFileSystem (alluxio.underfs.UnderFileSystem)1 TempBlockMeta (alluxio.worker.block.meta.TempBlockMeta)1 UnderFileSystemBlockMeta (alluxio.worker.block.meta.UnderFileSystemBlockMeta)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 TException (org.apache.thrift.TException)1