BackupVerification { public Optional<BackupVerificationResult> verifyBackup( BackupVersion backupVersion, boolean force, DateRange dateRange) throws UnsupportedTypeException, IllegalArgumentException { IMetaProxy metaProxy = getMetaProxy(backupVersion); if (metaProxy == null) { throw new UnsupportedTypeException( "BackupVersion type: " + backupVersion + " is not supported"); } if (dateRange == null) { throw new IllegalArgumentException("dateRange provided is null"); } List<BackupMetadata> metadata = backupStatusMgr.getLatestBackupMetadata(backupVersion, dateRange); if (metadata == null || metadata.isEmpty()) return Optional.empty(); for (BackupMetadata backupMetadata : metadata) { if (backupMetadata.getLastValidated() != null && !force) { BackupVerificationResult result = new BackupVerificationResult(); result.valid = true; result.manifestAvailable = true; result.snapshotInstant = backupMetadata.getStart().toInstant(); Path snapshotLocation = Paths.get(backupMetadata.getSnapshotLocation()); result.remotePath = snapshotLocation.subpath(1, snapshotLocation.getNameCount()).toString(); return Optional.of(result); } BackupVerificationResult backupVerificationResult = verifyBackup(metaProxy, backupMetadata); if (logger.isDebugEnabled()) logger.debug( "BackupVerification: metadata: {}, result: {}", backupMetadata, backupVerificationResult); if (backupVerificationResult.valid) { backupMetadata.setLastValidated(new Date(DateUtil.getInstant().toEpochMilli())); backupStatusMgr.update(backupMetadata); return Optional.of(backupVerificationResult); } } return Optional.empty(); } @Inject  BackupVerification(
            @Named("v1") IMetaProxy metaV1Proxy,
            @Named("v2") IMetaProxy metaV2Proxy,
            IBackupStatusMgr backupStatusMgr,
            Provider<AbstractBackupPath> abstractBackupPathProvider); IMetaProxy getMetaProxy(BackupVersion backupVersion); Optional<BackupVerificationResult> verifyBackup(
            BackupVersion backupVersion, boolean force, DateRange dateRange); List<BackupVerificationResult> verifyAllBackups(
            BackupVersion backupVersion, DateRange dateRange);  }
@Test public void illegalDateRange() throws UnsupportedTypeException { try { backupVerification.verifyBackup(BackupVersion.SNAPSHOT_BACKUP, false, null); Assert.assertTrue(false); } catch (IllegalArgumentException e) { Assert.assertTrue(true); } }
@Test public void noBackup() throws Exception { Optional<BackupVerificationResult> backupVerificationResultOptinal = backupVerification.verifyBackup( BackupVersion.SNAPSHOT_BACKUP, false, new DateRange(Instant.now(), Instant.now())); Assert.assertFalse(backupVerificationResultOptinal.isPresent()); backupVerificationResultOptinal = backupVerification.verifyBackup( BackupVersion.SNAPSHOT_META_SERVICE, false, new DateRange(Instant.now(), Instant.now())); Assert.assertFalse(backupVerificationResultOptinal.isPresent()); }
@Test public void verifyBackupVersion1() throws Exception { setUp(); Optional<BackupVerificationResult> backupVerificationResultOptinal = backupVerification.verifyBackup( BackupVersion.SNAPSHOT_BACKUP, false, new DateRange(backupDate + "," + backupDate)); Assert.assertTrue(backupVerificationResultOptinal.isPresent()); Assert.assertEquals(Instant.EPOCH, backupVerificationResultOptinal.get().snapshotInstant); Optional<BackupMetadata> backupMetadata = backupStatusMgr .getLatestBackupMetadata( BackupVersion.SNAPSHOT_BACKUP, new DateRange(backupDate + "," + backupDate)) .stream() .findFirst(); Assert.assertTrue(backupMetadata.isPresent()); Assert.assertNotNull(backupMetadata.get().getLastValidated()); backupMetadata = backupStatusMgr .getLatestBackupMetadata( BackupVersion.SNAPSHOT_META_SERVICE, new DateRange(backupDate + "," + backupDate)) .stream() .findFirst(); Assert.assertTrue(backupMetadata.isPresent()); Assert.assertNull(backupMetadata.get().getLastValidated()); }
@Test public void verifyBackupVersion2() throws Exception { setUp(); Optional<BackupVerificationResult> backupVerificationResultOptinal = backupVerification.verifyBackup( BackupVersion.SNAPSHOT_META_SERVICE, false, new DateRange(backupDate + "," + backupDate)); Assert.assertTrue(backupVerificationResultOptinal.isPresent()); Assert.assertEquals(Instant.EPOCH, backupVerificationResultOptinal.get().snapshotInstant); Assert.assertEquals("some_random", backupVerificationResultOptinal.get().remotePath); Optional<BackupMetadata> backupMetadata = backupStatusMgr .getLatestBackupMetadata( BackupVersion.SNAPSHOT_META_SERVICE, new DateRange(backupDate + "," + backupDate)) .stream() .findFirst(); Assert.assertTrue(backupMetadata.isPresent()); Assert.assertNotNull(backupMetadata.get().getLastValidated()); backupVerificationResultOptinal = backupVerification.verifyBackup( BackupVersion.SNAPSHOT_META_SERVICE, false, new DateRange(backupDate + "," + backupDate)); Assert.assertTrue(backupVerificationResultOptinal.isPresent()); Assert.assertEquals( DateUtil.parseInstant(backupDate), backupVerificationResultOptinal.get().snapshotInstant); Assert.assertNotEquals("some_random", backupVerificationResultOptinal.get().remotePath); Assert.assertEquals( location.subpath(1, location.getNameCount()).toString(), backupVerificationResultOptinal.get().remotePath); backupMetadata = backupStatusMgr .getLatestBackupMetadata( BackupVersion.SNAPSHOT_BACKUP, new DateRange(backupDate + "," + backupDate)) .stream() .findFirst(); Assert.assertTrue(backupMetadata.isPresent()); Assert.assertNull(backupMetadata.get().getLastValidated()); }