use of com.github.ambry.protocol.GetOption in project ambry by linkedin.
the class FrontendIntegrationTest method verifyOperationsAfterDelete.
/**
* Verifies that the right response code is returned for GET, HEAD and DELETE once a blob is deleted.
* @param blobId the ID of the blob that was deleted.
* @param expectedHeaders the expected headers in the response if the right options are provided.
* @param isPrivate {@code true} if the blob is expected to be private
* @param accountName the expected account name in {@code response}.
* @param containerName the expected container name in {@code response}.
* @param expectedContent the expected content of the blob if the right options are provided.
* @param usermetadata if non-null, this is expected to come as the body.
* @throws Exception
*/
private void verifyOperationsAfterDelete(String blobId, HttpHeaders expectedHeaders, boolean isPrivate, String accountName, String containerName, ByteBuffer expectedContent, byte[] usermetadata) throws Exception {
HttpHeaders headers = new DefaultHttpHeaders().add(RestUtils.Headers.GET_OPTION, GetOption.None.toString());
FullHttpRequest httpRequest = buildRequest(HttpMethod.GET, blobId, null, null);
verifyDeleted(httpRequest, HttpResponseStatus.GONE);
httpRequest = buildRequest(HttpMethod.GET, blobId, headers, null);
verifyDeleted(httpRequest, HttpResponseStatus.GONE);
httpRequest = buildRequest(HttpMethod.HEAD, blobId, null, null);
verifyDeleted(httpRequest, HttpResponseStatus.GONE);
httpRequest = buildRequest(HttpMethod.HEAD, blobId, headers, null);
verifyDeleted(httpRequest, HttpResponseStatus.GONE);
httpRequest = buildRequest(HttpMethod.DELETE, blobId, null, null);
verifyDeleted(httpRequest, HttpResponseStatus.ACCEPTED);
GetOption[] options = { GetOption.Include_Deleted_Blobs, GetOption.Include_All };
for (GetOption option : options) {
getBlobAndVerify(blobId, null, option, expectedHeaders, isPrivate, expectedContent);
getNotModifiedBlobAndVerify(blobId, option, isPrivate);
getUserMetadataAndVerify(blobId, option, expectedHeaders, usermetadata);
getBlobInfoAndVerify(blobId, option, expectedHeaders, isPrivate, accountName, containerName, usermetadata);
getHeadAndVerify(blobId, null, option, expectedHeaders, isPrivate, accountName, containerName);
}
}
use of com.github.ambry.protocol.GetOption in project ambry by linkedin.
the class RouterServerTestFramework method continueChain.
/**
* Submit the next operation in the chain to the router. If there are no more operations in the queue,
* mark the chain as completed.
* @param opChain the {@link OperationChain} to get the next operation from.
*/
private void continueChain(final OperationChain opChain) {
synchronized (opChain.testFutures) {
OperationType nextOp = opChain.operations.poll();
if (nextOp == null) {
opChain.latch.countDown();
return;
}
GetOption options = GetOption.None;
switch(nextOp) {
case PUT:
startPutBlob(opChain);
break;
case GET_INFO_DELETED_SUCCESS:
options = GetOption.Include_Deleted_Blobs;
case GET_INFO:
case GET_INFO_DELETED:
startGetBlobInfo(options, nextOp.checkDeleted, opChain);
break;
case GET_DELETED_SUCCESS:
options = GetOption.Include_Deleted_Blobs;
case GET:
case GET_DELETED:
startGetBlob(options, nextOp.checkDeleted, opChain);
break;
case DELETE:
startDeleteBlob(opChain);
break;
case AWAIT_CREATION:
startAwaitCreation(opChain);
break;
case AWAIT_DELETION:
startAwaitDeletion(opChain);
break;
default:
throw new IllegalArgumentException("Unknown op: " + nextOp);
}
}
}
use of com.github.ambry.protocol.GetOption in project ambry by linkedin.
the class FrontendTestUrlSigningServiceFactory method verifyOperationsAfterDelete.
/**
* Verifies that the right {@link ResponseStatus} is returned for GET, HEAD and DELETE once a blob is deleted.
* @param blobId the ID of the blob that was deleted.
* @param expectedHeaders the expected headers in the response if the right options are provided.
* @param expectedContent the expected content of the blob if the right options are provided.
* @param expectedAccount the {@link Account} details that are eventually expected to be populated.
* @param expectedContainer the {@link Container} details that are eventually expected to be populated.
* @throws Exception
*/
private void verifyOperationsAfterDelete(String blobId, JSONObject expectedHeaders, ByteBuffer expectedContent, Account expectedAccount, Container expectedContainer) throws Exception {
RestRequest restRequest = createRestRequest(RestMethod.GET, blobId, null, null);
verifyGone(restRequest);
restRequest = createRestRequest(RestMethod.HEAD, blobId, null, null);
verifyGone(restRequest);
restRequest = createRestRequest(RestMethod.DELETE, blobId, null, null);
verifyDeleteAccepted(restRequest);
GetOption[] options = { GetOption.Include_Deleted_Blobs, GetOption.Include_All };
for (GetOption option : options) {
getBlobAndVerify(blobId, null, option, expectedHeaders, expectedContent, expectedAccount, expectedContainer);
getNotModifiedBlobAndVerify(blobId, option);
getUserMetadataAndVerify(blobId, option, expectedHeaders);
getBlobInfoAndVerify(blobId, option, expectedHeaders, expectedAccount, expectedContainer);
getHeadAndVerify(blobId, null, option, expectedHeaders, expectedAccount, expectedContainer);
}
}
use of com.github.ambry.protocol.GetOption in project ambry by linkedin.
the class RestUtilsTest method getGetOptionTest.
/**
* Tests {@link RestUtils#getGetOption(RestRequest)}.
* @throws Exception
*/
@Test
public void getGetOptionTest() throws Exception {
for (GetOption option : GetOption.values()) {
JSONObject headers = new JSONObject();
headers.put(RestUtils.Headers.GET_OPTION, option.toString().toLowerCase());
RestRequest restRequest = createRestRequest(RestMethod.GET, "/", headers);
assertEquals("Option returned not as expected", option, RestUtils.getGetOption(restRequest));
}
// no value defined
RestRequest restRequest = createRestRequest(RestMethod.GET, "/", null);
assertEquals("Option returned not as expected", GetOption.None, RestUtils.getGetOption(restRequest));
// bad value
JSONObject headers = new JSONObject();
headers.put(RestUtils.Headers.GET_OPTION, "non_existent_option");
restRequest = createRestRequest(RestMethod.GET, "/", headers);
try {
RestUtils.getGetOption(restRequest);
fail("Should have failed to get GetOption because value of header is invalid");
} catch (RestServiceException e) {
assertEquals("Unexpected RestServiceErrorCode", RestServiceErrorCode.InvalidArgs, e.getErrorCode());
}
}
use of com.github.ambry.protocol.GetOption in project ambry by linkedin.
the class GetBlobOptionsTest method testToStringEqualsAndHashcode.
/**
* Test toString, equals, and hashCode methods.
*/
@Test
public void testToStringEqualsAndHashcode() {
ByteRange byteRange = ByteRange.fromLastNBytes(4);
GetOption getOption = GetOption.None;
GetBlobOptions.OperationType type = GetBlobOptions.OperationType.Data;
GetBlobOptions a = new GetBlobOptionsBuilder().operationType(type).getOption(getOption).range(byteRange).build();
GetBlobOptions b = new GetBlobOptionsBuilder().operationType(type).getOption(getOption).range(byteRange).build();
assertEquals("GetBlobOptions should be equal", a, b);
assertEquals("GetBlobOptions hashcodes should be equal", a.hashCode(), b.hashCode());
assertEquals("toString output not as expected", "GetBlobOptions{operationType=" + type + ", getOption=" + getOption + ", range=" + byteRange.toString() + "}", a.toString());
b = new GetBlobOptionsBuilder().operationType(type).getOption(getOption).range(ByteRange.fromOffsetRange(2, 7)).build();
assertFalse("GetBlobOptions should not be equal.", a.equals(b));
b = new GetBlobOptionsBuilder().operationType(GetBlobOptions.OperationType.All).getOption(getOption).range(byteRange).build();
assertFalse("GetBlobOptions should not be equal.", a.equals(b));
b = new GetBlobOptionsBuilder().operationType(type).getOption(GetOption.Include_All).range(byteRange).build();
assertFalse("GetBlobOptions should not be equal.", a.equals(b));
}
Aggregations