Search in sources :

Example 1 with VerifiableProperties

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

the class ReplicationTest method replicationPauseTest.

/**
 * Tests pausing replication for all and individual partitions.
 * @throws Exception
 */
@Test
public void replicationPauseTest() throws Exception {
    MockClusterMap clusterMap = new MockClusterMap();
    Host localHost = new Host(clusterMap.getDataNodeIds().get(0), clusterMap);
    Host remoteHost = new Host(clusterMap.getDataNodeIds().get(1), clusterMap);
    List<PartitionId> partitionIds = clusterMap.getAllPartitionIds();
    for (PartitionId partitionId : partitionIds) {
        // add  10 messages to the remote host only
        addPutMessagesToReplicasOfPartition(partitionId, Collections.singletonList(remoteHost), 10);
    }
    Properties properties = new Properties();
    properties.put("replication.wait.time.between.replicas.ms", "0");
    ReplicationConfig config = new ReplicationConfig(new VerifiableProperties(properties));
    ReplicationMetrics replicationMetrics = new ReplicationMetrics(new MetricRegistry(), clusterMap.getReplicaIds(localHost.dataNodeId));
    replicationMetrics.populatePerColoMetrics(Collections.singleton(remoteHost.dataNodeId.getDatacenterName()));
    StoreKeyFactory storeKeyFactory = Utils.getObj("com.github.ambry.commons.BlobIdFactory", clusterMap);
    Map<DataNodeId, List<RemoteReplicaInfo>> replicasToReplicate = new HashMap<>();
    replicasToReplicate.put(remoteHost.dataNodeId, localHost.getRemoteReplicaInfos(remoteHost, null));
    Map<DataNodeId, Host> hosts = new HashMap<>();
    hosts.put(remoteHost.dataNodeId, remoteHost);
    int batchSize = 4;
    MockConnectionPool connectionPool = new MockConnectionPool(hosts, clusterMap, batchSize);
    ReplicaThread replicaThread = new ReplicaThread("threadtest", replicasToReplicate, new MockFindTokenFactory(), clusterMap, new AtomicInteger(0), localHost.dataNodeId, connectionPool, config, replicationMetrics, null, storeKeyFactory, true, clusterMap.getMetricRegistry(), false, localHost.dataNodeId.getDatacenterName(), new ResponseHandler(clusterMap));
    Map<PartitionId, Integer> progressTracker = new HashMap<>();
    PartitionId idToLeaveOut = clusterMap.getAllPartitionIds().get(0);
    boolean allStopped = false;
    boolean onlyOneResumed = false;
    boolean allReenabled = false;
    Set<PartitionId> expectedPaused = new HashSet<>();
    assertEquals("There should be no disabled partitions", expectedPaused, replicaThread.getReplicationDisabledPartitions());
    while (true) {
        replicaThread.replicate(new ArrayList<>(replicasToReplicate.values()));
        boolean replicationDone = true;
        for (RemoteReplicaInfo replicaInfo : replicasToReplicate.get(remoteHost.dataNodeId)) {
            PartitionId id = replicaInfo.getReplicaId().getPartitionId();
            MockFindToken token = (MockFindToken) replicaInfo.getToken();
            int lastProgress = progressTracker.computeIfAbsent(id, id1 -> 0);
            int currentProgress = token.getIndex();
            boolean partDone = currentProgress + 1 == remoteHost.infosByPartition.get(id).size();
            if (allStopped || (onlyOneResumed && !id.equals(idToLeaveOut))) {
                assertEquals("There should have been no progress", lastProgress, currentProgress);
            } else if (!partDone) {
                assertTrue("There has been no progress", currentProgress > lastProgress);
                progressTracker.put(id, currentProgress);
            }
            replicationDone = replicationDone && partDone;
        }
        if (!allStopped && !onlyOneResumed && !allReenabled) {
            replicaThread.controlReplicationForPartitions(clusterMap.getAllPartitionIds(), false);
            expectedPaused.addAll(clusterMap.getAllPartitionIds());
            assertEquals("Disabled partitions sets do not match", expectedPaused, replicaThread.getReplicationDisabledPartitions());
            allStopped = true;
        } else if (!onlyOneResumed && !allReenabled) {
            // resume replication for first partition
            replicaThread.controlReplicationForPartitions(Collections.singletonList(partitionIds.get(0)), true);
            expectedPaused.remove(partitionIds.get(0));
            assertEquals("Disabled partitions sets do not match", expectedPaused, replicaThread.getReplicationDisabledPartitions());
            allStopped = false;
            onlyOneResumed = true;
        } else if (!allReenabled) {
            // not removing the first partition
            replicaThread.controlReplicationForPartitions(clusterMap.getAllPartitionIds(), true);
            onlyOneResumed = false;
            allReenabled = true;
            expectedPaused.clear();
            assertEquals("Disabled partitions sets do not match", expectedPaused, replicaThread.getReplicationDisabledPartitions());
        }
        if (replicationDone) {
            break;
        }
    }
    Map<PartitionId, List<MessageInfo>> missingInfos = remoteHost.getMissingInfos(localHost.infosByPartition);
    for (Map.Entry<PartitionId, List<MessageInfo>> entry : missingInfos.entrySet()) {
        assertEquals("No infos should be missing", 0, entry.getValue().size());
    }
    Map<PartitionId, List<ByteBuffer>> missingBuffers = remoteHost.getMissingBuffers(localHost.buffersByPartition);
    for (Map.Entry<PartitionId, List<ByteBuffer>> entry : missingBuffers.entrySet()) {
        assertEquals("No buffers should be missing", 0, entry.getValue().size());
    }
}
Also used : ResponseHandler(com.github.ambry.commons.ResponseHandler) HashMap(java.util.HashMap) BlobProperties(com.github.ambry.messageformat.BlobProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) StoreKeyFactory(com.github.ambry.store.StoreKeyFactory) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ReplicationConfig(com.github.ambry.config.ReplicationConfig) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) PartitionId(com.github.ambry.clustermap.PartitionId) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DataNodeId(com.github.ambry.clustermap.DataNodeId) Map(java.util.Map) HashMap(java.util.HashMap) ClusterMap(com.github.ambry.clustermap.ClusterMap) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Example 2 with VerifiableProperties

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

