Skip to content

Commit 2b6f53a

Browse files
committed
fix failing tests
1 parent e7ebbea commit 2b6f53a

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

server/src/test/java/org/apache/cloudstack/gpu/GpuServiceImplTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import org.mockito.Mock;
6969
import org.mockito.MockedStatic;
7070
import org.mockito.Mockito;
71+
import org.mockito.Spy;
7172
import org.mockito.junit.MockitoJUnitRunner;
7273

7374
import javax.naming.ConfigurationException;
@@ -86,6 +87,7 @@
8687
import static org.mockito.ArgumentMatchers.anyLong;
8788
import static org.mockito.ArgumentMatchers.anyString;
8889
import static org.mockito.ArgumentMatchers.eq;
90+
import static org.mockito.Mockito.doReturn;
8991
import static org.mockito.Mockito.mock;
9092
import static org.mockito.Mockito.never;
9193
import static org.mockito.Mockito.times;
@@ -176,6 +178,7 @@ public class GpuServiceImplTest {
176178
private ResourceManager resourceManager;
177179

178180
@InjectMocks
181+
@Spy
179182
private GpuServiceImpl gpuService;
180183

181184
@Mock
@@ -650,10 +653,14 @@ public void testDisableGpuDevice_Success() {
650653
when(device.getId()).thenReturn(GPU_DEVICE_ID_LONG);
651654
when(device.getManagedState()).thenReturn(GpuDevice.ManagedState.Managed);
652655
when(device.getVmId()).thenReturn(null);
656+
when(device.getHostId()).thenReturn(HOST_ID);
653657

654658
when(gpuDeviceDao.findById(GPU_DEVICE_ID_LONG)).thenReturn(device);
655659
when(gpuDeviceDao.update(eq(GPU_DEVICE_ID_LONG), any(GpuDeviceVO.class))).thenReturn(true);
656660

661+
when(hostDao.findById(HOST_ID)).thenReturn(mockHost);
662+
doReturn(null).when(gpuService).getGpuGroupDetailsFromGpuDevicesOnHost(any());
663+
657664
boolean result = gpuService.disableGpuDevice(cmd);
658665

659666
assertTrue(result);
@@ -669,10 +676,14 @@ public void testEnableGpuDevice_Success() {
669676
when(device.getId()).thenReturn(GPU_DEVICE_ID_LONG);
670677
when(device.getManagedState()).thenReturn(GpuDevice.ManagedState.Unmanaged);
671678
when(device.getVmId()).thenReturn(null);
679+
when(device.getHostId()).thenReturn(HOST_ID);
672680

673681
when(gpuDeviceDao.findById(GPU_DEVICE_ID_LONG)).thenReturn(device);
674682
when(gpuDeviceDao.update(eq(GPU_DEVICE_ID_LONG), any(GpuDeviceVO.class))).thenReturn(true);
675683

684+
when(hostDao.findById(HOST_ID)).thenReturn(mockHost);
685+
doReturn(null).when(gpuService).getGpuGroupDetailsFromGpuDevicesOnHost(any());
686+
676687
boolean result = gpuService.enableGpuDevice(cmd);
677688

678689
assertTrue(result);

0 commit comments

Comments
 (0)