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