the class RestServerMain method main.

public static void main(String[] args) {
    final RestServer restServer;
    int exitCode = 0;
    ClusterMap clusterMap = null;
    try {
        InvocationOptions options = new InvocationOptions(args);
        Properties properties = Utils.loadProps(options.serverPropsFilePath);
        VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
        ClusterMapConfig clusterMapConfig = new ClusterMapConfig(verifiableProperties);
        ClusterAgentsFactory clusterAgentsFactory = Utils.getObj(clusterMapConfig.clusterMapClusterAgentsFactory, clusterMapConfig, options.hardwareLayoutFilePath, options.partitionLayoutFilePath);
        clusterMap = clusterAgentsFactory.getClusterMap();
        SSLFactory sslFactory = getSSLFactoryIfRequired(verifiableProperties);
        logger.info("Bootstrapping RestServer");
        restServer = new RestServer(verifiableProperties, clusterMap, new LoggingNotificationSystem(), sslFactory);
        // attach shutdown handler to catch control-c
        Runtime.getRuntime().addShutdownHook(new Thread() {

            public void run() {
                logger.info("Received shutdown signal. Shutting down RestServer");
                restServer.shutdown();
            }
        });
        restServer.start();
        restServer.awaitShutdown();
    } catch (Exception e) {
        logger.error("Exception during bootstrap of RestServer", e);
        exitCode = 1;
    } finally {
        if (clusterMap != null) {
            clusterMap.close();
        }
    }
    logger.info("Exiting RestServerMain");
    System.exit(exitCode);
}
Also used : ClusterMap(com.github.ambry.clustermap.ClusterMap) SSLFactory(com.github.ambry.commons.SSLFactory) VerifiableProperties(com.github.ambry.config.VerifiableProperties) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) ClusterAgentsFactory(com.github.ambry.clustermap.ClusterAgentsFactory) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) InvocationOptions(com.github.ambry.utils.InvocationOptions) ClusterMapConfig(com.github.ambry.config.ClusterMapConfig) IOException(java.io.IOException) GeneralSecurityException(java.security.GeneralSecurityException)

Example 3 with VerifiableProperties

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

the class AsyncRequestResponseHandlerFactoryTest method getAsyncRequestResponseHandlerTest.

/**
 * Tests the instantiation of an {@link AsyncRequestResponseHandler} instance through the
 * {@link AsyncRequestResponseHandlerFactory}.
 * @throws InstantiationException
 */
