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());
}
}
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());
}
}
Aggregations