Search in sources :

Example 1 with NamedBlobRecord

use of com.github.ambry.named.NamedBlobRecord in project ambry by linkedin.

the class FrontendTestUrlSigningServiceFactory method listNamedBlobsTest.

/**
 * Tests the handling of list named blobs requests.
 * @throws Exception
 */
@Test
public void listNamedBlobsTest() throws Exception {
    List<NamedBlobRecord> blobs = Arrays.asList(new NamedBlobRecord(refAccount.getName(), refContainer.getName(), "blob1", "abc", Utils.Infinite_Time), new NamedBlobRecord(refAccount.getName(), refContainer.getName(), "blob2", "def", System.currentTimeMillis()), new NamedBlobRecord(refAccount.getName(), refContainer.getName(), "blob3", "ghi", Utils.Infinite_Time));
    Page<NamedBlobRecord> page = new Page<>(blobs, "blob4");
    doListNamedBlobsTest("blob", null, page, null);
    doListNamedBlobsTest("blob", "blob1", page, null);
    // leave off required prefix query param
    doListNamedBlobsTest(null, null, page, RestServiceErrorCode.BadRequest);
    // throw exception in NamedBlobDb
    doListNamedBlobsTest("blob", null, null, RestServiceErrorCode.ServiceUnavailable);
}
Also used : NamedBlobRecord(com.github.ambry.named.NamedBlobRecord) Test(org.junit.Test) RestUtilsTest(com.github.ambry.rest.RestUtilsTest) StorageStatsUtilTest(com.github.ambry.server.StorageStatsUtilTest)

Example 2 with NamedBlobRecord

use of com.github.ambry.named.NamedBlobRecord in project ambry by linkedin.

the class AmbryIdConverterFactoryTest method ambryIdConverterNamedBlobTest.

