Search in sources :

Example 91 with Container

use of com.github.ambry.account.Container in project ambry by linkedin.

the class FrontendTestUrlSigningServiceFactory method injectionAccountAndContainerForGetHeadDeleteBlobIdTest.

/**
 * Tests injecting target {@link Account} and {@link Container} for GET/HEAD/DELETE blobId string in {@link BlobId#BLOB_ID_V2}.
 * The {@link AccountService} is prepopulated with a reference account and {@link InMemAccountService#UNKNOWN_ACCOUNT}. The expected
 * behavior should be:
 *
 * <pre>
 *   AId in blobId    CId in blobId     expected Error      injected account      injected container
 *    realAId           realCId          NotFound            refAccount            refContainer       This can succeed if the blob exists in backend.
 *    realAId           UNKNOWN          InvalidContainer    null                  null
 *    realAId           nonExistCId      InvalidContainer    null                  null
 *    UNKNOWN           realCId          InvalidContainer    null                  null
 *    UNKNOWN           UNKNOWN          NotFound            UNKNOWN               UNKNOWN            This can succeed if the blob exists in backend.
 *    UNKNOWN           nonExistCId      InvalidContainer    null                  null
 *    nonExistAId       realCId          InvalidAccount      null                  null
 *    nonExistAId       UNKNOWN          InvalidAccount      null                  null
 *    nonExistAId       nonExistCId      InvalidAccount      null                  null
 * </pre>
 *
 * @throws Exception
 */
