use of com.github.ambry.named.NamedBlobDb 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.NamedBlobDb 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);
}
use of com.github.ambry.named.NamedBlobDb in project ambry by linkedin.
the class FrontendRestRequestServiceFactory method getRestRequestService.
/**
* Returns a new instance of {@link FrontendRestRequestService}.
* @return a new instance of {@link FrontendRestRequestService}.
*/
@Override
public RestRequestService getRestRequestService() {
try {
IdSigningService idSigningService = Utils.<IdSigningServiceFactory>getObj(frontendConfig.idSigningServiceFactory, verifiableProperties, clusterMap.getMetricRegistry()).getIdSigningService();
NamedBlobDb namedBlobDb = Utils.isNullOrEmpty(frontendConfig.namedBlobDbFactory) ? null : Utils.<NamedBlobDbFactory>getObj(frontendConfig.namedBlobDbFactory, verifiableProperties, clusterMap.getMetricRegistry(), accountService).getNamedBlobDb();
IdConverterFactory idConverterFactory = Utils.getObj(frontendConfig.idConverterFactory, verifiableProperties, clusterMap.getMetricRegistry(), idSigningService, namedBlobDb);
UrlSigningService urlSigningService = Utils.<UrlSigningServiceFactory>getObj(frontendConfig.urlSigningServiceFactory, verifiableProperties, clusterMap.getMetricRegistry()).getUrlSigningService();
AccountAndContainerInjector accountAndContainerInjector = new AccountAndContainerInjector(accountService, frontendMetrics, frontendConfig);
AccountStatsStore accountStatsStore = Utils.<AccountStatsStoreFactory>getObj(frontendConfig.accountStatsStoreFactory, verifiableProperties, clusterMapConfig, clusterMap.getMetricRegistry()).getAccountStatsStore();
QuotaConfig quotaConfig = new QuotaConfig(verifiableProperties);
QuotaManager quotaManager = ((QuotaManagerFactory) Utils.getObj(quotaConfig.quotaManagerFactory, quotaConfig, new SimpleQuotaRecommendationMergePolicy(quotaConfig), accountService, accountStatsStore, clusterMap.getMetricRegistry())).getQuotaManager();
SecurityServiceFactory securityServiceFactory = Utils.getObj(frontendConfig.securityServiceFactory, verifiableProperties, clusterMap, accountService, urlSigningService, idSigningService, accountAndContainerInjector, quotaManager);
return new FrontendRestRequestService(frontendConfig, frontendMetrics, router, clusterMap, idConverterFactory, securityServiceFactory, urlSigningService, idSigningService, namedBlobDb, accountService, accountAndContainerInjector, clusterMapConfig.clusterMapDatacenterName, clusterMapConfig.clusterMapHostName, clusterMapConfig.clusterMapClusterName, accountStatsStore, quotaManager);
} catch (Exception e) {
throw new IllegalStateException("Could not instantiate FrontendRestRequestService", e);
}
}
Aggregations