Skip to content

Commit c3006bf

Browse files
committed
Revert method signature change done for unit test
1 parent 33f9e6f commit c3006bf

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

engine/storage/src/main/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public List<StoragePool> reorderPools(List<StoragePool> pools, VirtualMachinePro
204204
account = vmProfile.getOwner();
205205
}
206206

207-
pools = reorderStoragePoolsBasedOnAlgorithm(pools, plan, account, VolumeOrchestrationService.VolumeAllocationAlgorithm.value());
207+
pools = reorderStoragePoolsBasedOnAlgorithm(pools, plan, account);
208208

209209
if (vmProfile.getVirtualMachine() == null) {
210210
if (logger.isTraceEnabled()) {
@@ -221,7 +221,8 @@ public List<StoragePool> reorderPools(List<StoragePool> pools, VirtualMachinePro
221221
return pools;
222222
}
223223

224-
List<StoragePool> reorderStoragePoolsBasedOnAlgorithm(List<StoragePool> pools, DeploymentPlan plan, Account account, String volumeAllocationAlgorithm) {
224+
List<StoragePool> reorderStoragePoolsBasedOnAlgorithm(List<StoragePool> pools, DeploymentPlan plan, Account account) {
225+
String volumeAllocationAlgorithm = VolumeOrchestrationService.VolumeAllocationAlgorithm.value();
225226
logger.debug("Using volume allocation algorithm {} to reorder pools.", volumeAllocationAlgorithm);
226227
if (volumeAllocationAlgorithm.equals("random") || volumeAllocationAlgorithm.equals("userconcentratedpod_random") || (account == null)) {
227228
reorderRandomPools(pools);

engine/storage/src/test/java/org/apache/cloudstack/storage/allocator/AbstractStoragePoolAllocatorTest.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import com.cloud.vm.DiskProfile;
2727
import com.cloud.vm.VirtualMachineProfile;
2828

29+
import org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService;
30+
import org.apache.cloudstack.framework.config.ConfigKey;
2931
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
3032

3133
import org.junit.After;
@@ -37,6 +39,7 @@
3739
import org.mockito.Mockito;
3840
import org.mockito.junit.MockitoJUnitRunner;
3941

42+
import java.lang.reflect.Field;
4043
import java.util.ArrayList;
4144
import java.util.HashSet;
4245
import java.util.List;
@@ -74,26 +77,28 @@ public void tearDown() {
7477
}
7578

7679
@Test
77-
public void reorderStoragePoolsBasedOnAlgorithm_random() {
78-
allocator.reorderStoragePoolsBasedOnAlgorithm(pools, plan, account, "random");
80+
public void reorderStoragePoolsBasedOnAlgorithm_random() throws Exception {
81+
overrideDefaultConfigValue( VolumeOrchestrationService.VolumeAllocationAlgorithm, "random");
82+
allocator.reorderStoragePoolsBasedOnAlgorithm(pools, plan, account);
7983
Mockito.verify(allocator, Mockito.times(0)).reorderPoolsByCapacity(plan, pools);
8084
Mockito.verify(allocator, Mockito.times(0)).reorderPoolsByNumberOfVolumes(plan, pools, account);
8185
Mockito.verify(allocator, Mockito.times(1)).reorderRandomPools(pools);
8286
}
8387

8488
@Test
85-
public void reorderStoragePoolsBasedOnAlgorithm_userdispersing() {
89+
public void reorderStoragePoolsBasedOnAlgorithm_userdispersing() throws Exception {
90+
overrideDefaultConfigValue(VolumeOrchestrationService.VolumeAllocationAlgorithm, "userdispersing");
8691
Mockito.doReturn(pools).when(allocator).reorderPoolsByNumberOfVolumes(plan, pools, account);
87-
allocator.reorderStoragePoolsBasedOnAlgorithm(pools, plan, account,"userdispersing");
92+
allocator.reorderStoragePoolsBasedOnAlgorithm(pools, plan, account);
8893
Mockito.verify(allocator, Mockito.times(0)).reorderPoolsByCapacity(plan, pools);
8994
Mockito.verify(allocator, Mockito.times(1)).reorderPoolsByNumberOfVolumes(plan, pools, account);
9095
Mockito.verify(allocator, Mockito.times(0)).reorderRandomPools(pools);
9196
}
9297

9398
@Test
94-
public void reorderStoragePoolsBasedOnAlgorithm_userdispersing_reorder_check() {
99+
public void reorderStoragePoolsBasedOnAlgorithm_userdispersing_reorder_check() throws Exception {
100+
overrideDefaultConfigValue(VolumeOrchestrationService.VolumeAllocationAlgorithm, "userdispersing");
95101
allocator.volumeDao = volumeDao;
96-
97102
when(plan.getDataCenterId()).thenReturn(1l);
98103
when(plan.getPodId()).thenReturn(1l);
99104
when(plan.getClusterId()).thenReturn(1l);
@@ -103,7 +108,7 @@ public void reorderStoragePoolsBasedOnAlgorithm_userdispersing_reorder_check() {
103108
poolIds.add(9l);
104109
when(volumeDao.listPoolIdsByVolumeCount(1l,1l,1l,1l)).thenReturn(poolIds);
105110

106-
List<StoragePool> reorderedPools = allocator.reorderStoragePoolsBasedOnAlgorithm(pools, plan, account, "userdispersing");
111+
List<StoragePool> reorderedPools = allocator.reorderStoragePoolsBasedOnAlgorithm(pools, plan, account);
107112
Assert.assertEquals(poolIds.size(),reorderedPools.size());
108113

109114
Mockito.verify(allocator, Mockito.times(0)).reorderPoolsByCapacity(plan, pools);
@@ -113,9 +118,10 @@ public void reorderStoragePoolsBasedOnAlgorithm_userdispersing_reorder_check() {
113118
}
114119

115120
@Test
116-
public void reorderStoragePoolsBasedOnAlgorithm_firstfitleastconsumed() {
121+
public void reorderStoragePoolsBasedOnAlgorithm_firstfitleastconsumed() throws Exception {
122+
overrideDefaultConfigValue(VolumeOrchestrationService.VolumeAllocationAlgorithm, "firstfitleastconsumed");
117123
Mockito.doReturn(pools).when(allocator).reorderPoolsByCapacity(plan, pools);
118-
allocator.reorderStoragePoolsBasedOnAlgorithm(pools, plan, account, "firstfitleastconsumed");
124+
allocator.reorderStoragePoolsBasedOnAlgorithm(pools, plan, account);
119125
Mockito.verify(allocator, Mockito.times(1)).reorderPoolsByCapacity(plan, pools);
120126
Mockito.verify(allocator, Mockito.times(0)).reorderPoolsByNumberOfVolumes(plan, pools, account);
121127
Mockito.verify(allocator, Mockito.times(0)).reorderRandomPools(pools);
@@ -130,6 +136,12 @@ public void reorderRandomPools() {
130136
}
131137
Assert.assertTrue(firstchoice.size() > 2);
132138
}
139+
140+
private void overrideDefaultConfigValue(final ConfigKey configKey, final String value) throws IllegalAccessException, NoSuchFieldException {
141+
final Field f = ConfigKey.class.getDeclaredField("_defaultValue");
142+
f.setAccessible(true);
143+
f.set(configKey, value);
144+
}
133145
}
134146

135147
class MockStorapoolAllocater extends AbstractStoragePoolAllocator {

0 commit comments

Comments
 (0)