Skip to content

Commit 4e4d120

Browse files
Daan Hooglandclaude
andcommitted
update ResourceManagerImplTest and ManagementServerImplTest for ConfigKeys
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 2173263 commit 4e4d120

2 files changed

Lines changed: 36 additions & 3 deletions

File tree

‎server/src/test/java/com/cloud/resource/ResourceManagerImplTest.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import com.cloud.host.Status;
3737
import com.cloud.host.dao.HostDao;
3838
import com.cloud.hypervisor.Hypervisor;
39+
import com.cloud.server.ManagementServer;
3940
import com.cloud.storage.ScopeType;
4041
import com.cloud.storage.StorageManager;
4142
import com.cloud.storage.StoragePoolHostVO;
@@ -198,7 +199,7 @@ public void setup() throws Exception {
198199
when(hostDao.findById(hostId)).thenReturn(host);
199200
when(host.getDetail("username")).thenReturn(hostUsername);
200201
when(host.getDetail("password")).thenReturn(hostPassword);
201-
when(configurationDao.getValue("ssh.privatekey")).thenReturn(hostPrivateKey);
202+
overrideDefaultConfigValue(ManagementServer.SshPrivateKey, "_value", hostPrivateKey);
202203
when(host.getStatus()).thenReturn(Status.Up);
203204
when(host.getPrivateIpAddress()).thenReturn(hostPrivateIp);
204205
when(vm1.getId()).thenReturn(vm1Id);
@@ -242,6 +243,7 @@ public void setup() throws Exception {
242243

243244
@After
244245
public void tearDown() throws Exception {
246+
overrideDefaultConfigValue(ManagementServer.SshPrivateKey, "_value", null);
245247
sshHelperMocked.close();
246248
actionEventUtilsMocked.close();
247249
getVncPortCommandMockedConstruction.close();
@@ -380,9 +382,9 @@ public void testConfigureVncAccessForKVMHostFailedMigrations() {
380382
}
381383

382384
@Test(expected = CloudRuntimeException.class)
383-
public void testGetHostCredentialsMissingParameter() {
385+
public void testGetHostCredentialsMissingParameter() throws Exception {
384386
when(host.getDetail("password")).thenReturn(null);
385-
when(configurationDao.getValue("ssh.privatekey")).thenReturn(null);
387+
overrideDefaultConfigValue(ManagementServer.SshPrivateKey, "_value", null);
386388
resourceManager.getHostCredentials(host);
387389
}
388390

‎server/src/test/java/com/cloud/server/ManagementServerImplTest.java‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@
4242
import java.util.ArrayList;
4343
import java.util.Arrays;
4444
import java.util.Collections;
45+
import java.util.HashMap;
4546
import java.util.List;
4647
import java.util.Map;
48+
import java.util.concurrent.ScheduledExecutorService;
49+
import java.util.concurrent.TimeUnit;
4750

4851
import org.apache.cloudstack.annotation.dao.AnnotationDao;
4952
import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
@@ -2493,4 +2496,32 @@ public void createDeploymentPlanForMigrationListingTestAllocatesInSourceClusterW
24932496
Assert.assertEquals(5L, (long) deploymentPlan.getPodId());
24942497
Assert.assertEquals(4L, (long) deploymentPlan.getClusterId());
24952498
}
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+
}
24962527
}

0 commit comments

Comments
 (0)