@Test
public void injectionAccountAndContainerForGetHeadDeleteBlobIdTest() throws Exception {
    List<Short> blobIdVersions = Arrays.stream(BlobId.getAllValidVersions()).filter(version -> version >= BlobId.BLOB_ID_V2).collect(Collectors.toList());
    for (short version : blobIdVersions) {
        populateAccountService();
        // aid=refAId, cid=refCId
        String blobId = new BlobId(version, BlobId.BlobIdType.NATIVE, ClusterMap.UNKNOWN_DATACENTER_ID, refAccount.getId(), refContainer.getId(), clusterMap.getWritablePartitionIds(MockClusterMap.DEFAULT_PARTITION_CLASS).get(0), false, BlobId.BlobDataType.DATACHUNK).getID();
        verifyAccountAndContainerFromBlobId(blobId, refAccount, refContainer, RestServiceErrorCode.NotFound);
        // aid=refAId, cid=unknownCId
        blobId = new BlobId(version, BlobId.BlobIdType.NATIVE, ClusterMap.UNKNOWN_DATACENTER_ID, refAccount.getId(), Container.UNKNOWN_CONTAINER_ID, clusterMap.getWritablePartitionIds(MockClusterMap.DEFAULT_PARTITION_CLASS).get(0), false, BlobId.BlobDataType.DATACHUNK).getID();
        verifyAccountAndContainerFromBlobId(blobId, null, null, RestServiceErrorCode.InvalidContainer);
        // aid=refAId, cid=nonExistCId
        blobId = new BlobId(version, BlobId.BlobIdType.NATIVE, ClusterMap.UNKNOWN_DATACENTER_ID, refAccount.getId(), (short) -1234, clusterMap.getWritablePartitionIds(MockClusterMap.DEFAULT_PARTITION_CLASS).get(0), false, BlobId.BlobDataType.DATACHUNK).getID();
        verifyAccountAndContainerFromBlobId(blobId, null, null, RestServiceErrorCode.InvalidContainer);
        // aid=unknownAId, cid=refCId
        blobId = new BlobId(version, BlobId.BlobIdType.NATIVE, ClusterMap.UNKNOWN_DATACENTER_ID, Account.UNKNOWN_ACCOUNT_ID, refContainer.getId(), clusterMap.getWritablePartitionIds(MockClusterMap.DEFAULT_PARTITION_CLASS).get(0), false, BlobId.BlobDataType.DATACHUNK).getID();
        verifyAccountAndContainerFromBlobId(blobId, null, null, RestServiceErrorCode.InvalidContainer);
        // aid=unknownAId, cid=unknownCId
        blobId = new BlobId(version, BlobId.BlobIdType.NATIVE, ClusterMap.UNKNOWN_DATACENTER_ID, Account.UNKNOWN_ACCOUNT_ID, Container.UNKNOWN_CONTAINER_ID, clusterMap.getWritablePartitionIds(MockClusterMap.DEFAULT_PARTITION_CLASS).get(0), false, BlobId.BlobDataType.DATACHUNK).getID();
        verifyAccountAndContainerFromBlobId(blobId, InMemAccountService.UNKNOWN_ACCOUNT, Container.UNKNOWN_CONTAINER, RestServiceErrorCode.NotFound);
        // aid=unknownAId, cid=nonExistCId
        blobId = new BlobId(version, BlobId.BlobIdType.NATIVE, ClusterMap.UNKNOWN_DATACENTER_ID, Account.UNKNOWN_ACCOUNT_ID, (short) -1234, clusterMap.getWritablePartitionIds(MockClusterMap.DEFAULT_PARTITION_CLASS).get(0), false, BlobId.BlobDataType.DATACHUNK).getID();
        verifyAccountAndContainerFromBlobId(blobId, null, null, RestServiceErrorCode.InvalidContainer);
        // aid=nonExistAId, cid=refCId
        blobId = new BlobId(version, BlobId.BlobIdType.NATIVE, ClusterMap.UNKNOWN_DATACENTER_ID, (short) -1234, refContainer.getId(), clusterMap.getWritablePartitionIds(MockClusterMap.DEFAULT_PARTITION_CLASS).get(0), false, BlobId.BlobDataType.DATACHUNK).getID();
        verifyAccountAndContainerFromBlobId(blobId, null, null, RestServiceErrorCode.InvalidAccount);
        // aid=nonExistAId, cid=unknownCId
        blobId = new BlobId(version, BlobId.BlobIdType.NATIVE, ClusterMap.UNKNOWN_DATACENTER_ID, (short) -1234, Container.UNKNOWN_CONTAINER_ID, clusterMap.getWritablePartitionIds(MockClusterMap.DEFAULT_PARTITION_CLASS).get(0), false, BlobId.BlobDataType.DATACHUNK).getID();
        verifyAccountAndContainerFromBlobId(blobId, null, null, RestServiceErrorCode.InvalidAccount);
        // aid=nonExistAId, cid=nonExistCId
        blobId = new BlobId(version, BlobId.BlobIdType.NATIVE, ClusterMap.UNKNOWN_DATACENTER_ID, (short) -1234, (short) -11, clusterMap.getWritablePartitionIds(MockClusterMap.DEFAULT_PARTITION_CLASS).get(0), false, BlobId.BlobDataType.DATACHUNK).getID();
        verifyAccountAndContainerFromBlobId(blobId, null, null, RestServiceErrorCode.InvalidAccount);
    }
}
Also used : GetOption(com.github.ambry.protocol.GetOption) MockRestRequest(com.github.ambry.rest.MockRestRequest) Arrays(java.util.Arrays) FrontendConfig(com.github.ambry.config.FrontendConfig) AggregatedPartitionClassStorageStats(com.github.ambry.server.storagestats.AggregatedPartitionClassStorageStats) BlobProperties(com.github.ambry.messageformat.BlobProperties) FutureResult(com.github.ambry.router.FutureResult) Future(java.util.concurrent.Future) JSONException(org.json.JSONException) TestUtils(com.github.ambry.utils.TestUtils) Map(java.util.Map) ChunkInfo(com.github.ambry.router.ChunkInfo) EnumSet(java.util.EnumSet) RouterErrorCode(com.github.ambry.router.RouterErrorCode) RestResponseHandler(com.github.ambry.rest.RestResponseHandler) ReadableStreamChannel(com.github.ambry.router.ReadableStreamChannel) ClusterMapSnapshotConstants(com.github.ambry.clustermap.ClusterMapSnapshotConstants) RestResponseChannel(com.github.ambry.rest.RestResponseChannel) Set(java.util.Set) StandardCharsets(java.nio.charset.StandardCharsets) AccountStatsStore(com.github.ambry.accountstats.AccountStatsStore) BlobInfo(com.github.ambry.messageformat.BlobInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException) AggregatedAccountStorageStats(com.github.ambry.server.storagestats.AggregatedAccountStorageStats) CountDownLatch(java.util.concurrent.CountDownLatch) RestServiceException(com.github.ambry.rest.RestServiceException) MockRestResponseChannel(com.github.ambry.rest.MockRestResponseChannel) Account(com.github.ambry.account.Account) InMemoryRouter(com.github.ambry.router.InMemoryRouter) SimpleDateFormat(java.text.SimpleDateFormat) RestTestUtils(com.github.ambry.rest.RestTestUtils) PutBlobOptions(com.github.ambry.router.PutBlobOptions) ArrayList(java.util.ArrayList) QuotaConfig(com.github.ambry.config.QuotaConfig) QuotaMode(com.github.ambry.quota.QuotaMode) Lists(com.google.common.collect.Lists) SSLSession(javax.net.ssl.SSLSession) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) SystemTime(com.github.ambry.utils.SystemTime) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) RestMethod(com.github.ambry.rest.RestMethod) VerifiableProperties(com.github.ambry.config.VerifiableProperties) IOException(java.io.IOException) Test(org.junit.Test) RouterException(com.github.ambry.router.RouterException) InMemAccountServiceFactory(com.github.ambry.account.InMemAccountServiceFactory) AmbryQuotaManager(com.github.ambry.quota.AmbryQuotaManager) QuotaMetrics(com.github.ambry.quota.QuotaMetrics) GetBlobResult(com.github.ambry.router.GetBlobResult) PutBlobOptionsBuilder(com.github.ambry.router.PutBlobOptionsBuilder) SimpleQuotaRecommendationMergePolicy(com.github.ambry.quota.SimpleQuotaRecommendationMergePolicy) Assert(org.junit.Assert) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) ResponseStatus(com.github.ambry.rest.ResponseStatus) ByteBufferReadableStreamChannel(com.github.ambry.commons.ByteBufferReadableStreamChannel) ContainerBuilder(com.github.ambry.account.ContainerBuilder) ByteBuffer(java.nio.ByteBuffer) AccountCollectionSerde(com.github.ambry.account.AccountCollectionSerde) RestUtilsTest(com.github.ambry.rest.RestUtilsTest) JSONObject(org.json.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) After(org.junit.After) Method(java.lang.reflect.Method) Container(com.github.ambry.account.Container) TimeZone(java.util.TimeZone) RestServiceErrorCode(com.github.ambry.rest.RestServiceErrorCode) Utils(com.github.ambry.utils.Utils) AccountBuilder(com.github.ambry.account.AccountBuilder) Collectors(java.util.stream.Collectors) NamedBlobRecord(com.github.ambry.named.NamedBlobRecord) AsyncWritableChannel(com.github.ambry.router.AsyncWritableChannel) List(java.util.List) QuotaTestUtils(com.github.ambry.quota.QuotaTestUtils) RestRequestMetricsTracker(com.github.ambry.rest.RestRequestMetricsTracker) Callback(com.github.ambry.commons.Callback) RestUtils(com.github.ambry.rest.RestUtils) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InMemAccountService(com.github.ambry.account.InMemAccountService) PartitionId(com.github.ambry.clustermap.PartitionId) BlobId(com.github.ambry.commons.BlobId) StorageStatsUtilTest(com.github.ambry.server.StorageStatsUtilTest) ByteRanges(com.github.ambry.router.ByteRanges) AccountService(com.github.ambry.account.AccountService) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) QuotaManager(com.github.ambry.quota.QuotaManager) HashSet(java.util.HashSet) NamedBlobDb(com.github.ambry.named.NamedBlobDb) CommonTestUtils(com.github.ambry.commons.CommonTestUtils) LinkedList(java.util.LinkedList) Router(com.github.ambry.router.Router) Pair(com.github.ambry.utils.Pair) Iterator(java.util.Iterator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) QuotaChargeCallback(com.github.ambry.quota.QuotaChargeCallback) ByteRange(com.github.ambry.router.ByteRange) ClusterMap(com.github.ambry.clustermap.ClusterMap) GetBlobOptions(com.github.ambry.router.GetBlobOptions) AccountServiceException(com.github.ambry.account.AccountServiceException) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) StatsReportType(com.github.ambry.server.StatsReportType) RestRequest(com.github.ambry.rest.RestRequest) Collections(java.util.Collections) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) BlobId(com.github.ambry.commons.BlobId) Test(org.junit.Test) RestUtilsTest(com.github.ambry.rest.RestUtilsTest) StorageStatsUtilTest(com.github.ambry.server.StorageStatsUtilTest)

