use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.
the class VideoSegmenterTest method testAnalyzeOptimization.
@Test
public void testAnalyzeOptimization() throws Exception {
Job receipt = vsegmenter1.segment(track1);
JobBarrier jobBarrier = new JobBarrier(null, serviceRegistry1, 1000, receipt);
jobBarrier.waitForJobs();
Catalog catalog = (Catalog) MediaPackageElementParser.getFromXml(receipt.getPayload());
Mpeg7Catalog mpeg7 = new Mpeg7CatalogImpl(catalog.getURI().toURL().openStream());
// Is there multimedia content in the mpeg7?
assertTrue("Audiovisual content was expected", mpeg7.hasVideoContent());
assertNotNull("Audiovisual content expected", mpeg7.multimediaContent().next().elements().hasNext());
MultimediaContentType contentType = mpeg7.multimediaContent().next().elements().next();
// Is there at least one segment?
TemporalDecomposition<? extends Segment> segments = contentType.getTemporalDecomposition();
Iterator<? extends Segment> si = segments.segments();
assertTrue(si.hasNext());
// Is the error of optimization small enough?
int segmentCounter = 0;
for (; si.hasNext(); ++segmentCounter) {
si.next();
}
float error = Math.abs((segmentCounter - vsegmenter1.prefNumber) / (float) vsegmenter1.prefNumber);
assertTrue("Error of Optimization is too big", error <= vsegmenter1.maxError);
}
use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.
the class VideoSegmenterTest method testAnalyze.
@Test
public void testAnalyze() throws Exception {
Job receipt = vsegmenter.segment(track);
JobBarrier jobBarrier = new JobBarrier(null, serviceRegistry, 1000, receipt);
jobBarrier.waitForJobs();
Catalog catalog = (Catalog) MediaPackageElementParser.getFromXml(receipt.getPayload());
Mpeg7Catalog mpeg7 = new Mpeg7CatalogImpl(catalog.getURI().toURL().openStream());
// Is there multimedia content in the mpeg7?
assertTrue("Audiovisual content was expected", mpeg7.hasVideoContent());
assertNotNull("Audiovisual content expected", mpeg7.multimediaContent().next().elements().hasNext());
MultimediaContentType contentType = mpeg7.multimediaContent().next().elements().next();
// Is there at least one segment?
TemporalDecomposition<? extends Segment> segments = contentType.getTemporalDecomposition();
Iterator<? extends Segment> si = segments.segments();
assertTrue(si.hasNext());
Segment firstSegment = si.next();
MediaTime firstSegmentMediaTime = firstSegment.getMediaTime();
long startTime = firstSegmentMediaTime.getMediaTimePoint().getTimeInMilliseconds();
long duration = firstSegmentMediaTime.getMediaDuration().getDurationInMilliseconds();
assertEquals("Unexpected start time of first segment", 0, startTime);
assertEquals("Unexpected duration of first segment", firstSegmentDuration, duration);
// What about the second one?
assertTrue("Video is expected to have more than one segment", si.hasNext());
Segment secondSegment = si.next();
MediaTime secondSegmentMediaTime = secondSegment.getMediaTime();
startTime = secondSegmentMediaTime.getMediaTimePoint().getTimeInMilliseconds();
duration = secondSegmentMediaTime.getMediaDuration().getDurationInMilliseconds();
assertEquals("Unexpected start time of second segment", firstSegmentDuration, startTime);
assertEquals("Unexpected duration of second segment", secondSegmentDuration, duration);
// There should be no third segment
assertFalse("Found an unexpected third video segment", si.hasNext());
}
use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.
the class VideoSegmenterTest method testAnalyzeOptimizedList.
@Test
public void testAnalyzeOptimizedList() throws Exception {
Job receipt = vsegmenter.segment(track);
JobBarrier jobBarrier = new JobBarrier(null, serviceRegistry, 1000, receipt);
jobBarrier.waitForJobs();
Catalog catalog = (Catalog) MediaPackageElementParser.getFromXml(receipt.getPayload());
Mpeg7Catalog mpeg7 = new Mpeg7CatalogImpl(catalog.getURI().toURL().openStream());
List<OptimizationStep> optimizedList = new LinkedList<OptimizationStep>();
OptimizationStep firstStep = new OptimizationStep(10, 0.015f, 46, 41, mpeg7, null);
OptimizationStep secondStep = new OptimizationStep(10, 0.167f, 34, 41, mpeg7, null);
OptimizationStep thirdStep = new OptimizationStep(10, 0.011f, 44, 41, mpeg7, null);
OptimizationStep fourthStep = new OptimizationStep(10, 0.200f, 23, 41, mpeg7, null);
// ~ 0.122
float error1 = (46 - 41) / (float) 41;
// ~ -0.171
float error2 = (34 - 41) / (float) 41;
// ~ 0.073
float error3 = (44 - 41) / (float) 41;
// ~ -0.439
float error4 = (23 - 41) / (float) 41;
optimizedList.add(firstStep);
optimizedList.add(secondStep);
optimizedList.add(thirdStep);
optimizedList.add(fourthStep);
Collections.sort(optimizedList);
// check if the errors were calculated correctly and whether the elements are in the correct order
assertEquals("first element of optimized list incorrect", error3, optimizedList.get(0).getError(), 0.0001f);
assertEquals("second element of optimized list incorrect", error1, optimizedList.get(1).getError(), 0.0001f);
assertEquals("third element of optimized list incorrect", error4, optimizedList.get(2).getError(), 0.0001f);
assertEquals("fourth element of optimized list incorrect", error2, optimizedList.get(3).getError(), 0.0001f);
assertTrue("first error in optimized list is not positive", optimizedList.get(0).getError() >= 0);
assertTrue("second error in optimized list is not bigger than first", optimizedList.get(1).getError() > optimizedList.get(0).getError());
assertTrue("third error in optimized list is not negative", optimizedList.get(2).getError() < 0);
assertTrue("fourth error in optimized list is smaller than third", optimizedList.get(3).getError() > optimizedList.get(2).getError());
}
use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.
the class StreamingDistributionServiceTest method testDistribution.
@Test
public void testDistribution() throws Exception {
// Distribute the mediapackage and all of its elements
Job job1 = service.distribute("engage-player", mp, "track-1");
Job job2 = service.distribute("oai-pmh", mp, "track-1");
JobBarrier jobBarrier = new JobBarrier(null, serviceRegistry, 500, job1, job2);
jobBarrier.waitForJobs();
// Add the new elements to the mediapackage
mp.add(MediaPackageElementParser.getFromXml(job1.getPayload()));
mp.add(MediaPackageElementParser.getFromXml(job2.getPayload()));
File mpDir = new File(distributionRoot, PathSupport.path(defaultOrganization.getId(), "engage-player", mp.getIdentifier().compact()));
File mediaDir = new File(mpDir, "track-1");
Assert.assertTrue(mediaDir.exists());
// the filenames are changed to reflect the element ID
Assert.assertTrue(new File(mediaDir, "media.mov").exists());
}
use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.
the class ServiceRegistryJpaImplTest method testHostAddedToPriorityListExceptWorkflowType.
@Test
public void testHostAddedToPriorityListExceptWorkflowType() throws Exception {
if (serviceRegistryJpaImpl.scheduledExecutor != null)
serviceRegistryJpaImpl.scheduledExecutor.shutdown();
serviceRegistryJpaImpl.scheduledExecutor = Executors.newScheduledThreadPool(1);
serviceRegistryJpaImpl.activate(null);
Hashtable<String, String> properties = new Hashtable<>();
properties.put("dispatchinterval", "1000");
serviceRegistryJpaImpl.updated(properties);
registerTestHostAndService();
serviceRegistryJpaImpl.registerService(TEST_SERVICE_3, TEST_HOST, TEST_PATH_3);
Job testJob = serviceRegistryJpaImpl.createJob(TEST_HOST, TEST_SERVICE_3, TEST_OPERATION, null, null, true, null);
JobBarrier barrier = new JobBarrier(null, serviceRegistryJpaImpl, testJob);
try {
barrier.waitForJobs(2000);
Assert.fail();
} catch (Exception e) {
Assert.assertEquals(0, serviceRegistryJpaImpl.dispatchPriorityList.size());
}
}
Aggregations