CompleteRestoreTaskRunner implements TaskRunner { @Override public String performTask(String taskParameters) { CompleteRestoreTaskParameters taskParams = CompleteRestoreTaskParameters.deserialize(taskParameters); String spaceId = taskParams.getSpaceId(); int daysToExpire = taskParams.getDaysToExpire(); String bucketName = unwrappedSnapshotProvider.getBucketName(spaceId); log.info("Performing Complete Restore Task for spaceID: " + spaceId + ". Restored content will expire in " + daysToExpire + " days"); BucketLifecycleConfiguration.Rule expireRule = new BucketLifecycleConfiguration.Rule() .withId("clear-content-rule") .withExpirationInDays(daysToExpire) .withStatus(BucketLifecycleConfiguration.ENABLED.toString()); List<BucketLifecycleConfiguration.Rule> rules = new ArrayList<>(); rules.add(expireRule); BucketLifecycleConfiguration configuration = new BucketLifecycleConfiguration().withRules(rules); s3Client.setBucketLifecycleConfiguration(bucketName, configuration); log.info("Complete Restore Task for space " + spaceId + " completed successfully"); String result = "Complete restore was successful"; return new CompleteSnapshotTaskResult(result).serialize(); } CompleteRestoreTaskRunner(StorageProvider snapshotProvider,
                                     SnapshotStorageProvider unwrappedSnapshotProvider,
                                     AmazonS3 s3Client); @Override String getName(); @Override String performTask(String taskParameters);  }
@Test public void testPerformTask() { String spaceId = "space-id"; String bucketName = "bucket-name"; int daysToExpire = 42; EasyMock.expect(unwrappedSnapshotProvider.getBucketName(spaceId)) .andReturn(bucketName); Capture<BucketLifecycleConfiguration> lifecycleConfigCapture = new Capture<>(); s3Client.setBucketLifecycleConfiguration(EasyMock.eq(bucketName), EasyMock.capture( lifecycleConfigCapture)); EasyMock.expectLastCall().once(); replayMocks(); taskRunner.performTask("{\"spaceId\":\"" + spaceId + "\"," + "\"daysToExpire\":" + daysToExpire + "}"); BucketLifecycleConfiguration lifecycleConfig = lifecycleConfigCapture.getValue(); BucketLifecycleConfiguration.Rule rule = lifecycleConfig.getRules().get(0); assertEquals(daysToExpire, rule.getExpirationInDays()); assertEquals("clear-content-rule", rule.getId()); assertEquals("Enabled", rule.getStatus()); }