@Test
public void getAsyncRequestResponseHandlerTest() throws InstantiationException, IOException {
    Properties properties = new Properties();
    VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
    Router router = new InMemoryRouter(verifiableProperties, new MockClusterMap());
    // Get response handler.
    AsyncRequestResponseHandlerFactory responseHandlerFactory = new AsyncRequestResponseHandlerFactory(1, METRIC_REGISTRY);
    RestResponseHandler restResponseHandler = responseHandlerFactory.getRestResponseHandler();
    assertNotNull("No RestResponseHandler returned", restResponseHandler);
    assertEquals("Did not receive an AsyncRequestResponseHandler instance", AsyncRequestResponseHandler.class.getCanonicalName(), restResponseHandler.getClass().getCanonicalName());
    BlobStorageService blobStorageService = new MockBlobStorageService(verifiableProperties, restResponseHandler, router);
    // Get request handler.
    AsyncRequestResponseHandlerFactory requestHandlerFactory = new AsyncRequestResponseHandlerFactory(1, METRIC_REGISTRY, blobStorageService);
    RestRequestHandler restRequestHandler = requestHandlerFactory.getRestRequestHandler();
    assertNotNull("No RestRequestHandler returned", restRequestHandler);
    assertEquals("Did not receive an AsyncRequestResponseHandler instance", AsyncRequestResponseHandler.class.getCanonicalName(), restRequestHandler.getClass().getCanonicalName());
    // make sure they are same instance
    assertEquals("Instances of AsyncRequestResponseHandler are not the same", restResponseHandler, restRequestHandler);
    // make sure the instance starts and shuts down OK.
    restRequestHandler.start();
    restRequestHandler.shutdown();
}
Also used : InMemoryRouter(com.github.ambry.router.InMemoryRouter) VerifiableProperties(com.github.ambry.config.VerifiableProperties) InMemoryRouter(com.github.ambry.router.InMemoryRouter) Router(com.github.ambry.router.Router) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Example 4 with VerifiableProperties

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

the class BadRestRequest method startRequestResponseHandler.

/**
 * Sets up all the tests by providing a started {@link AsyncRequestResponseHandler} for their use.
 * @throws InstantiationException
 * @throws IOException
 */
@BeforeClass
public static void startRequestResponseHandler() throws InstantiationException, IOException {
    verifiableProperties = new VerifiableProperties(new Properties());
    router = new InMemoryRouter(verifiableProperties, new MockClusterMap());
    asyncRequestResponseHandler = getAsyncRequestResponseHandler(5);
    blobStorageService.start();
    asyncRequestResponseHandler.start();
}
Also used : InMemoryRouter(com.github.ambry.router.InMemoryRouter) VerifiableProperties(com.github.ambry.config.VerifiableProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) BeforeClass(org.junit.BeforeClass)

Example 5 with VerifiableProperties

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

the class NettyServerFactoryTest method getNettyServerFactoryWithBadInputTest.

/**
 * Tests instantiation of {@link NettyServerFactory} with bad input.
 */
@Test
public void getNettyServerFactoryWithBadInputTest() {
    Properties properties = new Properties();
    properties.setProperty("netty.server.enable.ssl", "true");
    VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
    MetricRegistry metricRegistry = new MetricRegistry();
    doConstructionFailureTest(null, metricRegistry, REST_REQUEST_HANDLER, PUBLIC_ACCESS_LOGGER, REST_SERVER_STATE, SSL_FACTORY);
    doConstructionFailureTest(verifiableProperties, null, REST_REQUEST_HANDLER, PUBLIC_ACCESS_LOGGER, REST_SERVER_STATE, SSL_FACTORY);
    doConstructionFailureTest(verifiableProperties, metricRegistry, null, PUBLIC_ACCESS_LOGGER, REST_SERVER_STATE, SSL_FACTORY);
    doConstructionFailureTest(verifiableProperties, metricRegistry, REST_REQUEST_HANDLER, null, REST_SERVER_STATE, SSL_FACTORY);
    doConstructionFailureTest(verifiableProperties, metricRegistry, REST_REQUEST_HANDLER, PUBLIC_ACCESS_LOGGER, null, SSL_FACTORY);
    doConstructionFailureTest(verifiableProperties, metricRegistry, REST_REQUEST_HANDLER, PUBLIC_ACCESS_LOGGER, REST_SERVER_STATE, null);
}
Also used : 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)

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