Example 92 with Container

use of com.github.ambry.account.Container in project ambry by linkedin.

the class AmbrySecurityServiceTest method testGetSubResource.

/**
 * Tests GET of sub-resources.
 * @param subResource the {@link RestUtils.SubResource}  to test.
 * @throws Exception
 */
private void testGetSubResource(BlobInfo blobInfo, RestUtils.SubResource subResource) throws Exception {
    MockRestResponseChannel restResponseChannel = new MockRestResponseChannel();
    RestRequest restRequest = createRestRequest(RestMethod.GET, "/sampleId/" + subResource, null);
    Pair<Account, Container> accountAndContainer = getAccountAndContainer(blobInfo.getBlobProperties());
    insertAccountAndContainer(restRequest, accountAndContainer.getFirst(), accountAndContainer.getSecond());
    securityService.processResponse(restRequest, restResponseChannel, blobInfo).get();
    Assert.assertEquals("ProcessResponse status should have been set ", ResponseStatus.Ok, restResponseChannel.getStatus());
    Assert.assertNotNull("Date has not been set", restResponseChannel.getHeader(RestUtils.Headers.DATE));
    Assert.assertEquals("Last Modified does not match creation time", RestUtils.toSecondsPrecisionInMs(blobInfo.getBlobProperties().getCreationTimeInMs()), RestUtils.getTimeFromDateString(restResponseChannel.getHeader(RestUtils.Headers.LAST_MODIFIED)).longValue());
    if (subResource.equals(RestUtils.SubResource.BlobInfo)) {
        verifyBlobPropertiesHeaders(blobInfo.getBlobProperties(), restResponseChannel);
        verifyAccountAndContainerHeaders(restResponseChannel, accountAndContainer.getFirst(), accountAndContainer.getSecond());
        Assert.assertEquals("LifeVersion mismatch", Short.toString(blobInfo.getLifeVersion()), restResponseChannel.getHeader(RestUtils.Headers.LIFE_VERSION));
    } else {
        verifyAbsenceOfHeaders(restResponseChannel, RestUtils.Headers.PRIVATE, RestUtils.Headers.TTL, RestUtils.Headers.SERVICE_ID, RestUtils.Headers.OWNER_ID, RestUtils.Headers.AMBRY_CONTENT_TYPE, RestUtils.Headers.CREATION_TIME, RestUtils.Headers.BLOB_SIZE, RestUtils.Headers.ACCEPT_RANGES, RestUtils.Headers.CONTENT_RANGE, RestUtils.Headers.LIFE_VERSION);
    }
    Map<String, String> userMetadata = blobInfo.getUserMetadata() != null ? RestUtils.buildUserMetadata(blobInfo.getUserMetadata()) : null;
    if (userMetadata == null && !(blobInfo.getUserMetadata().length == 0)) {
        Assert.assertTrue("Internal key " + RestUtils.InternalKeys.SEND_USER_METADATA_AS_RESPONSE_BODY + " should be set", (Boolean) restRequest.getArgs().get(RestUtils.InternalKeys.SEND_USER_METADATA_AS_RESPONSE_BODY));
    } else if (!(blobInfo.getUserMetadata().length == 0)) {
        USER_METADATA.forEach((key, value) -> Assert.assertEquals("Value of " + key + " not as expected", value, restResponseChannel.getHeader(key)));
    }
}
Also used : MockRestRequest(com.github.ambry.rest.MockRestRequest) FrontendConfig(com.github.ambry.config.FrontendConfig) BlobProperties(com.github.ambry.messageformat.BlobProperties) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) ResponseStatus(com.github.ambry.rest.ResponseStatus) ByteBuffer(java.nio.ByteBuffer) ThrowingConsumer(com.github.ambry.utils.ThrowingConsumer) Future(java.util.concurrent.Future) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) HostThrottleConfig(com.github.ambry.config.HostThrottleConfig) TestUtils(com.github.ambry.utils.TestUtils) Locale(java.util.Locale) Map(java.util.Map) Container(com.github.ambry.account.Container) TimeZone(java.util.TimeZone) RestResponseChannel(com.github.ambry.rest.RestResponseChannel) RestServiceErrorCode(com.github.ambry.rest.RestServiceErrorCode) Utils(com.github.ambry.utils.Utils) BlobInfo(com.github.ambry.messageformat.BlobInfo) RestServiceException(com.github.ambry.rest.RestServiceException) MockRestResponseChannel(com.github.ambry.rest.MockRestResponseChannel) QuotaTestUtils(com.github.ambry.quota.QuotaTestUtils) Account(com.github.ambry.account.Account) Callback(com.github.ambry.commons.Callback) RestUtils(com.github.ambry.rest.RestUtils) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InMemAccountService(com.github.ambry.account.InMemAccountService) ByteRanges(com.github.ambry.router.ByteRanges) SimpleDateFormat(java.text.SimpleDateFormat) AccountService(com.github.ambry.account.AccountService) HashMap(java.util.HashMap) RestTestUtils(com.github.ambry.rest.RestTestUtils) QuotaManager(com.github.ambry.quota.QuotaManager) QuotaConfig(com.github.ambry.config.QuotaConfig) RequestPath(com.github.ambry.rest.RequestPath) QuotaMode(com.github.ambry.quota.QuotaMode) HostLevelThrottler(com.github.ambry.commons.HostLevelThrottler) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) Pair(com.github.ambry.utils.Pair) RestMethod(com.github.ambry.rest.RestMethod) VerifiableProperties(com.github.ambry.config.VerifiableProperties) ByteRange(com.github.ambry.router.ByteRange) IOException(java.io.IOException) Test(org.junit.Test) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) InMemAccountServiceFactory(com.github.ambry.account.InMemAccountServiceFactory) AmbryQuotaManager(com.github.ambry.quota.AmbryQuotaManager) Mockito(org.mockito.Mockito) QuotaMetrics(com.github.ambry.quota.QuotaMetrics) SimpleQuotaRecommendationMergePolicy(com.github.ambry.quota.SimpleQuotaRecommendationMergePolicy) Assert(org.junit.Assert) RestRequest(com.github.ambry.rest.RestRequest) Collections(java.util.Collections) Account(com.github.ambry.account.Account) Container(com.github.ambry.account.Container) MockRestRequest(com.github.ambry.rest.MockRestRequest) RestRequest(com.github.ambry.rest.RestRequest) MockRestResponseChannel(com.github.ambry.rest.MockRestResponseChannel)

