Search in sources :

Example 1 with Executor

use of com.linkedin.kafka.cruisecontrol.executor.Executor in project cruise-control by linkedin.

the class KafkaCruiseControlTest method testSanityCheckDryRun.

@Test
public void testSanityCheckDryRun() throws InterruptedException, ExecutionException, TimeoutException {
    Time time = EasyMock.mock(Time.class);
    AnomalyDetectorManager anomalyDetectorManager = EasyMock.mock(AnomalyDetectorManager.class);
    Executor executor = EasyMock.strictMock(Executor.class);
    LoadMonitor loadMonitor = EasyMock.mock(LoadMonitor.class);
    ExecutorService goalOptimizerExecutor = EasyMock.mock(ExecutorService.class);
    GoalOptimizer goalOptimizer = EasyMock.mock(GoalOptimizer.class);
    // For sanityCheckDryRun(false, true) and sanityCheckDryRun(false, false) (see #1 and #2 below).
    EasyMock.expect(executor.hasOngoingExecution()).andReturn(true).times(2);
    // For sanityCheckDryRun(false, XXX) (see #3 below)
    EasyMock.expect(executor.hasOngoingExecution()).andReturn(false).once();
    EasyMock.expect(executor.listPartitionsBeingReassigned()).andReturn(DUMMY_ONGOING_PARTITION_REASSIGNMENTS);
    EasyMock.expect(executor.maybeStopExternalAgent()).andReturn(true);
    // For sanityCheckDryRun(false, XXX) (see #4 below)
    EasyMock.expect(executor.hasOngoingExecution()).andReturn(false).once();
    EasyMock.expect(executor.listPartitionsBeingReassigned()).andReturn(Collections.emptySet());
    // For sanityCheckDryRun(false, XXX) (see #5 below)
    EasyMock.expect(executor.hasOngoingExecution()).andReturn(false).once();
    EasyMock.expect(executor.listPartitionsBeingReassigned()).andThrow(new TimeoutException()).once();
    EasyMock.replay(time, anomalyDetectorManager, executor, loadMonitor, goalOptimizerExecutor, goalOptimizer);
    KafkaCruiseControl kafkaCruiseControl = new KafkaCruiseControl(_config, time, anomalyDetectorManager, executor, loadMonitor, goalOptimizerExecutor, goalOptimizer, new NoopProvisioner());
    // Expect no failure (dryrun = true) regardless of ongoing executions.
    kafkaCruiseControl.sanityCheckDryRun(true, false);
    kafkaCruiseControl.sanityCheckDryRun(true, true);
    // 1. Expect no failure (dryrun = false), if there is ongoing execution started by CC, it must be requested to stop.
    kafkaCruiseControl.sanityCheckDryRun(false, true);
    // 2. Expect failure (dryrun = false), if there is ongoing execution started by CC, not requested to stop.
    assertThrows(IllegalStateException.class, () -> kafkaCruiseControl.sanityCheckDryRun(false, false));
    // 3. Expect no failure (dryrun = false), there is no execution started by CC, but ongoing replica reassignment, request to stop is irrelevant.
    kafkaCruiseControl.sanityCheckDryRun(false, false);
    // 4. Expect no failure (dryrun = false), there is no execution started by CC or other tools, request to stop is irrelevant.
    kafkaCruiseControl.sanityCheckDryRun(false, false);
    // 5. Expect failure (dryrun = false), there is no execution started by CC, but checking ongoing executions started
    // by other tools timed out, request to stop is irrelevant.
    assertThrows(IllegalStateException.class, () -> kafkaCruiseControl.sanityCheckDryRun(false, false));
    EasyMock.verify(time, anomalyDetectorManager, executor, loadMonitor, goalOptimizerExecutor, goalOptimizer);
    // Verify initialization and functioning of Admin Client
    AdminClient adminClient = kafkaCruiseControl.adminClient();
    assertNotNull(adminClient);
    assertEquals(clusterSize(), adminClient.describeCluster().nodes().get(CLIENT_REQUEST_TIMEOUT_MS, TimeUnit.MILLISECONDS).size());
}
Also used : Executor(com.linkedin.kafka.cruisecontrol.executor.Executor) AnomalyDetectorManager(com.linkedin.kafka.cruisecontrol.detector.AnomalyDetectorManager) GoalOptimizer(com.linkedin.kafka.cruisecontrol.analyzer.GoalOptimizer) NoopProvisioner(com.linkedin.kafka.cruisecontrol.detector.NoopProvisioner) ExecutorService(java.util.concurrent.ExecutorService) Time(org.apache.kafka.common.utils.Time) LoadMonitor(com.linkedin.kafka.cruisecontrol.monitor.LoadMonitor) TimeoutException(java.util.concurrent.TimeoutException) AdminClient(org.apache.kafka.clients.admin.AdminClient) Test(org.junit.Test)

