Skip to content

Commit 73daf4a

Browse files
rootnomadRamgopal Nagaboina
authored andcommitted
test: fold the snapshot-copy resource-count test into SnapshotManagerImplTest
Keep a single test suite per class. Move copySnapshotOnPoolChargesPrimaryStorageToTheSnapshotOwnerAccount into SnapshotManagerImplTest and drop the separate SnapshotManagerImplCopyResourceCountTest. The case reuses the mocks already declared on the suite, so the duplicate mock declarations and the separate runner are no longer needed.
1 parent 724a92e commit 73daf4a

2 files changed

Lines changed: 39 additions & 98 deletions

File tree

‎server/src/test/java/com/cloud/storage/snapshot/SnapshotManagerImplCopyResourceCountTest.java‎

Lines changed: 0 additions & 98 deletions
This file was deleted.

‎server/src/test/java/com/cloud/storage/snapshot/SnapshotManagerImplTest.java‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.cloud.exception.ResourceUnavailableException;
2727
import com.cloud.hypervisor.Hypervisor.HypervisorType;
2828
import com.cloud.org.Grouping;
29+
import com.cloud.configuration.Resource.ResourceType;
2930
import com.cloud.storage.DataStoreRole;
3031
import com.cloud.storage.ScopeType;
3132
import com.cloud.storage.Snapshot;
@@ -59,6 +60,7 @@
5960
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
6061
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult;
6162
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotService;
63+
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy;
6264
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
6365
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
6466
import org.apache.cloudstack.framework.async.AsyncCallFuture;
@@ -822,4 +824,41 @@ public void testEndCurrentChainIfNeededStopsOnMissingParentRef() {
822824

823825
Mockito.verify(snapshotStoreDao, Mockito.never()).update(Mockito.anyLong(), Mockito.any(SnapshotDataStoreVO.class));
824826
}
827+
828+
@Test
829+
@SuppressWarnings("unchecked")
830+
public void copySnapshotOnPoolChargesPrimaryStorageToTheSnapshotOwnerAccount() throws Exception {
831+
long ownerAccountId = 42L;
832+
long snapshotSize = 1024L;
833+
Long poolId = 5L;
834+
835+
SnapshotInfo snapshot = Mockito.mock(SnapshotInfo.class);
836+
SnapshotInfo snapshotOnStore = Mockito.mock(SnapshotInfo.class);
837+
SnapshotStrategy strategy = Mockito.mock(SnapshotStrategy.class);
838+
DataStore store = Mockito.mock(DataStore.class);
839+
AsyncCallFuture<SnapshotResult> future = Mockito.mock(AsyncCallFuture.class);
840+
SnapshotResult result = Mockito.mock(SnapshotResult.class);
841+
842+
Mockito.when(snapshot.getId()).thenReturn(100L);
843+
Mockito.when(snapshot.getSize()).thenReturn(snapshotSize);
844+
Mockito.when(snapshot.getAccountId()).thenReturn(ownerAccountId);
845+
Mockito.when(dataStoreManager.getDataStore(poolId, DataStoreRole.Primary)).thenReturn(store);
846+
Mockito.when(store.create(snapshot)).thenReturn(snapshotOnStore);
847+
Mockito.when(snapshotOnStore.getDataCenterId()).thenReturn(2L);
848+
Mockito.when(snapshotService.copySnapshot(snapshot, snapshotOnStore, strategy)).thenReturn(future);
849+
Mockito.when(future.get()).thenReturn(result);
850+
Mockito.when(result.isFailed()).thenReturn(false);
851+
852+
try (MockedStatic<CallContext> ctxMock = Mockito.mockStatic(CallContext.class)) {
853+
CallContext ctx = Mockito.mock(CallContext.class);
854+
ctxMock.when(CallContext::current).thenReturn(ctx);
855+
// A SYSTEM calling account skips the usage-event branch; this test only covers which account is charged.
856+
Mockito.when(ctx.getCallingAccountId()).thenReturn(Account.ACCOUNT_ID_SYSTEM);
857+
858+
snapshotManager.copySnapshotOnPool(snapshot, strategy, poolId);
859+
}
860+
861+
Mockito.verify(resourceLimitService).incrementResourceCount(
862+
Mockito.eq(ownerAccountId), Mockito.eq(ResourceType.primary_storage), Mockito.eq(snapshotSize));
863+
}
825864
}

0 commit comments

Comments
 (0)