use of org.opencastproject.job.api.Job in project opencast by opencast.
the class JobTest method testCountPerHostService.
@Test
public void testCountPerHostService() throws Exception {
// create some test data
testGetHostsCount();
// Add an additional dispatchable job. This is important as it leaves the processing host field empty.
Job localRunning1 = serviceRegistry.createJob(JOB_TYPE_2, OPERATION_NAME, null, null, true);
localRunning1.setStatus(Status.RUNNING);
localRunning1 = serviceRegistry.updateJob(localRunning1);
//
final Monadics.ListMonadic<String> jpql = resultToString(new Function.X<EntityManager, List<Object[]>>() {
@Override
public List<Object[]> xapply(EntityManager em) throws Exception {
return serviceRegistry.getCountPerHostService(em);
}
});
assertTrue(jpql.exists(eq("http://remotehost:8080,testing1,2,1")));
// <-- 2 jobs, one of them is the
assertTrue(jpql.exists(eq("http://localhost:8080,testing2,2,2")));
// dispatchable job
assertTrue(jpql.exists(eq("http://remotehost:8080,testing1,3,1")));
assertTrue(jpql.exists(eq("http://localhost:8080,testing2,3,1")));
assertTrue(jpql.exists(eq("http://localhost:8080,testing1,3,1")));
assertTrue(jpql.exists(eq("http://localhost:8080,testing1,2,2")));
assertEquals(6, jpql.value().size());
}
use of org.opencastproject.job.api.Job in project opencast by opencast.
the class JobTest method testMarshallingWithJsonPayload.
@Test
public void testMarshallingWithJsonPayload() throws Exception {
final String payload = "{'foo' : 'bar'}";
Job job = new JobImpl();
job.setPayload(payload);
String marshalledJob = JobParser.toXml(new JaxbJob(job));
Job unmarshalledJob = JobParser.parseJob(marshalledJob);
assertEquals("json from unmarshalled job should remain unchanged", StringUtils.trim(payload), StringUtils.trim(unmarshalledJob.getPayload()));
}
use of org.opencastproject.job.api.Job in project opencast by opencast.
the class JobTest method testGetActiveJobs.
@Test
public void testGetActiveJobs() throws Exception {
Job job = serviceRegistry.createJob(LOCALHOST, JOB_TYPE_1, OPERATION_NAME, null, null, false, null);
job.setStatus(Status.RUNNING);
job = serviceRegistry.updateJob(job);
job = serviceRegistry.createJob(LOCALHOST, JOB_TYPE_2, OPERATION_NAME, null, null, false, null);
job.setStatus(Status.RUNNING);
job = serviceRegistry.updateJob(job);
// Search using both the job type and status
List<Job> jobs = serviceRegistry.getActiveJobs();
assertEquals(2, jobs.size());
long jobId = jobs.get(0).getId();
for (Status status : Status.values()) {
job = serviceRegistry.getJob(jobId);
job.setStatus(status);
serviceRegistry.updateJob(job);
jobs = serviceRegistry.getActiveJobs();
if (status.isActive())
assertEquals(2, jobs.size());
else
assertEquals(1, jobs.size());
}
}
use of org.opencastproject.job.api.Job in project opencast by opencast.
the class JobTest method testVersionIncrements.
@Test
public void testVersionIncrements() throws Exception {
Job job = serviceRegistry.createJob(JOB_TYPE_1, "some_operation", null, null, false);
assertEquals("Newly created jobs should have a version of 1", 1, job.getVersion());
job = serviceRegistry.getJob(job.getId());
job.setPayload("update1");
job = serviceRegistry.updateJob(job);
job = serviceRegistry.getJob(job.getId());
assertEquals("Updated job should have a version of 2", 2, job.getVersion());
job = serviceRegistry.getJob(job.getId());
job.setPayload("update2");
job = serviceRegistry.updateJob(job);
job = serviceRegistry.getJob(job.getId());
assertEquals("Updated job should have a version of 3", 3, job.getVersion());
}
use of org.opencastproject.job.api.Job in project opencast by opencast.
the class ServiceRegistrationTest method testScenarioOneJobManyServices.
@Test
public void testScenarioOneJobManyServices() throws Exception {
Job jobTry1 = serviceRegistry.createJob(regType1Localhost.getHost(), regType1Localhost.getServiceType(), OPERATION_NAME_1, null, null, true, null);
Job jobTry2 = serviceRegistry.createJob(regType1Localhost.getHost(), regType1Localhost.getServiceType(), OPERATION_NAME_1, null, null, true, null);
Job jobTry3 = serviceRegistry.createJob(regType1Localhost.getHost(), regType1Localhost.getServiceType(), OPERATION_NAME_1, null, null, true, null);
Job jobTry4 = serviceRegistry.createJob(regType1Localhost.getHost(), regType1Localhost.getServiceType(), OPERATION_NAME_1, null, null, true, null);
ServiceRegistrationJpaImpl updatedService1;
ServiceRegistrationJpaImpl updatedService2;
ServiceRegistrationJpaImpl updatedService3;
// 1st try, failed on localhost
jobTry1.setStatus(Status.FAILED);
jobTry1.setJobType(regType1Localhost.getServiceType());
jobTry1.setProcessingHost(regType1Localhost.getHost());
jobTry1 = serviceRegistry.updateJob(jobTry1);
updatedService1 = (ServiceRegistrationJpaImpl) serviceRegistry.getServiceRegistration(JOB_TYPE_1, regType1Localhost.getHost());
Assert.assertEquals(ServiceState.WARNING, updatedService1.getServiceState());
Assert.assertEquals(0, updatedService1.getErrorStateTrigger());
// 2nd try, failed on remotehost1
jobTry2.setStatus(Status.FAILED);
jobTry2.setJobType(regType1Remotehost1.getServiceType());
jobTry2.setProcessingHost(regType1Remotehost1.getHost());
jobTry2 = serviceRegistry.updateJob(jobTry2);
updatedService1 = getUpdatedService(regType1Localhost);
updatedService2 = getUpdatedService(regType1Remotehost1);
Assert.assertEquals(ServiceState.NORMAL, updatedService1.getServiceState());
Assert.assertEquals(ServiceState.NORMAL, updatedService2.getServiceState());
Assert.assertEquals(0, updatedService2.getWarningStateTrigger());
Assert.assertEquals(0, updatedService2.getErrorStateTrigger());
// 3rd try, failed on remotehost2
jobTry3.setStatus(Status.FAILED);
jobTry3.setJobType(regType1Remotehost2.getServiceType());
jobTry3.setProcessingHost(regType1Remotehost2.getHost());
jobTry3 = serviceRegistry.updateJob(jobTry3);
updatedService1 = getUpdatedService(regType1Localhost);
updatedService2 = getUpdatedService(regType1Remotehost1);
updatedService3 = getUpdatedService(regType1Remotehost2);
Assert.assertEquals(ServiceState.NORMAL, updatedService1.getServiceState());
Assert.assertEquals(ServiceState.NORMAL, updatedService2.getServiceState());
Assert.assertEquals(ServiceState.WARNING, updatedService3.getServiceState());
Assert.assertEquals(0, updatedService2.getErrorStateTrigger());
// 4th try, finished on localhost
jobTry4.setStatus(Status.FINISHED);
jobTry4.setJobType(regType1Localhost.getServiceType());
jobTry4.setProcessingHost(regType1Localhost.getHost());
jobTry4 = serviceRegistry.updateJob(jobTry4);
updatedService1 = getUpdatedService(regType1Localhost);
updatedService2 = getUpdatedService(regType1Remotehost1);
updatedService3 = getUpdatedService(regType1Remotehost2);
Assert.assertEquals(ServiceState.NORMAL, updatedService1.getServiceState());
Assert.assertEquals(ServiceState.NORMAL, updatedService2.getServiceState());
Assert.assertEquals(ServiceState.ERROR, updatedService3.getServiceState());
}
Aggregations