Class TestBackupAdminImpl
java.lang.Object
org.apache.hadoop.hbase.backup.impl.TestBackupAdminImpl
@Tag("org.apache.hadoop.hbase.testclassification.SmallTests")
public class TestBackupAdminImpl
extends Object
Unit tests for
BackupAdminImpl.
This class improves test coverage by validating the behavior of key methods in BackupAdminImpl. Some methods are made package-private to enable testing.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate org.apache.hadoop.hbase.backup.impl.BackupAdminImplprivate org.apache.hadoop.hbase.backup.impl.BackupSystemTable -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate org.apache.hadoop.hbase.backup.BackupInfocreateBackupInfo(String id, long ts, org.apache.hadoop.hbase.backup.BackupType type, org.apache.hadoop.hbase.TableName... tables) private org.apache.hadoop.hbase.backup.BackupInfocreateBackupInfo(String id, org.apache.hadoop.hbase.backup.BackupType type, org.apache.hadoop.hbase.backup.BackupInfo.BackupState state, long ts, String dest, org.apache.hadoop.hbase.TableName... tables) voidsetUp()voidVerifies that checkIfValidForMerge fails if one of the provided backup IDs is not found in the system table (i.e., null is returned).voidVerifies that checkIfValidForMerge fails when there is a "hole" in the backup sequence — i.e., a required image from the full backup history is missing in the input list.voidVerifies that checkIfValidForMerge fails when backups come from different destinations.voidVerifies that checkIfValidForMerge fails if a FULL backup is included.voidVerifies that checkIfValidForMerge fails if any backup is not in COMPLETE state.voidVerifies that checkIfValidForMerge succeeds with valid INCREMENTAL, COMPLETE images from the same destination and no holes in the backup sequence.voidVerifies thatcleanupBackupDircorrectly deletes the target backup directory for a given table and backup ID using the mocked FileSystem.voidVerifies thatcleanupBackupDirthrows anIOExceptionif the FileSystem retrieval fails.voidTests that when a backup ID is not found, the method logs a warning and returns 0.voidTests that deleteBackup will update other backups by removing the table when it's not the last session.voidTests that deleteBackup will remove bulk-loaded files and handle exceptions gracefully.voidTests deleting a FULL backup when it is the last session for all its tables.voidScenario: - The initial incremental table set contains "table1" and "table2" - Only "table1" still exists in backup history Expectation: - The backup system should delete the existing set - Then re-add a filtered set that includes only "table1"voidScenario: - Two backup roots: - root1: one table with valid backup history → should be retained - root2: one table with no history → should not be retained Expectation: - root1 metadata deleted and re-added - root2 metadata only deletedvoidScenario: - The incremental table set has "tableX" - No backups exist for this table Expectation: - Backup metadata should be deleted - Nothing should be re-added since no tables are retainedvoidTests that when a current incremental backup is found in the history, all later incremental backups for the same table are returned.voidTests that a full backup for a different table is ignored and does not reset the affected list.voidTests that if a full backup appears after the current backup, the affected list is reset and incremental backups following that full backup are not included.voidTests that backups for other tables are ignored, even if they are incremental and fall after the current backup.voidTests that when a table is removed from a backup image that still contains other tables, it updates the BackupInfo correctly and does not delete the entire backup metadata.voidTests that when the last table in a backup image is removed, the backup metadata is deleted entirely and static cleanup is invoked.
-
Field Details
-
backupAdminImpl
-
mockTable
-
-
Constructor Details
-
TestBackupAdminImpl
public TestBackupAdminImpl()
-
-
Method Details
-
setUp
-
testFinalizeDelete_addsRetainedTablesBack
Scenario: - The initial incremental table set contains "table1" and "table2" - Only "table1" still exists in backup history Expectation: - The backup system should delete the existing set - Then re-add a filtered set that includes only "table1"- Throws:
IOException
-
testFinalizeDelete_retainedSetEmpty_doesNotAddBack
Scenario: - The incremental table set has "tableX" - No backups exist for this table Expectation: - Backup metadata should be deleted - Nothing should be re-added since no tables are retained- Throws:
IOException
-
testFinalizeDelete_multipleRoots
Scenario: - Two backup roots: - root1: one table with valid backup history → should be retained - root2: one table with no history → should not be retained Expectation: - root1 metadata deleted and re-added - root2 metadata only deleted- Throws:
IOException
-
testCleanupBackupDir_deletesTargetDirSuccessfully
Verifies thatcleanupBackupDircorrectly deletes the target backup directory for a given table and backup ID using the mocked FileSystem.This test ensures: - The correct path is constructed using BackupUtils. - FileSystem#delete is invoked with that path.
- Throws:
Exception
-
testCleanupBackupDir_throwsIOException
Verifies thatcleanupBackupDirthrows anIOExceptionif the FileSystem retrieval fails.This test simulates an exception while trying to obtain the FileSystem, and expects the method to propagate the exception.
- Throws:
Exception
-
testGetAffectedBackupSessions
Tests that when a current incremental backup is found in the history, all later incremental backups for the same table are returned. This simulates rolling forward from the current backup timestamp, capturing newer incremental backups that depend on it.- Throws:
IOException
-
testGetAffectedBackupSessions_resetsOnFullBackup
Tests that if a full backup appears after the current backup, the affected list is reset and incremental backups following that full backup are not included. This ensures full backups act as a reset boundary.- Throws:
IOException
-
testGetAffectedBackupSessions_skipsNonMatchingTable
Tests that backups for other tables are ignored, even if they are incremental and fall after the current backup. Only backups affecting the specified table should be considered.- Throws:
IOException
-
testGetAffectedBackupSessions_ignoresFullBackupOfOtherTable
Tests that a full backup for a different table is ignored and does not reset the affected list. Only full backups for the same table act as reset boundaries.- Throws:
IOException
-
createBackupInfo
private org.apache.hadoop.hbase.backup.BackupInfo createBackupInfo(String id, long ts, org.apache.hadoop.hbase.backup.BackupType type, org.apache.hadoop.hbase.TableName... tables) -
testRemoveTableFromBackupImage
Tests that when a table is removed from a backup image that still contains other tables, it updates the BackupInfo correctly and does not delete the entire backup metadata.- Throws:
IOException
-
testRemoveTableFromBackupImageDeletesWhenLastTableRemoved
Tests that when the last table in a backup image is removed, the backup metadata is deleted entirely and static cleanup is invoked.- Throws:
IOException
-
testDeleteBackupWhenBackupInfoNotFound
Tests that when a backup ID is not found, the method logs a warning and returns 0.- Throws:
IOException
-
testDeleteFullBackupWithLastSession
Tests deleting a FULL backup when it is the last session for all its tables. Ensures cleanup is called and metadata is deleted, but no other backups are affected.- Throws:
IOException
-
testDeleteBackupWithAffectedSessions
Tests that deleteBackup will update other backups by removing the table when it's not the last session.- Throws:
IOException
-
testDeleteBackupWithBulkLoadedFiles
Tests that deleteBackup will remove bulk-loaded files and handle exceptions gracefully.- Throws:
IOException
-
testCheckIfValidForMerge_validCase
Verifies that checkIfValidForMerge succeeds with valid INCREMENTAL, COMPLETE images from the same destination and no holes in the backup sequence.- Throws:
IOException
-
testCheckIfValidForMerge_failsWithFullBackup
Verifies that checkIfValidForMerge fails if a FULL backup is included.- Throws:
IOException
-
testCheckIfValidForMerge_failsWhenBackupInfoNotFound
Verifies that checkIfValidForMerge fails if one of the provided backup IDs is not found in the system table (i.e., null is returned).- Throws:
IOException
-
testCheckIfValidForMerge_failsWithDifferentDestinations
Verifies that checkIfValidForMerge fails when backups come from different destinations.- Throws:
IOException
-
testCheckIfValidForMerge_failsWithNonCompleteState
Verifies that checkIfValidForMerge fails if any backup is not in COMPLETE state.- Throws:
IOException
-
testCheckIfValidForMerge_failsWhenHoleInImages
Verifies that checkIfValidForMerge fails when there is a "hole" in the backup sequence — i.e., a required image from the full backup history is missing in the input list.- Throws:
IOException
-
createBackupInfo
private org.apache.hadoop.hbase.backup.BackupInfo createBackupInfo(String id, org.apache.hadoop.hbase.backup.BackupType type, org.apache.hadoop.hbase.backup.BackupInfo.BackupState state, long ts, String dest, org.apache.hadoop.hbase.TableName... tables)
-