use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class NamedBlobPutHandlerTest method initNamedBlobPutHandler.
/**
* Initates a {@link NamedBlobPutHandler}
* @param properties the properties to use to init the {@link NamedBlobPutHandler}
*/
private void initNamedBlobPutHandler(Properties properties) {
VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
frontendConfig = new FrontendConfig(verifiableProperties);
namedBlobPutHandler = new NamedBlobPutHandler(securityServiceFactory.getSecurityService(), idConverterFactory.getIdConverter(), idSigningService, router, injector, frontendConfig, metrics, CLUSTER_NAME, QuotaTestUtils.createDummyQuotaManager());
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class FrontendRestRequestServiceFactoryTest method getFrontendRestRequestServiceFactoryWithBadInputTest.
/**
* Tests instantiation of {@link FrontendRestRequestServiceFactory} with bad input.
* @throws Exception
*/
@Test
public void getFrontendRestRequestServiceFactoryWithBadInputTest() throws Exception {
// dud properties. server should pick up defaults
Properties properties = new Properties();
VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
ClusterMap clusterMap = new MockClusterMap();
Router router = new InMemoryRouter(verifiableProperties, clusterMap);
AccountService accountService = new InMemAccountService(false, true);
// VerifiableProperties null.
try {
new FrontendRestRequestServiceFactory(null, clusterMap, router, accountService);
fail("Instantiation should have failed because VerifiableProperties was null");
} catch (NullPointerException e) {
// expected. Nothing to do.
}
// ClusterMap null.
try {
new FrontendRestRequestServiceFactory(verifiableProperties, null, router, accountService);
fail("Instantiation should have failed because ClusterMap was null");
} catch (NullPointerException e) {
// expected. Nothing to do.
}
// Router null.
try {
new FrontendRestRequestServiceFactory(verifiableProperties, clusterMap, null, accountService);
fail("Instantiation should have failed because Router was null");
} catch (NullPointerException e) {
// expected. Nothing to do.
}
// AccountService null.
try {
new FrontendRestRequestServiceFactory(verifiableProperties, clusterMap, router, null);
fail("Instantiation should have failed because AccountService was null");
} catch (NullPointerException e) {
// expected. Nothing to do.
}
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class FrontendQuotaIntegrationTest method buildFrontendVPropsForQuota.
/**
* Builds properties required to start a {@link RestServer} as an Ambry frontend server.
* @param trustStoreFile the trust store file to add certificates to for SSL testing.
* @param isRequestQuotaEnabled flag to specify if request quota is enabled.
* @param quotaMode {@link QuotaMode} object.
* @param account {@link Account} for which quota needs to be specified.
* @param throttleRequest flag to indicate if the {@link com.github.ambry.quota.QuotaManager} should throttle request.
* @return a {@link VerifiableProperties} with the parameters for an Ambry frontend server.
*/
private static VerifiableProperties buildFrontendVPropsForQuota(File trustStoreFile, boolean isRequestQuotaEnabled, QuotaMode quotaMode, Account account, boolean throttleRequest) throws IOException, GeneralSecurityException {
Properties properties = buildFrontendVProps(trustStoreFile, true, PLAINTEXT_SERVER_PORT, SSL_SERVER_PORT);
// By default the usage and limit of quota will be 0 in the default JsonCUQuotaSource, and hence the default
// JsonCUQuotaEnforcer will reject requests. So for cases where we don't want requests to be rejected, we set a
// non 0 limit for quota.
JSONObject cuResourceQuotaJson = new JSONObject();
JSONObject quotaJson = new JSONObject();
quotaJson.put("rcu", throttleRequest ? 0 : 10737418240L);
quotaJson.put("wcu", throttleRequest ? 0 : 10737418240L);
cuResourceQuotaJson.put(Integer.toString(account.getId()), quotaJson);
properties.setProperty(QuotaConfig.RESOURCE_CU_QUOTA_IN_JSON, cuResourceQuotaJson.toString());
properties.setProperty(QuotaConfig.THROTTLING_MODE, quotaMode.name());
properties.setProperty(QuotaConfig.REQUEST_THROTTLING_ENABLED, String.valueOf(isRequestQuotaEnabled));
properties.setProperty(QuotaConfig.FRONTEND_CU_CAPACITY_IN_JSON, "{\n" + " \"rcu\": 1024,\n" + " \"wcu\": 1024\n" + "}");
long quotaValue = throttleRequest ? DEFAULT_REJECT_QUOTA : DEFAULT_ACCEPT_QUOTA;
properties.setProperty(QuotaConfig.RESOURCE_CU_QUOTA_IN_JSON, String.format("{\n" + " \"%s\": {\n" + " \"rcu\": %d,\n" + " \"wcu\": %d\n" + " }\n" + "}", account.getId(), quotaValue, quotaValue));
return new VerifiableProperties(properties);
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class AmbrySecurityServiceFactoryTest method getAmbrySecurityServiceFactoryTest.
/**
* Tests instantiation of {@link AmbrySecurityServiceFactory}.
* @throws Exception
*/
@Test
public void getAmbrySecurityServiceFactoryTest() throws Exception {
SecurityService securityService = new AmbrySecurityServiceFactory(new VerifiableProperties(new Properties()), new MockClusterMap(), null, null, null, null, QuotaTestUtils.createDummyQuotaManager()).getSecurityService();
Assert.assertNotNull(securityService);
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class AmbryUrlSigningServiceTest method factoryTest.
/**
* Tests for {@link AmbryUrlSigningServiceFactory}.
*/
@Test
public void factoryTest() {
Properties properties = new Properties();
JSONObject jsonObject = new JSONObject().put("POST", UPLOAD_ENDPOINT).put("GET", DOWNLOAD_ENDPOINT);
properties.setProperty(FrontendConfig.URL_SIGNER_ENDPOINTS, jsonObject.toString());
properties.setProperty("frontend.url.signer.default.url.ttl.secs", Long.toString(DEFAULT_URL_TTL_SECS));
properties.setProperty("frontend.url.signer.default.max.upload.size.bytes", Long.toString(DEFAULT_MAX_UPLOAD_SIZE));
properties.setProperty("frontend.url.signer.max.url.ttl.secs", Long.toString(MAX_URL_TTL_SECS));
properties.setProperty(FrontendConfig.CHUNK_UPLOAD_INITIAL_CHUNK_TTL_SECS_KEY, Long.toString(CHUNK_UPLOAD_INITIAL_CHUNK_TTL_SECS));
CommonTestUtils.populateRequiredRouterProps(properties);
properties.setProperty("router.max.put.chunk.size.bytes", Long.toString(CHUNK_UPLOAD_MAX_CHUNK_SIZE));
UrlSigningService signer = new AmbryUrlSigningServiceFactory(new VerifiableProperties(properties), new MetricRegistry()).getUrlSigningService();
assertNotNull("UrlSigningService is null", signer);
assertTrue("UrlSigningService is AmbryUrlSigningService", signer instanceof AmbryUrlSigningService);
assertTrue(((AmbryUrlSigningService) signer).getUploadEndpoint().contains(UPLOAD_ENDPOINT));
assertTrue(((AmbryUrlSigningService) signer).getDownloadEndpoint().contains(DOWNLOAD_ENDPOINT));
}
Aggregations