@Test
public void ambryIdConverterNamedBlobTest() throws Exception {
    Properties properties = new Properties();
    VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
    IdSigningService idSigningService = mock(IdSigningService.class);
    NamedBlobDb namedBlobDb = mock(NamedBlobDb.class);
    AmbryIdConverterFactory ambryIdConverterFactory = new AmbryIdConverterFactory(verifiableProperties, new MetricRegistry(), idSigningService, namedBlobDb);
    IdConverter idConverter = ambryIdConverterFactory.getIdConverter();
    assertNotNull("No IdConverter returned", idConverter);
    PartitionId partitionId = new MockPartitionId(partition, MockClusterMap.DEFAULT_PARTITION_CLASS);
    BlobId blobId = new BlobId(BLOB_ID_V6, BlobIdType.NATIVE, dataCenterId, accountId, containerId, partitionId, false, BlobDataType.DATACHUNK);
    List<String> idList = new ArrayList<>();
    idList.add(blobId.getID());
    for (String id : idList) {
        reset(idSigningService);
        reset(namedBlobDb);
        when(namedBlobDb.put(any())).thenReturn(CompletableFuture.completedFuture(new PutResult(new NamedBlobRecord("", "", "", id, Utils.Infinite_Time))));
        testConversionForNamedBlob(idConverter, RestMethod.PUT, null, id, id);
        verify(idSigningService, never()).getSignedId(any(), any());
        verify(namedBlobDb).put(any());
    }
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) NamedBlobDb(com.github.ambry.named.NamedBlobDb) MockPartitionId(com.github.ambry.clustermap.MockPartitionId) MetricRegistry(com.codahale.metrics.MetricRegistry) ArrayList(java.util.ArrayList) BlobProperties(com.github.ambry.messageformat.BlobProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MockPartitionId(com.github.ambry.clustermap.MockPartitionId) PartitionId(com.github.ambry.clustermap.PartitionId) BlobId(com.github.ambry.commons.BlobId) PutResult(com.github.ambry.named.PutResult) NamedBlobRecord(com.github.ambry.named.NamedBlobRecord) Test(org.junit.Test)

Example 3 with NamedBlobRecord

use of com.github.ambry.named.NamedBlobRecord in project ambry by linkedin.

the class AmbryIdConverterFactoryTest method ambryIdConverterTest.

/**
 * Tests the instantiation and use of the {@link IdConverter} instance returned through the
 * {@link AmbryIdConverterFactory}.
 * @throws Exception
 */
@Test
public void ambryIdConverterTest() throws Exception {
    // dud properties. server should pick up defaults
    Properties properties = new Properties();
    VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
    IdSigningService idSigningService = mock(IdSigningService.class);
    AmbryIdConverterFactory ambryIdConverterFactory = new AmbryIdConverterFactory(verifiableProperties, new MetricRegistry(), idSigningService, null);
    IdConverter idConverter = ambryIdConverterFactory.getIdConverter();
    assertNotNull("No IdConverter returned", idConverter);
    String input = TestUtils.getRandomString(10);
    String inputWithLeadingSlash = "/" + input;
    // GET
    // without leading slash
    reset(idSigningService);
    testConversion(idConverter, RestMethod.GET, null, input, input);
    verify(idSigningService, never()).parseSignedId(any());
    // with leading slash
    reset(idSigningService);
    testConversion(idConverter, RestMethod.GET, null, input, inputWithLeadingSlash);
    verify(idSigningService, never()).parseSignedId(any());
    // with signed ID input.
    String idFromParsedSignedId = "parsedId" + input;
    reset(idSigningService);
    when(idSigningService.isIdSigned(any())).thenReturn(true);
    when(idSigningService.parseSignedId(any())).thenReturn(new Pair<>(idFromParsedSignedId, Collections.emptyMap()));
    testConversion(idConverter, RestMethod.GET, null, idFromParsedSignedId, inputWithLeadingSlash);
    verify(idSigningService).parseSignedId(input);
    // test signed id parsing exception
    reset(idSigningService);
    when(idSigningService.isIdSigned(any())).thenReturn(true);
    when(idSigningService.parseSignedId(any())).thenThrow(new RestServiceException("expected", RestServiceErrorCode.InternalServerError));
    testConversionFailure(idConverter, new MockRestRequest(MockRestRequest.DUMMY_DATA, null), input, RestServiceErrorCode.InternalServerError);
    verify(idSigningService).parseSignedId(input);
    // with named blob
    NamedBlobDb namedBlobDb = mock(NamedBlobDb.class);
    ambryIdConverterFactory = new AmbryIdConverterFactory(verifiableProperties, new MetricRegistry(), idSigningService, namedBlobDb);
    idConverter = ambryIdConverterFactory.getIdConverter();
    assertNotNull("No IdConverter returned", idConverter);
    String outputId = "dummy-id";
    reset(idSigningService);
    reset(namedBlobDb);
    when(namedBlobDb.get(any(), any(), any())).thenReturn(CompletableFuture.completedFuture(new NamedBlobRecord("", "", "", outputId, Utils.Infinite_Time)));
    testConversion(idConverter, RestMethod.GET, null, outputId, NAMED_BLOB_PATH);
    verify(namedBlobDb).get(ACCOUNT_NAME, CONTAINER_NAME, BLOB_NAME);
    reset(idSigningService);
    reset(namedBlobDb);
    when(namedBlobDb.delete(any(), any(), any())).thenReturn(CompletableFuture.completedFuture(new DeleteResult(outputId, false)));
    testConversion(idConverter, RestMethod.DELETE, null, outputId, NAMED_BLOB_PATH);
    verify(namedBlobDb).delete(ACCOUNT_NAME, CONTAINER_NAME, BLOB_NAME);
    // POST
    // without leading slash (there will be no leading slashes returned from the Router)
    reset(idSigningService);
    testConversion(idConverter, RestMethod.POST, null, inputWithLeadingSlash, input);
    verify(idSigningService, never()).getSignedId(any(), any());
    // with signed id metadata set, requires signed ID.
    String signedId = "signedId/" + input;
    reset(idSigningService);
    when(idSigningService.getSignedId(any(), any())).thenReturn(signedId);
    Map<String, String> signedIdMetadata = Collections.singletonMap("test-key", "test-value");
    testConversion(idConverter, RestMethod.POST, signedIdMetadata, "/" + signedId, input);
    verify(idSigningService).getSignedId(input, signedIdMetadata);
    idConverter.close();
    testConversionFailure(idConverter, new MockRestRequest(MockRestRequest.DUMMY_DATA, null), input, RestServiceErrorCode.ServiceUnavailable);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) NamedBlobDb(com.github.ambry.named.NamedBlobDb) MetricRegistry(com.codahale.metrics.MetricRegistry) BlobProperties(com.github.ambry.messageformat.BlobProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MockRestRequest(com.github.ambry.rest.MockRestRequest) RestServiceException(com.github.ambry.rest.RestServiceException) DeleteResult(com.github.ambry.named.DeleteResult) NamedBlobRecord(com.github.ambry.named.NamedBlobRecord) Test(org.junit.Test)

Aggregations

NamedBlobRecord (com.github.ambry.named.NamedBlobRecord)3 Test (org.junit.Test)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 VerifiableProperties (com.github.ambry.config.VerifiableProperties)2 BlobProperties (com.github.ambry.messageformat.BlobProperties)2 NamedBlobDb (com.github.ambry.named.NamedBlobDb)2 Properties (java.util.Properties)2 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)1 PartitionId (com.github.ambry.clustermap.PartitionId)1 BlobId (com.github.ambry.commons.BlobId)1 DeleteResult (com.github.ambry.named.DeleteResult)1 PutResult (com.github.ambry.named.PutResult)1 MockRestRequest (com.github.ambry.rest.MockRestRequest)1 RestServiceException (com.github.ambry.rest.RestServiceException)1 RestUtilsTest (com.github.ambry.rest.RestUtilsTest)1 StorageStatsUtilTest (com.github.ambry.server.StorageStatsUtilTest)1 ArrayList (java.util.ArrayList)1