use of com.github.ambry.router.PutBlobOptionsBuilder in project ambry by linkedin.
the class UndeleteHandlerTest method setupBlob.
/**
* Setup a blob and delete it so later we can undelete it.
* @throws Exception
*/
public void setupBlob() throws Exception {
ReadableStreamChannel channel = new ByteBufferReadableStreamChannel(ByteBuffer.wrap(BLOB_DATA));
blobId = router.putBlob(BLOB_PROPERTIES, new byte[0], channel, new PutBlobOptionsBuilder().build()).get(1, TimeUnit.SECONDS);
idConverterFactory.translation = blobId;
router.deleteBlob(blobId, SERVICE_ID).get(1, TimeUnit.SECONDS);
}
use of com.github.ambry.router.PutBlobOptionsBuilder in project ambry by linkedin.
the class MockHeadCallback method handlePost.
@Override
public void handlePost(RestRequest restRequest, RestResponseChannel restResponseChannel) {
if (shouldProceed(restRequest, restResponseChannel)) {
try {
restRequest.setArg(RestUtils.InternalKeys.TARGET_ACCOUNT_KEY, InMemAccountService.UNKNOWN_ACCOUNT);
restRequest.setArg(RestUtils.InternalKeys.TARGET_CONTAINER_KEY, Container.UNKNOWN_CONTAINER);
BlobProperties blobProperties = RestUtils.buildBlobProperties(restRequest.getArgs());
byte[] usermetadata = RestUtils.buildUserMetadata(restRequest.getArgs());
router.putBlob(blobProperties, usermetadata, restRequest, new PutBlobOptionsBuilder().build(), new MockPostCallback(this, restRequest, restResponseChannel, blobProperties), null);
} catch (RestServiceException e) {
handleResponse(restRequest, restResponseChannel, null, e);
}
}
}
use of com.github.ambry.router.PutBlobOptionsBuilder in project ambry by linkedin.
the class FrontendTestUrlSigningServiceFactory method oldStyleUserMetadataTest.
/**
* Tests how metadata that has not been POSTed in the form of headers is returned.
* @throws Exception
*/
@Test
public void oldStyleUserMetadataTest() throws Exception {
ByteBuffer content = ByteBuffer.allocate(0);
BlobProperties blobProperties = new BlobProperties(0, "userMetadataTestOldStyleServiceID", Account.UNKNOWN_ACCOUNT_ID, Container.UNKNOWN_CONTAINER_ID, false);
byte[] usermetadata = TestUtils.getRandomBytes(25);
String blobId = router.putBlob(blobProperties, usermetadata, new ByteBufferReadableStreamChannel(content), new PutBlobOptionsBuilder().build()).get();
RestUtils.SubResource[] subResources = { RestUtils.SubResource.UserMetadata, RestUtils.SubResource.BlobInfo };
for (RestUtils.SubResource subResource : subResources) {
RestRequest restRequest = createRestRequest(RestMethod.GET, blobId + "/" + subResource, null, null);
MockRestResponseChannel restResponseChannel = new MockRestResponseChannel();
doOperation(restRequest, restResponseChannel);
assertEquals("Unexpected response status for " + subResource, ResponseStatus.Ok, restResponseChannel.getStatus());
assertEquals("Unexpected Content-Type for " + subResource, "application/octet-stream", restResponseChannel.getHeader(RestUtils.Headers.CONTENT_TYPE));
assertEquals("Unexpected Content-Length for " + subResource, usermetadata.length, Integer.parseInt(restResponseChannel.getHeader(RestUtils.Headers.CONTENT_LENGTH)));
assertArrayEquals("Unexpected user metadata for " + subResource, usermetadata, restResponseChannel.getResponseBody());
}
}
use of com.github.ambry.router.PutBlobOptionsBuilder in project ambry by linkedin.
the class PostBlobHandlerTest method uploadChunksViaRouter.
// stitchedUploadTest() helpers
/**
* Upload chunks using the router directly.
* @param creationTimeMs the creation time to set for the chunks.
* @param container the {@link Container} to create the chunks in.
* @param chunkSizes the sizes for each chunk to upload.
* @return a list of {@link ChunkInfo} objects that contains metadata about each chunk uploaded.
*/
private List<ChunkInfo> uploadChunksViaRouter(long creationTimeMs, Container container, int... chunkSizes) throws Exception {
long blobTtlSecs = TimeUnit.DAYS.toSeconds(1);
List<ChunkInfo> chunks = new ArrayList<>();
for (int chunkSize : chunkSizes) {
byte[] content = TestUtils.getRandomBytes(chunkSize);
BlobProperties blobProperties = new BlobProperties(-1, SERVICE_ID, OWNER_ID, CONTENT_TYPE, !container.isCacheable(), blobTtlSecs, creationTimeMs, container.getParentAccountId(), container.getId(), container.isEncrypted(), null, null, null);
String blobId = router.putBlob(blobProperties, null, new ByteBufferReadableStreamChannel(ByteBuffer.wrap(content)), new PutBlobOptionsBuilder().chunkUpload(true).build()).get(TIMEOUT_SECS, TimeUnit.SECONDS);
chunks.add(new ChunkInfo(blobId, chunkSize, Utils.addSecondsToEpochTime(creationTimeMs, blobTtlSecs)));
}
return chunks;
}
use of com.github.ambry.router.PutBlobOptionsBuilder in project ambry by linkedin.
the class NamedBlobPutHandlerTest method uploadChunksViaRouter.
/**
* Upload chunks using the router directly.
* @param creationTimeMs the creation time to set for the chunks.
* @param container the {@link Container} to create the chunks in.
* @param chunkSizes the sizes for each chunk to upload.
* @return a list of {@link ChunkInfo} objects that contains metadata about each chunk uploaded.
*/
private List<ChunkInfo> uploadChunksViaRouter(long creationTimeMs, Container container, int... chunkSizes) throws Exception {
long blobTtlSecs = TimeUnit.DAYS.toSeconds(1);
List<ChunkInfo> chunks = new ArrayList<>();
for (int chunkSize : chunkSizes) {
byte[] content = TestUtils.getRandomBytes(chunkSize);
BlobProperties blobProperties = new BlobProperties(-1, SERVICE_ID, OWNER_ID, CONTENT_TYPE, !container.isCacheable(), blobTtlSecs, creationTimeMs, container.getParentAccountId(), container.getId(), container.isEncrypted(), null, null, null);
String blobId = router.putBlob(blobProperties, null, new ByteBufferReadableStreamChannel(ByteBuffer.wrap(content)), new PutBlobOptionsBuilder().chunkUpload(true).build()).get(TIMEOUT_SECS, TimeUnit.SECONDS);
chunks.add(new ChunkInfo(blobId, chunkSize, Utils.addSecondsToEpochTime(creationTimeMs, blobTtlSecs)));
}
return chunks;
}
Aggregations