Search in sources :

Example 6 with Anomaly

use of com.linkedin.cruisecontrol.detector.Anomaly in project cruise-control by linkedin.

the class BrokerFailureDetectorTest method testDetectorStartWithFailedBrokers.

@Test
public void testDetectorStartWithFailedBrokers() throws Exception {
    Time mockTime = getMockTime();
    Queue<Anomaly> anomalies = new PriorityBlockingQueue<>(ANOMALY_DETECTOR_INITIAL_QUEUE_SIZE, anomalyComparator());
    File failedBrokersFile = File.createTempFile("testDetectorStartWithFailedBrokers", ".txt");
    BrokerFailureDetector detector = createBrokerFailureDetector(anomalies, mockTime, failedBrokersFile.getPath());
    try {
        String failedBrokerListString = detector.loadPersistedFailedBrokerList();
        assertTrue(failedBrokerListString.isEmpty());
        int brokerId = 0;
        long anomalyTime = mockTime.milliseconds();
        killBroker(brokerId);
        detector.startDetection();
        assertEquals(Collections.singletonMap(brokerId, 100L), detector.failedBrokers());
        failedBrokerListString = detector.loadPersistedFailedBrokerList();
        assertEquals(String.format("%d=%d", brokerId, anomalyTime), failedBrokerListString);
    } finally {
        detector.shutdown();
        Files.delete(failedBrokersFile.toPath());
    }
}
Also used : MockTime(org.apache.kafka.common.utils.MockTime) Time(org.apache.kafka.common.utils.Time) Anomaly(com.linkedin.cruisecontrol.detector.Anomaly) File(java.io.File) PriorityBlockingQueue(java.util.concurrent.PriorityBlockingQueue) Test(org.junit.Test)

Example 7 with Anomaly

use of com.linkedin.cruisecontrol.detector.Anomaly in project cruise-control by linkedin.

the class BrokerFailureDetectorTest method testLoadFailedBrokersFromFile.

@Test
public void testLoadFailedBrokersFromFile() throws Exception {
    Time mockTime = getMockTime();
    Queue<Anomaly> anomalies = new PriorityBlockingQueue<>(ANOMALY_DETECTOR_INITIAL_QUEUE_SIZE, anomalyComparator());
    File failedBrokersFile = File.createTempFile("testLoadFailedBrokersFromFile", ".txt");
    BrokerFailureDetector detector = createBrokerFailureDetector(anomalies, mockTime, failedBrokersFile.getPath());
    try {
        String failedBrokerListString = detector.loadPersistedFailedBrokerList();
        assertTrue(failedBrokerListString.isEmpty());
        detector.startDetection();
        int brokerId = 0;
        long anomalyTime = mockTime.milliseconds();
        killBroker(brokerId);
        long start = System.currentTimeMillis();
        while (anomalies.isEmpty() && System.currentTimeMillis() < start + 30000) {
        // Wait for the anomalies to be drained.
        }
        assertEquals(Collections.singletonMap(brokerId, anomalyTime), detector.failedBrokers());
        // shutdown, advance the clock and create a new detector.
        detector.shutdown();
        mockTime.sleep(100L);
        detector = createBrokerFailureDetector(anomalies, mockTime, failedBrokersFile.getPath());
        failedBrokerListString = detector.loadPersistedFailedBrokerList();
        assertEquals(String.format("%d=%d", brokerId, anomalyTime), failedBrokerListString);
        // start the newly created detector and the broker down time should remain previous time.
        detector.startDetection();
        assertEquals(Collections.singletonMap(brokerId, anomalyTime), detector.failedBrokers());
        failedBrokerListString = detector.loadPersistedFailedBrokerList();
        assertEquals(String.format("%d=%d", brokerId, anomalyTime), failedBrokerListString);
    } finally {
        detector.shutdown();
        Files.delete(failedBrokersFile.toPath());
    }
}
Also used : MockTime(org.apache.kafka.common.utils.MockTime) Time(org.apache.kafka.common.utils.Time) Anomaly(com.linkedin.cruisecontrol.detector.Anomaly) File(java.io.File) PriorityBlockingQueue(java.util.concurrent.PriorityBlockingQueue) Test(org.junit.Test)

Aggregations

Anomaly (com.linkedin.cruisecontrol.detector.Anomaly)7 PriorityBlockingQueue (java.util.concurrent.PriorityBlockingQueue)7 Test (org.junit.Test)6 KafkaCruiseControl (com.linkedin.kafka.cruisecontrol.KafkaCruiseControl)4 AnomalyNotifier (com.linkedin.kafka.cruisecontrol.detector.notifier.AnomalyNotifier)4 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 KafkaCruiseControlConfig (com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig)3 File (java.io.File)3 Properties (java.util.Properties)3 MockTime (org.apache.kafka.common.utils.MockTime)3 Time (org.apache.kafka.common.utils.Time)3 OptimizerResult (com.linkedin.kafka.cruisecontrol.analyzer.OptimizerResult)1 DeterministicCluster.generateClusterFromClusterModel (com.linkedin.kafka.cruisecontrol.common.DeterministicCluster.generateClusterFromClusterModel)1 DeterministicCluster.smallClusterModel (com.linkedin.kafka.cruisecontrol.common.DeterministicCluster.smallClusterModel)1 KafkaCruiseControlThreadFactory (com.linkedin.kafka.cruisecontrol.common.KafkaCruiseControlThreadFactory)1 ExecutorState (com.linkedin.kafka.cruisecontrol.executor.ExecutorState)1 ClusterModel (com.linkedin.kafka.cruisecontrol.model.ClusterModel)1 ModelCompletenessRequirements (com.linkedin.kafka.cruisecontrol.monitor.ModelCompletenessRequirements)1 BrokerEntity (com.linkedin.kafka.cruisecontrol.monitor.sampling.holder.BrokerEntity)1 BrokerStats (com.linkedin.kafka.cruisecontrol.servlet.response.stats.BrokerStats)1