BackupService implements IService { @Override public void scheduleService() throws Exception { TaskTimer snapshotTimer = SnapshotBackup.getTimer(config); scheduleTask(scheduler, SnapshotBackup.class, snapshotTimer); if (snapshotTimer != null) { scheduleTask(scheduler, UpdateCleanupPolicy.class, UpdateCleanupPolicy.getTimer()); scheduleTask( scheduler, CommitLogBackupTask.class, CommitLogBackupTask.getTimer(config)); } scheduleTask( scheduler, IncrementalBackup.class, IncrementalBackup.getTimer(config, backupRestoreConfig)); } @Inject  BackupService(
            IConfiguration config,
            IBackupRestoreConfig backupRestoreConfig,
            PriamScheduler priamScheduler,
            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() { { configuration.getBackupCronExpression(); result = "-1"; configuration.getDataFileLocation(); result = "target/data"; } }; Path dummyDataDirectoryLocation = Paths.get(configuration.getDataFileLocation()); Instant snapshotInstant = DateUtil.getInstant(); String snapshotV1Name = DateUtil.formatInstant(DateUtil.yyyyMMdd, snapshotInstant); BackupFileUtils.generateDummyFiles( dummyDataDirectoryLocation, 2, 3, 3, AbstractBackup.SNAPSHOT_FOLDER, snapshotV1Name, true); String snapshotName = "meta_v2_" + snapshotV1Name; BackupFileUtils.generateDummyFiles( dummyDataDirectoryLocation, 2, 3, 3, AbstractBackup.SNAPSHOT_FOLDER, snapshotName, false); IService backupService = new BackupService( configuration, backupRestoreConfig, scheduler, cassandraTunerService); backupService.scheduleService(); Assert.assertEquals(0, scheduler.getScheduler().getJobKeys(null).size()); Set<Path> backupPaths = AbstractBackup.getBackupDirectories(configuration, AbstractBackup.SNAPSHOT_FOLDER); for (Path backupPath : backupPaths) { Assert.assertTrue(Files.exists(Paths.get(backupPath.toString(), snapshotName))); Assert.assertFalse(Files.exists(Paths.get(backupPath.toString(), snapshotV1Name))); } }
@Test public void testBackupEnabled( @Mocked IConfiguration configuration, @Mocked IBackupRestoreConfig backupRestoreConfig) throws Exception { new Expectations() { { configuration.getBackupCronExpression(); result = "0 0/1 * 1/1 * ? *"; configuration.isIncrementalBackupEnabled(); result = false; } }; IService backupService = new BackupService( configuration, backupRestoreConfig, scheduler, cassandraTunerService); backupService.scheduleService(); Assert.assertEquals(2, scheduler.getScheduler().getJobKeys(null).size()); }
@Test public void testBackupEnabledWithIncremental( @Mocked IConfiguration configuration, @Mocked IBackupRestoreConfig backupRestoreConfig) throws Exception { new Expectations() { { configuration.getBackupCronExpression(); result = "0 0/1 * 1/1 * ? *"; configuration.isIncrementalBackupEnabled(); result = true; } }; IService backupService = new BackupService( configuration, backupRestoreConfig, scheduler, 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() { { configuration.getBackupCronExpression(); result = "0 0/1 * 1/1 * ? *"; result = "0 0/1 * 1/1 * ? *"; result = "-1"; result = "-1"; configuration.isIncrementalBackupEnabled(); result = true; backupRestoreConfig.enableV2Backups(); result = true; backupRestoreConfig.getSnapshotMetaServiceCronExpression(); result = "0 0/1 * 1/1 * ? *"; } }; IService backupService = new BackupService( configuration, backupRestoreConfig, scheduler, cassandraTunerService); backupService.scheduleService(); Assert.assertEquals(3, scheduler.getScheduler().getJobKeys(null).size()); System.out.println("After updated"); backupService.onChangeUpdateService(); System.out.println(scheduler.getScheduler().getJobKeys(null)); Assert.assertEquals(2, scheduler.getScheduler().getJobKeys(null).size()); }