Example 93 with Container

use of com.github.ambry.account.Container in project ambry by linkedin.

the class AmbrySecurityServiceTest method getAccountAndContainer.

/**
 * @param blobProperties the {@link BlobProperties} to read.
 * @return the {@link Account} and {@link Container} objects corresponding to the IDs in the {@link BlobProperties}.
 */
private Pair<Account, Container> getAccountAndContainer(BlobProperties blobProperties) {
    Account account = ACCOUNT_SERVICE.getAccountById(blobProperties.getAccountId());
    Container container = account.getContainerById(blobProperties.getContainerId());
    return new Pair<>(account, container);
}
Also used : Account(com.github.ambry.account.Account) Container(com.github.ambry.account.Container) Pair(com.github.ambry.utils.Pair)

Example 94 with Container

use of com.github.ambry.account.Container in project ambry by linkedin.

the class FrontendIntegrationTest method getAndUseSignedUrlTest.

/**
 * Tests the handling of {@link Operations#GET_SIGNED_URL} requests.
 * @throws Exception
 */
@Test
public void getAndUseSignedUrlTest() throws Exception {
    Account account = ACCOUNT_SERVICE.createAndAddRandomAccount();
    Container container = account.getContainerById(Container.DEFAULT_PRIVATE_CONTAINER_ID);
    // setup
    ByteBuffer content = ByteBuffer.wrap(TestUtils.getRandomBytes(10));
    String serviceId = "getAndUseSignedUrlTest";
    String contentType = "application/octet-stream";
    String ownerId = "getAndUseSignedUrlTest";
    HttpHeaders headers = new DefaultHttpHeaders();
    headers.add(RestUtils.Headers.URL_TYPE, RestMethod.POST.name());
    setAmbryHeadersForPut(headers, TTL_SECS, !container.isCacheable(), serviceId, contentType, ownerId, account.getName(), container.getName());
    headers.add(RestUtils.Headers.USER_META_DATA_HEADER_PREFIX + "key1", "value1");
    headers.add(RestUtils.Headers.USER_META_DATA_HEADER_PREFIX + "key2", "value2");
    // POST
    // Get signed URL
    FullHttpRequest httpRequest = buildRequest(HttpMethod.GET, Operations.GET_SIGNED_URL, headers, null);
    ResponseParts responseParts = nettyClient.sendRequest(httpRequest, null, null).get();
    HttpResponse response = getHttpResponse(responseParts);
    verifyTrackingHeaders(response);
    assertNotNull("There should be a response from the server", response);
    assertEquals("Unexpected response status", HttpResponseStatus.OK, response.status());
    String signedPostUrl = response.headers().get(RestUtils.Headers.SIGNED_URL);
    assertNotNull("Did not get a signed POST URL", signedPostUrl);
    assertNoContent(responseParts.queue, 1);
    // Use signed URL to POST
    URI uri = new URI(signedPostUrl);
    httpRequest = buildRequest(HttpMethod.POST, uri.getPath() + "?" + uri.getQuery(), null, content);
    responseParts = nettyClient.sendRequest(httpRequest, null, null).get();
    String blobId = verifyPostAndReturnBlobId(responseParts, content.capacity(), false);
    // verify POST
    headers.add(RestUtils.Headers.BLOB_SIZE, content.capacity());
    headers.add(RestUtils.Headers.LIFE_VERSION, "0");
    getBlobAndVerify(blobId, null, GetOption.None, false, headers, !container.isCacheable(), content, account.getName(), container.getName());
    getBlobInfoAndVerify(blobId, GetOption.None, headers, !container.isCacheable(), account.getName(), container.getName(), null);
    // GET
    // Get signed URL
    HttpHeaders getHeaders = new DefaultHttpHeaders();
    getHeaders.add(RestUtils.Headers.URL_TYPE, RestMethod.GET.name());
    getHeaders.add(RestUtils.Headers.BLOB_ID, addClusterPrefix ? "/" + CLUSTER_NAME + blobId : blobId);
    httpRequest = buildRequest(HttpMethod.GET, Operations.GET_SIGNED_URL, getHeaders, null);
    responseParts = nettyClient.sendRequest(httpRequest, null, null).get();
    response = getHttpResponse(responseParts);
    assertEquals("Unexpected response status", HttpResponseStatus.OK, response.status());
    verifyTrackingHeaders(response);
    String signedGetUrl = response.headers().get(RestUtils.Headers.SIGNED_URL);
    assertNotNull("Did not get a signed GET URL", signedGetUrl);
    assertNoContent(responseParts.queue, 1);
    // Use URL to GET blob
    uri = new URI(signedGetUrl);
    httpRequest = buildRequest(HttpMethod.GET, uri.getPath() + "?" + uri.getQuery(), null, null);
    responseParts = nettyClient.sendRequest(httpRequest, null, null).get();
    verifyGetBlobResponse(responseParts, null, false, headers, !container.isCacheable(), content, account.getName(), container.getName());
}
Also used : Account(com.github.ambry.account.Account) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) Container(com.github.ambry.account.Container) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) HttpResponse(io.netty.handler.codec.http.HttpResponse) ResponseParts(com.github.ambry.rest.NettyClient.ResponseParts) ByteBuffer(java.nio.ByteBuffer) URI(java.net.URI) Test(org.junit.Test)

