Search in sources :

Example 6 with GetBlobResult

use of com.github.ambry.router.GetBlobResult in project ambry by linkedin.

the class ServerTestUtil method checkBlobId.

private static void checkBlobId(Router router, BlobId blobId, byte[] data) throws Exception {
    GetBlobResult result = router.getBlob(blobId.getID(), new GetBlobOptionsBuilder().build()).get(20, TimeUnit.SECONDS);
    ReadableStreamChannel blob = result.getBlobDataChannel();
    assertEquals("Size does not match that of data", data.length, result.getBlobInfo().getBlobProperties().getBlobSize());
    RetainingAsyncWritableChannel channel = new RetainingAsyncWritableChannel();
    blob.readInto(channel, null).get(1, TimeUnit.SECONDS);
    try (InputStream is = channel.consumeContentAsInputStream()) {
        assertArrayEquals(data, Utils.readBytesFromStream(is, (int) channel.getBytesWritten()));
    }
}
Also used : GetBlobOptionsBuilder(com.github.ambry.router.GetBlobOptionsBuilder) GetBlobResult(com.github.ambry.router.GetBlobResult) ReadableStreamChannel(com.github.ambry.router.ReadableStreamChannel) ByteBufferReadableStreamChannel(com.github.ambry.commons.ByteBufferReadableStreamChannel) RetainingAsyncWritableChannel(com.github.ambry.commons.RetainingAsyncWritableChannel) NettyByteBufDataInputStream(com.github.ambry.utils.NettyByteBufDataInputStream) PutMessageFormatInputStream(com.github.ambry.messageformat.PutMessageFormatInputStream) ByteBufferInputStream(com.github.ambry.utils.ByteBufferInputStream) DataInputStream(java.io.DataInputStream) CrcInputStream(com.github.ambry.utils.CrcInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream)

Example 7 with GetBlobResult

use of com.github.ambry.router.GetBlobResult in project ambry by linkedin.

the class RouterServerTestFramework method startGetBlob.

/**
 * Submit a getBlob operation.
 * @param options the {@link GetOption} associated with the request.
 * @param checkDeleted {@code true}, checks that the blob is deleted.
 * @param opChain the {@link OperationChain} object that this operation is a part of.
 */
private void startGetBlob(GetOption options, final boolean checkDeleted, final OperationChain opChain) {
    Callback<GetBlobResult> callback = new TestCallback<>(opChain, checkDeleted);
    Future<GetBlobResult> future = router.getBlob(opChain.blobId, new GetBlobOptionsBuilder().operationType(GetBlobOptions.OperationType.All).getOption(options).build(), callback, quotaChargeCallback);
    TestFuture<GetBlobResult> testFuture = new TestFuture<GetBlobResult>(future, genLabel("getBlob", checkDeleted), opChain) {

        @Override
        void check() throws Exception {
            if (checkDeleted) {
                checkDeleted();
            } else {
                GetBlobResult result = get();
                checkBlobInfo(result.getBlobInfo(), opChain, getOperationName());
                checkBlob(result.getBlobDataChannel(), opChain, getOperationName());
            }
        }
    };
    opChain.testFutures.add(testFuture);
}
Also used : GetBlobOptionsBuilder(com.github.ambry.router.GetBlobOptionsBuilder) GetBlobResult(com.github.ambry.router.GetBlobResult)

Example 8 with GetBlobResult

use of com.github.ambry.router.GetBlobResult in project ambry by linkedin.

the class RouterServerTestFramework method startGetBlobAuthorizationFailTest.

/**
 * Submit a getBlob operation with incorrect accountId/ContainerId in blobId.
 * @param opChain the {@link OperationChain} object that this operation is a part of.
 */
private void startGetBlobAuthorizationFailTest(final OperationChain opChain) {
    Callback<GetBlobResult> callback = new TestCallback<>(opChain, true);
    BlobId originalId, fraudId;
    try {
        originalId = new BlobId(opChain.blobId, clusterMap);
        fraudId = BlobId.craft(originalId, originalId.getVersion(), (short) (originalId.getAccountId() + 1), (short) (originalId.getContainerId() + 1));
    } catch (IOException e) {
        // If there is a blobId creation failure, throw the exception and don't need to do actual action.
        FutureResult<Void> future = new FutureResult<>();
        // continue the chain
        future.done(null, e);
        callback.onCompletion(null, e);
        TestFuture<Void> testFuture = new TestFuture<Void>(future, genLabel("getBlobAuthorizationFail", true), opChain) {

            @Override
            void check() throws Exception {
                throw e;
            }
        };
        opChain.testFutures.add(testFuture);
        return;
    }
    // If everything good:
    Future<GetBlobResult> future = router.getBlob(fraudId.getID(), new GetBlobOptionsBuilder().operationType(GetBlobOptions.OperationType.All).getOption(GetOption.Include_All).build(), callback, quotaChargeCallback);
    TestFuture<GetBlobResult> testFuture = new TestFuture<GetBlobResult>(future, genLabel("getBlobAuthorizationFail", true), opChain) {

        @Override
        void check() throws Exception {
            checkExpectedRouterErrorCode(RouterErrorCode.BlobAuthorizationFailure);
        }
    };
    opChain.testFutures.add(testFuture);
}
Also used : GetBlobOptionsBuilder(com.github.ambry.router.GetBlobOptionsBuilder) GetBlobResult(com.github.ambry.router.GetBlobResult) IOException(java.io.IOException) IOException(java.io.IOException) RouterException(com.github.ambry.router.RouterException) ExecutionException(java.util.concurrent.ExecutionException) FutureResult(com.github.ambry.router.FutureResult) BlobId(com.github.ambry.commons.BlobId)

Aggregations

GetBlobResult (com.github.ambry.router.GetBlobResult)8 GetBlobOptionsBuilder (com.github.ambry.router.GetBlobOptionsBuilder)5 FutureResult (com.github.ambry.router.FutureResult)4 ByteBufferReadableStreamChannel (com.github.ambry.commons.ByteBufferReadableStreamChannel)2 BlobInfo (com.github.ambry.messageformat.BlobInfo)2 ReadableStreamChannel (com.github.ambry.router.ReadableStreamChannel)2 RouterException (com.github.ambry.router.RouterException)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 BlobId (com.github.ambry.commons.BlobId)1 ReadableStreamChannelInputStream (com.github.ambry.commons.ReadableStreamChannelInputStream)1 RetainingAsyncWritableChannel (com.github.ambry.commons.RetainingAsyncWritableChannel)1 PutMessageFormatInputStream (com.github.ambry.messageformat.PutMessageFormatInputStream)1 ByteBufferInputStream (com.github.ambry.utils.ByteBufferInputStream)1 CrcInputStream (com.github.ambry.utils.CrcInputStream)1 NettyByteBufDataInputStream (com.github.ambry.utils.NettyByteBufDataInputStream)1 DataInputStream (java.io.DataInputStream)1 FileInputStream (java.io.FileInputStream)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1