Search in sources :

Example 21 with FutureResult

use of com.github.ambry.router.FutureResult 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)

Example 22 with FutureResult

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

the class RouterServerTestFramework method startDeleteBlobAuthorizationFailTest.

/**
 * Submit a deleteBlob operation with incorrect accountId/ContainerId in blobId.
 * @param opChain the {@link OperationChain} object that this operation is a part of.
 */
private void startDeleteBlobAuthorizationFailTest(final OperationChain opChain) {
    Callback<Void> 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("deleteBlobAuthorizationFail", true), opChain) {

            @Override
            void check() throws Exception {
                throw e;
            }
        };
        opChain.testFutures.add(testFuture);
        return;
    }
    Future<Void> future = router.deleteBlob(fraudId.getID(), null, callback, quotaChargeCallback);
    TestFuture<Void> testFuture = new TestFuture<Void>(future, genLabel("deleteBlobAuthorizationFail", true), opChain) {

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

Aggregations

FutureResult (com.github.ambry.router.FutureResult)22 IOException (java.io.IOException)8 RestRequest (com.github.ambry.rest.RestRequest)7 RestServiceException (com.github.ambry.rest.RestServiceException)7 JSONObject (org.json.JSONObject)7 MockRestResponseChannel (com.github.ambry.rest.MockRestResponseChannel)6 RestResponseChannel (com.github.ambry.rest.RestResponseChannel)6 RouterException (com.github.ambry.router.RouterException)6 ClosedChannelException (java.nio.channels.ClosedChannelException)6 ExecutionException (java.util.concurrent.ExecutionException)5 GetBlobResult (com.github.ambry.router.GetBlobResult)4 InMemoryRouter (com.github.ambry.router.InMemoryRouter)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 URISyntaxException (java.net.URISyntaxException)4 ByteBufferReadableStreamChannel (com.github.ambry.commons.ByteBufferReadableStreamChannel)3 BlobInfo (com.github.ambry.messageformat.BlobInfo)3 ByteBuffer (java.nio.ByteBuffer)3 HashMap (java.util.HashMap)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2