Example 95 with Container

use of com.github.ambry.account.Container in project ambry by linkedin.

the class FrontendIntegrationTest method postGetHeadUpdateDeleteUndeleteTest.

/**
 * Tests blob POST, GET, HEAD, TTL update and DELETE operations.
 * @throws Exception
 */
@Test
public void postGetHeadUpdateDeleteUndeleteTest() throws Exception {
    // add some accounts
    Account refAccount = ACCOUNT_SERVICE.createAndAddRandomAccount();
    Container publicContainer = refAccount.getContainerById(Container.DEFAULT_PUBLIC_CONTAINER_ID);
    Container privateContainer = refAccount.getContainerById(Container.DEFAULT_PRIVATE_CONTAINER_ID);
    int refContentSize = (int) FRONTEND_CONFIG.chunkedGetResponseThresholdInBytes * 3;
    // with valid account and containers
    for (int i = 0; i < 2; i++) {
        Account account = ACCOUNT_SERVICE.createAndAddRandomAccount();
        for (Container container : account.getAllContainers()) {
            doPostGetHeadUpdateDeleteUndeleteTest(refContentSize, account, container, account.getName(), !container.isCacheable(), account.getName(), container.getName(), false);
        }
    }
    // valid account and container names but only serviceId passed as part of POST
    doPostGetHeadUpdateDeleteUndeleteTest(refContentSize, null, null, refAccount.getName(), false, refAccount.getName(), publicContainer.getName(), false);
    doPostGetHeadUpdateDeleteUndeleteTest(refContentSize, null, null, refAccount.getName(), true, refAccount.getName(), privateContainer.getName(), false);
    // unrecognized serviceId
    doPostGetHeadUpdateDeleteUndeleteTest(refContentSize, null, null, "unknown_service_id", false, null, null, false);
    doPostGetHeadUpdateDeleteUndeleteTest(refContentSize, null, null, "unknown_service_id", true, null, null, false);
    // different sizes
    for (int contentSize : new int[] { 0, (int) FRONTEND_CONFIG.chunkedGetResponseThresholdInBytes - 1, (int) FRONTEND_CONFIG.chunkedGetResponseThresholdInBytes, refContentSize }) {
        doPostGetHeadUpdateDeleteUndeleteTest(contentSize, refAccount, publicContainer, refAccount.getName(), !publicContainer.isCacheable(), refAccount.getName(), publicContainer.getName(), false);
    }
}
Also used : Account(com.github.ambry.account.Account) Container(com.github.ambry.account.Container) Test(org.junit.Test)

Aggregations

Container (com.github.ambry.account.Container)119 Account (com.github.ambry.account.Account)88 Test (org.junit.Test)61 ArrayList (java.util.ArrayList)30 RestServiceException (com.github.ambry.rest.RestServiceException)20 ContainerBuilder (com.github.ambry.account.ContainerBuilder)17 JSONObject (org.json.JSONObject)17 VerifiableProperties (com.github.ambry.config.VerifiableProperties)16 HashSet (java.util.HashSet)15 HashMap (java.util.HashMap)14 Properties (java.util.Properties)14 AccountBuilder (com.github.ambry.account.AccountBuilder)13 RestRequest (com.github.ambry.rest.RestRequest)13 ByteBuffer (java.nio.ByteBuffer)13 Map (java.util.Map)13 MetricRegistry (com.codahale.metrics.MetricRegistry)12 TestUtils (com.github.ambry.utils.TestUtils)12 Collections (java.util.Collections)12 List (java.util.List)12 Assert (org.junit.Assert)12