use of org.apache.sling.jobs.Job in project sling by apache.
the class InMemoryJobStorageTest method testRemove.
@Test
public void testRemove() throws Exception {
Job removed = jobStorage.remove(job);
assertNotNull(removed);
assertEquals(job.getId(), removed.getId());
assertNull(jobStorage.get(jobId));
}
use of org.apache.sling.jobs.Job in project sling by apache.
the class JobManagerTestComponent method activate.
@Activate
public void activate(Map<String, Object> props) {
for (int i = 0; i < 10; i++) {
Job job = jobManager.newJobBuilder(Types.jobQueue(TOPIC), Types.jobType(AsyncJobConsumer.JOB_TYPE)).addProperties(Collections.singletonMap("jobtest", (Object) "jobtest")).add();
assertNotNull(job);
LOGGER.info("Started Job {} ", job.getId());
}
// then start 10 sync jobs.
for (int i = 0; i < 10; i++) {
Job job = jobManager.newJobBuilder(Types.jobQueue(TOPIC), Types.jobType(FullySyncJob.JOB_TYPE)).addProperties(Collections.singletonMap("jobtest", (Object) "jobtest")).add();
assertNotNull(job);
LOGGER.info("Started Job {} ", job.getId());
}
}
use of org.apache.sling.jobs.Job in project sling by apache.
the class InMemoryJobStorage method remove.
@Nullable
@Override
public Job remove(@Nonnull String jobId) {
check();
Job j = store.get(jobId);
store.remove(jobId);
return j;
}
use of org.apache.sling.jobs.Job in project sling by apache.
the class JobBuilderImplTest method testAddJob.
@Test
public void testAddJob() {
long start = System.currentTimeMillis();
Map<String, Object> testMap = new HashMap<String, Object>();
testMap.put("job.name", "Jobname");
Job queuedJob = new JobBuilderImpl(jobStarter, Types.jobQueue("testtopic"), Types.jobType("testtype")).addProperties(testMap).add();
assertEquals(1, queue.size());
Job fromQueue = queue.remove();
assertEquals(queuedJob, fromQueue);
assertEquals(Types.jobQueue("testtopic"), fromQueue.getQueue());
assertEquals("Jobname", fromQueue.getProperties().get("job.name"));
assertNotNull(fromQueue.getId());
long now = System.currentTimeMillis();
assertTrue(fromQueue.getCreated() >= start);
assertTrue(fromQueue.getCreated() <= now);
assertEquals(Job.JobState.CREATED, fromQueue.getJobState());
assertNull(fromQueue.getController());
fromQueue.setJobController(jobController);
assertEquals(jobController, fromQueue.getController());
fromQueue.removeJobController();
assertNull(fromQueue.getController());
assertEquals("", fromQueue.getResultMessage());
assertEquals(0, fromQueue.getFinished());
assertEquals(0, fromQueue.getStarted());
assertEquals(0, fromQueue.getNumberOfRetries());
assertEquals(0, fromQueue.getRetryCount());
}
use of org.apache.sling.jobs.Job in project sling by apache.
the class ManagerSubscriberTest method test.
@Test
public void test() {
// fake up a remote send.
Map<String, Object> properties = new HashMap<String, Object>();
String testId = "testGetJobById" + System.currentTimeMillis();
properties.put("testid", testId);
properties.put("job.name", "Jobname");
String jobId = Utils.generateId();
Job job = new JobImpl(Types.jobQueue("testtopic"), jobId, Types.jobType("testtype"), properties);
JobUpdateImpl jobUpdate = new JobUpdateImpl(job, JobUpdate.JobUpdateCommand.START_JOB, job.getProperties());
Map<String, Object> message = Utils.toMapValue(jobUpdate);
// pump the topic message into the managerSubscriber and check that the job can be found.
managerSubscriber.onMessage(org.apache.sling.mom.Types.topicName("testtopic"), message);
Job searchedJob = jobManager.getJobById(jobId);
assertNotNull(searchedJob);
assertEquals(job.getId(), searchedJob.getId());
assertEquals(testId, searchedJob.getProperties().get("testid"));
}
Aggregations