@Test public void shouldCreateBackupIfEnabledAndLastBackupAndStartupWasNotToday() throws Exception { when(genericStorage.get("FirstStart", LocalDateTime.class)).thenReturn(Optional.of(LocalDateTime.now(testee.clock).minus(200, ChronoUnit.DAYS))); when(genericStorage.get(BackupTask.KEY, BackupData.class)).thenReturn(Optional.of(new BackupData(LocalDateTime.now(testee.clock).minus(8, ChronoUnit.DAYS)))); testee.createBackup(); verify(backupAndRestore).backup(); verify(genericStorage).save(eq("BackupData"), backupDataArgumentCaptor.capture()); BackupData backupData = backupDataArgumentCaptor.getValue(); assertThat(backupData.getLastBackup(), is(LocalDateTime.now(testee.clock))); }
@HydraTask(configId = "Backup", name = "Backup", interval = HOUR) public void createBackup() { boolean backupEnabled = configProvider.getBaseConfig().getMain().getBackupEveryXDays().isPresent(); if (!backupEnabled) { logger.debug("Automatic backup is disabled"); return; } int backupEveryXDays = configProvider.getBaseConfig().getMain().getBackupEveryXDays().get(); Optional<LocalDateTime> firstStartOptional = genericStorage.get("FirstStart", LocalDateTime.class); if (!firstStartOptional.isPresent()) { logger.debug("First start date time not set (for some reason), aborting backup"); return; } long daysSinceFirstStart = ChronoUnit.DAYS.between(firstStartOptional.get(), LocalDateTime.now(clock)); if (daysSinceFirstStart < backupEveryXDays) { logger.debug("{} days since first start but backup is to be executed every {} days", daysSinceFirstStart, backupEveryXDays); return; } Optional<BackupData> backupData = genericStorage.get(KEY, BackupData.class); if (!backupData.isPresent()) { logger.debug("Executing first backup: {} days since first start and backup is to be executed every {} days", daysSinceFirstStart, backupEveryXDays); executeBackup(); return; } long daysSinceLastBackup = ChronoUnit.DAYS.between(backupData.get().getLastBackup(), LocalDateTime.now(clock)); if (daysSinceLastBackup >= backupEveryXDays) { logger.debug("Executing backup: {} days since last backup and backup is to be executed every {} days", daysSinceLastBackup, backupEveryXDays); executeBackup(); } }
BackupTask { @HydraTask(configId = "Backup", name = "Backup", interval = HOUR) public void createBackup() { boolean backupEnabled = configProvider.getBaseConfig().getMain().getBackupEveryXDays().isPresent(); if (!backupEnabled) { logger.debug("Automatic backup is disabled"); return; } int backupEveryXDays = configProvider.getBaseConfig().getMain().getBackupEveryXDays().get(); Optional<LocalDateTime> firstStartOptional = genericStorage.get("FirstStart", LocalDateTime.class); if (!firstStartOptional.isPresent()) { logger.debug("First start date time not set (for some reason), aborting backup"); return; } long daysSinceFirstStart = ChronoUnit.DAYS.between(firstStartOptional.get(), LocalDateTime.now(clock)); if (daysSinceFirstStart < backupEveryXDays) { logger.debug("{} days since first start but backup is to be executed every {} days", daysSinceFirstStart, backupEveryXDays); return; } Optional<BackupData> backupData = genericStorage.get(KEY, BackupData.class); if (!backupData.isPresent()) { logger.debug("Executing first backup: {} days since first start and backup is to be executed every {} days", daysSinceFirstStart, backupEveryXDays); executeBackup(); return; } long daysSinceLastBackup = ChronoUnit.DAYS.between(backupData.get().getLastBackup(), LocalDateTime.now(clock)); if (daysSinceLastBackup >= backupEveryXDays) { logger.debug("Executing backup: {} days since last backup and backup is to be executed every {} days", daysSinceLastBackup, backupEveryXDays); executeBackup(); } } }
BackupTask { @HydraTask(configId = "Backup", name = "Backup", interval = HOUR) public void createBackup() { boolean backupEnabled = configProvider.getBaseConfig().getMain().getBackupEveryXDays().isPresent(); if (!backupEnabled) { logger.debug("Automatic backup is disabled"); return; } int backupEveryXDays = configProvider.getBaseConfig().getMain().getBackupEveryXDays().get(); Optional<LocalDateTime> firstStartOptional = genericStorage.get("FirstStart", LocalDateTime.class); if (!firstStartOptional.isPresent()) { logger.debug("First start date time not set (for some reason), aborting backup"); return; } long daysSinceFirstStart = ChronoUnit.DAYS.between(firstStartOptional.get(), LocalDateTime.now(clock)); if (daysSinceFirstStart < backupEveryXDays) { logger.debug("{} days since first start but backup is to be executed every {} days", daysSinceFirstStart, backupEveryXDays); return; } Optional<BackupData> backupData = genericStorage.get(KEY, BackupData.class); if (!backupData.isPresent()) { logger.debug("Executing first backup: {} days since first start and backup is to be executed every {} days", daysSinceFirstStart, backupEveryXDays); executeBackup(); return; } long daysSinceLastBackup = ChronoUnit.DAYS.between(backupData.get().getLastBackup(), LocalDateTime.now(clock)); if (daysSinceLastBackup >= backupEveryXDays) { logger.debug("Executing backup: {} days since last backup and backup is to be executed every {} days", daysSinceLastBackup, backupEveryXDays); executeBackup(); } }  }
BackupTask { @HydraTask(configId = "Backup", name = "Backup", interval = HOUR) public void createBackup() { boolean backupEnabled = configProvider.getBaseConfig().getMain().getBackupEveryXDays().isPresent(); if (!backupEnabled) { logger.debug("Automatic backup is disabled"); return; } int backupEveryXDays = configProvider.getBaseConfig().getMain().getBackupEveryXDays().get(); Optional<LocalDateTime> firstStartOptional = genericStorage.get("FirstStart", LocalDateTime.class); if (!firstStartOptional.isPresent()) { logger.debug("First start date time not set (for some reason), aborting backup"); return; } long daysSinceFirstStart = ChronoUnit.DAYS.between(firstStartOptional.get(), LocalDateTime.now(clock)); if (daysSinceFirstStart < backupEveryXDays) { logger.debug("{} days since first start but backup is to be executed every {} days", daysSinceFirstStart, backupEveryXDays); return; } Optional<BackupData> backupData = genericStorage.get(KEY, BackupData.class); if (!backupData.isPresent()) { logger.debug("Executing first backup: {} days since first start and backup is to be executed every {} days", daysSinceFirstStart, backupEveryXDays); executeBackup(); return; } long daysSinceLastBackup = ChronoUnit.DAYS.between(backupData.get().getLastBackup(), LocalDateTime.now(clock)); if (daysSinceLastBackup >= backupEveryXDays) { logger.debug("Executing backup: {} days since last backup and backup is to be executed every {} days", daysSinceLastBackup, backupEveryXDays); executeBackup(); } }  @HydraTask(configId = "Backup", name = "Backup", interval = HOUR) void createBackup(); }
BackupTask { @HydraTask(configId = "Backup", name = "Backup", interval = HOUR) public void createBackup() { boolean backupEnabled = configProvider.getBaseConfig().getMain().getBackupEveryXDays().isPresent(); if (!backupEnabled) { logger.debug("Automatic backup is disabled"); return; } int backupEveryXDays = configProvider.getBaseConfig().getMain().getBackupEveryXDays().get(); Optional<LocalDateTime> firstStartOptional = genericStorage.get("FirstStart", LocalDateTime.class); if (!firstStartOptional.isPresent()) { logger.debug("First start date time not set (for some reason), aborting backup"); return; } long daysSinceFirstStart = ChronoUnit.DAYS.between(firstStartOptional.get(), LocalDateTime.now(clock)); if (daysSinceFirstStart < backupEveryXDays) { logger.debug("{} days since first start but backup is to be executed every {} days", daysSinceFirstStart, backupEveryXDays); return; } Optional<BackupData> backupData = genericStorage.get(KEY, BackupData.class); if (!backupData.isPresent()) { logger.debug("Executing first backup: {} days since first start and backup is to be executed every {} days", daysSinceFirstStart, backupEveryXDays); executeBackup(); return; } long daysSinceLastBackup = ChronoUnit.DAYS.between(backupData.get().getLastBackup(), LocalDateTime.now(clock)); if (daysSinceLastBackup >= backupEveryXDays) { logger.debug("Executing backup: {} days since last backup and backup is to be executed every {} days", daysSinceLastBackup, backupEveryXDays); executeBackup(); } }  @HydraTask(configId = "Backup", name = "Backup", interval = HOUR) void createBackup(); static final String KEY; }