Skip to content

Commit 4207ea9

Browse files
committed
test(backup): set CHAIN_POSITION on sweep-up-pending-parent test fixtures
deletingLeafSweepsUpDeletePendingParent previously omitted CHAIN_POSITION because the old PARENT_BACKUP_ID-walking sweep didn't depend on it. The new getChainOrderedLeafToRoot helper (096bef1) sorts the chain by CHAIN_POSITION desc; without those mocks both backups returned MAX_VALUE, the stable sort left the leaf at index 0 and the parent never got swept. Real backups always carry CHAIN_POSITION (set in persistChainMetadata), so this aligns the fixtures with production data rather than papering over the new sort assumption.
1 parent 73c4206 commit 4207ea9

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

plugins/backup/nas/src/test/java/org/apache/cloudstack/backup/NASBackupProviderTest.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,22 +592,27 @@ public void deletingLeafSweepsUpDeletePendingParent()
592592
Mockito.when(backupRepositoryDao.findByBackupOfferingId(offeringId)).thenReturn(repo);
593593
Mockito.when(vmInstanceDao.findByIdIncludingRemoved(vmId)).thenReturn(vm);
594594

595-
// Leaf details.
595+
// Leaf details. CHAIN_POSITION=1 puts the leaf after the full anchor in the
596+
// ordered chain — getChainOrderedLeafToRoot sorts by CHAIN_POSITION descending.
596597
BackupDetailVO leafChainId = new BackupDetailVO(51L, NASBackupChainKeys.CHAIN_ID, "chain-1", true);
598+
BackupDetailVO leafChainPos = new BackupDetailVO(51L, NASBackupChainKeys.CHAIN_POSITION, "1", true);
597599
BackupDetailVO leafParent = new BackupDetailVO(51L, NASBackupChainKeys.PARENT_BACKUP_ID, "parent-uuid", true);
598600
Mockito.when(backupDetailsDao.findDetail(51L, NASBackupChainKeys.CHAIN_ID)).thenReturn(leafChainId);
601+
Mockito.when(backupDetailsDao.findDetail(51L, NASBackupChainKeys.CHAIN_POSITION)).thenReturn(leafChainPos);
599602
Mockito.when(backupDetailsDao.findDetail(51L, NASBackupChainKeys.PARENT_BACKUP_ID)).thenReturn(leafParent);
600603

601-
// Parent is tombstoned.
604+
// Parent is the tombstoned full anchor (CHAIN_POSITION=0).
602605
BackupDetailVO parentChainId = new BackupDetailVO(50L, NASBackupChainKeys.CHAIN_ID, "chain-1", true);
606+
BackupDetailVO parentChainPos = new BackupDetailVO(50L, NASBackupChainKeys.CHAIN_POSITION, "0", true);
603607
BackupDetailVO parentPending = new BackupDetailVO(50L, NASBackupChainKeys.DELETE_PENDING, "true", true);
604608
Mockito.when(backupDetailsDao.findDetail(50L, NASBackupChainKeys.CHAIN_ID)).thenReturn(parentChainId);
609+
Mockito.when(backupDetailsDao.findDetail(50L, NASBackupChainKeys.CHAIN_POSITION)).thenReturn(parentChainPos);
605610
Mockito.when(backupDetailsDao.findDetail(50L, NASBackupChainKeys.DELETE_PENDING)).thenReturn(parentPending);
606611
// Parent has no parent of its own (it's the full anchor).
607612
Mockito.when(backupDetailsDao.findDetail(50L, NASBackupChainKeys.PARENT_BACKUP_ID)).thenReturn(null);
608613

609-
// listByVmId is called repeatedly. We use a mutable list so the sweep observes the
610-
// leaf has been removed and treats the parent as childless.
614+
// listByVmId is called once now (chain snapshot taken before the leaf delete).
615+
// We still use a mutable list + remove() answer so the DAO contract is realistic.
611616
java.util.List<Backup> liveBackups = new java.util.ArrayList<>(List.of(parent, leaf));
612617
Mockito.when(backupDao.listByVmId(null, vmId)).thenAnswer(inv -> new java.util.ArrayList<>(liveBackups));
613618

0 commit comments

Comments
 (0)