Search in sources :

Example 76 with VerifiableProperties

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) {
    }
}
Also used : JSONObject(org.json.JSONObject) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) Test(org.junit.Test)

Example 77 with VerifiableProperties

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

Example 78 with VerifiableProperties

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

Example 79 with VerifiableProperties

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();
}
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) ReplicaId(com.github.ambry.clustermap.ReplicaId) DataNodeId(com.github.ambry.clustermap.DataNodeId) MockDataNodeId(com.github.ambry.clustermap.MockDataNodeId) Test(org.junit.Test)

Example 80 with VerifiableProperties

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());
}
Also used : Path(java.nio.file.Path) HostAccountStorageStats(com.github.ambry.server.storagestats.HostAccountStorageStats) HostAccountStorageStatsWrapper(com.github.ambry.server.HostAccountStorageStatsWrapper) VerifiableProperties(com.github.ambry.config.VerifiableProperties) StatsHeader(com.github.ambry.server.StatsHeader) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) AccountStatsMySqlConfig(com.github.ambry.config.AccountStatsMySqlConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) StorageStatsUtilTest(com.github.ambry.server.StorageStatsUtilTest)

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