Search in sources :

Example 41 with VerifiableProperties

use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.

the class HelixParticipantTest method testBadCases.

/**
 * Test bad instantiation and initialization scenarios of the {@link HelixParticipant}
 * @throws IOException
 */
@Test
public void testBadCases() throws IOException {
    // Connect failure.
    ClusterMapConfig clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
    helixManagerFactory.helixManager.beBad = true;
    HelixParticipant helixParticipant = new HelixParticipant(clusterMapConfig, helixManagerFactory);
    try {
        helixParticipant.initialize("localhost", 2200, Collections.EMPTY_LIST);
        fail("Initialization should have failed");
    } catch (IOException e) {
    // OK
    }
    // Bad param during instantiation.
    props.setProperty("clustermap.cluster.name", "");
    clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
    try {
        new HelixParticipant(clusterMapConfig, helixManagerFactory);
        fail("Instantiation should have failed");
    } catch (IllegalStateException e) {
    // OK
    }
    props.setProperty("clustermap.cluster.name", "HelixParticipantTestCluster");
    props.setProperty("clustermap.dcs.zk.connect.strings", "");
    clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
    try {
        new HelixParticipant(clusterMapConfig, helixManagerFactory);
        fail("Instantiation should have failed");
    } catch (IOException e) {
    // OK
    }
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) IOException(java.io.IOException) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig) Test(org.junit.Test)

Example 42 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 43 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 44 with VerifiableProperties

use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.

the class HelixAccountServiceTest method testBackgroundUpdater.

/**
 * Tests the background updater for updating accounts from remote. During the initialization of
 * {@link HelixAccountService}, its internal {@link HelixPropertyStore} will be read to first time get account data.
 * Because of the background account updater, it should continuously make get calls to the {@link HelixPropertyStore},
 * even no notification for account updates is received. Therefore, there will be more than 1 get calls to the
 * {@link HelixPropertyStore}.
 * @throws Exception
 */
@Test
public void testBackgroundUpdater() throws Exception {
    helixConfigProps.setProperty(HelixAccountServiceConfig.UPDATER_POLLING_INTERVAL_MS_KEY, "1");
    vHelixConfigProps = new VerifiableProperties(helixConfigProps);
    storeConfig = new HelixPropertyStoreConfig(vHelixConfigProps);
    String updaterThreadPrefix = UUID.randomUUID().toString();
    MockHelixAccountServiceFactory mockHelixAccountServiceFactory = new MockHelixAccountServiceFactory(vHelixConfigProps, new MetricRegistry(), notifier, updaterThreadPrefix);
    accountService = mockHelixAccountServiceFactory.getAccountService();
    CountDownLatch latch = new CountDownLatch(1);
    mockHelixAccountServiceFactory.getHelixStore(storeConfig).setReadLatch(latch);
    assertEquals("Wrong number of thread for account updater.", 1, numThreadsByThisName(updaterThreadPrefix));
    awaitLatchOrTimeout(latch, 100);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) HelixPropertyStoreConfig(com.github.ambry.config.HelixPropertyStoreConfig) MetricRegistry(com.codahale.metrics.MetricRegistry) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 45 with VerifiableProperties

use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.

the class SingleKeyManagementServiceTest method testSingleKMS.

/**
 * Test {@link SingleKeyManagementService#getKey(short, short)}
 */
@Test
public void testSingleKMS() throws Exception {
    int[] keySizes = { 16, 32, 64, 128 };
    for (int keySize : keySizes) {
        String key = TestUtils.getRandomKey(keySize);
        Properties props = getKMSProperties(key, DEFAULT_RANDOM_KEY_SIZE_BITS);
        VerifiableProperties verifiableProperties = new VerifiableProperties((props));
        KMSConfig config = new KMSConfig(verifiableProperties);
        SecretKeySpec secretKeySpec = new SecretKeySpec(Hex.decode(key), config.kmsKeyGenAlgo);
        KeyManagementService<SecretKeySpec> kms = new SingleKeyManagementServiceFactory(verifiableProperties, CLUSTER_NAME, REGISTRY).getKeyManagementService();
        SecretKeySpec keyFromKMS = kms.getKey(Utils.getRandomShort(TestUtils.RANDOM), Utils.getRandomShort(TestUtils.RANDOM));
        Assert.assertEquals("Secret key mismatch ", secretKeySpec, keyFromKMS);
    }
}
Also used : KMSConfig(com.github.ambry.config.KMSConfig) VerifiableProperties(com.github.ambry.config.VerifiableProperties) SecretKeySpec(javax.crypto.spec.SecretKeySpec) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) Test(org.junit.Test) UtilsTest(com.github.ambry.utils.UtilsTest)

Aggregations

VerifiableProperties (com.github.ambry.config.VerifiableProperties)137 Properties (java.util.Properties)88 Test (org.junit.Test)71 MetricRegistry (com.codahale.metrics.MetricRegistry)42 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)40 BlobProperties (com.github.ambry.messageformat.BlobProperties)35 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)25 StoreConfig (com.github.ambry.config.StoreConfig)25 ArrayList (java.util.ArrayList)25 ClusterMap (com.github.ambry.clustermap.ClusterMap)24 IOException (java.io.IOException)21 LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)20 RouterConfig (com.github.ambry.config.RouterConfig)18 CountDownLatch (java.util.concurrent.CountDownLatch)18 ClusterAgentsFactory (com.github.ambry.clustermap.ClusterAgentsFactory)15 MockTime (com.github.ambry.utils.MockTime)14 BlobId (com.github.ambry.commons.BlobId)13 HashMap (java.util.HashMap)12 File (java.io.File)11 AtomicReference (java.util.concurrent.atomic.AtomicReference)11