Search in sources :

Example 21 with VerifiableProperties

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

the class NonBlockingRouterTest method getNonBlockingRouterProperties.

/**
 * Constructs and returns a VerifiableProperties instance with the defaults required for instantiating
 * the {@link NonBlockingRouter}.
 * @return the created VerifiableProperties instance.
 */
private Properties getNonBlockingRouterProperties(String routerDataCenter) {
    Properties properties = new Properties();
    properties.setProperty("router.hostname", "localhost");
    properties.setProperty("router.datacenter.name", routerDataCenter);
    properties.setProperty("router.put.request.parallelism", Integer.toString(PUT_REQUEST_PARALLELISM));
    properties.setProperty("router.put.success.target", Integer.toString(PUT_SUCCESS_TARGET));
    properties.setProperty("router.max.put.chunk.size.bytes", Integer.toString(maxPutChunkSize));
    properties.setProperty("router.get.request.parallelism", Integer.toString(GET_REQUEST_PARALLELISM));
    properties.setProperty("router.get.success.target", Integer.toString(GET_SUCCESS_TARGET));
    properties.setProperty("router.delete.request.parallelism", Integer.toString(DELETE_REQUEST_PARALLELISM));
    properties.setProperty("router.delete.success.target", Integer.toString(DELETE_SUCCESS_TARGET));
    properties.setProperty("router.connection.checkout.timeout.ms", Integer.toString(CHECKOUT_TIMEOUT_MS));
    properties.setProperty("router.request.timeout.ms", Integer.toString(REQUEST_TIMEOUT_MS));
    properties.setProperty("clustermap.cluster.name", "test");
    properties.setProperty("clustermap.datacenter.name", "dc1");
    properties.setProperty("clustermap.host.name", "localhost");
    properties.setProperty("kms.default.container.key", TestUtils.getRandomKey(128));
    return properties;
}
Also used : BlobProperties(com.github.ambry.messageformat.BlobProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties)

Example 22 with VerifiableProperties

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

the class MockReadableStreamChannel method testFailureOnKMS.

/**
 * Tests a failure scenario where connects to server nodes throw exceptions.
 */
@Test
public void testFailureOnKMS() throws Exception {
    if (testEncryption) {
        setupEncryptionCast(new VerifiableProperties(new Properties()));
        instantiateEncryptionCast = false;
        kms.exceptionToThrow.set(GSE);
        // simple blob
        requestAndResultsList.clear();
        requestAndResultsList.add(new RequestAndResult(random.nextInt(chunkSize) + 1));
        Exception expectedException = new RouterException("", GSE, RouterErrorCode.UnexpectedInternalError);
        submitPutsAndAssertFailure(expectedException, false, true, true);
        // this should not close the router.
        Assert.assertTrue("Router should not be closed", router.isOpen());
        assertCloseCleanup();
        setupEncryptionCast(new VerifiableProperties(new Properties()));
        instantiateEncryptionCast = false;
        kms.exceptionToThrow.set(GSE);
        // composite blob
        requestAndResultsList.clear();
        requestAndResultsList.add(new RequestAndResult(chunkSize * random.nextInt(10)));
        submitPutsAndAssertFailure(expectedException, false, true, true);
        // this should not close the router.
        Assert.assertTrue("Router should not be closed", router.isOpen());
        assertCloseCleanup();
    }
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) BlobProperties(com.github.ambry.messageformat.BlobProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) Test(org.junit.Test)

Example 23 with VerifiableProperties

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

the class RouterFactoryTest method testRouterFactory.

/**
 * Tests the instantiation of a {@link Router} implementation through its {@link RouterFactory} implementation
 * @throws IOException
 */
@Test
public void testRouterFactory() throws Exception {
    VerifiableProperties verifiableProperties = getVerifiableProperties();
    List<FactoryAndRouter> factoryAndRouters = new ArrayList<FactoryAndRouter>();
    factoryAndRouters.add(new FactoryAndRouter("com.github.ambry.router.NonBlockingRouterFactory", "com.github.ambry.router.NonBlockingRouter"));
    for (FactoryAndRouter factoryAndRouter : factoryAndRouters) {
        RouterFactory routerFactory = Utils.getObj(factoryAndRouter.factoryStr, verifiableProperties, new MockClusterMap(), new LoggingNotificationSystem(), null);
        Router router = routerFactory.getRouter();
        Assert.assertEquals("Did not receive expected Router instance", factoryAndRouter.routerStr, router.getClass().getCanonicalName());
        router.close();
    }
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) ArrayList(java.util.ArrayList) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Example 24 with VerifiableProperties

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

