GetUrlHlsTaskRunner extends BaseHlsTaskRunner { public String performTask(String taskParameters) { GetHlsUrlTaskParameters taskParams = GetHlsUrlTaskParameters.deserialize(taskParameters); String spaceId = taskParams.getSpaceId(); String contentId = taskParams.getContentId(); log.info("Performing " + TASK_NAME + " task with parameters: spaceId=" + spaceId + ", contentId=" + contentId); String bucketName = unwrappedS3Provider.getBucketName(spaceId); GetUrlTaskResult taskResult = new GetUrlTaskResult(); checkThatStreamingServiceIsEnabled(spaceId, TASK_NAME); DistributionSummary existingDist = getExistingDistribution(bucketName); if (null == existingDist) { throw new UnsupportedTaskException(TASK_NAME, "The " + TASK_NAME + " task can only be used after a space has " + "been configured to enable HLS streaming. Use " + StorageTaskConstants.ENABLE_HLS_TASK_NAME + " to enable HLS streaming on this space."); } String domainName = existingDist.getDomainName(); taskResult.setStreamUrl("https: String toReturn = taskResult.serialize(); log.info("Result of " + TASK_NAME + " task: " + toReturn); return toReturn; } GetUrlHlsTaskRunner(StorageProvider s3Provider,
                               S3StorageProvider unwrappedS3Provider,
                               AmazonCloudFrontClient cfClient); String getName(); String performTask(String taskParameters);  }
@Test public void testPerformTaskNoDistributionDomain() { EasyMock.expect(unwrappedS3Provider.getBucketName(EasyMock.isA(String.class))) .andReturn(bucketName); EasyMock.expect(s3Provider.getSpaceProperties(spaceId)) .andReturn(new HashMap<>()); GetUrlHlsTaskRunner runner = new GetUrlHlsTaskRunner(s3Provider, unwrappedS3Provider, cfClient); replayMocks(); try { runner.performTask(null); fail("Exception expected"); } catch (Exception expected) { assertNotNull(expected); } GetHlsUrlTaskParameters taskParams = new GetHlsUrlTaskParameters(); taskParams.setSpaceId(spaceId); taskParams.setContentId(contentId); try { runner.performTask(taskParams.serialize()); fail("Exception expected"); } catch (Exception expected) { assertNotNull(expected); } }
@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); ListDistributionsResult distSummaryResult = new ListDistributionsResult().withDistributionList(new DistributionList()); EasyMock.expect(cfClient.listDistributions(EasyMock.isA(ListDistributionsRequest.class))) .andReturn(distSummaryResult); GetUrlHlsTaskRunner runner = new GetUrlHlsTaskRunner(s3Provider, unwrappedS3Provider, cfClient); replayMocks(); GetHlsUrlTaskParameters taskParams = new GetHlsUrlTaskParameters(); taskParams.setSpaceId(spaceId); taskParams.setContentId(contentId); try { runner.performTask(taskParams.serialize()); fail("Exception expected"); } catch (Exception expected) { assertNotNull(expected); } }
@Test public void testPerformTaskSuccess() { 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); cfClientExpectValidDistribution(cfClient); GetUrlHlsTaskRunner runner = new GetUrlHlsTaskRunner(s3Provider, unwrappedS3Provider, cfClient); replayMocks(); GetHlsUrlTaskParameters taskParams = new GetHlsUrlTaskParameters(); taskParams.setSpaceId(spaceId); taskParams.setContentId(contentId); String results = runner.performTask(taskParams.serialize()); assertNotNull(results); GetUrlTaskResult taskResult = GetUrlTaskResult.deserialize(results); assertNotNull(taskResult); String streamUrl = taskResult.getStreamUrl(); assertNotNull(streamUrl); assertEquals("https: }