BackupV2Service implements IService { @Override public void scheduleService() throws Exception { TaskTimer snapshotMetaTimer = SnapshotMetaTask.getTimer(configuration, backupRestoreConfig); scheduleTask(scheduler, SnapshotMetaTask.class, snapshotMetaTimer); if (snapshotMetaTimer != null) { snapshotMetaTask.uploadFiles(); scheduleTask( scheduler, BackupTTLTask.class, BackupTTLTask.getTimer(backupRestoreConfig)); scheduleTask( scheduler, BackupVerificationTask.class, BackupVerificationTask.getTimer(backupRestoreConfig)); } else { scheduler.deleteTask(BackupTTLTask.JOBNAME); scheduler.deleteTask(BackupVerificationTask.JOBNAME); } scheduleTask( scheduler, IncrementalBackup.class, IncrementalBackup.getTimer(configuration, backupRestoreConfig)); } @Inject  BackupV2Service(
            IConfiguration configuration,
            IBackupRestoreConfig backupRestoreConfig,
            PriamScheduler scheduler,
            SnapshotMetaTask snapshotMetaService,
            CassandraTunerService cassandraTunerService); @Override void scheduleService(); @Override void updateServicePre(); @Override void updateServicePost();  }
@Test public void testBackupDisabled( @Mocked IConfiguration configuration, @Mocked IBackupRestoreConfig backupRestoreConfig) throws Exception { new Expectations() { { backupRestoreConfig.getSnapshotMetaServiceCronExpression(); result = "-1"; configuration.getDataFileLocation(); result = "target/data"; } }; Path dummyDataDirectoryLocation = Paths.get(configuration.getDataFileLocation()); Instant snapshotInstant = DateUtil.getInstant(); String snapshotName = snapshotMetaTask.generateSnapshotName(snapshotInstant); BackupFileUtils.generateDummyFiles( dummyDataDirectoryLocation, 2, 3, 3, AbstractBackup.SNAPSHOT_FOLDER, snapshotName, true); String snapshotV1Name = DateUtil.formatInstant(DateUtil.yyyyMMdd, snapshotInstant); BackupFileUtils.generateDummyFiles( dummyDataDirectoryLocation, 2, 3, 3, AbstractBackup.SNAPSHOT_FOLDER, snapshotV1Name, false); IService backupService = new BackupV2Service( configuration, backupRestoreConfig, scheduler, snapshotMetaTask, cassandraTunerService); backupService.scheduleService(); Assert.assertTrue(scheduler.getScheduler().getJobGroupNames().isEmpty()); Set<Path> backupPaths = AbstractBackup.getBackupDirectories(configuration, AbstractBackup.SNAPSHOT_FOLDER); for (Path backupPath : backupPaths) { Assert.assertFalse(Files.exists(Paths.get(backupPath.toString(), snapshotName))); Assert.assertTrue(Files.exists(Paths.get(backupPath.toString(), snapshotV1Name))); } }
@Test public void testBackupEnabled( @Mocked IConfiguration configuration, @Mocked IBackupRestoreConfig backupRestoreConfig) throws Exception { new Expectations() { { backupRestoreConfig.getSnapshotMetaServiceCronExpression(); result = "0 0 0/1 1/1 * ? *"; backupRestoreConfig.getBackupTTLMonitorPeriodInSec(); result = 600; backupRestoreConfig.getBackupVerificationCronExpression(); result = "0 0 0/1 1/1 * ? *"; backupRestoreConfig.enableV2Backups(); result = true; configuration.isIncrementalBackupEnabled(); result = true; configuration.getBackupCronExpression(); result = "-1"; } }; IService backupService = new BackupV2Service( configuration, backupRestoreConfig, scheduler, snapshotMetaTask, cassandraTunerService); backupService.scheduleService(); Assert.assertEquals(4, scheduler.getScheduler().getJobKeys(null).size()); }
@Test public void testBackup( @Mocked IConfiguration configuration, @Mocked IBackupRestoreConfig backupRestoreConfig) throws Exception { new Expectations() { { backupRestoreConfig.getSnapshotMetaServiceCronExpression(); result = "0 0 0/1 1/1 * ? *"; backupRestoreConfig.getBackupTTLMonitorPeriodInSec(); result = 600; backupRestoreConfig.getBackupVerificationCronExpression(); result = "0 0 0/1 1/1 * ? *"; configuration.isIncrementalBackupEnabled(); result = false; configuration.getDataFileLocation(); result = "target/data"; } }; IService backupService = new BackupV2Service( configuration, backupRestoreConfig, scheduler, snapshotMetaTask, cassandraTunerService); backupService.scheduleService(); Assert.assertEquals(3, scheduler.getScheduler().getJobKeys(null).size()); }
@Test public void updateService( @Mocked IConfiguration configuration, @Mocked IBackupRestoreConfig backupRestoreConfig, @Mocked JMXNodeTool nodeTool, @Mocked TuneCassandra tuneCassandra) throws Exception { new Expectations() { { backupRestoreConfig.getSnapshotMetaServiceCronExpression(); result = "0 0 0/1 1/1 * ? *"; result = "0 0 0/1 1/1 * ? *"; result = "-1"; result = "-1"; configuration.isIncrementalBackupEnabled(); result = true; backupRestoreConfig.enableV2Backups(); result = true; backupRestoreConfig.getBackupVerificationCronExpression(); result = "-1"; backupRestoreConfig.getBackupTTLMonitorPeriodInSec(); result = 600; configuration.getBackupCronExpression(); result = "-1"; } }; IService backupService = new BackupV2Service( configuration, backupRestoreConfig, scheduler, snapshotMetaTask, cassandraTunerService); backupService.scheduleService(); Assert.assertEquals(3, scheduler.getScheduler().getJobKeys(null).size()); backupService.onChangeUpdateService(); Assert.assertEquals(0, scheduler.getScheduler().getJobKeys(null).size()); }