Search in sources :

Example 1 with BlockReadRequest

use of alluxio.wire.BlockReadRequest in project alluxio by Alluxio.

the class DefaultBlockWorkerTest method getBlockReader.

@Test
public void getBlockReader() throws Exception {
    long blockId = mRandom.nextLong();
    long sessionId = mRandom.nextLong();
    mBlockWorker.createBlock(sessionId, blockId, 0, Constants.MEDIUM_MEM, 1);
    mBlockWorker.commitBlock(sessionId, blockId, true);
    BlockReadRequest request = new BlockReadRequest(ReadRequest.newBuilder().setBlockId(blockId).setOffset(0).setLength(10).build());
    BlockReader reader = mBlockWorker.createBlockReader(request);
    // reader will hold the lock
    assertThrows(DeadlineExceededException.class, () -> mBlockStore.removeBlockInternal(sessionId, blockId, BlockStoreLocation.anyTier(), 10));
    reader.close();
    mBlockStore.removeBlockInternal(sessionId, blockId, BlockStoreLocation.anyTier(), 10);
}
Also used : BlockReadRequest(alluxio.wire.BlockReadRequest) BlockReader(alluxio.worker.block.io.BlockReader) Test(org.junit.Test)

Example 2 with BlockReadRequest

use of alluxio.wire.BlockReadRequest in project alluxio by Alluxio.

the class BlockReadHandlerTest method before.

@Before
public void before() throws Exception {
    ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.ADVANCED);
    mFile = mTestFolder.newFile();
    mBlockReader = new LocalFileBlockReader(mFile.getPath());
    mBlockWorker = new NoopBlockWorker() {

        @Override
        public BlockReader createBlockReader(BlockReadRequest request) throws IOException {
            ((FileChannel) mBlockReader.getChannel()).position(request.getStart());
            return mBlockReader;
        }
    };
    mResponseObserver = Mockito.mock(ServerCallStreamObserver.class);
    Mockito.when(mResponseObserver.isReady()).thenReturn(true);
    doAnswer(args -> {
        mResponseCompleted = true;
        return null;
    }).when(mResponseObserver).onCompleted();
    doAnswer(args -> {
        mResponseCompleted = true;
        mError = args.getArgument(0, Throwable.class);
        return null;
    }).when(mResponseObserver).onError(any(Throwable.class));
    doAnswer((args) -> {
        // make a copy of response data before it is released
        mResponses.add(ReadResponse.parseFrom(args.getArgument(0, ReadResponse.class).toByteString()));
        return null;
    }).when(mResponseObserver).onNext(any(ReadResponse.class));
    mReadHandler = new BlockReadHandler(GrpcExecutors.BLOCK_READER_EXECUTOR, mBlockWorker, mResponseObserver, new AuthenticatedUserInfo(), false);
}
Also used : LocalFileBlockReader(alluxio.worker.block.io.LocalFileBlockReader) ServerCallStreamObserver(io.grpc.stub.ServerCallStreamObserver) BlockReadRequest(alluxio.wire.BlockReadRequest) ReadResponse(alluxio.grpc.ReadResponse) LocalFileBlockReader(alluxio.worker.block.io.LocalFileBlockReader) BlockReader(alluxio.worker.block.io.BlockReader) AuthenticatedUserInfo(alluxio.security.authentication.AuthenticatedUserInfo) NoopBlockWorker(alluxio.worker.block.NoopBlockWorker) IOException(java.io.IOException) Before(org.junit.Before)

Example 3 with BlockReadRequest

use of alluxio.wire.BlockReadRequest in project alluxio by Alluxio.

the class BlockReadHandler method onError.

@Override
public void onError(Throwable cause) {
    BlockReadRequest r = mContext == null ? null : mContext.getRequest();
    LogUtils.warnWithException(LOG, "Exception occurred while processing read request onError " + "sessionId: {}, {}", r, r == null ? null : r.getSessionId(), cause);
    setError(new Error(AlluxioStatusException.fromThrowable(cause), false));
}
Also used : BlockReadRequest(alluxio.wire.BlockReadRequest)

Aggregations

BlockReadRequest (alluxio.wire.BlockReadRequest)3 BlockReader (alluxio.worker.block.io.BlockReader)2 ReadResponse (alluxio.grpc.ReadResponse)1 AuthenticatedUserInfo (alluxio.security.authentication.AuthenticatedUserInfo)1 NoopBlockWorker (alluxio.worker.block.NoopBlockWorker)1 LocalFileBlockReader (alluxio.worker.block.io.LocalFileBlockReader)1 ServerCallStreamObserver (io.grpc.stub.ServerCallStreamObserver)1 IOException (java.io.IOException)1 Before (org.junit.Before)1 Test (org.junit.Test)1