2626import com .cloud .vm .DiskProfile ;
2727import com .cloud .vm .VirtualMachineProfile ;
2828
29+ import org .apache .cloudstack .engine .orchestration .service .VolumeOrchestrationService ;
30+ import org .apache .cloudstack .framework .config .ConfigKey ;
2931import org .apache .cloudstack .storage .datastore .db .StoragePoolVO ;
3032
3133import org .junit .After ;
3739import org .mockito .Mockito ;
3840import org .mockito .junit .MockitoJUnitRunner ;
3941
42+ import java .lang .reflect .Field ;
4043import java .util .ArrayList ;
4144import java .util .HashSet ;
4245import 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
135147class MockStorapoolAllocater extends AbstractStoragePoolAllocator {
0 commit comments