use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class AmbryUrlSigningServiceTest method factoryTestBadJson.
/**
* Tests for {@link AmbryUrlSigningServiceFactory}.
*/
@Test
public void factoryTestBadJson() {
Properties properties = new Properties();
CommonTestUtils.populateRequiredRouterProps(properties);
// Missing GET
JSONObject jsonObject = new JSONObject().put("POST", UPLOAD_ENDPOINT);
properties.setProperty(FrontendConfig.URL_SIGNER_ENDPOINTS, jsonObject.toString());
try {
new AmbryUrlSigningServiceFactory(new VerifiableProperties(properties), new MetricRegistry()).getUrlSigningService();
fail("Expected exception");
} catch (IllegalStateException ex) {
}
// Missing POST
jsonObject = new JSONObject().put("GET", DOWNLOAD_ENDPOINT);
properties.setProperty(FrontendConfig.URL_SIGNER_ENDPOINTS, jsonObject.toString());
try {
new AmbryUrlSigningServiceFactory(new VerifiableProperties(properties), new MetricRegistry()).getUrlSigningService();
fail("Expected exception");
} catch (IllegalStateException ex) {
}
// Gibberish
properties.setProperty(FrontendConfig.URL_SIGNER_ENDPOINTS, "[Garbage string &%#123");
try {
new AmbryUrlSigningServiceFactory(new VerifiableProperties(properties), new MetricRegistry()).getUrlSigningService();
fail("Expected exception");
} catch (IllegalStateException ex) {
}
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class AccountStatsMySqlStoreIntegrationTest method createAccountStatsMySqlStore.
private AccountStatsMySqlStore createAccountStatsMySqlStore(String clusterName, String hostname, int port) throws Exception {
Path localBackupFilePath = createTemporaryFile();
Properties configProps = Utils.loadPropsFromResource("accountstats_mysql.properties");
configProps.setProperty(ClusterMapConfig.CLUSTERMAP_CLUSTER_NAME, clusterName);
configProps.setProperty(ClusterMapConfig.CLUSTERMAP_HOST_NAME, hostname);
configProps.setProperty(ClusterMapConfig.CLUSTERMAP_DATACENTER_NAME, "dc1");
configProps.setProperty(ClusterMapConfig.CLUSTERMAP_PORT, String.valueOf(port));
configProps.setProperty(AccountStatsMySqlConfig.DOMAIN_NAMES_TO_REMOVE, ".github.com");
configProps.setProperty(AccountStatsMySqlConfig.UPDATE_BATCH_SIZE, String.valueOf(batchSize));
configProps.setProperty(AccountStatsMySqlConfig.POOL_SIZE, String.valueOf(5));
configProps.setProperty(AccountStatsMySqlConfig.LOCAL_BACKUP_FILE_PATH, localBackupFilePath.toString());
VerifiableProperties verifiableProperties = new VerifiableProperties(configProps);
return (AccountStatsMySqlStore) new AccountStatsMySqlStoreFactory(verifiableProperties, new ClusterMapConfig(verifiableProperties), new MetricRegistry()).getAccountStatsStore();
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class PartitionClassReportsDaoTest method createAccountStatsMySqlStore.
private static AccountStatsMySqlStore createAccountStatsMySqlStore(String clusterName, String hostname, int port, int batchSize) throws Exception {
Path tempDir = Files.createTempDirectory("PartitionClassReportsDaoTest");
Properties configProps = Utils.loadPropsFromResource("accountstats_mysql.properties");
configProps.setProperty(ClusterMapConfig.CLUSTERMAP_CLUSTER_NAME, clusterName);
configProps.setProperty(ClusterMapConfig.CLUSTERMAP_HOST_NAME, hostname);
configProps.setProperty(ClusterMapConfig.CLUSTERMAP_DATACENTER_NAME, "dc1");
configProps.setProperty(ClusterMapConfig.CLUSTERMAP_PORT, String.valueOf(port));
configProps.setProperty(AccountStatsMySqlConfig.DOMAIN_NAMES_TO_REMOVE, ".github.com");
configProps.setProperty(AccountStatsMySqlConfig.UPDATE_BATCH_SIZE, String.valueOf(batchSize));
configProps.setProperty(AccountStatsMySqlConfig.LOCAL_BACKUP_FILE_PATH, tempDir.toString());
VerifiableProperties verifiableProperties = new VerifiableProperties(configProps);
return (AccountStatsMySqlStore) new AccountStatsMySqlStoreFactory(verifiableProperties, new ClusterMapConfig(verifiableProperties), new MetricRegistry()).getAccountStatsStore();
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class MockSelector method testCloseWithDanglingRequest.
/**
* Test when close the router, the dangling requests will be correctly released.
*/
@Test
public void testCloseWithDanglingRequest() throws Exception {
Properties props = new Properties();
props.setProperty(NetworkConfig.NETWORK_CLIENT_ENABLE_CONNECTION_REPLENISHMENT, "true");
VerifiableProperties vprops = new VerifiableProperties(props);
NetworkConfig networkConfig = new NetworkConfig(vprops);
MockSelector mockSelector = new MockSelector(networkConfig);
NetworkMetrics localNetworkMetrics = new NetworkMetrics(new MetricRegistry());
SocketNetworkClient localNetworkClient = new SocketNetworkClient(mockSelector, networkConfig, localNetworkMetrics, MAX_PORTS_PLAIN_TEXT, MAX_PORTS_SSL, CHECKOUT_TIMEOUT_MS, time);
DataNodeId dataNodeId = localPlainTextDataNodes.get(0);
ReplicaId replicaId = sslDisabledClusterMap.getReplicaIds(dataNodeId).get(0);
List<RequestInfo> requestInfoList = new ArrayList<>();
List<ResponseInfo> responseInfoList;
requestInfoList.add(new RequestInfo(dataNodeId.getHostname(), dataNodeId.getPortToConnectTo(), new MockSend(1), replicaId, null));
requestInfoList.add(new RequestInfo(dataNodeId.getHostname(), dataNodeId.getPortToConnectTo(), new MockSend(2), replicaId, null));
// This call would create two connection and not send any requests out
localNetworkClient.sendAndPoll(requestInfoList, Collections.EMPTY_SET, POLL_TIMEOUT_MS);
requestInfoList.clear();
requestInfoList.add(new RequestInfo(dataNodeId.getHostname(), dataNodeId.getPortToConnectTo(), new MockSend(3), replicaId, null));
requestInfoList.add(new RequestInfo(dataNodeId.getHostname(), dataNodeId.getPortToConnectTo(), new MockSend(4), replicaId, null));
mockSelector.setState(MockSelectorState.IdlePoll);
// This call would send first two requests out. At the same time, keep last two requests in the pendingRequests queue.
localNetworkClient.sendAndPoll(requestInfoList, Collections.EMPTY_SET, POLL_TIMEOUT_MS);
localNetworkClient.close();
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class AccountStatsMySqlStoreTest method testLocalBackupFile.
@Test
public void testLocalBackupFile() throws IOException {
// First, make sure there is no local backup file.
Path tempDir = Files.createTempDirectory("AccountStatsMySqlStoreTest");
Path localBackupFilePath = tempDir.resolve("localbackup");
Properties prop = new Properties();
prop.setProperty(AccountStatsMySqlConfig.LOCAL_BACKUP_FILE_PATH, localBackupFilePath.toString());
AccountStatsMySqlConfig accountStatsMySqlConfig = new AccountStatsMySqlConfig(new VerifiableProperties(prop));
AccountStatsMySqlStore store = new AccountStatsMySqlStore(accountStatsMySqlConfig, mockDataSource, clusterName, hostname, null, new MetricRegistry());
assertNull(store.getPreviousHostAccountStorageStatsWrapper());
// Second, save a backup file.
HostAccountStorageStats hostAccountStorageStats = new HostAccountStorageStats(StorageStatsUtilTest.generateRandomHostAccountStorageStats(10, 10, 10, 10000L, 2, 10));
StatsHeader header = new StatsHeader(StatsHeader.StatsDescription.STORED_DATA_SIZE, System.currentTimeMillis(), 10, 10, null);
HostAccountStorageStatsWrapper statsWrapper = new HostAccountStorageStatsWrapper(header, hostAccountStorageStats);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.writeValue(localBackupFilePath.toFile(), statsWrapper);
store = new AccountStatsMySqlStore(accountStatsMySqlConfig, mockDataSource, clusterName, hostname, null, new MetricRegistry());
HostAccountStorageStatsWrapper backupWrapper = store.getPreviousHostAccountStorageStatsWrapper();
assertNotNull(backupWrapper);
assertStatsHeader(backupWrapper.getHeader(), 10, 10);
Assert.assertEquals(hostAccountStorageStats.getStorageStats(), backupWrapper.getStats().getStorageStats());
}
Aggregations