the class RouterFactoryTest method getVerifiableProperties.

/**
 * Constructs and returns a VerifiableProperties instance with the defaults required for instantiating
 * any router.
 * @return the created VerifiableProperties instance.
 */
private VerifiableProperties getVerifiableProperties() {
    Properties properties = new Properties();
    properties.setProperty("router.hostname", "localhost");
    properties.setProperty("router.datacenter.name", "DC1");
    properties.setProperty("clustermap.cluster.name", "test");
    properties.setProperty("clustermap.datacenter.name", "DC1");
    properties.setProperty("clustermap.host.name", "localhost");
    properties.setProperty("kms.default.container.key", TestUtils.getRandomKey(32));
    return new VerifiableProperties(properties);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties)

Example 25 with VerifiableProperties

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

the class StaticClusterManagerTest method clusterMapInterface.

@Test
public void clusterMapInterface() throws Exception {
    // Exercise entire clusterMap interface
    TestUtils.TestHardwareLayout testHardwareLayout = new TestUtils.TestHardwareLayout("Alpha");
    TestUtils.TestPartitionLayout testPartitionLayout = new TestUtils.TestPartitionLayout(testHardwareLayout);
    // add 3 partitions with read_only state.
    testPartitionLayout.partitionState = PartitionState.READ_ONLY;
    testPartitionLayout.addNewPartitions(3);
    testPartitionLayout.partitionState = PartitionState.READ_WRITE;
    Datacenter localDatacenter = testHardwareLayout.getRandomDatacenter();
    Properties props = new Properties();
    props.setProperty("clustermap.host.name", "localhost");
    props.setProperty("clustermap.cluster.name", "cluster");
    props.setProperty("clustermap.datacenter.name", localDatacenter.getName());
    ClusterMapConfig clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
    ClusterMap clusterMapManager = (new StaticClusterAgentsFactory(clusterMapConfig, testPartitionLayout.getPartitionLayout())).getClusterMap();
    for (String metricName : clusterMapManager.getMetricRegistry().getNames()) {
        System.out.println(metricName);
    }
    assertEquals("Incorrect local datacenter ID", localDatacenter.getId(), clusterMapManager.getLocalDatacenterId());
    List<? extends PartitionId> writablePartitionIds = clusterMapManager.getWritablePartitionIds();
    List<? extends PartitionId> partitionIds = clusterMapManager.getAllPartitionIds();
    assertEquals(writablePartitionIds.size(), testPartitionLayout.getPartitionCount() - 3);
    assertEquals(partitionIds.size(), testPartitionLayout.getPartitionCount());
    for (PartitionId partitionId : partitionIds) {
        if (partitionId.getPartitionState().equals(PartitionState.READ_WRITE)) {
            assertTrue("Partition not found in writable set ", writablePartitionIds.contains(partitionId));
        } else {
            assertFalse("READ_ONLY Partition found in writable set ", writablePartitionIds.contains(partitionId));
        }
    }
    for (int i = 0; i < partitionIds.size(); i++) {
        PartitionId partitionId = partitionIds.get(i);
        assertEquals(partitionId.getReplicaIds().size(), testPartitionLayout.getTotalReplicaCount());
        DataInputStream partitionStream = new DataInputStream(new ByteBufferInputStream(ByteBuffer.wrap(partitionId.getBytes())));
        try {
            PartitionId fetchedPartitionId = clusterMapManager.getPartitionIdFromStream(partitionStream);
            assertEquals(partitionId, fetchedPartitionId);
        } catch (IOException e) {
            assertEquals(true, false);
        }
    }
    for (Datacenter datacenter : testHardwareLayout.getHardwareLayout().getDatacenters()) {
        for (DataNode dataNode : datacenter.getDataNodes()) {
            DataNodeId dataNodeId = clusterMapManager.getDataNodeId(dataNode.getHostname(), dataNode.getPort());
            assertEquals(dataNodeId, dataNode);
            for (ReplicaId replicaId : clusterMapManager.getReplicaIds(dataNodeId)) {
                assertEquals(dataNodeId, replicaId.getDataNodeId());
            }
        }
    }
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) ByteBufferInputStream(com.github.ambry.utils.ByteBufferInputStream) IOException(java.io.IOException) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) DataInputStream(java.io.DataInputStream) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig) Test(org.junit.Test)

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