DeleteHlsTaskRunner extends BaseHlsTaskRunner { public String performTask(String taskParameters) { DeleteStreamingTaskParameters taskParams = DeleteStreamingTaskParameters.deserialize(taskParameters); String spaceId = taskParams.getSpaceId(); log.info("Performing " + TASK_NAME + " task on space " + spaceId); String bucketName = unwrappedS3Provider.getBucketName(spaceId); DeleteStreamingTaskResult taskResult = new DeleteStreamingTaskResult(); removeHlsStreamingHostFromSpaceProps(spaceId); s3Client.deleteBucketPolicy(bucketName); s3Client.deleteBucketCrossOriginConfiguration(bucketName); List<DistributionSummary> existingDists = getAllExistingWebDistributions(bucketName); if (existingDists != null && existingDists.size() > 0) { for (DistributionSummary existingDist : existingDists) { String distId = existingDist.getId(); if (existingDist.isEnabled()) { setDistributionState(distId, false); } Runnable deleteWorker = () -> waitAndDelete(distId); new Thread(deleteWorker).start(); } } else { throw new RuntimeException("No streaming distribution " + "exists for space " + spaceId); } taskResult.setResult(TASK_NAME + " task completed successfully"); String toReturn = taskResult.serialize(); log.info("Result of " + TASK_NAME + " task: " + toReturn); return toReturn; } DeleteHlsTaskRunner(StorageProvider s3Provider,
                               S3StorageProvider unwrappedS3Provider,
                               AmazonS3 s3Client,
                               AmazonCloudFrontClient cfClient); String getName(); String performTask(String taskParameters);  }
@Test public void testPerformTaskNoDistribution() { EasyMock.expect(unwrappedS3Provider.getBucketName(EasyMock.isA(String.class))) .andReturn(bucketName); Map<String, String> props = new HashMap<>(); props.put(HLS_STREAMING_HOST_PROP, domainName); EasyMock.expect(s3Provider.getSpaceProperties(spaceId)) .andReturn(props).once(); unwrappedS3Provider.setNewSpaceProperties(EasyMock.eq(spaceId), EasyMock.isA(Map.class)); EasyMock.expectLastCall().once(); s3Client.deleteBucketPolicy(EasyMock.eq(bucketName)); EasyMock.expectLastCall().once(); s3Client.deleteBucketCrossOriginConfiguration(EasyMock.eq(bucketName)); EasyMock.expectLastCall().once(); ListDistributionsResult listDistResult = new ListDistributionsResult().withDistributionList( new DistributionList().withItems(new ArrayList()).withIsTruncated(false)); EasyMock.expect(cfClient.listDistributions(EasyMock.isA(ListDistributionsRequest.class))) .andReturn(listDistResult) .once(); DeleteHlsTaskRunner runner = new DeleteHlsTaskRunner(s3Provider, unwrappedS3Provider, s3Client, cfClient); replayMocks(); try { runner.performTask(null); fail("Exception expected"); } catch (Exception expected) { assertNotNull(expected); } DeleteStreamingTaskParameters taskParams = new DeleteStreamingTaskParameters(); taskParams.setSpaceId(spaceId); try { runner.performTask(taskParams.serialize()); fail("Exception expected"); } catch (Exception expected) { assertNotNull(expected); } }