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()));
}
}
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);
}
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);
}
Aggregations