|
42 | 42 | import java.util.ArrayList; |
43 | 43 | import java.util.Arrays; |
44 | 44 | import java.util.Collections; |
| 45 | +import java.util.HashMap; |
45 | 46 | import java.util.List; |
46 | 47 | import java.util.Map; |
| 48 | +import java.util.concurrent.ScheduledExecutorService; |
| 49 | +import java.util.concurrent.TimeUnit; |
47 | 50 |
|
48 | 51 | import org.apache.cloudstack.annotation.dao.AnnotationDao; |
49 | 52 | import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao; |
@@ -2493,4 +2496,32 @@ public void createDeploymentPlanForMigrationListingTestAllocatesInSourceClusterW |
2493 | 2496 | Assert.assertEquals(5L, (long) deploymentPlan.getPodId()); |
2494 | 2497 | Assert.assertEquals(4L, (long) deploymentPlan.getClusterId()); |
2495 | 2498 | } |
| 2499 | + |
| 2500 | + @Test |
| 2501 | + public void configureSchedulesAlertPurgeTaskWhenAlertPurgeDelayIsNonZero() throws Exception { |
| 2502 | + when(configDao.getConfiguration()).thenReturn(new HashMap<>()); |
| 2503 | + overrideDefaultConfigValue(spy.AlertPurgeInterval, "_defaultValue", "10"); |
| 2504 | + overrideDefaultConfigValue(spy.AlertPurgeDelay, "_defaultValue", "5"); |
| 2505 | + ScheduledExecutorService alertExecutor = mock(ScheduledExecutorService.class); |
| 2506 | + ReflectionTestUtils.setField(spy, "_alertExecutor", alertExecutor); |
| 2507 | + |
| 2508 | + spy.configure("management-server", new HashMap<>()); |
| 2509 | + |
| 2510 | + Mockito.verify(alertExecutor).scheduleAtFixedRate(any(Runnable.class), Mockito.eq(10L), Mockito.eq(10L), Mockito.eq(TimeUnit.SECONDS)); |
| 2511 | + Assert.assertEquals(5, ReflectionTestUtils.getField(spy, "_alertPurgeDelay")); |
| 2512 | + } |
| 2513 | + |
| 2514 | + @Test |
| 2515 | + public void configureDoesNotScheduleAlertPurgeTaskWhenAlertPurgeDelayIsZero() throws Exception { |
| 2516 | + when(configDao.getConfiguration()).thenReturn(new HashMap<>()); |
| 2517 | + overrideDefaultConfigValue(spy.AlertPurgeInterval, "_defaultValue", "10"); |
| 2518 | + overrideDefaultConfigValue(spy.AlertPurgeDelay, "_defaultValue", "0"); |
| 2519 | + ScheduledExecutorService alertExecutor = mock(ScheduledExecutorService.class); |
| 2520 | + ReflectionTestUtils.setField(spy, "_alertExecutor", alertExecutor); |
| 2521 | + |
| 2522 | + spy.configure("management-server", new HashMap<>()); |
| 2523 | + |
| 2524 | + Mockito.verifyNoInteractions(alertExecutor); |
| 2525 | + Assert.assertEquals(0, ReflectionTestUtils.getField(spy, "_alertPurgeDelay")); |
| 2526 | + } |
2496 | 2527 | } |
0 commit comments