use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class HostnameHelperTest method createAccountStatsMySqlConfig.
private AccountStatsMySqlConfig createAccountStatsMySqlConfig(String domainNamesToRemove) {
Properties properties = new Properties();
properties.setProperty(AccountStatsMySqlConfig.DOMAIN_NAMES_TO_REMOVE, domainNamesToRemove);
return new AccountStatsMySqlConfig(new VerifiableProperties(properties));
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class BlockingChannelConnectionPoolTest method startServer.
/**
* Starts up an ambry server given a port number in localhost
*
* @param port the port number over which ambry server needs to be started
* @return the {@link SocketServer} referring to ambry's instance
* @throws IOException
* @throws InterruptedException
*/
private SocketServer startServer(int port) throws IOException, InterruptedException {
Properties props = new Properties();
props.setProperty("port", "" + port);
props.setProperty("clustermap.cluster.name", "test");
props.setProperty("clustermap.datacenter.name", "dc1");
props.setProperty("clustermap.host.name", "localhost");
VerifiableProperties propverify = new VerifiableProperties(props);
NetworkConfig config = new NetworkConfig(propverify);
ArrayList<Port> ports = new ArrayList<Port>();
ports.add(new Port(port, PortType.PLAINTEXT));
ports.add(new Port(port + 1000, PortType.SSL));
SocketServer server = new SocketServer(config, serverSSLConfig1, new MetricRegistry(), ports);
server.start();
return server;
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class BlockingChannelConnectionPoolTest method testSSLBlockingChannelConnectionPool.
// @Test
public void testSSLBlockingChannelConnectionPool() throws Exception {
Properties props = new Properties();
props.put("connectionpool.max.connections.per.port.plain.text", "5");
props.put("connectionpool.max.connections.per.port.ssl", "5");
props.put("clustermap.cluster.name", "test");
props.put("clustermap.datacenter.name", "dc1");
props.put("clustermap.host.name", "localhost");
ConnectionPool connectionPool = new BlockingChannelConnectionPool(new ConnectionPoolConfig(new VerifiableProperties(props)), sslConfig, sslEnabledClusterMapConfig, new MetricRegistry());
connectionPool.start();
CountDownLatch shouldRelease = new CountDownLatch(1);
CountDownLatch releaseComplete = new CountDownLatch(10);
AtomicReference<Exception> exception = new AtomicReference<Exception>();
Map<String, CountDownLatch> channelCount = new HashMap<String, CountDownLatch>();
channelCount.put("localhost" + 7667, new CountDownLatch(5));
channelCount.put("localhost" + 7668, new CountDownLatch(5));
channelCount.put("localhost" + 7669, new CountDownLatch(5));
Map<String, Port> channelToPortMap = new HashMap<String, Port>();
channelToPortMap.put("localhost" + 7667, new Port(7667, PortType.SSL));
channelToPortMap.put("localhost" + 7668, new Port(7668, PortType.SSL));
channelToPortMap.put("localhost" + 7669, new Port(7669, PortType.SSL));
for (int i = 0; i < 10; i++) {
ConnectionPoolThread connectionPoolThread = new ConnectionPoolThread(channelCount, channelToPortMap, connectionPool, false, shouldRelease, releaseComplete, exception);
Thread t = new Thread(connectionPoolThread);
t.start();
}
for (String channelStr : channelCount.keySet()) {
awaitCountdown(channelCount.get(channelStr), 1000, exception, "Timed out waiting for channel count to reach 5");
}
// reset
for (String channelStr : channelCount.keySet()) {
channelCount.put(channelStr, new CountDownLatch(5));
}
shouldRelease.countDown();
for (String channelStr : channelCount.keySet()) {
awaitCountdown(channelCount.get(channelStr), 1000, exception, "Timed out waiting for channel count to reach 5");
}
awaitCountdown(releaseComplete, 2000, exception, "Timed out while waiting for channels to be released");
connectionPool.shutdown();
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class EmbeddedChannelPool method createHttp2ClientConfig.
/**
* Create a {@link Http2ClientConfig} with given timeout values.
* @param acquireTimeoutMs The timeout in ms for acquiring a channel.
* @param sendTimeoutMs The timeout for sending request out.
* @param receiveTimeoutMs The timeout for receiving response.
* @return
*/
private Http2ClientConfig createHttp2ClientConfig(long acquireTimeoutMs, long sendTimeoutMs, long receiveTimeoutMs) {
Properties properties = new Properties();
properties.setProperty(Http2ClientConfig.HTTP2_BLOCKING_CHANNEL_ACQUIRE_TIMEOUT_MS, String.valueOf(acquireTimeoutMs));
properties.setProperty(Http2ClientConfig.HTTP2_BLOCKING_CHANNEL_SEND_TIMEOUT_MS, String.valueOf(sendTimeoutMs));
properties.setProperty(Http2ClientConfig.HTTP2_BLOCKING_CHANNEL_RECEIVE_TIMEOUT_MS, String.valueOf(receiveTimeoutMs));
return new Http2ClientConfig(new VerifiableProperties(properties));
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class MySqlStorageUsageRefresherTest method testFetchMonthlyStorageUsage.
/**
* Test to update container storage usage monthly base.
*/
@Test
public void testFetchMonthlyStorageUsage() throws Exception {
MockTime mockTime = new MockTime(SystemTime.getInstance().milliseconds());
MySqlStorageUsageRefresher.time = mockTime;
try {
String currentMonth = MySqlStorageUsageRefresher.getCurrentMonth();
Map<String, Map<String, Long>> containerStorageUsages = TestUtils.makeStorageMap(10, 10, 100000, 1000);
StatsSnapshot snapshot = TestUtils.makeAccountStatsSnapshotFromContainerStorageMap(containerStorageUsages);
accountStatsMySqlStore.storeAggregatedAccountStats(snapshot);
accountStatsMySqlStore.takeSnapshotOfAggregatedAccountStatsAndUpdateMonth(currentMonth);
properties.remove(StorageQuotaConfig.REFRESHER_POLLING_INTERVAL_MS);
StorageQuotaConfig storageQuotaConfig = new StorageQuotaConfig(new VerifiableProperties(properties));
AccountStatsMySqlStore newAccountStatsMySqlStore = createAccountStatsMySqlStore();
MySqlStorageUsageRefresher refresher = new MySqlStorageUsageRefresher(newAccountStatsMySqlStore, scheduler, storageQuotaConfig, metrics);
// Fetch monthly storage usage
refresher.fetchStorageUsageMonthlyBase();
assertEquals(containerStorageUsages, refresher.getContainerStorageUsageMonthlyBase());
// Change the month
String notCurrentMonth = "1970-01";
Map<String, Map<String, Long>> newContainerStorageUsages = TestUtils.makeStorageMap(10, 10, 100000, 1000);
snapshot = TestUtils.makeAccountStatsSnapshotFromContainerStorageMap(newContainerStorageUsages);
accountStatsMySqlStore.storeAggregatedAccountStats(snapshot);
accountStatsMySqlStore.takeSnapshotOfAggregatedAccountStatsAndUpdateMonth(notCurrentMonth);
refresher.fetchStorageUsageMonthlyBase();
// Monthly storage usage still the old one
assertEquals(containerStorageUsages, refresher.getContainerStorageUsageMonthlyBase());
// Change the month back to the current month
accountStatsMySqlStore.takeSnapshotOfAggregatedAccountStatsAndUpdateMonth(currentMonth);
// Wait for schedule to retry
Thread.sleep(MYSQL_RETRY_BACKOFF_MS * 2);
assertEquals(newContainerStorageUsages, refresher.getContainerStorageUsageMonthlyBase());
// Forward the time to next month
mockTime.sleep((MySqlStorageUsageRefresher.secondsToNextMonthTick(currentMonth, storageQuotaConfig.mysqlMonthlyBaseFetchOffsetSec) + 10) * 1000);
String nextMonth = MySqlStorageUsageRefresher.getCurrentMonth();
Function<String, Integer> stringMonthToInteger = (monthInStr) -> {
String[] parts = monthInStr.split("-");
int year = Integer.parseInt(parts[0]);
int month = Integer.parseInt(parts[1]);
return year * 12 + month;
};
assertEquals(stringMonthToInteger.apply(currentMonth) + 1, (int) stringMonthToInteger.apply(nextMonth));
// Update the month to next month
Map<String, Map<String, Long>> nextContainerStorageUsages = TestUtils.makeStorageMap(10, 10, 100000, 1000);
snapshot = TestUtils.makeAccountStatsSnapshotFromContainerStorageMap(nextContainerStorageUsages);
accountStatsMySqlStore.storeAggregatedAccountStats(snapshot);
accountStatsMySqlStore.takeSnapshotOfAggregatedAccountStatsAndUpdateMonth(nextMonth);
refresher.fetchStorageUsageMonthlyBase();
assertEquals(nextContainerStorageUsages, refresher.getContainerStorageUsageMonthlyBase());
// A backup file should be create as well
assertEquals(nextContainerStorageUsages, refresher.getBackupFileManager().getBackupFileContent(nextMonth));
} finally {
MySqlStorageUsageRefresher.time = SystemTime.getInstance();
}
}
Aggregations