Search in sources :

Example 81 with VerifiableProperties

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));
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) AccountStatsMySqlConfig(com.github.ambry.config.AccountStatsMySqlConfig)

Example 82 with VerifiableProperties

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;
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) NetworkConfig(com.github.ambry.config.NetworkConfig) ArrayList(java.util.ArrayList) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties)

Example 83 with VerifiableProperties

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();
}
Also used : ConnectionPoolConfig(com.github.ambry.config.ConnectionPoolConfig) VerifiableProperties(com.github.ambry.config.VerifiableProperties) HashMap(java.util.HashMap) MetricRegistry(com.codahale.metrics.MetricRegistry) AtomicReference(java.util.concurrent.atomic.AtomicReference) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException)

Example 84 with VerifiableProperties

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));
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) Http2ClientConfig(com.github.ambry.config.Http2ClientConfig) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties)

Example 85 with VerifiableProperties

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();
    }
}
Also used : HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) AccountStatsMySqlStoreFactory(com.github.ambry.accountstats.AccountStatsMySqlStoreFactory) TestUtils(com.github.ambry.utils.TestUtils) Map(java.util.Map) After(org.junit.After) SystemTime(com.github.ambry.utils.SystemTime) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Path(java.nio.file.Path) Before(org.junit.Before) AfterClass(org.junit.AfterClass) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) Files(java.nio.file.Files) AccountStatsMySqlStore(com.github.ambry.accountstats.AccountStatsMySqlStore) VerifiableProperties(com.github.ambry.config.VerifiableProperties) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Utils(com.github.ambry.utils.Utils) Test(org.junit.Test) AccountStatsMySqlConfig(com.github.ambry.config.AccountStatsMySqlConfig) TimeUnit(java.util.concurrent.TimeUnit) StorageQuotaConfig(com.github.ambry.config.StorageQuotaConfig) CountDownLatch(java.util.concurrent.CountDownLatch) MockTime(com.github.ambry.utils.MockTime) Paths(java.nio.file.Paths) StatsSnapshot(com.github.ambry.server.StatsSnapshot) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig) Assert(org.junit.Assert) VerifiableProperties(com.github.ambry.config.VerifiableProperties) StorageQuotaConfig(com.github.ambry.config.StorageQuotaConfig) HashMap(java.util.HashMap) Map(java.util.Map) AccountStatsMySqlStore(com.github.ambry.accountstats.AccountStatsMySqlStore) MockTime(com.github.ambry.utils.MockTime) StatsSnapshot(com.github.ambry.server.StatsSnapshot) Test(org.junit.Test)

Aggregations

VerifiableProperties (com.github.ambry.config.VerifiableProperties)335 Properties (java.util.Properties)219 Test (org.junit.Test)192 MetricRegistry (com.codahale.metrics.MetricRegistry)131 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)80 ArrayList (java.util.ArrayList)62 BlobProperties (com.github.ambry.messageformat.BlobProperties)61 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)52 StoreConfig (com.github.ambry.config.StoreConfig)51 IOException (java.io.IOException)47 File (java.io.File)39 RouterConfig (com.github.ambry.config.RouterConfig)37 ClusterMap (com.github.ambry.clustermap.ClusterMap)36 JSONObject (org.json.JSONObject)34 HashMap (java.util.HashMap)33 BlobId (com.github.ambry.commons.BlobId)31 LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)31 CountDownLatch (java.util.concurrent.CountDownLatch)31 Map (java.util.Map)28 InMemAccountService (com.github.ambry.account.InMemAccountService)26