|
22 | 22 | import java.util.HashMap; |
23 | 23 | import java.util.List; |
24 | 24 | import java.util.Map; |
25 | | -import org.apache.cloudstack.api.command.admin.storage.ChangeStoragePoolScopeCmd; |
26 | | -import com.cloud.agent.api.StoragePoolInfo; |
27 | | -import com.cloud.dc.ClusterVO; |
28 | | -import com.cloud.dc.DataCenter; |
29 | | -import com.cloud.dc.DataCenterVO; |
30 | | -import com.cloud.dc.dao.ClusterDao; |
31 | | -import com.cloud.dc.dao.DataCenterDao; |
32 | | -import com.cloud.exception.ConnectionException; |
33 | | -import com.cloud.exception.InvalidParameterValueException; |
34 | | -import com.cloud.exception.PermissionDeniedException; |
35 | | -import com.cloud.host.Host; |
36 | | -import com.cloud.hypervisor.Hypervisor.HypervisorType; |
37 | | -import com.cloud.storage.dao.VolumeDao; |
38 | | -import com.cloud.user.AccountManagerImpl; |
39 | | -import com.cloud.utils.Pair; |
40 | | -import com.cloud.utils.exception.CloudRuntimeException; |
41 | | -import com.cloud.vm.VMInstanceVO; |
42 | | -import com.cloud.vm.dao.VMInstanceDao; |
43 | 25 |
|
44 | 26 | import org.apache.cloudstack.api.ApiConstants; |
| 27 | +import org.apache.cloudstack.api.command.admin.storage.ChangeStoragePoolScopeCmd; |
| 28 | +import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver; |
45 | 29 | import org.apache.cloudstack.framework.config.ConfigDepot; |
46 | 30 | import org.apache.cloudstack.framework.config.ConfigKey; |
47 | 31 | import org.apache.cloudstack.framework.config.dao.ConfigurationDao; |
|
65 | 49 |
|
66 | 50 | import com.cloud.agent.AgentManager; |
67 | 51 | import com.cloud.agent.api.Command; |
| 52 | +import com.cloud.agent.api.StoragePoolInfo; |
68 | 53 | import com.cloud.capacity.CapacityManager; |
| 54 | +import com.cloud.dc.ClusterVO; |
| 55 | +import com.cloud.dc.DataCenter; |
| 56 | +import com.cloud.dc.DataCenterVO; |
69 | 57 | import com.cloud.dc.VsphereStoragePolicyVO; |
| 58 | +import com.cloud.dc.dao.ClusterDao; |
| 59 | +import com.cloud.dc.dao.DataCenterDao; |
70 | 60 | import com.cloud.dc.dao.VsphereStoragePolicyDao; |
71 | 61 | import com.cloud.exception.AgentUnavailableException; |
| 62 | +import com.cloud.exception.ConnectionException; |
| 63 | +import com.cloud.exception.InvalidParameterValueException; |
72 | 64 | import com.cloud.exception.OperationTimedoutException; |
| 65 | +import com.cloud.exception.PermissionDeniedException; |
73 | 66 | import com.cloud.exception.StorageUnavailableException; |
| 67 | +import com.cloud.host.Host; |
| 68 | +import com.cloud.hypervisor.Hypervisor.HypervisorType; |
74 | 69 | import com.cloud.hypervisor.HypervisorGuruManager; |
| 70 | +import com.cloud.storage.dao.VolumeDao; |
| 71 | +import com.cloud.user.AccountManagerImpl; |
| 72 | +import com.cloud.utils.Pair; |
| 73 | +import com.cloud.utils.exception.CloudRuntimeException; |
75 | 74 | import com.cloud.vm.DiskProfile; |
| 75 | +import com.cloud.vm.VMInstanceVO; |
| 76 | +import com.cloud.vm.dao.VMInstanceDao; |
76 | 77 |
|
77 | 78 | @RunWith(MockitoJUnitRunner.class) |
78 | 79 | public class StorageManagerImplTest { |
@@ -835,4 +836,63 @@ public void testCheckPoolforSpaceForResize4() throws NoSuchFieldException, Illeg |
835 | 836 | boolean result = storageManagerImpl.checkPoolforSpace(pool, allocatedSizeWithTemplate, totalAskingSize, true); |
836 | 837 | Assert.assertTrue(result); |
837 | 838 | } |
| 839 | + |
| 840 | + @Test |
| 841 | + public void testGetStoragePoolIopsStats_ReturnsDriverResultWhenNotNull() { |
| 842 | + StoragePool pool = Mockito.mock(StoragePool.class); |
| 843 | + PrimaryDataStoreDriver primaryStoreDriver = Mockito.mock(PrimaryDataStoreDriver.class); |
| 844 | + Pair<Long, Long> expectedResult = new Pair<>(1000L, 500L); |
| 845 | + Mockito.when(primaryStoreDriver.getStorageIopsStats(pool)).thenReturn(expectedResult); |
| 846 | + |
| 847 | + Pair<Long, Long> result = storageManagerImpl.getStoragePoolIopsStats(primaryStoreDriver, pool); |
| 848 | + |
| 849 | + Assert.assertSame("Should return the result from primaryStoreDriver.getStorageIopsStats", expectedResult, result); |
| 850 | + Mockito.verify(primaryStoreDriver, Mockito.never()).getUsedIops(Mockito.any()); |
| 851 | + Mockito.verify(pool, Mockito.never()).getCapacityIops(); |
| 852 | + } |
| 853 | + |
| 854 | + @Test |
| 855 | + public void testGetStoragePoolIopsStats_UsedIopsPositive() { |
| 856 | + StoragePool pool = Mockito.mock(StoragePool.class); |
| 857 | + PrimaryDataStoreDriver primaryStoreDriver = Mockito.mock(PrimaryDataStoreDriver.class); |
| 858 | + Mockito.when(primaryStoreDriver.getStorageIopsStats(pool)).thenReturn(null); |
| 859 | + Mockito.when(primaryStoreDriver.getUsedIops(pool)).thenReturn(500L); |
| 860 | + Mockito.when(pool.getCapacityIops()).thenReturn(1000L); |
| 861 | + |
| 862 | + Pair<Long, Long> result = storageManagerImpl.getStoragePoolIopsStats(primaryStoreDriver, pool); |
| 863 | + |
| 864 | + Assert.assertNotNull(result); |
| 865 | + Assert.assertEquals("Capacity IOPS should match pool's capacity IOPS", 1000L, result.first().longValue()); |
| 866 | + Assert.assertEquals("Used IOPS should match the positive value returned", 500L, result.second().longValue()); |
| 867 | + } |
| 868 | + |
| 869 | + @Test |
| 870 | + public void testGetStoragePoolIopsStats_UsedIopsZero() { |
| 871 | + StoragePool pool = Mockito.mock(StoragePool.class); |
| 872 | + PrimaryDataStoreDriver primaryStoreDriver = Mockito.mock(PrimaryDataStoreDriver.class); |
| 873 | + Mockito.when(primaryStoreDriver.getStorageIopsStats(pool)).thenReturn(null); |
| 874 | + Mockito.when(primaryStoreDriver.getUsedIops(pool)).thenReturn(0L); |
| 875 | + Mockito.when(pool.getCapacityIops()).thenReturn(1000L); |
| 876 | + |
| 877 | + Pair<Long, Long> result = storageManagerImpl.getStoragePoolIopsStats(primaryStoreDriver, pool); |
| 878 | + |
| 879 | + Assert.assertNotNull(result); |
| 880 | + Assert.assertEquals("Capacity IOPS should match pool's capacity IOPS", 1000L, result.first().longValue()); |
| 881 | + Assert.assertNull("Used IOPS should be null when usedIops <= 0", result.second()); |
| 882 | + } |
| 883 | + |
| 884 | + @Test |
| 885 | + public void testGetStoragePoolIopsStats_UsedIopsNegative() { |
| 886 | + StoragePool pool = Mockito.mock(StoragePool.class); |
| 887 | + PrimaryDataStoreDriver primaryStoreDriver = Mockito.mock(PrimaryDataStoreDriver.class); |
| 888 | + Mockito.when(primaryStoreDriver.getStorageIopsStats(pool)).thenReturn(null); |
| 889 | + Mockito.when(primaryStoreDriver.getUsedIops(pool)).thenReturn(-100L); |
| 890 | + Mockito.when(pool.getCapacityIops()).thenReturn(1000L); |
| 891 | + |
| 892 | + Pair<Long, Long> result = storageManagerImpl.getStoragePoolIopsStats(primaryStoreDriver, pool); |
| 893 | + |
| 894 | + Assert.assertNotNull(result); |
| 895 | + Assert.assertEquals("Capacity IOPS should match pool's capacity IOPS", 1000L, result.first().longValue()); |
| 896 | + Assert.assertNull("Used IOPS should be null when usedIops <= 0", result.second()); |
| 897 | + } |
838 | 898 | } |
0 commit comments