use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.
the class SearchServiceImplTest method testDeleteIndexNotInDbMediaPackage.
/**
* Test removal from the search index even when it is missing from database #MH-11616
*/
@Test
public void testDeleteIndexNotInDbMediaPackage() throws Exception {
MediaPackage mediaPackage = getMediaPackage("/manifest-simple.xml");
// Make sure our mocked ACL has the read and write permission
acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, READ.toString(), true));
acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, WRITE.toString(), true));
// Add the media package to the search index
Job job = service.add(mediaPackage);
JobBarrier barrier = new JobBarrier(null, serviceRegistry, 1000, job);
barrier.waitForJobs();
// Delete the mediapackage from persistence (leave it in index)
Date dateDeletedFromDb = new Date();
searchDatabase.deleteMediaPackage(mediaPackage.getIdentifier().toString(), dateDeletedFromDb);
// Verify it is not marked as deleted
SearchQuery qDel = new SearchQuery();
qDel.withDeletedSince(dateDeletedFromDb);
assertEquals(0, service.getByQuery(qDel).size());
// Verify that it is still active in index
SearchQuery q = new SearchQuery();
q.includeEpisodes(true);
q.includeSeries(false);
q.withId(mediaPackage.getIdentifier().toString());
assertEquals(1, service.getByQuery(q).size());
// Try delete it
job = service.delete(mediaPackage.getIdentifier().toString());
barrier = new JobBarrier(null, serviceRegistry, 1000, job);
barrier.waitForJobs();
assertEquals("Job to delete mediapackage did not finish", Job.Status.FINISHED, job.getStatus());
// Verify that it is now not active in the index
assertEquals(0, service.getByQuery(q).size());
// Verify that it is now marked as deleted in the index
q = new SearchQuery();
q.withDeletedSince(dateDeletedFromDb);
assertEquals(1, service.getByQuery(q).size());
}
use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.
the class SearchServiceImplTest method testAddSimpleMediaPackage.
/**
* Adds a simple media package that has a dublin core for the episode only.
*/
@Test
public void testAddSimpleMediaPackage() throws Exception {
MediaPackage mediaPackage = getMediaPackage("/manifest-simple.xml");
// Make sure our mocked ACL has the read and write permission
acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, READ.toString(), true));
acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, WRITE.toString(), true));
// Add the media package to the search index
Job job = service.add(mediaPackage);
JobBarrier barrier = new JobBarrier(null, serviceRegistry, 1000, job);
barrier.waitForJobs();
assertEquals("Job to add mediapckage did not finish", Job.Status.FINISHED, job.getStatus());
// Make sure it's properly indexed and returned
SearchQuery q = new SearchQuery();
q.includeEpisodes(true);
q.includeSeries(false);
q.withId("10.0000/1");
assertEquals(1, service.getByQuery(q).size());
q = new SearchQuery();
q.includeEpisodes(true);
q.includeSeries(false);
assertEquals(1, service.getByQuery(q).size());
// Test for various fields
q = new SearchQuery();
q.includeEpisodes(true);
q.includeSeries(false);
q.withId("10.0000/1");
SearchResult result = service.getByQuery(q);
assertEquals(1, result.getTotalSize());
SearchResultItem resultItem = result.getItems()[0];
assertNotNull(resultItem.getMediaPackage());
assertEquals(1, resultItem.getMediaPackage().getCatalogs().length);
}
use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.
the class SearchServiceImplTest method testGetMediaPackage.
/**
* Adds a simple media package that has a dublin core for the episode only.
*/
@Test
public void testGetMediaPackage() throws Exception {
MediaPackage mediaPackage = getMediaPackage("/manifest-simple.xml");
// Make sure our mocked ACL has the read and write permission
acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, READ.toString(), true));
acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, WRITE.toString(), true));
// Add the media package to the search index
Job job = service.add(mediaPackage);
JobBarrier barrier = new JobBarrier(null, serviceRegistry, 1000, job);
barrier.waitForJobs();
assertEquals("Job to add mediapckage did not finish", Job.Status.FINISHED, job.getStatus());
// Make sure it's properly indexed and returned for authorized users
SearchQuery q = new SearchQuery();
q.includeEpisodes(true);
q.includeSeries(false);
q.withId("10.0000/1");
assertEquals(1, service.getByQuery(q).size());
acl.getEntries().clear();
acl.getEntries().add(new AccessControlEntry("ROLE_UNKNOWN", READ.toString(), true));
acl.getEntries().add(new AccessControlEntry(ROLE_STUDENT, WRITE.toString(), true));
// Add the media package to the search index
job = service.add(mediaPackage);
barrier = new JobBarrier(null, serviceRegistry, 1000, job);
barrier.waitForJobs();
assertEquals("Job to add mediapckage did not finish", Job.Status.FINISHED, job.getStatus());
// This mediapackage should not be readable by the current user (due to the lack of role ROLE_UNKNOWN)
q = new SearchQuery();
q.includeEpisodes(true);
q.includeSeries(false);
q.withId("10.0000/1");
assertEquals(0, service.getByQuery(q).size());
}
use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.
the class SearchServiceImplTest method testSorting.
@Test
public void testSorting() throws Exception {
MediaPackage mediaPackageNewer = getMediaPackage("/manifest-full.xml");
MediaPackage mediaPackageOlder = getMediaPackage("/manifest-full-older.xml");
// MH-10573, ensure first job finishes publishing before job2
Job job = service.add(mediaPackageNewer);
JobBarrier barrier = new JobBarrier(null, serviceRegistry, 1000, job);
barrier.waitForJobs();
Job job2 = service.add(mediaPackageOlder);
JobBarrier barrier2 = new JobBarrier(null, serviceRegistry, 1000, job2);
barrier2.waitForJobs();
String olderTitle = "Older Recording";
String newerTitle = "Land and Vegetation: Key players on the Climate Scene";
SearchQuery query = new SearchQuery();
query.withSort(SearchQuery.Sort.DATE_CREATED);
assertEquals(2, service.getByQuery(query).size());
assertEquals(olderTitle, service.getByQuery(query).getItems()[0].getDcTitle());
query.withSort(SearchQuery.Sort.DATE_CREATED, false);
assertEquals(newerTitle, service.getByQuery(query).getItems()[0].getDcTitle());
// FYI: DATE_PUBLISHED is the time of Search update, not DC modified (MH-10573)
query.withSort(SearchQuery.Sort.DATE_PUBLISHED);
assertEquals(newerTitle, service.getByQuery(query).getItems()[0].getDcTitle());
query.withSort(SearchQuery.Sort.DATE_PUBLISHED, false);
assertEquals(olderTitle, service.getByQuery(query).getItems()[0].getDcTitle());
SearchQuery q = new SearchQuery();
q.withSort(SearchQuery.Sort.TITLE);
assertEquals(newerTitle, service.getByQuery(q).getItems()[0].getDcTitle());
query.withSort(SearchQuery.Sort.TITLE, false);
assertEquals(2, service.getByQuery(q).size());
assertEquals(olderTitle, service.getByQuery(query).getItems()[0].getDcTitle());
query.withSort(SearchQuery.Sort.LICENSE);
// Just checking that the search index works for this field
assertEquals(2, service.getByQuery(query).size());
query.withSort(SearchQuery.Sort.SERIES_ID);
// Just checking that the search index works for this field
assertEquals(2, service.getByQuery(query).size());
query.withSort(SearchQuery.Sort.MEDIA_PACKAGE_ID);
// Just checking that the search index works for this field
assertEquals(2, service.getByQuery(query).size());
query.withSort(SearchQuery.Sort.CONTRIBUTOR);
// Just checking that the search index works for this field
assertEquals(2, service.getByQuery(query).size());
query.withSort(SearchQuery.Sort.CREATOR);
// Just checking that the search index works for this field
assertEquals(2, service.getByQuery(query).size());
query.withSort(SearchQuery.Sort.LANGUAGE);
// Just checking that the search index works for this field
assertEquals(2, service.getByQuery(query).size());
query.withSort(SearchQuery.Sort.SUBJECT);
// Just checking that the search index works for this field
assertEquals(2, service.getByQuery(query).size());
}
use of org.opencastproject.job.api.JobBarrier in project opencast by opencast.
the class ServiceRegistryJpaImplTest method testIgnoreHostsInPriorityList.
@Test
public void testIgnoreHostsInPriorityList() 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();
Job testJob = serviceRegistryJpaImpl.createJob(TEST_HOST, TEST_SERVICE_2, TEST_OPERATION, null, null, true, null);
Job testJob2 = serviceRegistryJpaImpl.createJob(TEST_HOST, TEST_SERVICE, TEST_OPERATION, null, null, true, null);
serviceRegistryJpaImpl.dispatchPriorityList.put(testJob2.getId(), TEST_HOST);
JobBarrier barrier = new JobBarrier(null, serviceRegistryJpaImpl, testJob, testJob2);
try {
barrier.waitForJobs(2000);
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(StringUtils.isBlank(serviceRegistryJpaImpl.getJob(testJob.getId()).getProcessingHost()));
Assert.assertTrue(StringUtils.isNotBlank(serviceRegistryJpaImpl.getJob(testJob2.getId()).getProcessingHost()));
Assert.assertEquals(1, serviceRegistryJpaImpl.dispatchPriorityList.size());
String blockingHost = serviceRegistryJpaImpl.dispatchPriorityList.get(testJob2.getId());
Assert.assertEquals(TEST_HOST, blockingHost);
}
}
Aggregations