Example 2 with Executor

use of com.linkedin.kafka.cruisecontrol.executor.Executor in project cruise-control by linkedin.

the class KafkaCruiseControlTest method testDisableAutoStopExternalAgent.

@Test
public void testDisableAutoStopExternalAgent() throws InterruptedException, ExecutionException, TimeoutException {
    Time time = EasyMock.mock(Time.class);
    AnomalyDetectorManager anomalyDetectorManager = EasyMock.mock(AnomalyDetectorManager.class);
    Executor executor = EasyMock.strictMock(Executor.class);
    LoadMonitor loadMonitor = EasyMock.mock(LoadMonitor.class);
    ExecutorService goalOptimizerExecutor = EasyMock.mock(ExecutorService.class);
    GoalOptimizer goalOptimizer = EasyMock.mock(GoalOptimizer.class);
    Properties properties = KafkaCruiseControlUnitTestUtils.getKafkaCruiseControlProperties();
    properties.put(MonitorConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers());
    properties.put(ExecutorConfig.ZOOKEEPER_CONNECT_CONFIG, zkConnect());
    properties.put(ExecutorConfig.AUTO_STOP_EXTERNAL_AGENT_CONFIG, false);
    properties.put(KafkaSampleStore.PARTITION_METRIC_SAMPLE_STORE_TOPIC_CONFIG, "__partition_samples");
    properties.put(KafkaSampleStore.BROKER_METRIC_SAMPLE_STORE_TOPIC_CONFIG, "__broker_samples");
    _config = new KafkaCruiseControlConfig(properties);
    EasyMock.expect(executor.hasOngoingExecution()).andReturn(false).once();
    EasyMock.expect(executor.listPartitionsBeingReassigned()).andReturn(DUMMY_ONGOING_PARTITION_REASSIGNMENTS);
    EasyMock.replay(time, anomalyDetectorManager, executor, loadMonitor, goalOptimizerExecutor, goalOptimizer);
    KafkaCruiseControl kafkaCruiseControl = new KafkaCruiseControl(_config, time, anomalyDetectorManager, executor, loadMonitor, goalOptimizerExecutor, goalOptimizer, new NoopProvisioner());
    // Expect failure (dryrun = false), if there is no execution started by CC, but ongoing replica reassignment, request to stop is irrelevant.
    assertThrows(IllegalStateException.class, () -> kafkaCruiseControl.sanityCheckDryRun(false, false));
    EasyMock.verify(time, anomalyDetectorManager, executor, loadMonitor, goalOptimizerExecutor, goalOptimizer);
    // Verify initialization and functioning of Admin Client
    AdminClient adminClient = kafkaCruiseControl.adminClient();
    assertNotNull(adminClient);
    assertEquals(clusterSize(), adminClient.describeCluster().nodes().get(CLIENT_REQUEST_TIMEOUT_MS, TimeUnit.MILLISECONDS).size());
}
Also used : Executor(com.linkedin.kafka.cruisecontrol.executor.Executor) AnomalyDetectorManager(com.linkedin.kafka.cruisecontrol.detector.AnomalyDetectorManager) GoalOptimizer(com.linkedin.kafka.cruisecontrol.analyzer.GoalOptimizer) NoopProvisioner(com.linkedin.kafka.cruisecontrol.detector.NoopProvisioner) ExecutorService(java.util.concurrent.ExecutorService) KafkaCruiseControlConfig(com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig) Time(org.apache.kafka.common.utils.Time) Properties(java.util.Properties) LoadMonitor(com.linkedin.kafka.cruisecontrol.monitor.LoadMonitor) AdminClient(org.apache.kafka.clients.admin.AdminClient) Test(org.junit.Test)

Aggregations

GoalOptimizer (com.linkedin.kafka.cruisecontrol.analyzer.GoalOptimizer)2 AnomalyDetectorManager (com.linkedin.kafka.cruisecontrol.detector.AnomalyDetectorManager)2 NoopProvisioner (com.linkedin.kafka.cruisecontrol.detector.NoopProvisioner)2 Executor (com.linkedin.kafka.cruisecontrol.executor.Executor)2 LoadMonitor (com.linkedin.kafka.cruisecontrol.monitor.LoadMonitor)2 ExecutorService (java.util.concurrent.ExecutorService)2 AdminClient (org.apache.kafka.clients.admin.AdminClient)2 Time (org.apache.kafka.common.utils.Time)2 Test (org.junit.Test)2 KafkaCruiseControlConfig (com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig)1 Properties (java.util.Properties)1 TimeoutException (java.util.concurrent.TimeoutException)1